From aa4a7d3a4e78aeb70ab0c72437f2aa5703219501 Mon Sep 17 00:00:00 2001 From: Pankov Date: Wed, 12 Dec 2018 18:29:27 +0300 Subject: [PATCH 01/13] EWC-418 added registry email validation --- src/schemas/registry.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/schemas/registry.js b/src/schemas/registry.js index de986a302..6acd7e6f8 100644 --- a/src/schemas/registry.js +++ b/src/schemas/registry.js @@ -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"} }, @@ -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"} }, From 3de21b679127f3531f09d0d18417173d4a28106d Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 17 Dec 2018 11:35:45 +0300 Subject: [PATCH 02/13] EWC-421 strace feature bug --- src/routes/agent.js | 2 +- src/schemas/agent.js | 4 ++-- src/sequelize/managers/iofog-manager.js | 4 ++-- src/services/agent-service.js | 18 ++++++++++++++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/routes/agent.js b/src/routes/agent.js index f2610e1e1..2ab7f255d 100644 --- a/src/routes/agent.js +++ b/src/routes/agent.js @@ -278,7 +278,7 @@ module.exports = [ method: 'put', path: '/api/v3/agent/strace', middleware: async (req, res) => { - const successCode = constants.HTTP_CODE_SUCCESS; + const successCode = constants.HTTP_CODE_NO_CONTENT; const errorCodes = [ { code: constants.HTTP_CODE_NOT_FOUND, diff --git a/src/schemas/agent.js b/src/schemas/agent.js index 3d3c19cc5..5dd990aa4 100644 --- a/src/schemas/agent.js +++ b/src/schemas/agent.js @@ -104,10 +104,10 @@ const straceData = { "id": "/straceData", "type": "object", "properties": { - "microserviceId": {"type": "string"}, + "microserviceUuid": {"type": "string"}, "buffer": {"type": "string"} }, - "required": ["microserviceId", "buffer"], + "required": ["microserviceUuid", "buffer"], "additionalProperties": false }; diff --git a/src/sequelize/managers/iofog-manager.js b/src/sequelize/managers/iofog-manager.js index 4289ef7b5..0ac555f4e 100644 --- a/src/sequelize/managers/iofog-manager.js +++ b/src/sequelize/managers/iofog-manager.js @@ -54,11 +54,11 @@ class FogManager extends BaseManager { { model: Microservice, as: 'microservice', - required: false, + required: true, include: [{ model: Strace, as: 'strace', - required: false + required: true }] }], where: where diff --git a/src/services/agent-service.js b/src/services/agent-service.js index 8160eb82e..f92a5330d 100644 --- a/src/services/agent-service.js +++ b/src/services/agent-service.js @@ -300,7 +300,7 @@ const getAgentTunnel = async function (fog, transaction) { }; const getAgentStrace = async function (fog, transaction) { - const fogWithStrace = FogManager.findFogStraces({ + const fogWithStrace = await FogManager.findFogStraces({ uuid: fog.uuid }, transaction); @@ -308,16 +308,26 @@ const getAgentStrace = async function (fog, transaction) { throw new Errors.NotFoundError(ErrorMessages.STRACE_NOT_FOUND); } - return fogWithStrace.strace; + const straceArr = []; + for (let msData of fogWithStrace.microservice) { + straceArr.push({ + microserviceUuid: msData.strace.microserviceUuid, + straceRun: msData.strace.straceRun + }) + }; + + return { + straceValues: straceArr + } }; const updateAgentStrace = async function (straceData, fog, transaction) { await Validator.validate(straceData, Validator.schemas.updateAgentStrace); for (const strace of straceData.straceData) { - const microserviceId = strace.microserviceId; + const microserviceUuid = strace.microserviceUuid; const buffer = strace.buffer; - await StraceManager.pushBufferByMicroserviceId(microserviceId, buffer, transaction) + await StraceManager.pushBufferByMicroserviceId(microserviceUuid, buffer, transaction) } }; From 7c60954a3ada97e8c8ee78e79896eb51a10c4497 Mon Sep 17 00:00:00 2001 From: Pankov Date: Mon, 17 Dec 2018 13:46:39 +0300 Subject: [PATCH 03/13] EWC-421 strace feature bug fix --- src/cli/diagnostics.js | 4 ++-- src/services/agent-service.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cli/diagnostics.js b/src/cli/diagnostics.js index dd5e096d0..7f156f5c2 100644 --- a/src/cli/diagnostics.js +++ b/src/cli/diagnostics.js @@ -131,7 +131,6 @@ const _changeMicroserviceStraceState = async function (obj) { 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); }; @@ -139,7 +138,8 @@ const _getMicroserviceStraceData = async function (obj) { logger.info(JSON.stringify(obj)); const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceUuid, {format: obj.format}, {}, true); - logger.info(JSON.stringify(result, null, 2)); + logger.info('Strace data:'); + logger.info(result.data); logger.info('Microservice strace data has been retrieved successfully.'); }; diff --git a/src/services/agent-service.js b/src/services/agent-service.js index 96c439702..c2463e712 100644 --- a/src/services/agent-service.js +++ b/src/services/agent-service.js @@ -325,9 +325,9 @@ const updateAgentStrace = async function (straceData, fog, transaction) { await Validator.validate(straceData, Validator.schemas.updateAgentStrace); for (const strace of straceData.straceData) { - const microserviceId = strace.microserviceId; + const microserviceUuid = strace.microserviceUuid; const buffer = strace.buffer; - await StraceManager.pushBufferByMicroserviceId(microserviceUuid, buffer, transaction) + await StraceManager.pushBufferByMicroserviceUuid(microserviceUuid, buffer, transaction) } }; From 9e613db9a8d0ed109ecfc24d9ea486e2cc41a56f Mon Sep 17 00:00:00 2001 From: Pankov Date: Wed, 19 Dec 2018 12:00:31 +0300 Subject: [PATCH 04/13] bug(fix) iofog agent API: core network containers are returned when flow isn't active (EWC-424) --- src/sequelize/managers/microservice-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sequelize/managers/microservice-manager.js b/src/sequelize/managers/microservice-manager.js index 2e6729cae..ca103f664 100644 --- a/src/sequelize/managers/microservice-manager.js +++ b/src/sequelize/managers/microservice-manager.js @@ -153,7 +153,8 @@ class MicroserviceManager extends BaseManager { '$flow.is_activated$': true }, { - '$catalogItem.category$': {[Op.eq]: 'SYSTEM'} + '$catalogItem.category$': {[Op.eq]: 'SYSTEM'}, + '$catalogItem.id$': {[Op.ne]: 1} } ] From ddbc7c7ce048d6467e9ebe1064d1fe15d6937851 Mon Sep 17 00:00:00 2001 From: Pankov Date: Thu, 20 Dec 2018 16:45:13 +0300 Subject: [PATCH 05/13] bug(fix) microservice removal: port mapping removal (EWC-424) --- src/cli/diagnostics.js | 1 + src/services/microservices-service.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/cli/diagnostics.js b/src/cli/diagnostics.js index 7f156f5c2..1a0445f3d 100644 --- a/src/cli/diagnostics.js +++ b/src/cli/diagnostics.js @@ -139,6 +139,7 @@ const _getMicroserviceStraceData = async function (obj) { const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceUuid, {format: obj.format}, {}, true); logger.info('Strace data:'); + logger.info('============================='); logger.info(result.data); logger.info('Microservice strace data has been retrieved successfully.'); }; diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index f0e0b7dd1..137e65bbe 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -243,6 +243,8 @@ async function _deleteMicroservice(microserviceUuid, microserviceData, user, isC throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)); } + await _deletePortMappings(microservice, user, transaction); + if (microservice.microserviceStatus.status === MicroserviceStates.NOT_RUNNING) { await _deleteMicroserviceWithRoutes(microserviceUuid, transaction); } else { @@ -258,6 +260,20 @@ async function _deleteMicroservice(microserviceUuid, microserviceData, user, isC await _updateChangeTracking(false, microservice.iofogUuid, transaction) } +async function _deletePortMappings(microservice, user, transaction) { + const msPortMappings = await MicroservicePortManager.findAll({ + microserviceUuid: microservice.uuid + }, transaction); + + for (let msPorts of msPortMappings) { + if (msPorts.isPublic) { + await _deletePortMappingOverConnector(microservice, msPorts, user, transaction) + } else { + await _deleteSimplePortMapping(microservice, msPorts, user, transaction) + } + } +} + async function _deleteNotRunningMicroservices(transaction) { const microservices = await MicroserviceManager.findAllWithStatuses(transaction); microservices From 3982963002e159934fac764cff82f558608b54fc Mon Sep 17 00:00:00 2001 From: Pankov Date: Thu, 20 Dec 2018 16:53:01 +0300 Subject: [PATCH 06/13] bug(fix) microservice removal: switched to const (EWC-424) --- src/services/microservices-service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 137e65bbe..2bb619c45 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -265,7 +265,7 @@ async function _deletePortMappings(microservice, user, transaction) { microserviceUuid: microservice.uuid }, transaction); - for (let msPorts of msPortMappings) { + for (const msPorts of msPortMappings) { if (msPorts.isPublic) { await _deletePortMappingOverConnector(microservice, msPorts, user, transaction) } else { From 53b82ee6134290c740f1fdad9dc497c4d74a90c6 Mon Sep 17 00:00:00 2001 From: Pankov Date: Fri, 28 Dec 2018 17:00:52 +0300 Subject: [PATCH 07/13] bug(fix) routes removal: added routes update on connector update (EWC-374) --- src/config/development.json | 8 +- src/helpers/app-helper.js | 1 - .../microservice-public-mode-manager.js | 18 +++- src/sequelize/managers/routing-manager.js | 16 ++++ src/services/connector-service.js | 8 +- src/services/microservices-service.js | 85 +++++++++++++++++-- 6 files changed, 123 insertions(+), 13 deletions(-) diff --git a/src/config/development.json b/src/config/development.json index 9217782be..3757c3764 100644 --- a/src/config/development.json +++ b/src/config/development.json @@ -4,7 +4,10 @@ }, "Server": { "Port": 51121, - "DevMode": true + "DevMode": true, + "SslCert": "/home/owner/Downloads/iofog_certs/iofog.org/ssl_certificate.crt", + "SslKey": "/home/owner/Downloads/iofog_certs/iofog.org/server-key.pem", + "IntermediateCert": "/home/owner/Downloads/iofog_certs/iofog.org/IntermediateCA.crt" }, "Email": { "ActivationEnabled": false, @@ -29,5 +32,4 @@ "Diagnostics": { "DiagnosticDir": "diagnostic" } -} - +} \ No newline at end of file diff --git a/src/helpers/app-helper.js b/src/helpers/app-helper.js index 5f9d2cde7..690a17113 100644 --- a/src/helpers/app-helper.js +++ b/src/helpers/app-helper.js @@ -278,7 +278,6 @@ function isEmpty(obj) { return true; } - module.exports = { encryptText, decryptText, diff --git a/src/sequelize/managers/microservice-public-mode-manager.js b/src/sequelize/managers/microservice-public-mode-manager.js index 5d0561b69..e25e26968 100644 --- a/src/sequelize/managers/microservice-public-mode-manager.js +++ b/src/sequelize/managers/microservice-public-mode-manager.js @@ -13,12 +13,28 @@ const BaseManager = require('../managers/base-manager') const models = require('./../models'); -const MicroservicePublicMode = models.MicroservicePublicMode +const MicroservicePublicMode = models.MicroservicePublicMode; +const ConnectorPort = models.ConnectorPort; class MicroservicePublicModeManager extends BaseManager { getEntity() { return MicroservicePublicMode } + + findAllMicroservicePublicModesByConnectorId(connectorId, transaction) { + return MicroservicePublicMode.findAll({ + include: [ + { + model: ConnectorPort, + as: 'connectorPort', + required: true + } + ], + where: { + '$connectorPort.connector_id$': connectorId + } + }, {transaction: transaction}) + } } const instance = new MicroservicePublicModeManager() diff --git a/src/sequelize/managers/routing-manager.js b/src/sequelize/managers/routing-manager.js index 0ba42fd1e..df135f232 100644 --- a/src/sequelize/managers/routing-manager.js +++ b/src/sequelize/managers/routing-manager.js @@ -14,11 +14,27 @@ const BaseManager = require('./base-manager'); const models = require('./../models'); const Routing = models.Routing; +const ConnectorPort = models.ConnectorPort; class RoutingManager extends BaseManager { getEntity() { return Routing; } + + findAllRoutesByConnectorId(connectorId, transaction) { + return Routing.findAll({ + include: [ + { + model: ConnectorPort, + as: 'connectorPort', + required: true + } + ], + where: { + '$connectorPort.connector_id$': connectorId + } + }, {transaction: transaction}) + } } const instance = new RoutingManager(); diff --git a/src/services/connector-service.js b/src/services/connector-service.js index 2f1ceab98..0e510c53c 100644 --- a/src/services/connector-service.js +++ b/src/services/connector-service.js @@ -26,6 +26,7 @@ const Op = require('sequelize').Op; const Sequelize = require('sequelize'); const fs = require('fs'); const ConnectorPortManager = require('../sequelize/managers/connector-port-manager'); +const MicroserviceService = require('../services/microservices-service'); async function _createConnector(connectorData, transaction) { await Validator.validate(connectorData, Validator.schemas.connectorCreate); @@ -44,12 +45,15 @@ async function _createConnector(connectorData, transaction) { } async function _updateConnector(connectorData, transaction) { - await Validator.validate(connectorData, Validator.schemas.connectorUpdate) + await Validator.validate(connectorData, Validator.schemas.connectorUpdate); validateConnectorData(connectorData); const queryConnectorData = { publicIp: connectorData.publicIp }; - await ConnectorManager.update(queryConnectorData, connectorData, transaction) + await ConnectorManager.update(queryConnectorData, connectorData, transaction); + const connector = await ConnectorManager.findOne({name: connectorData.name}, transaction); + await MicroserviceService.updateRouteOverConnector(connector, transaction); + await MicroserviceService.updatePortMappingOverConnector(connector, transaction); } function validateConnectorData(connectorData) { diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 2bb619c45..03f130fc5 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -33,6 +33,7 @@ const CatalogService = require('../services/catalog-service'); const RoutingManager = require('../sequelize/managers/routing-manager'); const Op = require('sequelize').Op; const fs = require('fs'); +const _ = require('underscore'); async function _listMicroservices(flowId, user, isCLI, transaction) { if (!isCLI) { @@ -274,7 +275,7 @@ async function _deletePortMappings(microservice, user, transaction) { } } -async function _deleteNotRunningMicroservices(transaction) { +async function deleteNotRunningMicroservices(transaction) { const microservices = await MicroserviceManager.findAllWithStatuses(transaction); microservices .filter(microservice => microservice.delete) @@ -379,12 +380,49 @@ async function _createSimpleRoute(sourceMicroservice, destMicroservice, transact await _switchOnUpdateFlagsForMicroservicesInRoute(sourceMicroservice, destMicroservice, transaction) } +async function updateRouteOverConnector(connector, transaction) { + const routes = await RoutingManager.findAllRoutesByConnectorId(connector.id, transaction); + const networkMicroserviceUuids = _.flatten(_.map( + routes, route => [route.sourceNetworkMicroserviceUuid, route.destNetworkMicroserviceUuid] + )); + const microservices = await MicroserviceManager.findAll({uuid: networkMicroserviceUuids}, transaction); + + let cert; + if (!connector.devMode && connector.cert) { + cert = AppHelper.trimCertificate(fs.readFileSync(connector.cert, "utf-8")) + } + + for (const microservice of microservices) { + const msConfig = JSON.parse(microservice.config); + msConfig.host = connector.domain; + msConfig.cert = cert; + msConfig.devmode = connector.devMode; + const newConfig = { + config: JSON.stringify(msConfig), + rebuild: true + }; + await MicroserviceManager.update({ + uuid: microservice.uuid + }, newConfig, transaction); + } + + const onlyUnique = (value, index, self) => self.indexOf(value) === index; + const iofogUuids = microservices + .map(obj => obj.iofogUuid) + .filter(onlyUnique) + .filter(val => val !== null); + + for (const iofogUuid of iofogUuids) { + await ChangeTrackingService.update(iofogUuid, ChangeTrackingService.events.microserviceCommon, transaction); + } +} + async function _createRouteOverConnector(sourceMicroservice, destMicroservice, user, transaction) { //open comsat const justOpenedConnectorsPorts = await ConnectorService.openPortOnRandomConnector(false, transaction) - const ports = justOpenedConnectorsPorts.ports - const connector = justOpenedConnectorsPorts.connector + const ports = justOpenedConnectorsPorts.ports; + const connector = justOpenedConnectorsPorts.connector; const createConnectorPortData = { port1: ports.port1, @@ -398,9 +436,9 @@ async function _createRouteOverConnector(sourceMicroservice, destMicroservice, u connectorId: ports.connectorId, mappingId: ports.id }; - const connectorPort = await ConnectorPortManager.create(createConnectorPortData, transaction) + const connectorPort = await ConnectorPortManager.create(createConnectorPortData, transaction); - const networkCatalogItem = await CatalogService.getNetworkCatalogItem(transaction) + const networkCatalogItem = await CatalogService.getNetworkCatalogItem(transaction); let cert; if (!connector.devMode && connector.cert) { @@ -610,6 +648,39 @@ async function _createSimplePortMapping(microservice, portMappingData, user, tra await _switchOnUpdateFlagsForMicroservicesForPortMapping(microservice, false, transaction) } +async function updatePortMappingOverConnector(connector, transaction) { + const microservicePublicModes = await MicroservicePublicModeManager.findAllMicroservicePublicModesByConnectorId(connector.id, transaction); + const networkMicroserviceUuids = microservicePublicModes.map(obj => obj.networkMicroserviceUuid); + const microservices = await MicroserviceManager.findAll({uuid: networkMicroserviceUuids}, transaction); + + let cert; + if (!connector.devMode && connector.cert) { + cert = AppHelper.trimCertificate(fs.readFileSync(connector.cert, "utf-8")) + } + + for (const microservice of microservices) { + const msConfig = JSON.parse(microservice.config); + msConfig.host = connector.domain; + msConfig.cert = cert; + msConfig.devmode = connector.devMode; + const newConfig = { + config: JSON.stringify(msConfig), + rebuild: true + }; + await MicroserviceManager.update({uuid: microservice.uuid}, newConfig, transaction); + } + + const onlyUnique = (value, index, self) => self.indexOf(value) === index; + const iofogUuids = microservices + .map(obj => obj.iofogUuid) + .filter(onlyUnique) + .filter(val => val !== null); + + for (const iofogUuid of iofogUuids) { + await ChangeTrackingService.update(iofogUuid, ChangeTrackingService.events.microserviceCommon, transaction); + } +} + async function _createPortMappingOverConnector(microservice, portMappingData, user, transaction) { //open comsat const justOpenedConnectorsPorts = await ConnectorService.openPortOnRandomConnector(true, transaction) @@ -973,5 +1044,7 @@ module.exports = { deleteVolumeMapping: TransactionDecorator.generateTransaction(_deleteVolumeMapping), listVolumeMappings: TransactionDecorator.generateTransaction(_listVolumeMappings), getPhysicalConections: getPhysicalConections, - deleteNotRunningMicroservices: _deleteNotRunningMicroservices + deleteNotRunningMicroservices: deleteNotRunningMicroservices, + updateRouteOverConnector: updateRouteOverConnector, + updatePortMappingOverConnector: updatePortMappingOverConnector }; From c67de0c98ddaf0183a7e7fe87e2f969a727a369b Mon Sep 17 00:00:00 2001 From: Pankov Date: Fri, 28 Dec 2018 17:02:05 +0300 Subject: [PATCH 08/13] bug(fix) routes removal: added routes update on connector update (EWC-374) --- src/config/development.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/config/development.json b/src/config/development.json index 3757c3764..5dffbac92 100644 --- a/src/config/development.json +++ b/src/config/development.json @@ -4,10 +4,7 @@ }, "Server": { "Port": 51121, - "DevMode": true, - "SslCert": "/home/owner/Downloads/iofog_certs/iofog.org/ssl_certificate.crt", - "SslKey": "/home/owner/Downloads/iofog_certs/iofog.org/server-key.pem", - "IntermediateCert": "/home/owner/Downloads/iofog_certs/iofog.org/IntermediateCA.crt" + "DevMode": true }, "Email": { "ActivationEnabled": false, From 214295683d14b3ca74ca61a7564c124ed424a91a Mon Sep 17 00:00:00 2001 From: Pankov Date: Fri, 28 Dec 2018 17:57:00 +0300 Subject: [PATCH 09/13] bug(fix) tests (EWC-374) --- test/src/services/connector-service.test.js | 60 ++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/test/src/services/connector-service.test.js b/test/src/services/connector-service.test.js index 5467cc39f..e2351dd32 100644 --- a/test/src/services/connector-service.test.js +++ b/test/src/services/connector-service.test.js @@ -2,6 +2,7 @@ const {expect} = require('chai'); const sinon = require('sinon'); const ConnectorManager = require('../../../src/sequelize/managers/connector-manager'); +const MicroserviceService = require('../../../src/services/microservices-service'); const ConnectorService = require('../../../src/services/connector-service'); const Validator = require('../../../src/schemas'); const AppHelper = require('../../../src/helpers/app-helper'); @@ -167,12 +168,17 @@ describe('Connector Service', () => { devMode: true }; + const connector = {}; + def('subject', () => $subject.updateConnector(connectorData, transaction)); def('validatorResponse', () => Promise.resolve(true)); def('isValidDomainResponse', () => false); def('isValidPublicIpResponse', () => true); def('isValidPublicIpResponse2', () => true); def('updateConnectorResponse', () => Promise.resolve()); + def('findOneConnectorResponse', () => Promise.resolve(connector)); + def('updateRouteOverConnectorResponse', () => Promise.resolve()); + def('updatePortMappingOverConnectorResponse', () => Promise.resolve()); const queryConnectorData = { publicIp: connectorData.publicIp @@ -185,6 +191,9 @@ describe('Connector Service', () => { .onFirstCall().returns($isValidPublicIpResponse) .onSecondCall().returns($isValidPublicIpResponse2); $sandbox.stub(ConnectorManager, 'update').returns($updateConnectorResponse); + $sandbox.stub(ConnectorManager, 'findOne').returns($findOneConnectorResponse); + $sandbox.stub(MicroserviceService, 'updateRouteOverConnector').returns($updateRouteOverConnectorResponse); + $sandbox.stub(MicroserviceService, 'updatePortMappingOverConnector').returns($updatePortMappingOverConnectorResponse); }); it('calls Validator#validate() with correct args', async () => { @@ -257,8 +266,55 @@ describe('Connector Service', () => { }); context('when ConnectorManager#update() succeeds', () => { - it('fulfills the promise', () => { - return expect($subject).to.eventually.equal(undefined) + it('calls ConnectorManager#findOne() with correct args', async () => { + await $subject; + expect(ConnectorManager.findOne).to.have.been.calledWith({ + name: connectorData.name + }, transaction); + }); + + context('when ConnectorManager#findOne() fails', () => { + def('findOneConnectorResponse', () => Promise.reject(error)); + + it(`fails with ${error}`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when ConnectorManager#findOne() succeeds', () => { + it('calls MicroserviceService#updateRouteOverConnector() with correct args', async () => { + await $subject; + expect(MicroserviceService.updateRouteOverConnector).to.have.been.calledWith(connector, transaction); + }); + + context('when MicroserviceService#updateRouteOverConnector() fails', () => { + def('updateRouteOverConnectorResponse', () => Promise.reject(error)); + + it(`fails with ${error}`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when MicroserviceService#updateRouteOverConnector() succeeds', () => { + it('calls MicroserviceService#updatePortMappingOverConnector() with correct args', async () => { + await $subject; + expect(MicroserviceService.updatePortMappingOverConnector).to.have.been.calledWith(connector, transaction); + }); + + context('when MicroserviceService#updatePortMappingOverConnector() fails', () => { + def('updatePortMappingOverConnectorResponse', () => Promise.reject(error)); + + it(`fails with ${error}`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when MicroserviceService#updatePortMappingOverConnector() succeeds', () => { + it('fulfills the promise', () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + }) }) }) }) From 1308df13c959571c5cb65f3d1f362895b38bb39f Mon Sep 17 00:00:00 2001 From: Pankov Date: Sat, 29 Dec 2018 12:40:54 +0300 Subject: [PATCH 10/13] bug(fix) create connectorPortService (EWC-374) --- src/services/connector-port-service.js | 153 +++++++++++++++++++++++++ src/services/connector-service.js | 138 +--------------------- src/services/microservices-service.js | 10 +- 3 files changed, 159 insertions(+), 142 deletions(-) create mode 100644 src/services/connector-port-service.js diff --git a/src/services/connector-port-service.js b/src/services/connector-port-service.js new file mode 100644 index 000000000..7d8bb89ee --- /dev/null +++ b/src/services/connector-port-service.js @@ -0,0 +1,153 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2018 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +const ConnectorManager = require('../sequelize/managers/connector-manager'); +const https = require('https'); +const http = require('http'); +const constants = require('../helpers/constants'); +const logger = require('../logger'); +const qs = require('qs'); +const fs = require('fs'); + +async function openPortOnRandomConnector(isPublicAccess, transaction) { + let isConnectorPortOpen = false; + let ports = null; + let connector = null; + const maxAttempts = 5; + for (let i = 0; i < maxAttempts; i++) { + try { + connector = await _getRandomConnector(transaction); + ports = await _openPortsOnConnector(connector, isPublicAccess); + if (ports) { + isConnectorPortOpen = true; + break; + } + } catch (e) { + logger.warn(`Failed to open ports on Connector. Attempts ${i + 1}/${maxAttempts}`) + } + } + if (!isConnectorPortOpen) { + throw new Error('Not able to open port on remote Connector. Gave up after 5 attempts.') + } + ports.connectorId = connector.id; + return {ports: ports, connector: connector} +} + +async function _openPortsOnConnector(connector, isPublicAccess) { + let data = isPublicAccess + ? await qs.stringify({ + mapping: '{"type":"public","maxconnections":60,"heartbeatabsencethreshold":200000}' + }) + : await qs.stringify({ + mapping: '{"type":"private","maxconnectionsport1":1, "maxconnectionsport2":1, ' + + '"heartbeatabsencethresholdport1":200000, "heartbeatabsencethresholdport2":200000}' + }); + + let port = connector.devMode ? constants.CONNECTOR_HTTP_PORT : constants.CONNECTOR_HTTPS_PORT; + + let options = { + host: connector.domain, + port: port, + path: '/api/v2/mapping/add', + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Length': Buffer.byteLength(data) + } + }; + if (!connector.devMode && connector.cert && connector.isSelfSignedCert === true) { + const ca = fs.readFileSync(connector.cert); + options.ca = new Buffer.from(ca); + } + + const ports = await _makeRequest(connector, options, data); + return ports +} + +async function _getRandomConnector(transaction) { + const connectors = await ConnectorManager.findAll({}, transaction); + + if (connectors && connectors.length > 0) { + const randomNumber = Math.round((Math.random() * (connectors.length - 1))); + return connectors[randomNumber] + } else { + throw new Error('no connectors defined') + } +} + +async function closePortOnConnector(connector, ports) { + let data = qs.stringify({ + mappingid: ports.mappingId + }); + console.log(data); + + let port = connector.devMode ? constants.CONNECTOR_HTTP_PORT : constants.CONNECTOR_HTTPS_PORT; + + let options = { + host: connector.domain, + port: port, + path: '/api/v2/mapping/remove', + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Length': Buffer.byteLength(data) + } + }; + if (!connector.devMode && connector.cert && connector.isSelfSignedCert === true) { + const ca = fs.readFileSync(connector.cert); + options.ca = new Buffer.from(ca); + } + + + await _makeRequest(connector, options, data) +} + +async function _makeRequest(connector, options, data) { + return new Promise((resolve, reject) => { + let httpreq = (connector.devMode ? http : https).request(options, function (response) { + console.log(response.statusCode); + let output = ''; + response.setEncoding('utf8'); + + response.on('data', function (chunk) { + output += chunk; + }); + + response.on('end', function () { + let responseObj = JSON.parse(output); + console.log(responseObj); + if (responseObj.errormessage) { + return reject(new Error(responseObj.errormessage)); + } else { + return resolve(responseObj); + } + }); + }); + + httpreq.on('error', function (err) { + console.log(err); + if (err instanceof Error) + return reject(new Error(err.message)); + else + return reject(new Error(JSON.stringify(err))); + }); + + httpreq.write(data); + httpreq.end(); + }) +} + +module.exports = { + openPortOnRandomConnector: openPortOnRandomConnector, + closePortOnConnector: closePortOnConnector +}; diff --git a/src/services/connector-service.js b/src/services/connector-service.js index 76af4df6d..78fc7a8e8 100644 --- a/src/services/connector-service.js +++ b/src/services/connector-service.js @@ -17,13 +17,7 @@ const ConnectorManager = require('../sequelize/managers/connector-manager'); const Errors = require('../helpers/errors'); const ErrorMessages = require('../helpers/error-messages'); const AppHelper = require('../helpers/app-helper'); -const https = require('https'); -const http = require('http'); -const constants = require('../helpers/constants'); -const logger = require('../logger'); -const qs = require('qs'); const Op = require('sequelize').Op; -const fs = require('fs'); const ConnectorPortManager = require('../sequelize/managers/connector-port-manager'); const MicroserviceService = require('../services/microservices-service'); @@ -81,92 +75,6 @@ async function getConnectorList(transaction) { return await ConnectorManager.findAll({}, transaction) } -async function openPortOnRandomConnector(isPublicAccess, transaction) { - let isConnectorPortOpen = false; - let ports = null; - let connector = null; - const maxAttempts = 5; - for (let i = 0; i < maxAttempts; i++) { - try { - connector = await _getRandomConnector(transaction); - ports = await _openPortsOnConnector(connector, isPublicAccess); - if (ports) { - isConnectorPortOpen = true; - break; - } - } catch (e) { - logger.warn(`Failed to open ports on Connector. Attempts ${i + 1}/${maxAttempts}`) - } - } - if (!isConnectorPortOpen) { - throw new Error('Not able to open port on remote Connector. Gave up after 5 attempts.') - } - ports.connectorId = connector.id; - return {ports: ports, connector: connector} -} - -async function _makeRequest(connector, options, data) { - return new Promise((resolve, reject) => { - let httpreq = (connector.devMode ? http : https).request(options, function (response) { - console.log(response.statusCode); - let output = ''; - response.setEncoding('utf8'); - - response.on('data', function (chunk) { - output += chunk; - }); - - response.on('end', function () { - let responseObj = JSON.parse(output); - console.log(responseObj); - if (responseObj.errormessage) { - return reject(new Error(responseObj.errormessage)); - } else { - return resolve(responseObj); - } - }); - }); - - httpreq.on('error', function (err) { - console.log(err); - if (err instanceof Error) - return reject(new Error(err.message)); - else - return reject(new Error(JSON.stringify(err))); - }); - - httpreq.write(data); - httpreq.end(); - }) -} - -async function closePortOnConnector(connector, ports) { - let data = qs.stringify({ - mappingid: ports.mappingId - }); - console.log(data); - - let port = connector.devMode ? constants.CONNECTOR_HTTP_PORT : constants.CONNECTOR_HTTPS_PORT; - - let options = { - host: connector.domain, - port: port, - path: '/api/v2/mapping/remove', - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Content-Length': Buffer.byteLength(data) - } - }; - if (!connector.devMode && connector.cert && connector.isSelfSignedCert === true) { - const ca = fs.readFileSync(connector.cert); - options.ca = new Buffer.from(ca); - } - - - await _makeRequest(connector, options, data) -} - function _validateConnectorData(connectorData) { if (connectorData.domain) { const validDomain = AppHelper.isValidDomain(connectorData.domain) || AppHelper.isValidPublicIP(connectorData.domain); @@ -180,53 +88,9 @@ function _validateConnectorData(connectorData) { } } -async function _openPortsOnConnector(connector, isPublicAccess) { - let data = isPublicAccess - ? await qs.stringify({ - mapping: '{"type":"public","maxconnections":60,"heartbeatabsencethreshold":200000}' - }) - : await qs.stringify({ - mapping: '{"type":"private","maxconnectionsport1":1, "maxconnectionsport2":1, ' + - '"heartbeatabsencethresholdport1":200000, "heartbeatabsencethresholdport2":200000}' - }); - - let port = connector.devMode ? constants.CONNECTOR_HTTP_PORT : constants.CONNECTOR_HTTPS_PORT; - - let options = { - host: connector.domain, - port: port, - path: '/api/v2/mapping/add', - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Content-Length': Buffer.byteLength(data) - } - }; - if (!connector.devMode && connector.cert && connector.isSelfSignedCert === true) { - const ca = fs.readFileSync(connector.cert); - options.ca = new Buffer.from(ca); - } - - const ports = await _makeRequest(connector, options, data); - return ports -} - -async function _getRandomConnector(transaction) { - const connectors = await ConnectorManager.findAll({}, transaction); - - if (connectors && connectors.length > 0) { - const randomNumber = Math.round((Math.random() * (connectors.length - 1))); - return connectors[randomNumber] - } else { - throw new Error('no connectors defined') - } -} - module.exports = { createConnector: TransactionDecorator.generateTransaction(createConnector), updateConnector: TransactionDecorator.generateTransaction(updateConnector), deleteConnector: TransactionDecorator.generateTransaction(deleteConnector), - getConnectorList: TransactionDecorator.generateTransaction(getConnectorList), - openPortOnRandomConnector: openPortOnRandomConnector, - closePortOnConnector: closePortOnConnector + getConnectorList: TransactionDecorator.generateTransaction(getConnectorList) }; \ No newline at end of file diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index c99edb9bd..0297ad49a 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -22,12 +22,12 @@ const ConnectorManager = require('../sequelize/managers/connector-manager'); const ConnectorPortManager = require('../sequelize/managers/connector-port-manager'); const MicroservicePublicModeManager = require('../sequelize/managers/microservice-public-mode-manager'); const ChangeTrackingService = require('./change-tracking-service'); +const ConnectorPortService = require('./connector-port-service'); const IoFogService = require('../services/iofog-service'); const AppHelper = require('../helpers/app-helper'); const Errors = require('../helpers/errors'); const ErrorMessages = require('../helpers/error-messages'); const Validation = require('../schemas/index'); -const ConnectorService = require('../services/connector-service'); const FlowService = require('../services/flow-service'); const CatalogService = require('../services/catalog-service'); const RoutingManager = require('../sequelize/managers/routing-manager'); @@ -419,7 +419,7 @@ async function updateRouteOverConnector(connector, transaction) { async function _createRouteOverConnector(sourceMicroservice, destMicroservice, user, transaction) { //open connector - const justOpenedConnectorsPorts = await ConnectorService.openPortOnRandomConnector(false, transaction) + const justOpenedConnectorsPorts = await ConnectorPortService.openPortOnRandomConnector(false, transaction) const ports = justOpenedConnectorsPorts.ports; const connector = justOpenedConnectorsPorts.connector; @@ -580,7 +580,7 @@ async function _deleteRouteOverConnector(route, transaction) { const connector = await ConnectorManager.findOne({id: ports.connectorId}, transaction) try { - await ConnectorService.closePortOnConnector(connector, ports); + await ConnectorPortService.closePortOnConnector(connector, ports); } catch (e) { logger.warn(`Can't close ports pair ${ports.mappingId} on connector ${connector.publicIp}. Delete manually if necessary`); } @@ -683,7 +683,7 @@ async function updatePortMappingOverConnector(connector, transaction) { async function _createPortMappingOverConnector(microservice, portMappingData, user, transaction) { //open connector - const justOpenedConnectorsPorts = await ConnectorService.openPortOnRandomConnector(true, transaction) + const justOpenedConnectorsPorts = await ConnectorPortService.openPortOnRandomConnector(true, transaction) const ports = justOpenedConnectorsPorts.ports const connector = justOpenedConnectorsPorts.connector @@ -812,7 +812,7 @@ async function _deletePortMappingOverConnector(microservice, msPorts, user, tran const connector = await ConnectorManager.findOne({id: ports.connectorId}, transaction); try { - await ConnectorService.closePortOnConnector(connector, ports); + await ConnectorPortService.closePortOnConnector(connector, ports); } catch (e) { logger.warn(`Can't close ports pair ${ports.mappingId} on connector ${connector.publicIp}. Delete manually if necessary`); } From 7addbeab7dc28818936ab280259914814fd8a6cb Mon Sep 17 00:00:00 2001 From: Pankov Date: Sat, 29 Dec 2018 12:57:09 +0300 Subject: [PATCH 11/13] bug(fix) tests (EWC-374) --- .../services/connector-port-service.test.js | 61 +++++++++++++++++ test/src/services/connector-service.test.js | 65 ------------------- 2 files changed, 61 insertions(+), 65 deletions(-) create mode 100644 test/src/services/connector-port-service.test.js diff --git a/test/src/services/connector-port-service.test.js b/test/src/services/connector-port-service.test.js new file mode 100644 index 000000000..c2cb72e22 --- /dev/null +++ b/test/src/services/connector-port-service.test.js @@ -0,0 +1,61 @@ +// TODO finish with qs.stringify mock EWC-452 +// describe('.openPortOnRandomConnector()', () => { +// const transaction = {}; +// const error = 'Error!'; +// +// const isPublicAccess = false; +// +// const connectors = [ +// { +// id: 15 +// }, +// { +// id: 16 +// } +// ]; +// +// def('subject', () => $subject.openPortOnRandomConnector(isPublicAccess, transaction)); +// def('findConnectorsResponse', () => Promise.resolve(connectors)); +// def('stringifyResponse', () => Promise.resolve()); +// +// beforeEach(() => { +// $sandbox.stub(ConnectorManager, 'findAll').returns($findConnectorsResponse); +// $sandbox.stub(qs, 'stringify').returns($stringifyResponse); +// }); +// +// it('calls ConnectorManager#findAll() with correct args', async () => { +// await $subject; +// expect(ConnectorManager.findAll).to.have.been.calledWith({}, transaction); +// }); +// +// context('when ConnectorManager#findAll() fails', () => { +// def('findConnectorsResponse', () => Promise.reject(error)); +// +// it(`fails with ${error}`, () => { +// return expect($subject).to.be.rejectedWith(error) +// }) +// }); +// +// context('when ConnectorManager#findAll() succeeds', () => { +// it('calls qs#stringify() with correct args', async () => { +// await $subject; +// expect(qs.stringify).to.have.been.calledWith({ +// mapping: '{"type":"public","maxconnections":60,"heartbeatabsencethreshold":200000}' +// }); +// }); +// +// context('when qs#stringify() fails', () => { +// def('stringifyResponse', () => error); +// +// it(`fails with ${error}`, () => { +// return expect($subject).to.eventually.equal(undefined) +// }) +// }); +// +// context('when qs#stringify() succeeds', () => { +// it('fulfills the promise', () => { +// return expect($subject).to.eventually.equal(undefined) +// }) +// }) +// }) +// }); \ No newline at end of file diff --git a/test/src/services/connector-service.test.js b/test/src/services/connector-service.test.js index e2351dd32..2abf8b4fe 100644 --- a/test/src/services/connector-service.test.js +++ b/test/src/services/connector-service.test.js @@ -455,69 +455,4 @@ describe('Connector Service', () => { }) }) }); - - - // TODO finish with qs.stringify mock EWC-452 - // describe('.openPortOnRandomConnector()', () => { - // const transaction = {}; - // const error = 'Error!'; - // - // const isPublicAccess = false; - // - // const connectors = [ - // { - // id: 15 - // }, - // { - // id: 16 - // } - // ]; - // - // def('subject', () => $subject.openPortOnRandomConnector(isPublicAccess, transaction)); - // def('findConnectorsResponse', () => Promise.resolve(connectors)); - // def('stringifyResponse', () => Promise.resolve()); - // - // beforeEach(() => { - // $sandbox.stub(ConnectorManager, 'findAll').returns($findConnectorsResponse); - // $sandbox.stub(qs, 'stringify').returns($stringifyResponse); - // }); - // - // it('calls ConnectorManager#findAll() with correct args', async () => { - // await $subject; - // expect(ConnectorManager.findAll).to.have.been.calledWith({}, transaction); - // }); - // - // context('when ConnectorManager#findAll() fails', () => { - // def('findConnectorsResponse', () => Promise.reject(error)); - // - // it(`fails with ${error}`, () => { - // return expect($subject).to.be.rejectedWith(error) - // }) - // }); - // - // context('when ConnectorManager#findAll() succeeds', () => { - // it('calls qs#stringify() with correct args', async () => { - // await $subject; - // expect(qs.stringify).to.have.been.calledWith({ - // mapping: '{"type":"public","maxconnections":60,"heartbeatabsencethreshold":200000}' - // }); - // }); - // - // context('when qs#stringify() fails', () => { - // def('stringifyResponse', () => error); - // - // it(`fails with ${error}`, () => { - // return expect($subject).to.eventually.equal(undefined) - // }) - // }); - // - // context('when qs#stringify() succeeds', () => { - // it('fulfills the promise', () => { - // return expect($subject).to.eventually.equal(undefined) - // }) - // }) - // }) - // }); - - }); \ No newline at end of file From e78e61dfd4172d99b21dc10af62415b1b11ea35d Mon Sep 17 00:00:00 2001 From: Pankov Date: Sat, 29 Dec 2018 13:09:07 +0300 Subject: [PATCH 12/13] bug(fix) refactoring (EWC-374) --- src/services/microservices-service.js | 33 ++++----------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 0297ad49a..0ed9a1e97 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -385,6 +385,10 @@ async function updateRouteOverConnector(connector, transaction) { const networkMicroserviceUuids = _.flatten(_.map( routes, route => [route.sourceNetworkMicroserviceUuid, route.destNetworkMicroserviceUuid] )); + await _updateNetworkMicroserviceConfigs(networkMicroserviceUuids, connector, transaction); +} + +async function _updateNetworkMicroserviceConfigs(networkMicroserviceUuids, connector, transaction) { const microservices = await MicroserviceManager.findAll({uuid: networkMicroserviceUuids}, transaction); let cert; @@ -651,34 +655,7 @@ async function _createSimplePortMapping(microservice, portMappingData, user, tra async function updatePortMappingOverConnector(connector, transaction) { const microservicePublicModes = await MicroservicePublicModeManager.findAllMicroservicePublicModesByConnectorId(connector.id, transaction); const networkMicroserviceUuids = microservicePublicModes.map(obj => obj.networkMicroserviceUuid); - const microservices = await MicroserviceManager.findAll({uuid: networkMicroserviceUuids}, transaction); - - let cert; - if (!connector.devMode && connector.cert) { - cert = AppHelper.trimCertificate(fs.readFileSync(connector.cert, "utf-8")) - } - - for (const microservice of microservices) { - const msConfig = JSON.parse(microservice.config); - msConfig.host = connector.domain; - msConfig.cert = cert; - msConfig.devmode = connector.devMode; - const newConfig = { - config: JSON.stringify(msConfig), - rebuild: true - }; - await MicroserviceManager.update({uuid: microservice.uuid}, newConfig, transaction); - } - - const onlyUnique = (value, index, self) => self.indexOf(value) === index; - const iofogUuids = microservices - .map(obj => obj.iofogUuid) - .filter(onlyUnique) - .filter(val => val !== null); - - for (const iofogUuid of iofogUuids) { - await ChangeTrackingService.update(iofogUuid, ChangeTrackingService.events.microserviceCommon, transaction); - } + await _updateNetworkMicroserviceConfigs(networkMicroserviceUuids, connector, transaction); } async function _createPortMappingOverConnector(microservice, portMappingData, user, transaction) { From 59467be01da4fa2a587796d53ab5596a0302866a Mon Sep 17 00:00:00 2001 From: Pankov Date: Thu, 3 Jan 2019 12:55:11 +0300 Subject: [PATCH 13/13] bug(fix) usb hal info: fixed cli usb function (EWC-449) --- src/cli/iofog.js | 14 ++++++++++---- src/services/flow-service.js | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cli/iofog.js b/src/cli/iofog.js index 8749dbb83..4bc0c6fb3 100644 --- a/src/cli/iofog.js +++ b/src/cli/iofog.js @@ -359,8 +359,11 @@ async function _getHalHardwareInfo(obj) { logger.info("Parameters" + JSON.stringify(uuidObj)); - const info = await FogService.getHalHardwareInfo(uuidObj, {}, true); - logger.info(JSON.stringify(info, null, 2)); + const data = await FogService.getHalHardwareInfo(uuidObj, {}, true); + if (data.info) { + data.info = JSON.parse(data.info); + } + logger.info(JSON.stringify(data, null, 2)); logger.info('Hardware info has been retrieved successfully.') } @@ -371,8 +374,11 @@ async function _getHalUsbInfo(obj) { logger.info("Parameters" + JSON.stringify(uuidObj)); - const info = await FogService.getHalHardwareInfo(uuidObj, {}, true); - logger.info(JSON.stringify(info, null, 2)); + const data = await FogService.getHalUsbInfo(uuidObj, {}, true); + if (data.info) { + data.info = JSON.parse(data.info); + } + logger.info(JSON.stringify(data, null, 2)); logger.info('Usb info has been retrieved successfully.') } diff --git a/src/services/flow-service.js b/src/services/flow-service.js index 55c446850..a2a38ecdf 100644 --- a/src/services/flow-service.js +++ b/src/services/flow-service.js @@ -18,6 +18,7 @@ const Errors = require('../helpers/errors'); const ErrorMessages = require('../helpers/error-messages'); const Validation = require('../schemas'); const ChangeTrackingService = require('./change-tracking-service'); +const Op = require('sequelize').Op; const _createFlow = async function (flowData, user, isCLI, transaction) { await Validation.validate(flowData, Validation.schemas.flowCreate);