Skip to content
Merged
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
16 changes: 8 additions & 8 deletions src/cli/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Diagnostics extends BaseCLIHandler {
group: [constants.CMD_STRACE_UPDATE]
},
{
name: 'microservice-id', alias: 'i', type: String, description: 'Microservice ID',
name: 'microservice-uuid', alias: 'i', type: String, description: 'Microservice UUID',
group: [constants.CMD_STRACE_UPDATE, constants.CMD_STRACE_INFO, constants.CMD_STRACE_FTP_POST,
constants.CMD_IMAGE_SNAPSHOT_CREATE, constants.CMD_IMAGE_SNAPSHOT_GET]
},
Expand Down Expand Up @@ -128,38 +128,38 @@ const _executeCase = async function (diagnosticCommand, commandName, f, isUserRe
const _changeMicroserviceStraceState = async function (obj) {
logger.info(JSON.stringify(obj));

const enable = AppHelper.validateBooleanCliOptions(obj.enable, obj.disable);
await DiagnosticService.changeMicroserviceStraceState(obj.microserviceId, {enable: enable}, {}, true);
const msg = enable ? 'Microservice strace has been enabled' : 'Microservice strace has been disabled';
const isEnable = AppHelper.validateBooleanCliOptions(obj.enable, obj.disable);
await DiagnosticService.changeMicroserviceStraceState(obj.microserviceUuid, {enable: isEnable}, {}, true);
const msg = isEnable ? 'Microservice strace has been enabled' : 'Microservice strace has been disabled';
logger.info(msg);
};

const _getMicroserviceStraceData = async function (obj) {
logger.info(JSON.stringify(obj));

const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceId, {format: obj.format}, {}, true);
const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceUuid, {format: obj.format}, {}, true);
logger.info(JSON.stringify(result, null, 2));
logger.info('Microservice strace data has been retrieved successfully.');
};

const _postMicroserviceStraceDataToFtp = async function (obj) {
logger.info(JSON.stringify(obj));

await DiagnosticService.postMicroserviceStraceDatatoFtp(obj.microserviceId, obj, {}, true);
await DiagnosticService.postMicroserviceStraceDatatoFtp(obj.microserviceUuid, obj, {}, true);
logger.info('Strace data has been posted to ftp successfully.');
};

const _postMicroserviceImageSnapshotCreate = async function (obj) {
logger.info(JSON.stringify(obj));

await DiagnosticService.postMicroserviceImageSnapshotCreate(obj.microserviceId, {}, true);
await DiagnosticService.postMicroserviceImageSnapshotCreate(obj.microserviceUuid, {}, true);
logger.info('Microservice image snapshot has been created successfully.');
};

const _getMicroserviceImageSnapshot = async function (obj) {
logger.info(JSON.stringify(obj));

const filePath = await DiagnosticService.getMicroserviceImageSnapshot(obj.microserviceId, {}, true);
const filePath = await DiagnosticService.getMicroserviceImageSnapshot(obj.microserviceUuid, {}, true);
logger.info('Microservice images path = ' + filePath);
};

Expand Down
24 changes: 11 additions & 13 deletions src/controllers/diagnostic-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,36 @@ const AuthDecorator = require('./../decorators/authorization-decorator');

const changeMicroserviceStraceStateEndPoint = async function (req, user) {
logger.info("Parameters: " + JSON.stringify(req.body));
logger.info("Microservice id: " + req.params.id);
return await DiagnosticService.changeMicroserviceStraceState(req.params.id, req.body, user, false);
logger.info("Microservice UUID: " + req.params.uuid);
return await DiagnosticService.changeMicroserviceStraceState(req.params.uuid, req.body, user, false);
};

const getMicroserviceStraceDataEndPoint = async function (req, user) {
logger.info("Parameters:" + JSON.stringify(req.query));
logger.info("Microservice id: " + req.params.id);
return await DiagnosticService.getMicroserviceStraceData(req.params.id, req.query, user, false);
logger.info("Microservice UUID: " + req.params.uuid);
return await DiagnosticService.getMicroserviceStraceData(req.params.uuid, req.query, user, false);
};

