Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] upgrade hapi #571

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/database/sthDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration.js');
const sthUtils = require(ROOT_PATH + '/lib/utils/sthUtils.js');
const sthDatabaseNaming = require(ROOT_PATH + '/lib/database/model/sthDatabaseNaming');
const mongoClient = require('mongodb').MongoClient;
const boom = require('boom');
const boom = require('@hapi/boom');
const jsoncsv = require('json-csv');
const fs = require('fs');
const path = require('path');
Expand Down
241 changes: 179 additions & 62 deletions lib/server/handlers/sthGetDataHandler.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions lib/server/handlers/sthGetDataHandlerV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ function getDataHandler(request, reply) {
*/
function replyHandler(payload) {
if (payload.isBoom) {
return reply({
error: payload.output.payload.error.replace(/ /, ''),
description: payload.output.payload.message
}).code(payload.output.payload.statusCode);
return reply
.response({
error: payload.output.payload.error.replace(/ /, ''),
description: payload.output.payload.message
})
.code(payload.output.payload.statusCode);
}
return reply(payload);
return reply.response(payload);
}

request.params.entityType = request.query.type;
request.params.version = 2;

sthGetDataHandlerV1(request, replyHandler);
return sthGetDataHandlerV1(request, null, replyHandler);
}

module.exports = getDataHandler;
3 changes: 2 additions & 1 deletion lib/server/handlers/sthGetLogLevelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ function getLogLevelHandler(request, reply) {

sthLogger.info(request.sth.context, 'Responding with logging level: ' + level);

const response = reply(getLogLevelResponse(level));
const response = reply.response(getLogLevelResponse(level));
sthServerUtils.addFiwareCorrelator(request, response);
return response;
}

module.exports = getLogLevelHandler;
2 changes: 1 addition & 1 deletion lib/server/handlers/sthGetVersionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sthUtils = require(ROOT_PATH + '/lib/utils/sthUtils');
*/
function getVersionHandler(request, reply) {
const message = sthUtils.getVersion();
return reply(message);
return reply.response(message);
}

module.exports = getVersionHandler;
5 changes: 3 additions & 2 deletions lib/server/handlers/sthNotFoundHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ function notFoundHandler(request, reply) {
'404 - Not Found route for the request: ' + request.method.toUpperCase() + ' ' + request.url.path
);
if (request.path.startsWith('/STH/v2')) {
response = reply({ error: 'NotFound', description: 'invalid path' }).code(404);
response = reply.response({ error: 'NotFound', description: 'invalid path' }).code(404);
} else {
response = reply({ statusCode: 404, error: 'Not Found' }).code(404);
response = reply.response({ statusCode: 404, error: 'Not Found' }).code(404);
}
sthServerUtils.addFiwareCorrelator(request, response);
return response;
}

module.exports = notFoundHandler;
16 changes: 8 additions & 8 deletions lib/server/handlers/sthNotificationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sthLogger = require('logops');
const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration');
const sthServerUtils = require(ROOT_PATH + '/lib/server/utils/sthServerUtils');
const sthDatabase = require(ROOT_PATH + '/lib/database/sthDatabase');
const boom = require('boom');
const boom = require('@hapi/boom');

/**
* Returns the total number of attributes to be processed
Expand Down Expand Up @@ -163,7 +163,7 @@ function storeRawData(data, reply, callback) {
// There was an error when getting the collection
sthLogger.error(request.sth.context, 'Error when getting the raw data collection for storing:' + err);
if (++counterObj.counter === totalTasks) {
response = reply(err);
response = reply.response(err);
sthServerUtils.addFiwareCorrelator(request, response);
}
process.nextTick(callback.bind(null, err));
Expand Down Expand Up @@ -195,7 +195,7 @@ function storeRawData(data, reply, callback) {
sthLogger.debug(request.sth.context, 'Raw data successfully stored');
}
if (++counterObj.counter === totalTasks) {
response = reply(err);
response = reply.response(err);
sthServerUtils.addFiwareCorrelator(request, response);
}
process.nextTick(callback.bind(null, err));
Expand Down Expand Up @@ -255,7 +255,7 @@ function storeAggregatedData(data, reply) {
// There was an error when getting the collection
sthLogger.error(request.sth.context, 'Error when getting the aggregated data collection for storing');
if (++counterObj.counter === totalTasks) {
response = reply(err);
response = reply.response(err);
sthServerUtils.addFiwareCorrelator(request, response);
}
} else {
Expand All @@ -282,7 +282,7 @@ function storeAggregatedData(data, reply) {
sthLogger.debug(request.sth.context, 'Aggregated data successfully stored');
}
if (++counterObj.counter === totalTasks) {
response = reply(err);
response = reply.response(err);
sthServerUtils.addFiwareCorrelator(request, response);
}
}
Expand Down Expand Up @@ -334,13 +334,13 @@ function processAttribute(data, reply) {
err = null;
}
if (++data.counterObj.counter === data.totalTasks) {
reply(err);
reply.response(err);
}
} else if (isAggregatableValue) {
// Store the aggregated data into the database
storeAggregatedData(data, reply);
} else if (++data.counterObj.counter === data.totalTasks) {
reply();
reply.response();
}
});
} else {
Expand Down Expand Up @@ -390,7 +390,7 @@ function processNotification(recvTime, request, reply) {
);
const error = boom.badRequest(message);
error.output.payload.validation = { source: 'payload', keys: ['attributes'] };
return reply(error);
return reply.response(error);
}

for (let i = 0; i < contextResponses.length; i++) {
Expand Down
10 changes: 5 additions & 5 deletions lib/server/handlers/sthRemoveDataHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const sthLogger = require('logops');
const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration');
const sthServerUtils = require(ROOT_PATH + '/lib/server/utils/sthServerUtils');
const sthDatabase = require(ROOT_PATH + '/lib/database/sthDatabase');
const boom = require('boom');
const boom = require('@hapi/boom');

/**
* Returns a textual description of the received request and the data included in it
Expand Down Expand Up @@ -74,7 +74,7 @@ function removeDataHandler(request, reply) {
sthLogger.debug(request.sth.context, 'Responding with 500- Internal error');
const error = boom.internal(message);
error.output.payload.message = message;
reply(error);
reply.response(error);
} else if (
err.name === 'MongoError' &&
err.message.includes('does not exist. Currently in strict mode')
Expand All @@ -85,19 +85,19 @@ function removeDataHandler(request, reply) {
'No data associated to the provided ' + getRequestDescription(request) + ' available'
);
// Reply with no error
response = reply();
response = reply.response();
response.code(204);
} else {
sthLogger.warn(request.sth.context, 'Error when removing the data associated to an entity: ' + err);
// Reply with error
response = reply(err);
response = reply.response(err);
}
} else {
sthLogger.debug(
request.sth.context,
'Data associated to the provided ' + getRequestDescription(request) + ' successfully removed'
);
response = reply();
response = reply.response();
response.code(204);
}
sthServerUtils.addFiwareCorrelator(request, response);
Expand Down
3 changes: 2 additions & 1 deletion lib/server/handlers/sthSetLogLevelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ function setLogLevelHandler(request, reply) {

sthLogger.info(request.sth.context, 'Log level set to: ' + level);

const response = reply();
const response = reply.response();
sthServerUtils.addFiwareCorrelator(request, response);
return response;
}

module.exports = setLogLevelHandler;
Loading
Loading