From 5eda32867062d8a63ee8d329e7ecef08f552809e Mon Sep 17 00:00:00 2001 From: Pankov Date: Thu, 8 Nov 2018 18:17:50 +0300 Subject: [PATCH 01/10] volume mapping & delete with clean up --- specs/swagger.yml | 111 ++++++++++++++++++++ src/controllers/microservices-controller.js | 5 +- src/services/microservices-service.js | 6 +- 3 files changed, 116 insertions(+), 6 deletions(-) diff --git a/specs/swagger.yml b/specs/swagger.yml index 47dd9b939..90b4d10d6 100644 --- a/specs/swagger.yml +++ b/specs/swagger.yml @@ -1532,6 +1532,117 @@ paths: description: Not Found '500': description: Internal Server Error + '/microservices/{uuid}/volume-mapping': + post: + tags: + - Microservices + description: Creates a volume mapping for microservice + operationId: createMicroserviceVolumeMapping + parameters: + - in: header + name: Authorization + description: User Token + required: true + type: string + - in: path + name: uuid + description: Microservice Uuid + required: true + type: string + - in: body + name: volumeMappingData + description: information about volume mapping + required: true + schema: + $ref: '#/definitions/VolumeMappingAgentRequest' + responses: + '201': + description: Created + schema: + type: object + properties: + id: + type: number + headers: + X-Timestamp: + type: number + description: FogController server timestamp + '400': + description: Not Valid + '401': + description: Not Authorized + '404': + description: Not Found + '500': + description: Internal Server Error + get: + tags: + - Microservices + description: Get a volume mapping list for microservice + operationId: getMicroserviceVolumeMapping + parameters: + - in: header + name: Authorization + description: User Token + required: true + type: string + - in: path + name: uuid + description: Microservice Uuid + required: true + type: string + responses: + '200': + description: Success + schema: + type: array + items: + $ref: '#/definitions/VolumeMappingAgentRequest' + headers: + X-Timestamp: + type: number + description: FogController server timestamp + '401': + description: Not Authorized + '404': + description: Not Found + '500': + description: Internal Server Error + '/microservices/{uuid}/volume-mapping/{id}': + delete: + tags: + - Microservices + description: Deletes a volume mapping for microservice + operationId: deleteMicroserviceVolumeMapping + parameters: + - in: header + name: Authorization + description: User Token + required: true + type: string + - in: path + name: uuid + description: Microservice Uuid + required: true + type: string + - in: path + name: id + description: Volume id + required: true + type: string + responses: + '204': + description: Success + headers: + X-Timestamp: + type: number + description: FogController server timestamp + '401': + description: Not Authorized + '404': + description: Not Found + '500': + description: Internal Server Error '/microservices/{id}/image-snapshot': post: tags: diff --git a/src/controllers/microservices-controller.js b/src/controllers/microservices-controller.js index 65ae7e30d..e3fa6d73f 100644 --- a/src/controllers/microservices-controller.js +++ b/src/controllers/microservices-controller.js @@ -43,12 +43,11 @@ const _updateMicroserviceEndPoint = async function (req, user) { const _deleteMicroserviceEndPoint = async function (req, user) { const microserviceUuid = req.params.uuid; - const deleteWithCleanUp = (req.query.withCleanUp == 'true'); logger.info("Microservice uuid:" + JSON.stringify(microserviceUuid)); - logger.info("Delete with cleanup:" + JSON.stringify(deleteWithCleanUp)); + logger.info("Request body:" + JSON.stringify(req.body)); - return await MicroservicesService.deleteMicroserviceWithTransaction(microserviceUuid, deleteWithCleanUp, user, false) + return await MicroservicesService.deleteMicroserviceWithTransaction(microserviceUuid, req.body, user, false) }; const _getMicroservicesByFlowEndPoint = async function (req, user) { diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 830544eff..d7ed40fcd 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -231,7 +231,7 @@ const _deleteMicroservice = async function (microserviceUuid, deleteWithCleanUp, }, { delete: true, - deleteWithCleanUp: !!deleteWithCleanUp + deleteWithCleanUp: deleteWithCleanUp }, transaction); } @@ -241,14 +241,14 @@ const _deleteMicroservice = async function (microserviceUuid, deleteWithCleanUp, const _deleteNotRunningMicroservices = async function (transaction) { const microservices = await MicroserviceManager.findAllWithStatuses(transaction); microservices - .filter(microservice => !!microservice.delete) + .filter(microservice => microservice.delete) .filter(microservice => microservice.microserviceStatus.status === MicroserviceStates.NOT_RUNNING) .forEach(microservice => { MicroserviceManager.delete({ uuid: microservice.uuid }, transaction); }); -} +}; const _checkForDuplicateName = async function (name, item, userId, transaction) { if (name) { From f4b4540e9e772e65cb38d86f46de9164ede9f9d3 Mon Sep 17 00:00:00 2001 From: Pankov Date: Fri, 9 Nov 2018 17:44:06 +0300 Subject: [PATCH 02/10] volume mapping & delete with clean up --- specs/swagger.yml | 18 ++- src/cli/microservice.js | 107 ++++++++++++----- src/controllers/microservices-controller.js | 56 ++++++--- src/helpers/constants.js | 3 + src/helpers/error-messages.js | 3 + src/routes/microservices.js | 110 ++++++++++++++++-- src/schemas/microservice.js | 13 ++- .../managers/volume-mapping-manager.js | 14 ++- src/services/microservices-service.js | 83 +++++++++++-- 9 files changed, 338 insertions(+), 69 deletions(-) diff --git a/specs/swagger.yml b/specs/swagger.yml index 90b4d10d6..ae7ffb966 100644 --- a/specs/swagger.yml +++ b/specs/swagger.yml @@ -1334,11 +1334,15 @@ paths: description: Microservice Uuid required: true type: string - - in: query - name: withCleanUp - description: Delete with cleanup - required: true - type: boolean + - in: body + name: WithCleanupOption + description: Delete option + required: false + schema: + type: object + properties: + withCleanup: + type: boolean responses: '204': description: Success @@ -1346,6 +1350,8 @@ paths: X-Timestamp: type: number description: FogController server timestamp + '400': + description: Bad Request '401': description: Not Authorized '404': @@ -1637,6 +1643,8 @@ paths: X-Timestamp: type: number description: FogController server timestamp + '400': + description: Not Valid '401': description: Not Authorized '404': diff --git a/src/cli/microservice.js b/src/cli/microservice.js index d33e3cce3..288b6fafa 100644 --- a/src/cli/microservice.js +++ b/src/cli/microservice.js @@ -18,7 +18,6 @@ const logger = require('../logger'); const MicroserviceService = require('../services/microservices-service'); const fs = require('fs'); const AppHelper = require('../helpers/app-helper'); -const AuthDecorator = require('../decorators/cli-decorator'); const JSON_SCHEMA_ADD = AppHelper.stringifyCliJsonSchema( { @@ -81,7 +80,8 @@ class Microservice extends BaseCLIHandler { { name: 'microservice-id', alias: 'i', type: String, description: 'Microservice ID', group: [constants.CMD_UPDATE, constants.CMD_REMOVE, constants.CMD_INFO, constants.CMD_PORT_MAPPING_CREATE, - constants.CMD_PORT_MAPPING_REMOVE, constants.CMD_PORT_MAPPING_LIST] + constants.CMD_PORT_MAPPING_REMOVE, constants.CMD_PORT_MAPPING_LIST, constants.CMD_VOLUME_MAPPING_CREATE, + constants.CMD_VOLUME_MAPPING_REMOVE, constants.CMD_VOLUME_MAPPING_LIST] }, { name: 'name', alias: 'n', type: String, description: 'Microservice name', @@ -125,7 +125,7 @@ class Microservice extends BaseCLIHandler { }, { name: 'mapping', alias: 'P', type: String, description: 'Container port mapping', - group: [constants.CMD_PORT_MAPPING_CREATE] + group: [constants.CMD_PORT_MAPPING_CREATE, constants.CMD_VOLUME_MAPPING_CREATE] }, { name: 'routes', alias: 't', type: String, description: 'Microservice route(s) (receiving microservices)', multiple: true, @@ -144,12 +144,16 @@ class Microservice extends BaseCLIHandler { group: [constants.CMD_UPDATE] }, { - name: 'cleanUp', alias: 'z', type: Boolean, description: 'Delete microservice with cleanup', + name: 'cleanup', alias: 'z', type: Boolean, description: 'Delete microservice with cleanup', group: [constants.CMD_REMOVE] }, { name: 'user-id', alias: 'u', type: Number, description: 'User\'s id', group: [constants.CMD_ADD] + }, + { + name: 'mapping-id', alias: 'a', type: Number, description: 'Volume mapping id', + group: [constants.CMD_VOLUME_MAPPING_REMOVE] } ] this.commands = { @@ -162,7 +166,10 @@ class Microservice extends BaseCLIHandler { [constants.CMD_ROUTE_REMOVE]: 'Remove microservice route.', [constants.CMD_PORT_MAPPING_CREATE]: 'Create microservice port mapping.', [constants.CMD_PORT_MAPPING_REMOVE]: 'Remove microservice port mapping.', - [constants.CMD_PORT_MAPPING_LIST]: 'List microservice port mapping.' + [constants.CMD_PORT_MAPPING_LIST]: 'List microservice port mapping.', + [constants.CMD_VOLUME_MAPPING_CREATE]: 'Create microservice volume mapping.', + [constants.CMD_VOLUME_MAPPING_REMOVE]: 'Remove microservice volume mapping.', + [constants.CMD_VOLUME_MAPPING_LIST]: 'List microservice volume mapping.', } } @@ -200,6 +207,15 @@ class Microservice extends BaseCLIHandler { case constants.CMD_PORT_MAPPING_LIST: await _executeCase(microserviceCommand, constants.CMD_PORT_MAPPING_LIST, _listPortMappings); break; + case constants.CMD_VOLUME_MAPPING_CREATE: + await _executeCase(microserviceCommand, constants.CMD_VOLUME_MAPPING_CREATE, _createVolumeMapping); + break; + case constants.CMD_VOLUME_MAPPING_REMOVE: + await _executeCase(microserviceCommand, constants.CMD_VOLUME_MAPPING_REMOVE, _removeVolumeMapping); + break; + case constants.CMD_VOLUME_MAPPING_LIST: + await _executeCase(microserviceCommand, constants.CMD_VOLUME_MAPPING_LIST, _listVolumeMappings); + break; case constants.CMD_HELP: default: return this.help() @@ -227,11 +243,11 @@ class Microservice extends BaseCLIHandler { content: [ { desc: '1. Single mapping', - example: '$ iofog-controller microservice add [other required options] --volumes /host_src:/container_src', + example: '$ iofog-controller microservice add [other required options] --volumes /host_src:/container_src:rw', }, { desc: '2. Multiple mappings', - example: '$ iofog-controller microservice add [other required options] --volumes /host_src:/container_src /host_bin:/container_bin', + example: '$ iofog-controller microservice add [other required options] --volumes /host_src:/container_src:rw /host_bin:/container_bin:r', }, { desc: '3. Port mapping (80:8080:false - internal port : external port : public mode)', @@ -256,6 +272,14 @@ class Microservice extends BaseCLIHandler { { desc: '8. Delete port mapping (80 - internal port, ABC - microservice id)', example: '$ iofog-controller microservice port-mapping-remove --internal-port 80 -i ABC' + }, + { + desc: '9. Create volume mapping', + example: '$ iofog-controller microservice volume-mapping-create --mapping /host_src:/container_src:rw -i ABC' + }, + { + desc: '10. Delete volume mapping', + example: '$ iofog-controller microservice volume-mapping-remove -i ABC -a 1' } ], }, @@ -304,7 +328,15 @@ const _createPortMapping = async function (obj) { logger.info(JSON.stringify(obj)); const mapping = parsePortMappingObject(obj.mapping, ErrorMessages.CLI.INVALID_PORT_MAPPING); await MicroserviceService.createPortMappingWithTransaction(obj.microserviceId, mapping, {}, true); - logger.info('Port mapping has been create successfully'); + logger.info('Port mapping has been create successfully.'); +}; + +const _createVolumeMapping = async function (obj) { + logger.info(JSON.stringify(obj)); + const mapping = parseVolumeMappingObject(obj.mapping, ErrorMessages.CLI.INVALID_VOLUME_MAPPING); + const result = await MicroserviceService.createVolumeMapping(obj.microserviceId, mapping, {}, true); + logger.info(JSON.stringify(result, null, 2)); + logger.info('Volume mapping has been created successfully.') }; const _removePortMapping = async function (obj) { @@ -312,21 +344,37 @@ const _removePortMapping = async function (obj) { try { const internalPort = parseInt(obj.internalPort); await MicroserviceService.deletePortMappingWithTransaction(obj.microserviceId, internalPort, {}, true); - logger.info('Port mapping has been deleted successfully'); + logger.info('Port mapping has been deleted successfully.'); } catch(e) { logger.error(ErrorMessages.CLI.INVALID_INTERNAL_PORT); } }; +const _removeVolumeMapping = async function (obj) { + logger.info(JSON.stringify(obj)); + try { + await MicroserviceService.deleteVolumeMapping(obj.microserviceId, obj.mappingId, {}, true); + logger.info('Volume mapping has been deleted successfully.'); + } catch(e) { + logger.error(ErrorMessages.CLI.INVALID_VOLUME_MAPPING); + } +}; + const _listPortMappings = async function (obj) { - const result = await MicroserviceService.getMicroservicePortMappingListWithTransaction(obj.microserviceId, {}, true); + const result = await MicroserviceService.listMicroservicePortMappingsWithTransaction(obj.microserviceId, {}, true); logger.info(JSON.stringify(result)); - logger.info('Port mappings have been retrieved successfully'); + logger.info('Port mappings have been retrieved successfully.'); +}; + +const _listVolumeMappings = async function (obj) { + const result = await MicroserviceService.listVolumeMappings(obj.microserviceId, {}, true); + logger.info(JSON.stringify(result, null, 2)); + logger.info('Volume mappings have been retrieved successfully.'); }; const _removeMicroservice = async function (obj) { logger.info(JSON.stringify(obj)); - await MicroserviceService.deleteMicroserviceWithTransaction(obj.microserviceId, obj.cleanUp, {}, true); + await MicroserviceService.deleteMicroserviceWithTransaction(obj.microserviceId, obj.cleanup, {}, true); logger.info('Microservice has been removed successfully.') }; @@ -377,7 +425,7 @@ const _updateMicroserviceObject = function (obj) { }; if (obj.volumes) { - microserviceObj.volumeMappings = parseVolumes(obj.volumes, 'Error during parsing of volume mapping option.'); + microserviceObj.volumeMappings = parseVolumeMappingArray(obj.volumes, 'Error during parsing of volume mapping option.'); } return AppHelper.deleteUndefinedFields(microserviceObj); @@ -396,7 +444,7 @@ const _createMicroserviceObject = function (obj) { }; if (obj.volumes) { - microserviceObj.volumeMappings = parseVolumes(obj.volumes, ErrorMessages.CLI.INVALID_VOLUME_MAPPING); + microserviceObj.volumeMappings = parseVolumeMappingArray(obj.volumes, ErrorMessages.CLI.INVALID_VOLUME_MAPPING); } if (obj.ports) { microserviceObj.ports = parsePortMappingArray(obj.ports, ErrorMessages.CLI.INVALID_PORT_MAPPING); @@ -405,22 +453,23 @@ const _createMicroserviceObject = function (obj) { return AppHelper.deleteUndefinedFields(microserviceObj); }; - -const parseVolumes = function (arr, errMsg) { - return arr.map(item => { - let result = {}; - try { - const props = item.split(':'); - result = { - hostDestination: props[0], - containerDestination: props[1], - accessMode: props[2] - } - } catch(e) { - logger.warn(errMsg); +const parseVolumeMappingObject = function (obj, errMsg) { + let result = {}; + try { + const props = obj.split(':'); + result = { + hostDestination: props[0], + containerDestination: props[1], + accessMode: props[2] } - return result; - }) + } catch(e) { + logger.warn(errMsg); + } + return result; +}; + +const parseVolumeMappingArray = function (arr, errMsg) { + return arr.map(obj => parseVolumeMappingObject(obj, errMsg)); }; const parsePortMappingObject = function (obj, errMsg) { diff --git a/src/controllers/microservices-controller.js b/src/controllers/microservices-controller.js index e3fa6d73f..1f003d113 100644 --- a/src/controllers/microservices-controller.js +++ b/src/controllers/microservices-controller.js @@ -35,7 +35,7 @@ const _updateMicroserviceEndPoint = async function (req, user) { const microservice = req.body; const microserviceUuid = req.params.uuid; - logger.info("Parameters:" + JSON.stringify(microservice)); + logger.info("Parameters: " + JSON.stringify(microservice)); logger.info("Microservice uuid:" + JSON.stringify(microserviceUuid)); return await MicroservicesService.updateMicroserviceWithTransaction(microserviceUuid, microservice, user, false) @@ -43,11 +43,11 @@ const _updateMicroserviceEndPoint = async function (req, user) { const _deleteMicroserviceEndPoint = async function (req, user) { const microserviceUuid = req.params.uuid; - + const microserviceData = req.body || {}; logger.info("Microservice uuid:" + JSON.stringify(microserviceUuid)); - logger.info("Request body:" + JSON.stringify(req.body)); + logger.info("Parameters: " + JSON.stringify(microserviceData)); - return await MicroservicesService.deleteMicroserviceWithTransaction(microserviceUuid, req.body, user, false) + return await MicroservicesService.deleteMicroserviceWithTransaction(microserviceUuid, microserviceData, user, false) }; const _getMicroservicesByFlowEndPoint = async function (req, user) { @@ -58,42 +58,65 @@ const _getMicroservicesByFlowEndPoint = async function (req, user) { return await MicroservicesService.listMicroservicesWithTransaction(flowId, user, false) }; -async function _createMicroserviceRoute(req, user) { +const _createMicroserviceRouteEndPoint = async function (req, user) { const sourceUuid = req.params.uuid; const distUuid = req.params.receiverUuid; logger.info(`Creating route from ${sourceUuid} to ${distUuid}`); return await MicroservicesService.createRouteWithTransaction(sourceUuid, distUuid, user, false) } -async function _deleteMicroserviceRoute(req, user) { +const _deleteMicroserviceRouteEndPoint = async function (req, user) { const sourceUuid = req.params.uuid; const distUuid = req.params.receiverUuid; logger.info(`Creating route from ${sourceUuid} to ${distUuid}`); return await MicroservicesService.deleteRouteWithTransaction(sourceUuid, distUuid, user, false) } -async function _createMicroservicePortMapping(req, user) { +const _createMicroservicePortMappingEndPoint = async function (req, user) { const uuid = req.params.uuid; const portMappingData = req.body; logger.info(`Creating port mapping for ${uuid}`); return await MicroservicesService.createPortMappingWithTransaction(uuid, portMappingData, user, false) } -async function _deleteMicroservicePortMapping(req, user) { +const _deleteMicroservicePortMappingEndPoint = async function (req, user) { const uuid = req.params.uuid; const internalPort = req.params.internalPort; logger.info(`Deleting port mapping for ${uuid}`); return await MicroservicesService.deletePortMappingWithTransaction(uuid, internalPort, user, false) } -async function _getMicroservicePortMappingList(req, user) { +const _listMicroservicePortMappingsEndPoint = async function (req, user) { const uuid = req.params.uuid; logger.info(`Getting all port mappings for ${uuid}`); const ports = await MicroservicesService.getMicroservicePortMappingListWithTransaction(uuid, user, false); return { ports: ports } -} +}; + +const _createMicroserviceVolumeMappingEndPoint = async function (req, user) { + const microserviceUuid = req.params.uuid; + const volumeMappingData = req.body; + logger.info(`Creating volume mapping for ${microserviceUuid}`); + const volumeMapping = await MicroservicesService.createVolumeMapping(microserviceUuid, volumeMappingData, user, false); + return { + id: volumeMapping.id + } +}; + +const _listMicroserviceVolumeMappingsEndPoint = async function (req, user) { + const uuid = req.params.uuid; + logger.info(`Getting all volume mappings for ${uuid}`); + return await MicroservicesService.listVolumeMappings(uuid, user, false); +}; + +const _deleteMicroserviceVolumeMappingEndPoint = async function (req, user) { + const uuid = req.params.uuid; + const id = req.params.id; + logger.info(`Deleting volume mapping ${id} for ${uuid}`); + return await MicroservicesService.deleteVolumeMapping(uuid, id, user, false); +}; module.exports = { createMicroservicesOnFogEndPoint: AuthDecorator.checkAuthToken(_createMicroservicesOnFogEndPoint), @@ -101,9 +124,12 @@ module.exports = { updateMicroserviceEndPoint: AuthDecorator.checkAuthToken(_updateMicroserviceEndPoint), deleteMicroserviceEndPoint: AuthDecorator.checkAuthToken(_deleteMicroserviceEndPoint), getMicroservicesByFlowEndPoint: AuthDecorator.checkAuthToken(_getMicroservicesByFlowEndPoint), - createMicroserviceRoute: AuthDecorator.checkAuthToken(_createMicroserviceRoute), - deleteMicroserviceRoute: AuthDecorator.checkAuthToken(_deleteMicroserviceRoute), - createMicroservicePortMapping: AuthDecorator.checkAuthToken(_createMicroservicePortMapping), - deleteMicroservicePortMapping: AuthDecorator.checkAuthToken(_deleteMicroservicePortMapping), - getMicroservicePortMappingList: AuthDecorator.checkAuthToken(_getMicroservicePortMappingList) + createMicroserviceRouteEndPoint: AuthDecorator.checkAuthToken(_createMicroserviceRouteEndPoint), + deleteMicroserviceRouteEndPoint: AuthDecorator.checkAuthToken(_deleteMicroserviceRouteEndPoint), + createMicroservicePortMappingEndPoint: AuthDecorator.checkAuthToken(_createMicroservicePortMappingEndPoint), + deleteMicroservicePortMappingEndPoint: AuthDecorator.checkAuthToken(_deleteMicroservicePortMappingEndPoint), + getMicroservicePortMappingListEndPoint: AuthDecorator.checkAuthToken(_listMicroservicePortMappingsEndPoint), + createMicroserviceVolumeMappingEndPoint: AuthDecorator.checkAuthToken(_createMicroserviceVolumeMappingEndPoint), + listMicroserviceVolumeMappingsEndPoint: AuthDecorator.checkAuthToken(_listMicroserviceVolumeMappingsEndPoint), + deleteMicroserviceVolumeMappingEndPoint: AuthDecorator.checkAuthToken(_deleteMicroserviceVolumeMappingEndPoint) }; \ No newline at end of file diff --git a/src/helpers/constants.js b/src/helpers/constants.js index 3e7eee6d1..17a98d9a4 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -41,6 +41,9 @@ module.exports = { CMD_PORT_MAPPING_CREATE: 'port-mapping-create', CMD_PORT_MAPPING_REMOVE: 'port-mapping-remove', CMD_PORT_MAPPING_LIST: 'port-mapping-list', + CMD_VOLUME_MAPPING_CREATE: 'volume-mapping-create', + CMD_VOLUME_MAPPING_REMOVE: 'volume-mapping-remove', + CMD_VOLUME_MAPPING_LIST: 'volume-mapping-list', CMD_REGISTRY: 'registry', CMD_ACTIVATE: 'activate', CMD_SUSPEND: 'suspend', diff --git a/src/helpers/error-messages.js b/src/helpers/error-messages.js index c7cc1317c..989907761 100644 --- a/src/helpers/error-messages.js +++ b/src/helpers/error-messages.js @@ -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_VOLUME_MAPPING_UUID: "Invalid volume mapping id '{}'", ACTIVATION_CODE_NOT_FOUND: 'Activation code not found', INVALID_OLD_PASSWORD: 'Old password is incorrect', ACCOUNT_NOT_FOUND: 'Account not found', @@ -52,6 +53,8 @@ module.exports = { FILE_DOES_NOT_EXIST: 'File does not exist.', RESTRICTED_PUBLISHER: "You are not allowed to add catalog item as 'Eclipse ioFog' publisher", REQUIRED_FOG_NODE: 'ioFog node is required.', + PORT_MAPPING_ALREADY_EXISTS: 'Port mapping already exists', + VOLUME_MAPPING_ALREADY_EXISTS: 'Volume mapping already exists', INVALID_CONNECTOR_DOMAIN: 'Invalid connector domain {}', CERT_PROPERTY_REQUIRED: 'Property "certificate" is required if property "requiresCert" is set to true', TUNNEL_NOT_FOUND: 'Tunnel not found', diff --git a/src/routes/microservices.js b/src/routes/microservices.js index 122c0ef30..65c8e3093 100644 --- a/src/routes/microservices.js +++ b/src/routes/microservices.js @@ -162,8 +162,8 @@ module.exports = [ } ]; - const createMicroserviceRoute = ResponseDecorator.handleErrors(MicroservicesController.createMicroserviceRoute, successCode, errorCodes); - const responseObject = await createMicroserviceRoute(req); + const createMicroserviceRouteEndPoint = ResponseDecorator.handleErrors(MicroservicesController.createMicroserviceRouteEndPoint, successCode, errorCodes); + const responseObject = await createMicroserviceRouteEndPoint(req); res .status(responseObject.code) @@ -190,8 +190,8 @@ module.exports = [ } ]; - const deleteMicroserviceRoute = ResponseDecorator.handleErrors(MicroservicesController.deleteMicroserviceRoute, successCode, errorCodes); - const responseObject = await deleteMicroserviceRoute(req); + const deleteMicroserviceRouteEndPoint = ResponseDecorator.handleErrors(MicroservicesController.deleteMicroserviceRouteEndPoint, successCode, errorCodes); + const responseObject = await deleteMicroserviceRouteEndPoint(req); res .status(responseObject.code) @@ -218,8 +218,8 @@ module.exports = [ } ]; - const createMicroservicePortMapping = ResponseDecorator.handleErrors(MicroservicesController.createMicroservicePortMapping, successCode, errorCodes); - const responseObject = await createMicroservicePortMapping(req); + const createMicroservicePortMappingEndPoint = ResponseDecorator.handleErrors(MicroservicesController.createMicroservicePortMappingEndPoint, successCode, errorCodes); + const responseObject = await createMicroservicePortMappingEndPoint(req); res .status(responseObject.code) @@ -242,7 +242,7 @@ module.exports = [ } ]; - const deleteMicroservicePortMapping = ResponseDecorator.handleErrors(MicroservicesController.deleteMicroservicePortMapping, successCode, errorCodes); + const deleteMicroservicePortMapping = ResponseDecorator.handleErrors(MicroservicesController.deleteMicroservicePortMappingEndPoint, successCode, errorCodes); const responseObject = await deleteMicroservicePortMapping(req); res @@ -266,7 +266,7 @@ module.exports = [ } ]; - const getMicroservicePortMapping = ResponseDecorator.handleErrors(MicroservicesController.getMicroservicePortMappingList, successCode, errorCodes); + const getMicroservicePortMapping = ResponseDecorator.handleErrors(MicroservicesController.getMicroservicePortMappingListEndPoint, successCode, errorCodes); const responseObject = await getMicroservicePortMapping(req); res @@ -274,4 +274,96 @@ module.exports = [ .send(responseObject.body) }, }, -] + { + method: 'get', + path: '/api/v3/microservices/:uuid/volume-mapping', + middleware: async (req, res) => { + const successCode = constants.HTTP_CODE_SUCCESS; + const errorCodes = [ + { + code: constants.HTTP_CODE_UNAUTHORIZED, + errors: [Errors.AuthenticationError] + }, + { + code: constants.HTTP_CODE_NOT_FOUND, + errors: [Errors.NotFoundError] + } + ]; + + const listMicroserviceVolumeMappingEndPoint = ResponseDecorator.handleErrors( + MicroservicesController.listMicroserviceVolumeMappingsEndPoint, + successCode, + errorCodes + ); + const responseObject = await listMicroserviceVolumeMappingEndPoint(req); + + res + .status(responseObject.code) + .send(responseObject.body) + }, + }, + { + method: 'post', + path: '/api/v3/microservices/:uuid/volume-mapping', + middleware: async (req, res) => { + const successCode = constants.HTTP_CODE_CREATED; + const errorCodes = [ + { + code: constants.HTTP_CODE_BAD_REQUEST, + errors: [Errors.ValidationError] + }, + { + code: constants.HTTP_CODE_UNAUTHORIZED, + errors: [Errors.AuthenticationError] + }, + { + code: constants.HTTP_CODE_NOT_FOUND, + errors: [Errors.NotFoundError] + } + ]; + + const createMicroserviceVolumeMappingEndPoint = ResponseDecorator.handleErrors( + MicroservicesController.createMicroserviceVolumeMappingEndPoint, + successCode, + errorCodes + ); + const responseObject = await createMicroserviceVolumeMappingEndPoint(req); + + res + .status(responseObject.code) + .send(responseObject.body) + }, + }, + { + method: 'delete', + path: '/api/v3/microservices/:uuid/volume-mapping/:id', + middleware: async (req, res) => { + const successCode = constants.HTTP_CODE_NO_CONTENT; + const errorCodes = [ + { + code: constants.HTTP_CODE_BAD_REQUEST, + errors: [Errors.ValidationError] + }, + { + code: constants.HTTP_CODE_UNAUTHORIZED, + errors: [Errors.AuthenticationError] + }, + { + code: constants.HTTP_CODE_NOT_FOUND, + errors: [Errors.NotFoundError] + } + ]; + + const deleteMicroserviceVolumeMappingEndPoint = ResponseDecorator.handleErrors( + MicroservicesController.deleteMicroserviceVolumeMappingEndPoint, + successCode, + errorCodes + ); + const responseObject = await deleteMicroserviceVolumeMappingEndPoint(req); + + res + .status(responseObject.code) + .send(responseObject.body) + }, + }, +]; diff --git a/src/schemas/microservice.js b/src/schemas/microservice.js index 833e20a2f..70d44bfa1 100644 --- a/src/schemas/microservice.js +++ b/src/schemas/microservice.js @@ -48,6 +48,17 @@ const microserviceUpdate = { "additionalProperties": false }; +const microserviceDelete = { + "id": "/microserviceDelete", + "type": "object", + "properties": { + "withCleanup": { + "type": "boolean" + }, + "additionalProperties": false + } +}; + const ports = { "id": "/ports", "type": "object", @@ -85,6 +96,6 @@ const volumeMappings = { }; module.exports = { - mainSchemas: [microserviceCreate, microserviceUpdate, ports, portsCreate], + mainSchemas: [microserviceCreate, microserviceUpdate, ports, portsCreate, microserviceDelete, volumeMappings], innerSchemas: [volumeMappings, ports] }; \ No newline at end of file diff --git a/src/sequelize/managers/volume-mapping-manager.js b/src/sequelize/managers/volume-mapping-manager.js index e1357d570..28f515e97 100644 --- a/src/sequelize/managers/volume-mapping-manager.js +++ b/src/sequelize/managers/volume-mapping-manager.js @@ -14,11 +14,19 @@ const BaseManager = require('./base-manager'); const models = require('./../models'); const VolumeMapping = models.VolumeMapping; +const Microservice = models.Microservice; class VolumeMappingManager extends BaseManager { - getEntity() { - return VolumeMapping - } + getEntity() { + return VolumeMapping + } + + findAll(where, transaction) { + return VolumeMapping.findAll({ + where: where, + attributes: ['hostDestination', 'containerDestination', 'accessMode', 'id'] + }, {transaction: transaction}) + } } const instance = new VolumeMappingManager(); diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index d7ed40fcd..82b8eaddb 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -202,7 +202,7 @@ const _updateChangeTracking = async function (configUpdated, fogNodeUuid, transa } }; -const _deleteMicroservice = async function (microserviceUuid, deleteWithCleanUp, user, isCLI, transaction) { +const _deleteMicroservice = async function (microserviceUuid, microserviceData, user, isCLI, transaction) { const where = isCLI ? @@ -231,7 +231,7 @@ const _deleteMicroservice = async function (microserviceUuid, deleteWithCleanUp, }, { delete: true, - deleteWithCleanUp: deleteWithCleanUp + deleteWithCleanUp: !!microserviceData.withCleanup }, transaction); } @@ -551,7 +551,7 @@ async function _createPortMapping(microserviceUuid, portMappingData, user, isCLI ] }, transaction); if (msPorts) { - throw new Errors.ValidationError('port mapping already exists') + throw new Errors.ValidationError(ErrorMessages.PORT_MAPPING_ALREADY_EXISTS); } if (portMappingData.publicMode) { @@ -745,7 +745,7 @@ async function _buildPortsList(portsPairs, transaction) { return res } -async function _getPortMappingList(microserviceUuid, user, isCLI, transaction) { +async function _listPortMappings(microserviceUuid, user, isCLI, transaction) { const where = isCLI ? {uuid: microserviceUuid} : {uuid: microserviceUuid, updatedBy: user.id}; @@ -755,8 +755,7 @@ async function _getPortMappingList(microserviceUuid, user, isCLI, transaction) { } const portsPairs = await MicroservicePortManager.findAll({microserviceUuid: microserviceUuid}, transaction) - const res = await _buildPortsList(portsPairs, transaction); - return res + return await _buildPortsList(portsPairs, transaction) } async function getPhysicalConections(microservice, transaction) { @@ -789,6 +788,73 @@ async function _buildLink(protocol, ip, port) { return `${protocol}://${ip}:${port}` } +async function _createVolumeMapping(microserviceUuid, volumeMappingData, user, isCLI, transaction) { + await Validation.validate(volumeMappingData, Validation.schemas.volumeMappings); + + const where = isCLI + ? {uuid: microserviceUuid} + : {uuid: microserviceUuid, updatedBy: user.id}; + + const microservice = await MicroserviceManager.findOne(where, transaction); + if (!microservice) { + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)) + } + + const volueMapping = await VolumeMappingManager.findOne({ + microserviceUuid: microserviceUuid, + hostDestination: volumeMappingData.hostDestination, + containerDestination: volumeMappingData.containerDestination + }, transaction); + if (volueMapping) { + throw new Errors.ValidationError(ErrorMessages.VOLUME_MAPPING_ALREADY_EXISTS); + } + + const volumeMappingObj = { + microserviceUuid: microserviceUuid, + hostDestination: volumeMappingData.hostDestination, + containerDestination: volumeMappingData.containerDestination, + accessMode: volumeMappingData.accessMode + }; + + return await VolumeMappingManager.create(volumeMappingObj, transaction); +} + +async function _deleteVolumeMapping(microserviceUuid, volumeMappingUuid, user, isCLI, transaction) { + const where = isCLI + ? {uuid: microserviceUuid} + : {uuid: microserviceUuid, updatedBy: user.id}; + + const microservice = await MicroserviceManager.findOne(where, transaction); + if (!microservice) { + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)) + } + + const volumeMappingWhere = { + uuid: volumeMappingUuid, + microserviceUuid: microserviceUuid + }; + + const affectedRows = await VolumeMappingManager.delete(volumeMappingWhere, transaction); + if (affectedRows === 0) { + throw new Errors.ValidationError(AppHelper.formatMessage(ErrorMessages.INVALID_VOLUME_MAPPING_UUID, volumeMappingUuid)); + } +} + +async function _listVolumeMappings(microserviceUuid, user, isCLI, transaction) { + const where = isCLI + ? {uuid: microserviceUuid} + : {uuid: microserviceUuid, updatedBy: user.id}; + const microservice = await MicroserviceManager.findOne(where, transaction) + if (!microservice) { + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)) + } + + const volumeMappingWhere = { + microserviceUuid: microserviceUuid + }; + return await VolumeMappingManager.findAll(volumeMappingWhere, transaction); +} + module.exports = { createMicroserviceOnFogWithTransaction: TransactionDecorator.generateTransaction(_createMicroserviceOnFog), listMicroservicesWithTransaction: TransactionDecorator.generateTransaction(_listMicroservices), @@ -798,8 +864,11 @@ module.exports = { createRouteWithTransaction: TransactionDecorator.generateTransaction(_createRoute), deleteRouteWithTransaction: TransactionDecorator.generateTransaction(_deleteRoute), createPortMappingWithTransaction: TransactionDecorator.generateTransaction(_createPortMapping), - getMicroservicePortMappingListWithTransaction: TransactionDecorator.generateTransaction(_getPortMappingList), + listMicroservicePortMappingsWithTransaction: TransactionDecorator.generateTransaction(_listPortMappings), deletePortMappingWithTransaction: TransactionDecorator.generateTransaction(_deletePortMapping), + createVolumeMapping: TransactionDecorator.generateTransaction(_createVolumeMapping), + deleteVolumeMapping: TransactionDecorator.generateTransaction(_deleteVolumeMapping), + listVolumeMappings: TransactionDecorator.generateTransaction(_listVolumeMappings), getPhysicalConections: getPhysicalConections, listMicroservices: _listMicroservices, deleteNotRunningMicroservices: _deleteNotRunningMicroservices From b0f0044d3b171ce5f510e393e4e474ab4f78da99 Mon Sep 17 00:00:00 2001 From: Pankov Date: Fri, 9 Nov 2018 18:53:25 +0300 Subject: [PATCH 03/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- specs/swagger.yml | 28 ++++++++++++++++++++------- src/cli/microservice.js | 20 +++++++++---------- src/services/microservices-service.js | 8 ++++---- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/specs/swagger.yml b/specs/swagger.yml index ae7ffb966..57d7fb063 100644 --- a/specs/swagger.yml +++ b/specs/swagger.yml @@ -1560,7 +1560,7 @@ paths: description: information about volume mapping required: true schema: - $ref: '#/definitions/VolumeMappingAgentRequest' + $ref: '#/definitions/VolumeMapping' responses: '201': description: Created @@ -1603,7 +1603,7 @@ paths: schema: type: array items: - $ref: '#/definitions/VolumeMappingAgentRequest' + $ref: '#/definitions/VolumeMappingRequest' headers: X-Timestamp: type: number @@ -2753,7 +2753,7 @@ definitions: VolumeMappings: type: array items: - $ref: '#/definitions/VolumeMappingAgentRequest' + $ref: '#/definitions/VolumeMapping' imageSnapshot: type: string removeWithCleanUp: @@ -2764,7 +2764,7 @@ definitions: type: array items: type: string - VolumeMappingAgentRequest: + VolumeMapping: type: object properties: hostDestination: @@ -2776,6 +2776,20 @@ definitions: accessMode: type: string example: rw + VolumeMappingRequest: + type: object + properties: + id: + type: number + hostDestination: + type: string + example: /var/dest + containerDestination: + type: string + example: /var/dest + accessMode: + type: string + example: rw PortMappingsResponse: type: object properties: @@ -3008,7 +3022,7 @@ definitions: volumeMappings: type: array items: - $ref: '#/definitions/VolumeMappingAgentRequest' + $ref: '#/definitions/VolumeMappingRequest' ports: type: array items: @@ -3035,7 +3049,7 @@ definitions: volumeMappings: type: array items: - $ref: '#/definitions/VolumeMappingAgentRequest' + $ref: '#/definitions/VolumeMapping' ports: type: array items: @@ -3062,7 +3076,7 @@ definitions: volumeMappings: type: array items: - $ref: '#/definitions/VolumeMappingAgentRequest' + $ref: '#/definitions/VolumeMapping' IOFogNodeTunnelStatusInfoResponse: type: object properties: diff --git a/src/cli/microservice.js b/src/cli/microservice.js index 288b6fafa..8f00b21f5 100644 --- a/src/cli/microservice.js +++ b/src/cli/microservice.js @@ -302,7 +302,7 @@ const _createRoute = async function (obj) { const arr = obj.route.split(':'); const sourceMicroserviceId = arr[0]; const destMicroserviceId = arr[1]; - await MicroserviceService.createRouteWithTransaction(sourceMicroserviceId, destMicroserviceId, {}, true); + await MicroserviceService.createRoute(sourceMicroserviceId, destMicroserviceId, {}, true); logger.info(`Microservice route with source microservice ${sourceMicroserviceId} and dest microservice ${destMicroserviceId} has been created successfully.`) } catch (e) { @@ -316,7 +316,7 @@ const _removeRoute = async function (obj) { const arr = obj.route.split(':'); const sourceMicroserviceId = arr[0]; const destMicroserviceId = arr[1]; - await MicroserviceService.deleteRouteWithTransaction(sourceMicroserviceId, destMicroserviceId, {}, true); + await MicroserviceService.deleteRoute(sourceMicroserviceId, destMicroserviceId, {}, true); logger.info(`Microservice route with source microservice ${obj.sourceMicroserviceId} and dest microservice ${obj.destMicroserviceId} has been removed successfully.`); } catch (e) { @@ -327,7 +327,7 @@ const _removeRoute = async function (obj) { const _createPortMapping = async function (obj) { logger.info(JSON.stringify(obj)); const mapping = parsePortMappingObject(obj.mapping, ErrorMessages.CLI.INVALID_PORT_MAPPING); - await MicroserviceService.createPortMappingWithTransaction(obj.microserviceId, mapping, {}, true); + await MicroserviceService.createPortMapping(obj.microserviceId, mapping, {}, true); logger.info('Port mapping has been create successfully.'); }; @@ -343,7 +343,7 @@ const _removePortMapping = async function (obj) { logger.info(JSON.stringify(obj)); try { const internalPort = parseInt(obj.internalPort); - await MicroserviceService.deletePortMappingWithTransaction(obj.microserviceId, internalPort, {}, true); + await MicroserviceService.deletePortMapping(obj.microserviceId, internalPort, {}, true); logger.info('Port mapping has been deleted successfully.'); } catch(e) { logger.error(ErrorMessages.CLI.INVALID_INTERNAL_PORT); @@ -361,7 +361,7 @@ const _removeVolumeMapping = async function (obj) { }; const _listPortMappings = async function (obj) { - const result = await MicroserviceService.listMicroservicePortMappingsWithTransaction(obj.microserviceId, {}, true); + const result = await MicroserviceService.listMicroservicePortMappings(obj.microserviceId, {}, true); logger.info(JSON.stringify(result)); logger.info('Port mappings have been retrieved successfully.'); }; @@ -374,19 +374,19 @@ const _listVolumeMappings = async function (obj) { const _removeMicroservice = async function (obj) { logger.info(JSON.stringify(obj)); - await MicroserviceService.deleteMicroserviceWithTransaction(obj.microserviceId, obj.cleanup, {}, true); + await MicroserviceService.deleteMicroservice(obj.microserviceId, obj.cleanup, {}, true); logger.info('Microservice has been removed successfully.') }; const _listMicroservices = async function () { - const result = await MicroserviceService.listMicroservicesWithTransaction({}, {}, true); + const result = await MicroserviceService.listMicroservices({}, {}, true); logger.info(JSON.stringify(result)); logger.info('Microservices have been retrieved successfully.'); }; const _getMicroservice = async function (obj) { logger.info(JSON.stringify(obj)); - const result = await MicroserviceService.getMicroserviceWithTransaction(obj.microserviceId, {}, true); + const result = await MicroserviceService.getMicroservice(obj.microserviceId, {}, true); logger.info(JSON.stringify(result, null, 2)); logger.info('Microservice has been retrieved successfully.'); }; @@ -398,7 +398,7 @@ const _createMicroservice = async function (obj) { logger.info(JSON.stringify(microservice)); - const result = await MicroserviceService.createMicroserviceOnFogWithTransaction(microservice, {}, true); + const result = await MicroserviceService.createMicroserviceOnFog(microservice, {}, true); logger.info(JSON.stringify(result)); logger.info('Microservice has been created successfully.'); }; @@ -410,7 +410,7 @@ const _updateMicroservice = async function (obj) { logger.info(JSON.stringify(microservice)); - await MicroserviceService.updateMicroserviceWithTransaction(obj.microserviceId, microservice, {}, true); + await MicroserviceService.updateMicroservice(obj.microserviceId, microservice, {}, true); logger.info('Microservice has been updated successfully.'); }; diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 3ddfb8687..0aa79ddf9 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -793,7 +793,7 @@ async function _createVolumeMapping(microserviceUuid, volumeMappingData, user, i const where = isCLI ? {uuid: microserviceUuid} - : {uuid: microserviceUuid, updatedBy: user.id}; + : {uuid: microserviceUuid, userId: user.id}; const microservice = await MicroserviceManager.findOne(where, transaction); if (!microservice) { @@ -822,7 +822,7 @@ async function _createVolumeMapping(microserviceUuid, volumeMappingData, user, i async function _deleteVolumeMapping(microserviceUuid, volumeMappingUuid, user, isCLI, transaction) { const where = isCLI ? {uuid: microserviceUuid} - : {uuid: microserviceUuid, updatedBy: user.id}; + : {uuid: microserviceUuid, userId: user.id}; const microservice = await MicroserviceManager.findOne(where, transaction); if (!microservice) { @@ -843,7 +843,7 @@ async function _deleteVolumeMapping(microserviceUuid, volumeMappingUuid, user, i async function _listVolumeMappings(microserviceUuid, user, isCLI, transaction) { const where = isCLI ? {uuid: microserviceUuid} - : {uuid: microserviceUuid, updatedBy: user.id}; + : {uuid: microserviceUuid, userId: user.id}; const microservice = await MicroserviceManager.findOne(where, transaction) if (!microservice) { throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)) @@ -864,7 +864,7 @@ module.exports = { createRoute: TransactionDecorator.generateTransaction(_createRoute), deleteRoute: TransactionDecorator.generateTransaction(_deleteRoute), createPortMapping: TransactionDecorator.generateTransaction(_createPortMapping), - listMicroservicePortMappings: TransactionDecorator.generateTransaction(_listMicroservicePortMappings), + listMicroservicePortMappings: TransactionDecorator.generateTransaction(_listPortMappings), deletePortMapping: TransactionDecorator.generateTransaction(_deletePortMapping), createVolumeMapping: TransactionDecorator.generateTransaction(_createVolumeMapping), deleteVolumeMapping: TransactionDecorator.generateTransaction(_deleteVolumeMapping), From bfcb07b6e8e9a205af0227ee2943d4b89968ffa2 Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 12 Nov 2018 12:24:17 +0300 Subject: [PATCH 04/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- src/controllers/microservices-controller.js | 7 +- ...Controller Testing.postman_collection.json | 166 ++++++++++++++++-- 2 files changed, 160 insertions(+), 13 deletions(-) diff --git a/src/controllers/microservices-controller.js b/src/controllers/microservices-controller.js index f857e02e0..7cbfb0ae5 100644 --- a/src/controllers/microservices-controller.js +++ b/src/controllers/microservices-controller.js @@ -89,7 +89,7 @@ const _deleteMicroservicePortMappingEndPoint = async function (req, user) { const _listMicroservicePortMappingsEndPoint = async function (req, user) { const uuid = req.params.uuid; logger.info(`Getting all port mappings for ${uuid}`); - const ports = await MicroservicesService.getMicroservicePortMappingList(uuid, user, false); + const ports = await MicroservicesService.listMicroservicePortMappings(uuid, user, false); return { ports: ports } @@ -108,7 +108,10 @@ const _createMicroserviceVolumeMappingEndPoint = async function (req, user) { const _listMicroserviceVolumeMappingsEndPoint = async function (req, user) { const uuid = req.params.uuid; logger.info(`Getting all volume mappings for ${uuid}`); - return await MicroservicesService.listVolumeMappings(uuid, user, false); + const volumeMappings = await MicroservicesService.listVolumeMappings(uuid, user, false); + return { + volumeMappings: volumeMappings + } }; const _deleteMicroserviceVolumeMappingEndPoint = async function (req, user) { diff --git a/tests/Controller Testing.postman_collection.json b/tests/Controller Testing.postman_collection.json index a6ac512d2..b040d08c0 100644 --- a/tests/Controller Testing.postman_collection.json +++ b/tests/Controller Testing.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "5a9e5363-c42e-4cfe-ad53-4ba7f9594334", + "_postman_id": "507ec948-6bd6-48ad-9272-ab609e6ce965", "name": "Controller Testing", "description": "iofog-controller collection", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" @@ -8,6 +8,7 @@ "item": [ { "name": "User", + "description": "User collection", "item": [ { "name": "Create user", @@ -507,7 +508,6 @@ "response": [] } ], - "description": "User collection", "event": [ { "listen": "prerequest", @@ -533,6 +533,7 @@ }, { "name": "General", + "description": "General collection", "item": [ { "name": "Status", @@ -652,7 +653,6 @@ "response": [] } ], - "description": "General collection", "event": [ { "listen": "prerequest", @@ -678,6 +678,7 @@ }, { "name": "Agent", + "description": "Agent collection", "item": [ { "name": "Create user", @@ -1765,7 +1766,6 @@ "response": [] } ], - "description": "Agent collection", "event": [ { "listen": "prerequest", @@ -1791,6 +1791,7 @@ }, { "name": "Flow", + "description": "Flow collection", "item": [ { "name": "Create user", @@ -2174,7 +2175,6 @@ "response": [] } ], - "description": "Flow collection", "event": [ { "listen": "prerequest", @@ -2200,6 +2200,7 @@ }, { "name": "Catalog", + "description": "Catalog collection", "item": [ { "name": "Create user", @@ -2592,7 +2593,6 @@ "response": [] } ], - "description": "Catalog collection", "event": [ { "listen": "prerequest", @@ -2618,6 +2618,7 @@ }, { "name": "Tunnel", + "description": "Tunnel collection", "item": [ { "name": "Create user", @@ -2958,7 +2959,6 @@ "response": [] } ], - "description": "Tunnel collection", "event": [ { "listen": "prerequest", @@ -2984,6 +2984,7 @@ }, { "name": "Microservices", + "description": "Microservices collection", "item": [ { "name": "Create user", @@ -3678,6 +3679,150 @@ }, "response": [] }, + { + "name": "Create volume mapping", + "event": [ + { + "listen": "test", + "script": { + "id": "df8a73e8-2b55-48f1-a143-0c243d787dac", + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 201\"] = responseCode.code === 201;", + "", + "var data = JSON.parse(responseBody);", + "", + "tests[\"Response validation passed\"] = data.hasOwnProperty('id');", + "", + "", + "postman.setGlobalVariable(\"volume-id\", data.id);", + "" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Authorization", + "value": "{{user-token}}" + } + ], + "body": { + "mode": "raw", + "raw": " {\n \"hostDestination\": \"/var/dest7\",\n \"containerDestination\": \"/var/dest\",\n \"accessMode\": \"rw\"\n }" + }, + "url": { + "raw": "{{host}}/api/v3/microservices/{{ms-id}}/volume-mapping", + "host": [ + "{{host}}" + ], + "path": [ + "api", + "v3", + "microservices", + "{{ms-id}}", + "volume-mapping" + ] + } + }, + "response": [] + }, + { + "name": "List volume mappings", + "event": [ + { + "listen": "test", + "script": { + "id": "422b4beb-ae6e-4cfc-9656-5eee3c5e792f", + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 200\"] = responseCode.code === 200;", + "", + "var data = JSON.parse(responseBody);", + "", + "tests[\"Response validation passed\"] = data.hasOwnProperty('volumeMappings');" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "{{user-token}}" + } + ], + "body": {}, + "url": { + "raw": "{{host}}/api/v3/microservices/{{ms-id}}/volume-mapping", + "host": [ + "{{host}}" + ], + "path": [ + "api", + "v3", + "microservices", + "{{ms-id}}", + "volume-mapping" + ] + } + }, + "response": [] + }, + { + "name": "Delete volume mapping", + "event": [ + { + "listen": "test", + "script": { + "id": "98751304-dec8-4149-99ec-e7e76c5ac9ea", + "type": "text/javascript", + "exec": [ + "tests[\"Status code is 204\"] = responseCode.code === 204;" + ] + } + } + ], + "request": { + "method": "DELETE", + "header": [ + { + "key": "Authorization", + "value": "{{user-token}}" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{host}}/api/v3/microservices/{{ms-id}}/volume-mapping/{{volume-id}}", + "host": [ + "{{host}}" + ], + "path": [ + "api", + "v3", + "microservices", + "{{ms-id}}", + "volume-mapping", + "{{volume-id}}" + ] + } + }, + "response": [] + }, { "name": "Delete a Microservice", "event": [ @@ -3917,7 +4062,6 @@ "response": [] } ], - "description": "Microservices collection", "event": [ { "listen": "prerequest", @@ -3943,6 +4087,7 @@ }, { "name": "Diagnostics", + "description": "Diagnostics collection", "item": [ { "name": "Create user", @@ -4738,7 +4883,6 @@ "response": [] } ], - "description": "Diagnostics collection", "event": [ { "listen": "prerequest", @@ -4764,6 +4908,7 @@ }, { "name": "ioFog", + "description": "ioFog collection", "item": [ { "name": "Create user", @@ -5467,7 +5612,6 @@ "response": [] } ], - "description": "ioFog collection", "event": [ { "listen": "prerequest", @@ -5493,6 +5637,7 @@ }, { "name": "Registries", + "description": "Registries collection", "item": [ { "name": "Create user", @@ -5827,7 +5972,6 @@ "response": [] } ], - "description": "Registries collection", "event": [ { "listen": "prerequest", From fe5ec892cac79946679a302df65bd10beb63b897 Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 12 Nov 2018 12:46:40 +0300 Subject: [PATCH 05/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- src/cli/microservice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/microservice.js b/src/cli/microservice.js index 8f00b21f5..1628f9360 100644 --- a/src/cli/microservice.js +++ b/src/cli/microservice.js @@ -328,7 +328,7 @@ const _createPortMapping = async function (obj) { logger.info(JSON.stringify(obj)); const mapping = parsePortMappingObject(obj.mapping, ErrorMessages.CLI.INVALID_PORT_MAPPING); await MicroserviceService.createPortMapping(obj.microserviceId, mapping, {}, true); - logger.info('Port mapping has been create successfully.'); + logger.info('Port mapping has been created successfully.'); }; const _createVolumeMapping = async function (obj) { From cfec99dd6af46af989d81683eace4bb66d620f3d Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 12 Nov 2018 13:00:18 +0300 Subject: [PATCH 06/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- src/cli/catalog.js | 2 +- src/cli/connector.js | 2 +- src/cli/diagnostics.js | 7 ++++--- src/cli/flow.js | 8 +++++--- src/cli/iofog.js | 18 ++++++++++-------- src/cli/microservice.js | 4 ++-- src/cli/tunnel.js | 24 +++++++++++------------- src/cli/user.js | 5 +++-- 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/cli/catalog.js b/src/cli/catalog.js index b8b321fb3..9a6b50152 100644 --- a/src/cli/catalog.js +++ b/src/cli/catalog.js @@ -167,7 +167,7 @@ const _deleteCatalogItem = async function (obj) { const _listCatalogItems = async function () { const result = await CatalogItemService.listCatalogItems({}, true); - logger.info(JSON.stringify(result)); + logger.info(JSON.stringify(result, null, 2)); logger.info('Catalog items have been successfully retrieved.'); }; diff --git a/src/cli/connector.js b/src/cli/connector.js index 0c2903c93..a2f76102f 100644 --- a/src/cli/connector.js +++ b/src/cli/connector.js @@ -116,8 +116,8 @@ async function _deleteConnector(obj) { async function _getConnectorList(obj) { const list = await ConnectorService.getConnectorList() + logger.info(JSON.stringify(list, null, 2)); logger.info('Connector list has been gotten successfully'); - logger.info(JSON.stringify(list)); } function _createConnectorObject(cliData) { diff --git a/src/cli/diagnostics.js b/src/cli/diagnostics.js index 434b54ddd..a069abb2f 100644 --- a/src/cli/diagnostics.js +++ b/src/cli/diagnostics.js @@ -130,21 +130,22 @@ const _getMicroserviceStraceData = async function (obj) { logger.info(JSON.stringify(obj)); const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceId, {format: obj.format}, {}, true); - logger.info(JSON.stringify(result)); + 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); - logger.info('Strace data has been posted to ftp successfully'); + 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); - logger.info('Microservice image snapshot has been created successfully'); + logger.info('Microservice image snapshot has been created successfully.'); }; const _getMicroserviceImageSnapshot = async function (obj) { diff --git a/src/cli/flow.js b/src/cli/flow.js index 57e7566ac..77a3f15a1 100644 --- a/src/cli/flow.js +++ b/src/cli/flow.js @@ -134,9 +134,10 @@ const _deleteFlow = async function (flowData) { logger.info('Flow removed successfully.'); }; -const _getAllFlows = async function (emptyObj) { +const _getAllFlows = async function () { const flows = await FlowService.getAllFlows(true); - logger.info(JSON.stringify(flows)); + logger.info(JSON.stringify(flows, null, 2)); + logger.info('All flows have been retrieved successfully.'); }; const _getFlow = async function (flowData) { @@ -145,7 +146,8 @@ const _getFlow = async function (flowData) { const flowId = flowData.flowId; const flow = await FlowService.getFlowWithTransaction(flowId, {}, true); - logger.info(JSON.stringify(flow)); + logger.info(JSON.stringify(flow, null, 2)); + logger.info(`Flow with id ${flowId} has been retrieved successfully.`) }; function _createFlowObject(data) { diff --git a/src/cli/iofog.js b/src/cli/iofog.js index 495e52a70..2318808fe 100644 --- a/src/cli/iofog.js +++ b/src/cli/iofog.js @@ -193,23 +193,23 @@ async function _deleteFog(obj, user) { async function _getFogList(obj, user) { const emptyFilters = [] const list = await FogService.getFogList(emptyFilters, user, true); - logger.info('Fog list has been gotten successfully'); - logger.info(JSON.stringify(list)); + logger.info(JSON.stringify(list, null, 2)); + logger.info('Fog list has been gotten successfully.'); } async function _getFog(obj, user) { const fog = _createFogObject(obj); const res = await FogService.getFogWithTransaction(fog, user, true); - logger.info('Fog has been gotten successfully'); - logger.info(JSON.stringify(res)); + logger.info(JSON.stringify(res, null, 2)); + logger.info('Fog has been gotten successfully.'); } async function _generateProvision(obj, user) { const fog = _createFogObject(obj); logger.info(JSON.stringify(fog)); const res = await FogService.generateProvisioningKey(fog, user, true); - logger.info('Fog provisioning key has been generated successfully'); - logger.info('Provisioning key: '+ JSON.stringify(res)); + logger.info('Provisioning key: '+ JSON.stringify(res, null, 2)); + logger.info('Fog provisioning key has been generated successfully.'); } async function _setFogRebootCommand(obj, user) { @@ -237,7 +237,8 @@ async function _getHalHardwareInfo(obj) { logger.info("Parameters" + JSON.stringify(uuidObj)); const info = await FogService.getHalHardwareInfo(uuidObj, {}, true); - logger.info(JSON.stringify(info)); + logger.info(JSON.stringify(info, null, 2)); + logger.info('Hardware info has been retrieved successfully.') } async function _getHalUsbInfo(obj) { @@ -248,7 +249,8 @@ async function _getHalUsbInfo(obj) { logger.info("Parameters" + JSON.stringify(uuidObj)); const info = await FogService.getHalHardwareInfo(uuidObj, {}, true); - logger.info(JSON.stringify(info)); + logger.info(JSON.stringify(info, null, 2)); + logger.info('Usb info has been retrieved successfully.') } function _createFogObject(cliData) { diff --git a/src/cli/microservice.js b/src/cli/microservice.js index 1628f9360..f96622a58 100644 --- a/src/cli/microservice.js +++ b/src/cli/microservice.js @@ -362,7 +362,7 @@ const _removeVolumeMapping = async function (obj) { const _listPortMappings = async function (obj) { const result = await MicroserviceService.listMicroservicePortMappings(obj.microserviceId, {}, true); - logger.info(JSON.stringify(result)); + logger.info(JSON.stringify(result, null, 2)); logger.info('Port mappings have been retrieved successfully.'); }; @@ -380,7 +380,7 @@ const _removeMicroservice = async function (obj) { const _listMicroservices = async function () { const result = await MicroserviceService.listMicroservices({}, {}, true); - logger.info(JSON.stringify(result)); + logger.info(JSON.stringify(result, null, 2)); logger.info('Microservices have been retrieved successfully.'); }; diff --git a/src/cli/tunnel.js b/src/cli/tunnel.js index d5b326462..34fcb6980 100644 --- a/src/cli/tunnel.js +++ b/src/cli/tunnel.js @@ -74,11 +74,10 @@ async function _updateTunnel(obj, user) { logger.info('Tunnel has been updated successfully.'); } -async function _tunnelList(obj) { +async function _tunnelList() { const tunnels = await TunnelService.findAll(); - logger.info(JSON.stringify(tunnels)); + logger.info(JSON.stringify(tunnels, null, 2)); logger.info('Tunnels has been received successfully.'); - return tunnels; } async function _executeCase(commands, commandName, f, isUserRequired) { @@ -98,15 +97,14 @@ async function _executeCase(commands, commandName, f, isUserRequired) { function _createTunnelObject(cliData) { const rsa = cliData.rsaKey ? fs.readFileSync(cliData.rsaKey, 'utf8') : ""; - const tunnel = { - host: cliData.host, - username: cliData.username, - password: cliData.password, - rsakey: rsa, - lport: cliData.port, - iofogUuid: cliData.iofogUuid - } - return tunnel; + return { + host: cliData.host, + username: cliData.username, + password: cliData.password, + rsakey: rsa, + lport: cliData.port, + iofogUuid: cliData.iofogUuid + }; } -module.exports = new Tunnel() \ No newline at end of file +module.exports = new Tunnel(); \ No newline at end of file diff --git a/src/cli/user.js b/src/cli/user.js index 61416b4e4..5be79c11a 100644 --- a/src/cli/user.js +++ b/src/cli/user.js @@ -129,9 +129,10 @@ const _deleteUser = async function (emailObj, user) { logger.info('User removed successfully.'); }; -const _getAllUsers = async function (emptyObj) { +const _getAllUsers = async function () { const users = await UserService.list(true); - logger.info(JSON.stringify(users)); + logger.info(JSON.stringify(users, null, 2)); + logger.info('All users have been retrieved successfully.') }; const _generateToken = async function (emailObj, user) { From 189046bb073b9cfad7b4a6f6b4b4e5410e5284d4 Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 12 Nov 2018 13:57:24 +0300 Subject: [PATCH 07/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- src/cli/config.js | 16 ++++++++-------- src/schemas/index.js | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/cli/config.js b/src/cli/config.js index 4b7258422..66511d22c 100644 --- a/src/cli/config.js +++ b/src/cli/config.js @@ -82,7 +82,7 @@ const _executeCase = async function (catalogCommand, commandName, f) { const _addConfigOption = async function (options) { await Validator.validate(options, Validator.schemas.configUpdate); - updateConfig(options.port, 'port', 'Server:Port', async (onSuccess) => { + await updateConfig(options.port, 'port', 'Server:Port', async (onSuccess) => { const port = options.port; const status = await AppHelper.checkPortAvailability(port); if (status === 'closed') { @@ -93,7 +93,7 @@ const _addConfigOption = async function (options) { } }); - updateConfig(options.sslCert, 'ssl-cert', 'Server:SslCert', (onSuccess) => { + await updateConfig(options.sslCert, 'ssl-cert', 'Server:SslCert', (onSuccess) => { const sslCert = options.sslCert; if (!AppHelper.isFileExists(sslCert)) { logger.error(ErrorMessages.INVALID_FILE_PATH); @@ -113,7 +113,7 @@ const _addConfigOption = async function (options) { logger.info('Config option ssl-key has been updated.'); } - updateConfig(options.intermediateCert, 'intermediate-cert', 'Server:IntermediateCert', (onSuccess) => { + await updateConfig(options.intermediateCert, 'intermediate-cert', 'Server:IntermediateCert', (onSuccess) => { const intermediateCert = options.intermediateCert; if (!AppHelper.isFileExists(intermediateCert)) { logger.error(ErrorMessages.INVALID_FILE_PATH); @@ -123,12 +123,12 @@ const _addConfigOption = async function (options) { onSuccess(); }); - updateConfig(options.homeUrl, 'home-url', 'Email:HomeUrl', (onSuccess) => { + await updateConfig(options.homeUrl, 'home-url', 'Email:HomeUrl', (onSuccess) => { config.set('Email:HomeUrl', options.homeUrl); onSuccess(); }); - updateConfig(options.emailAddress, 'email-address', 'Email:Address', (onSuccess) => { + await updateConfig(options.emailAddress, 'email-address', 'Email:Address', (onSuccess) => { if (options.emailPassword) { logger.info('When changing email address, password must be provided.'); return; @@ -142,17 +142,17 @@ const _addConfigOption = async function (options) { logger.info('Config option email-password has been updated.'); } - updateConfig(options.emailService, 'email-service', 'Email:Service', (onSuccess) => { + await updateConfig(options.emailService, 'email-service', 'Email:Service', (onSuccess) => { config.set('Email:Service', options.emailService); onSuccess(); }); - updateConfig(options.logDir, 'log-dir', 'Service:LogsDirectory', (onSuccess) => { + await updateConfig(options.logDir, 'log-dir', 'Service:LogsDirectory', (onSuccess) => { config.set('Service:LogsDirectory', options.logDir); onSuccess(); }); - updateConfig(options.logSize, 'log-size', 'Service:LogsFileSize', (onSuccess) => { + await updateConfig(options.logSize, 'log-size', 'Service:LogsFileSize', (onSuccess) => { config.set('Service:LogsFileSize', options.logSize * 1024); onSuccess(); }) diff --git a/src/schemas/index.js b/src/schemas/index.js index ba825c658..158302d73 100644 --- a/src/schemas/index.js +++ b/src/schemas/index.js @@ -52,7 +52,6 @@ fs.readdirSync(__dirname) async function validate(object, schema) { const response = v.validate(object, schema); if (!response.valid) { - Logger.info(JSON.stringify(response)); await handleValidationError(response.errors[0]); } return response From 4a6b6472ba9c11333ef8fe24081b5d16dc12bae1 Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 12 Nov 2018 15:26:29 +0300 Subject: [PATCH 08/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- specs/swagger.yml | 11 ++++++++--- src/cli/connector.js | 24 ++++++++++++------------ src/cli/diagnostics.js | 8 ++++---- src/services/connector-service.js | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/specs/swagger.yml b/specs/swagger.yml index 57d7fb063..871370ee8 100644 --- a/specs/swagger.yml +++ b/specs/swagger.yml @@ -1601,9 +1601,7 @@ paths: '200': description: Success schema: - type: array - items: - $ref: '#/definitions/VolumeMappingRequest' + $ref: '#/definitions/VolumeMappingResponse' headers: X-Timestamp: type: number @@ -2776,6 +2774,13 @@ definitions: accessMode: type: string example: rw + VolumeMappingResponse: + type: object + properties: + volumeMappings: + type: array + items: + $ref: '#/definitions/VolumeMappingRequest' VolumeMappingRequest: type: object properties: diff --git a/src/cli/connector.js b/src/cli/connector.js index a2f76102f..ef7961560 100644 --- a/src/cli/connector.js +++ b/src/cli/connector.js @@ -42,21 +42,21 @@ class Connector extends BaseCLIHandler { } async run(args) { - const connectorCommand = this.parseCommandLineArgs(this.commandDefinitions, { argv: args.argv }) + const connectorCommand = this.parseCommandLineArgs(this.commandDefinitions, { argv: args.argv }); switch (connectorCommand.command.command) { case constants.CMD_ADD: - await _executeCase(connectorCommand, constants.CMD_ADD, _createConnector, false) - break + await _executeCase(connectorCommand, constants.CMD_ADD, _createConnector, false); + break; case constants.CMD_UPDATE: - await _executeCase(connectorCommand, constants.CMD_UPDATE, _updateConnector, false) - break + await _executeCase(connectorCommand, constants.CMD_UPDATE, _updateConnector, false); + break; case constants.CMD_REMOVE: - await _executeCase(connectorCommand, constants.CMD_REMOVE, _deleteConnector, false) - break + await _executeCase(connectorCommand, constants.CMD_REMOVE, _deleteConnector, false); + break; case constants.CMD_LIST: - await _executeCase(connectorCommand, constants.CMD_LIST, _getConnectorList, false) - break + await _executeCase(connectorCommand, constants.CMD_LIST, _getConnectorList, false); + break; case constants.CMD_HELP: default: return this.help([constants.CMD_LIST]) @@ -81,7 +81,7 @@ async function _executeCase(commands, commandName, f, isUserRequired) { } async function _createConnector(obj) { - const connector = _createConnectorObject(obj) + const connector = _createConnectorObject(obj); logger.info(JSON.stringify(connector)); try { const result = await ConnectorService.createConnector(connector) @@ -114,7 +114,7 @@ async function _deleteConnector(obj) { } } -async function _getConnectorList(obj) { +async function _getConnectorList() { const list = await ConnectorService.getConnectorList() logger.info(JSON.stringify(list, null, 2)); logger.info('Connector list has been gotten successfully'); @@ -126,7 +126,7 @@ function _createConnectorObject(cliData) { domain: cliData.domain, publicIp: cliData.publicIp, cert: cliData.cert, - isSelfSignedCert: AppHelper.validateBooleanCliOptions(cliData.selfSignedEnable, cliData.selfSignedDisable), + isSelfSignedCert: AppHelper.validateBooleanCliOptions(cliData.selfSignedOn, cliData.selfSignedOff), devMode: AppHelper.validateBooleanCliOptions(cliData.devModeOn, cliData.devModeOff) } diff --git a/src/cli/diagnostics.js b/src/cli/diagnostics.js index a069abb2f..f296b35e8 100644 --- a/src/cli/diagnostics.js +++ b/src/cli/diagnostics.js @@ -35,12 +35,12 @@ class Diagnostics extends BaseCLIHandler { }, { name: 'disable', alias: 'o', type: Boolean, description: 'Disable microservice strace', - group: [constants.CMD_STRACE_UPDATE ] + group: [constants.CMD_STRACE_UPDATE] }, { name: 'microservice-id', alias: 'i', type: String, description: 'Microservice ID', group: [constants.CMD_STRACE_UPDATE, constants.CMD_STRACE_INFO, constants.CMD_STRACE_FTP_POST, - constants.CMD_IMAGE_SNAPSHOT_CREATE, constants.CMD_IMAGE_SNAPSHOT_GET] + constants.CMD_IMAGE_SNAPSHOT_CREATE, constants.CMD_IMAGE_SNAPSHOT_GET] }, { name: 'format', alias: 'f', type: String, description: 'Format of strace data to receive', @@ -77,7 +77,7 @@ class Diagnostics extends BaseCLIHandler { } async run(args) { - const diagnosticCommand = this.parseCommandLineArgs(this.commandDefinitions, { argv: args.argv }) + const diagnosticCommand = this.parseCommandLineArgs(this.commandDefinitions, {argv: args.argv}) switch (diagnosticCommand.command.command) { case constants.CMD_STRACE_UPDATE: @@ -102,7 +102,7 @@ class Diagnostics extends BaseCLIHandler { } } -const _executeCase = async function (diagnosticCommand, commandName, f, isUserRequired) { +const _executeCase = async function (diagnosticCommand, commandName, f, isUserRequired) { try { const item = diagnosticCommand[commandName]; diff --git a/src/services/connector-service.js b/src/services/connector-service.js index f1a53555b..a2a6a5bae 100644 --- a/src/services/connector-service.js +++ b/src/services/connector-service.js @@ -39,7 +39,7 @@ async function _createConnector(connectorData, transaction) { if (connector) { throw new Errors.ValidationError(ErrorMessages.ALREADY_EXISTS) } - await ConnectorManager.create(connectorData, transaction) + return await ConnectorManager.create(connectorData, transaction) } async function _updateConnector(connectorData, transaction) { From c935f4272b7e1dc172355a35f3c8c84811f70390 Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 12 Nov 2018 15:35:03 +0300 Subject: [PATCH 09/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- src/services/microservices-service.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 0aa79ddf9..8fd62b5b6 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -217,14 +217,14 @@ const _deleteMicroservice = async function (microserviceUuid, microserviceData, const microservice = await MicroserviceManager.findOneWithStatus(where, transaction); + if (!microservice) { + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)); + } if (microservice.microserviceStatus.status === MicroserviceStates.NOT_RUNNING) { - const affectedRows = await MicroserviceManager.delete({ + await MicroserviceManager.delete({ uuid: microserviceUuid }, transaction); - if (affectedRows === 0) { - throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)); - } } else { await MicroserviceManager.update({ uuid: microserviceUuid From f2b6d836b819553d57f85d571c51b578305f1188 Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 12 Nov 2018 15:37:47 +0300 Subject: [PATCH 10/10] Merge branch 'develop' of https://github.com/ioFog/FogController into epankou/feature-volume-mapping-endpoint-EWC-332 # Conflicts: # src/cli/microservice.js # src/controllers/microservices-controller.js # src/services/microservices-service.js --- ...Controller Testing.postman_collection.json | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/Controller Testing.postman_collection.json b/tests/Controller Testing.postman_collection.json index b040d08c0..4b593b828 100644 --- a/tests/Controller Testing.postman_collection.json +++ b/tests/Controller Testing.postman_collection.json @@ -3829,11 +3829,12 @@ { "listen": "test", "script": { - "id": "4f7a9f52-12cc-49d0-9e2f-147b6f5cb6fa", + "id": "6d078bca-3762-400b-bf9f-2701f7f5b01b", + "type": "text/javascript", "exec": [ - "tests[\"Status code is 204\"] = responseCode.code === 204;" - ], - "type": "text/javascript" + "tests[\"Status code is 204\"] = responseCode.code === 204;", + "" + ] } } ], @@ -3846,16 +3847,15 @@ }, { "key": "Authorization", - "value": "{{user-token}}", - "type": "text" + "value": "{{user-token}}" } ], "body": { "mode": "raw", - "raw": "" + "raw": "{\n\t\"withCleanup\": false\n}" }, "url": { - "raw": "{{host}}/api/v3/microservices/{{ms-id}}?withCleanUp=true", + "raw": "{{host}}/api/v3/microservices/{{ms-id}}", "host": [ "{{host}}" ], @@ -3864,12 +3864,6 @@ "v3", "microservices", "{{ms-id}}" - ], - "query": [ - { - "key": "withCleanUp", - "value": "true" - } ] } },