const postMicroserviceStraceDataToFtpEndPoint = async function (req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
logger.info("Microservice id: " + req.params.id);
return await DiagnosticService.postMicroserviceStraceDatatoFtp(req.params.id, req.body, user, false);
logger.info("Microservice UUID: " + req.params.uuid);
return await DiagnosticService.postMicroserviceStraceDatatoFtp(req.params.uuid, req.body, user, false);
};

const createMicroserviceImageSnapshotEndPoint = async function (req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
logger.info("Microservice id: " + req.params.id);
return await DiagnosticService.postMicroserviceImageSnapshotCreate(req.params.id, user, false);
logger.info("Microservice UUID: " + req.params.uuid);
return await DiagnosticService.postMicroserviceImageSnapshotCreate(req.params.uuid, user, false);
};

const getMicroserviceImageSnapshotEndPoint = async function (req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
logger.info("Microservice id: " + req.params.id);
return await DiagnosticService.getMicroserviceImageSnapshot(req.params.id, user, false);
logger.info("Microservice UUID: " + req.params.uuid);
return await DiagnosticService.getMicroserviceImageSnapshot(req.params.uuid, user, false);
};

module.exports = {
changeMicroserviceStraceStateEndPoint: AuthDecorator.checkAuthToken(changeMicroserviceStraceStateEndPoint),
getMicroserviceStraceDataEndPoint: AuthDecorator.checkAuthToken(getMicroserviceStraceDataEndPoint),
postMicroserviceStraceDataToFtpEndPoint: AuthDecorator.checkAuthToken(postMicroserviceStraceDataToFtpEndPoint),
createMicroserviceImageSnapshotEndPoint: AuthDecorator.checkAuthToken(createMicroserviceImageSnapshotEndPoint),
getMicroserviceImageSnapshotEndPoint: AuthDecorator.checkAuthToken(getMicroserviceImageSnapshotEndPoint),
getMicroserviceImageSnapshotEndPoint: AuthDecorator.checkAuthToken(getMicroserviceImageSnapshotEndPoint)
};
28 changes: 14 additions & 14 deletions src/controllers/flow-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,48 @@ const logger = require('../logger');
const AuthDecorator = require('./../decorators/authorization-decorator');
const FlowService = require('../services/flow-service');

const _createFlowEndPoint = async function (req, user) {
const createFlowEndPoint = async function (req, user) {
const flow = req.body;

logger.info("Parameters:" + JSON.stringify(flow));

return await FlowService.createFlow(flow, user, false)
};

const _getFlowsByUserEndPoint = async function (req, user) {
const getFlowsByUserEndPoint = async function (req, user) {
return await FlowService.getUserFlows(user, false)
};

const _getFlowEndPoint = async function (req, user) {
const getFlowEndPoint = async function (req, user) {
const flowId = req.params.id;

logger.info("Flow id:" + JSON.stringify(flowId))
logger.info("Flow id:" + JSON.stringify(flowId));

return await FlowService.getFlowWithTransaction(flowId, user, false)
};

const _updateFlowEndPoint = async function (req, user) {
const updateFlowEndPoint = async function (req, user) {
const flow = req.body;
const flowId = req.params.id;

logger.info("Parameters:" + JSON.stringify(flow))
logger.info("Flow id:" + JSON.stringify(flowId))
logger.info("Parameters:" + JSON.stringify(flow));
logger.info("Flow id:" + JSON.stringify(flowId));

return await FlowService.updateFlow(flow, flowId, user, false)
};

const _deleteFlowEndPoint = async function (req, user) {
const deleteFlowEndPoint = async function (req, user) {
const flowId = req.params.id;

logger.info("Flow id:" + JSON.stringify(flowId))
logger.info("Flow id:" + JSON.stringify(flowId));

return await FlowService.deleteFlow(flowId, user, false)
};

module.exports = {
createFlowEndPoint: AuthDecorator.checkAuthToken(_createFlowEndPoint),
getFlowsByUserEndPoint: AuthDecorator.checkAuthToken(_getFlowsByUserEndPoint),
getFlowEndPoint: AuthDecorator.checkAuthToken(_getFlowEndPoint),
updateFlowEndPoint: AuthDecorator.checkAuthToken(_updateFlowEndPoint),
deleteFlowEndPoint: AuthDecorator.checkAuthToken(_deleteFlowEndPoint)
createFlowEndPoint: AuthDecorator.checkAuthToken(createFlowEndPoint),
getFlowsByUserEndPoint: AuthDecorator.checkAuthToken(getFlowsByUserEndPoint),
getFlowEndPoint: AuthDecorator.checkAuthToken(getFlowEndPoint),
updateFlowEndPoint: AuthDecorator.checkAuthToken(updateFlowEndPoint),
deleteFlowEndPoint: AuthDecorator.checkAuthToken(deleteFlowEndPoint)
};
37 changes: 20 additions & 17 deletions src/controllers/iofog-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ async function updateFogEndPoint(req, user) {
}

async function deleteFogEndPoint(req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
const deleteFog = {};
deleteFog.uuid = req.params.uuid;
const deleteFog = {
uuid: req.params.uuid
};
return await FogService.deleteFog(deleteFog, user, false)
}

async function getFogEndPoint(req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
const getFog = {};
getFog.uuid = req.params.uuid;
const getFog = {
uuid: req.params.uuid
};

return await FogService.getFogWithTransaction(getFog, user, false)
}

Expand All @@ -50,24 +51,27 @@ async function getFogListEndPoint(req, user) {
}

async function generateProvisionKeyEndPoint(req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
const fog = {};
fog.uuid = req.params.uuid;
const fog = {
uuid: req.params.uuid
};

return await FogService.generateProvisioningKey(fog, user, false)
}

async function setFogVersionCommandEndPoint(req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
const fogVersionCommand = {};
fogVersionCommand.uuid = req.params.uuid;
fogVersionCommand.versionCommand = req.params.versionCommand;
const fogVersionCommand = {
uuid: req.params.uuid,
versionCommand: req.params.versionCommand
};

return await FogService.setFogVersionCommand(fogVersionCommand, user, false)
}

async function setFogRebootCommandEndPoint(req, user) {
logger.info("Parameters:" + JSON.stringify(req.body));
const fog = {};
fog.uuid = req.params.uuid;
const fog = {
uuid: req.params.uuid
};

return await FogService.setFogRebootCommand(fog, user, false)
}

Expand All @@ -81,7 +85,6 @@ async function getHalHardwareInfoEndPoint(req, user) {
return await FogService.getHalHardwareInfo(uuidObj, user, false);
}


async function getHalUsbInfoEndPoint(req, user) {
const uuidObj = {
uuid: req.params.uuid
Expand Down
1 change: 1 addition & 0 deletions src/helpers/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
INVALID_FOG_NODE_UUID: 'Invalid ioFog UUID {}',
INVALID_USER_EMAIL: 'Invalid user email',
INVALID_MICROSERVICE_UUID: "Invalid microservice UUID '{}'",
INVALID_MICROSERVICE_STRACE: "Strace data for this microservice not found",
INVALID_VOLUME_MAPPING_UUID: "Invalid volume mapping id '{}'",
ACTIVATION_CODE_NOT_FOUND: 'Activation code not found',
INVALID_OLD_PASSWORD: 'Old password is incorrect',
Expand Down
11 changes: 5 additions & 6 deletions src/routes/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ const constants = require('../helpers/constants');
const DiagnosticController = require('../controllers/diagnostic-controller');
const ResponseDecorator = require('../decorators/response-decorator');
const Errors = require('../helpers/errors');
const ErrorMessages = require('../helpers/error-messages');
const fs = require('fs');

module.exports = [
{
method: 'post',
path: '/api/v3/microservices/:id/image-snapshot',
path: '/api/v3/microservices/:uuid/image-snapshot',
middleware: async (req, res) => {

const successCode = constants.HTTP_CODE_CREATED;
Expand Down Expand Up @@ -49,7 +48,7 @@ module.exports = [
},
{
method: 'get',
path: '/api/v3/microservices/:id/image-snapshot',
path: '/api/v3/microservices/:uuid/image-snapshot',
middleware: async (req, res) => {
const successCode = constants.HTTP_CODE_SUCCESS;
const errorCodes = [
Expand Down Expand Up @@ -85,7 +84,7 @@ module.exports = [
},
{
method: 'patch',
path: '/api/v3/microservices/:id/strace',
path: '/api/v3/microservices/:uuid/strace',
middleware: async (req, res) => {

const successCode = constants.HTTP_CODE_NO_CONTENT;
Expand Down Expand Up @@ -118,7 +117,7 @@ module.exports = [
},
{
method: 'get',
path: '/api/v3/microservices/:id/strace',
path: '/api/v3/microservices/:uuid/strace',
middleware: async (req, res) => {

const successCode = constants.HTTP_CODE_SUCCESS;
Expand Down Expand Up @@ -147,7 +146,7 @@ module.exports = [
},
{
method: 'put',
path: '/api/v3/microservices/:id/strace',
path: '/api/v3/microservices/:uuid/strace',
middleware: async (req, res) => {
const successCode = constants.HTTP_CODE_NO_CONTENT;
const errorCodes = [
Expand Down
10 changes: 8 additions & 2 deletions src/schemas/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const registryCreate = {
"isPublic": {"type": "boolean"},
"username": {"type": "string", "minLength": 1},
"password": {"type": "string"},
"email": {"type": "string"},
"email": {
"type": "string",
"pattern": "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"
},
"requiresCert": {"type": "boolean"},
"certificate": {"type": "string"}
},
Expand All @@ -45,7 +48,10 @@ const registryUpdate = {
"isPublic": {"type": "boolean"},
"username": {"type": "string", "minLength": 1},
"password": {"type": "string"},
"email": {"type": "string"},
"email": {
"type": "string",
"pattern": "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"
},
"requiresCert": {"type": "boolean"},
"certificate": {"type": "string"}
},
Expand Down
16 changes: 13 additions & 3 deletions src/sequelize/managers/microservice-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const User = models.User;
const Routing = models.Routing;
const Registry = models.Registry;
const MicroserviceStatus = models.MicroserviceStatus;
const Op = require('sequelize').Op;

const microserviceExcludedFields = [
'configLastUpdated',
Expand Down Expand Up @@ -135,18 +136,27 @@ class MicroserviceManager extends BaseManager {
attributes: ['url']
}
],
attributes: ['picture']
attributes: ['picture', 'category']
},
{
model: Flow,
as: 'flow',
required: true,
required: false,
attributes: ['isActivated']
}
],
where: {
iofogUuid: iofogUuid,
'$flow.is_activated$': true
[Op.or]:
[
{
'$flow.is_activated$': true
},
{
'$catalogItem.category$': {[Op.eq]: 'SYSTEM'}
}
]

}
}, {transaction: transaction})
}
Expand Down
4 changes: 4 additions & 0 deletions src/services/diagnostic-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const getMicroserviceStraceData = async function (id, data, user, isCLI, transac
}

const straceData = await StraceDiagnosticManager.findOne({microserviceUuid: id}, transaction);
if (!straceData) {
throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_STRACE, id))
}

const dir = config.get('Diagnostics:DiagnosticDir') || 'diagnostics';
const filePath = dir + '/' + id;

Expand Down
Loading