From b28006e49c70af0f5f8fcf3e356efc9f77c7ce7f Mon Sep 17 00:00:00 2001 From: dbusel Date: Mon, 28 Jan 2019 15:59:26 +0300 Subject: [PATCH 1/9] fix cli issues with /update/delete system microservices --- src/helpers/error-messages.js | 5 +- .../managers/microservice-manager.js | 46 +++++++++++++------ src/services/microservices-service.js | 26 +++++------ 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/helpers/error-messages.js b/src/helpers/error-messages.js index 54698334e..bb280e357 100644 --- a/src/helpers/error-messages.js +++ b/src/helpers/error-messages.js @@ -24,6 +24,8 @@ module.exports = { INVALID_IOFOG_UUID: "Invalid ioFog UUID '{}'", INVALID_USER_EMAIL: 'Invalid user email', INVALID_MICROSERVICE_UUID: "Invalid microservice UUID '{}'", + INVALID_SOURCE_MICROSERVICE_UUID: "Invalid source microservice UUID '{}'", + INVALID_DEST_MICROSERVICE_UUID: "Invalid destination microservice UUID '{}'", INVALID_MICROSERVICE_STRACE: "Strace data for this microservice not found", INVALID_VOLUME_MAPPING_UUID: "Invalid volume mapping id '{}'", ACTIVATION_CODE_NOT_FOUND: 'Activation code not found', @@ -77,5 +79,6 @@ module.exports = { INVALID_VERSION_COMMAND_ROLLBACK: 'Can\'t rollback version now. There are no backups on agent', CATALOG_ITEM_IMAGES_IS_FROZEN: 'Can\'t update catalog item images for item used for running microservices', SYSTEM_CATALOG_ITEM_UPDATE: 'Catalog item id {} is systemic and can\'t be updated', - SYSTEM_CATALOG_ITEM_DELETE: 'Catalog item id {} is systemic and can\'t be deleted' + SYSTEM_CATALOG_ITEM_DELETE: 'Catalog item id {} is systemic and can\'t be deleted', + SYSTEM_MICROSERVICE_UPDATE: 'Microservice id {} is systemic and iofogUuid parameter can\'t be updated', }; diff --git a/src/sequelize/managers/microservice-manager.js b/src/sequelize/managers/microservice-manager.js index 00d73f571..4bad07804 100644 --- a/src/sequelize/managers/microservice-manager.js +++ b/src/sequelize/managers/microservice-manager.js @@ -220,19 +220,6 @@ class MicroserviceManager extends BaseManager { }, {transaction: transaction}) } - findOneWithStatus(where, transaction) { - return Microservice.findOne({ - include: [ - { - model: MicroserviceStatus, - as: 'microserviceStatus', - required: true - } - ], - where: where - }, {transaction: transaction}) - } - findAllWithStatuses(where, transaction) { return Microservice.findAll({ include: [ @@ -288,6 +275,39 @@ class MicroserviceManager extends BaseManager { transaction: transaction }); } + + findOneWithCategory(where, transaction) { + return Microservice.findOne({ + include: [ + { + model: CatalogItem, + as: 'catalogItem', + required: true, + attributes: ['category'] + } + ], + where: where + }, {transaction: transaction}) + } + + findAllWithStatusesAndCategory(where, transaction) { + return Microservice.findAll({ + include: [ + { + model: MicroserviceStatus, + as: 'microserviceStatus', + required: true + }, + { + model: CatalogItem, + as: 'catalogItem', + required: true, + attributes: ['category'] + } + ], + where: where + }, {transaction: transaction}) + } } const instance = new MicroserviceManager(); diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 49ad32501..222adbc46 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -128,11 +128,9 @@ async function updateMicroservice(microserviceUuid, microserviceData, user, isCL userId: user.id }; - const config = _validateMicroserviceConfig(microserviceData.config); - const microserviceToUpdate = { name: microserviceData.name, - config: config, + config: microserviceData.config ? _validateMicroserviceConfig(microserviceData.config) : null, rebuild: microserviceData.rebuild, iofogUuid: microserviceData.iofogUuid, rootHostAccess: microserviceData.rootHostAccess, @@ -142,11 +140,15 @@ async function updateMicroservice(microserviceUuid, microserviceData, user, isCL const microserviceDataUpdate = AppHelper.deleteUndefinedFields(microserviceToUpdate); - const microservice = await MicroserviceManager.findOne(query, transaction); + const microservice = await MicroserviceManager.findOneWithCategory(query, transaction); if (!microservice) { throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid)) } + if (microservice.catalogItem.category === "SYSTEM") { + throw new Errors.ValidationError(AppHelper.formatMessage(ErrorMessages.SYSTEM_MICROSERVICE_UPDATE, microserviceUuid)) + } + if (microserviceDataUpdate.name) { const userId = isCLI ? microservice.userId : user.id; await _checkForDuplicateName(microserviceDataUpdate.name, {id: microserviceUuid}, userId, transaction); @@ -195,11 +197,6 @@ async function deleteMicroservice(microserviceUuid, microserviceData, user, isCL userId: user.id }; - 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) { await deleteMicroserviceWithRoutesAndPortMappings(microserviceUuid, transaction); } else { @@ -216,10 +213,11 @@ async function deleteMicroservice(microserviceUuid, microserviceData, user, isCL } async function deleteNotRunningMicroservices(transaction) { - const microservices = await MicroserviceManager.findAllWithStatuses(transaction); + const microservices = await MicroserviceManager.findAllWithStatusesAndCategory(transaction); microservices .filter(microservice => microservice.delete) .filter(microservice => microservice.microserviceStatus.status === MicroserviceStates.NOT_RUNNING) + .filter(microservice => microservice.catalogItem.category != "SYSTEM") .forEach(microservice => deleteMicroserviceWithRoutesAndPortMappings(microservice.uuid, transaction)); } @@ -230,7 +228,7 @@ async function createRoute(sourceMicroserviceUuid, destMicroserviceUuid, user, i const sourceMicroservice = await MicroserviceManager.findOne(sourceWhere, transaction); if (!sourceMicroservice) { - throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, sourceMicroserviceUuid)) + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_SOURCE_MICROSERVICE_UUID, sourceMicroserviceUuid)) } const destWhere = isCLI @@ -239,7 +237,7 @@ async function createRoute(sourceMicroserviceUuid, destMicroserviceUuid, user, i const destMicroservice = await MicroserviceManager.findOne(destWhere, transaction); if (!destMicroservice) { - throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, destMicroserviceUuid)) + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_DEST_MICROSERVICE_UUID, destMicroserviceUuid)) } if (!sourceMicroservice.iofogUuid || !destMicroservice.iofogUuid) { @@ -279,7 +277,7 @@ async function deleteRoute(sourceMicroserviceUuid, destMicroserviceUuid, user, i const sourceMicroservice = await MicroserviceManager.findOne(sourceWhere, transaction); if (!sourceMicroservice) { - throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, sourceMicroserviceUuid)) + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_SOURCE_MICROSERVICE_UUID, sourceMicroserviceUuid)) } const destWhere = isCLI @@ -288,7 +286,7 @@ async function deleteRoute(sourceMicroserviceUuid, destMicroserviceUuid, user, i const destMicroservice = await MicroserviceManager.findOne(destWhere, transaction); if (!destMicroservice) { - throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, destMicroserviceUuid)) + throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_DEST_MICROSERVICE_UUID, destMicroserviceUuid)) } const route = await RoutingManager.findOne({ From e5d74dacba8289b77ca45d050482a0b087acdaaa Mon Sep 17 00:00:00 2001 From: dbusel Date: Mon, 28 Jan 2019 17:09:59 +0300 Subject: [PATCH 2/9] fix according team solution --- src/helpers/error-messages.js | 4 +++- src/sequelize/managers/microservice-manager.js | 13 +++++++++++++ src/services/microservices-service.js | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/helpers/error-messages.js b/src/helpers/error-messages.js index 300ddc152..44fd1a071 100644 --- a/src/helpers/error-messages.js +++ b/src/helpers/error-messages.js @@ -80,5 +80,7 @@ module.exports = { CATALOG_ITEM_IMAGES_IS_FROZEN: 'Can\'t update catalog item images for item used for running microservices', CATALOG_UPDATE_NO_FIELDS: 'Add some parameters which should be updated.', CATALOG_UPDATE_REQUIRES_ID: "Parameter '--item-id' is missing, update requires Catalog id.", - SYSTEM_CATALOG_ITEM_UPDATE: 'Catalog item id {} is systemic and can\'t be updated' + SYSTEM_CATALOG_ITEM_UPDATE: 'Catalog item id {} is systemic and can\'t be updated', + SYSTEM_CATALOG_ITEM_DELETE: 'Catalog item id {} is systemic and can\'t be deleted', + SYSTEM_MICROSERVICE_UPDATE: 'Microservice id {} is systemic and can\'t be updated' }; diff --git a/src/sequelize/managers/microservice-manager.js b/src/sequelize/managers/microservice-manager.js index 4bad07804..491ec83bb 100644 --- a/src/sequelize/managers/microservice-manager.js +++ b/src/sequelize/managers/microservice-manager.js @@ -220,6 +220,19 @@ class MicroserviceManager extends BaseManager { }, {transaction: transaction}) } + findOneWithStatus(where, transaction) { + return Microservice.findOne({ + include: [ + { + model: MicroserviceStatus, + as: 'microserviceStatus', + required: true + } + ], + where: where + }, {transaction: transaction}) + } + findAllWithStatuses(where, transaction) { return Microservice.findAll({ include: [ diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index e2b771201..7beb5d44d 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -197,6 +197,11 @@ async function deleteMicroservice(microserviceUuid, microserviceData, user, isCL userId: user.id }; + 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) { await deleteMicroserviceWithRoutesAndPortMappings(microserviceUuid, transaction); } else { From 485eb8d0b1244f39849dfef36d75d4b26c014bbc Mon Sep 17 00:00:00 2001 From: dbusel <10116634+dbusel@users.noreply.github.com> Date: Mon, 28 Jan 2019 17:37:44 +0300 Subject: [PATCH 3/9] Update default.json --- src/config/default.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config/default.json b/src/config/default.json index d10f5fa4b..6e4990cda 100644 --- a/src/config/default.json +++ b/src/config/default.json @@ -16,9 +16,11 @@ }, "Settings": { "UserTokenExpirationIntervalSeconds": 3600, - "FogTokenExpirationIntervalSeconds": 3600 + "FogTokenExpirationIntervalSeconds": 3600, + "FogStatusUpdateIntervalSeconds": 120, + "FogStatusFrequencySeconds": 60 }, "Diagnostics": { "DiagnosticDir": "diagnostic" } -} \ No newline at end of file +} From b57f10527760ab99d6442258a80eb3441b46ff44 Mon Sep 17 00:00:00 2001 From: dbusel <10116634+dbusel@users.noreply.github.com> Date: Mon, 28 Jan 2019 17:38:53 +0300 Subject: [PATCH 4/9] Update development.json --- src/config/development.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config/development.json b/src/config/development.json index 5dffbac92..d7b36c289 100644 --- a/src/config/development.json +++ b/src/config/development.json @@ -16,7 +16,9 @@ }, "Settings": { "UserTokenExpirationIntervalSeconds": 360000, - "FogTokenExpirationIntervalSeconds": 3600000 + "FogTokenExpirationIntervalSeconds": 3600000, + "FogStatusUpdateIntervalSeconds": 120, + "FogStatusFrequencySeconds": 60 }, "Tunnel": { "Username": "username", @@ -29,4 +31,4 @@ "Diagnostics": { "DiagnosticDir": "diagnostic" } -} \ No newline at end of file +} From 6459adf2e0216efccc5349666c9dbb9643fe4b80 Mon Sep 17 00:00:00 2001 From: dbusel <10116634+dbusel@users.noreply.github.com> Date: Mon, 28 Jan 2019 17:39:34 +0300 Subject: [PATCH 5/9] Update production.json --- src/config/production.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config/production.json b/src/config/production.json index 6f7bc6ab8..ba72f7189 100644 --- a/src/config/production.json +++ b/src/config/production.json @@ -11,6 +11,8 @@ }, "Settings": { "UserTokenExpirationIntervalSeconds": 3600, - "FogTokenExpirationIntervalSeconds": 3600 + "FogTokenExpirationIntervalSeconds": 3600, + "FogStatusUpdateIntervalSeconds": 120, + "FogStatusFrequencySeconds": 60 } -} \ No newline at end of file +} From faadde4eae84f636c7a8fc3a02b6f7c2ef86e4e4 Mon Sep 17 00:00:00 2001 From: dbusel Date: Mon, 28 Jan 2019 17:45:49 +0300 Subject: [PATCH 6/9] fix remove of not running system microservices --- .../managers/microservice-manager.js | 19 ------------------- src/services/microservices-service.js | 3 +-- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/sequelize/managers/microservice-manager.js b/src/sequelize/managers/microservice-manager.js index 491ec83bb..cd5eee6ad 100644 --- a/src/sequelize/managers/microservice-manager.js +++ b/src/sequelize/managers/microservice-manager.js @@ -302,25 +302,6 @@ class MicroserviceManager extends BaseManager { where: where }, {transaction: transaction}) } - - findAllWithStatusesAndCategory(where, transaction) { - return Microservice.findAll({ - include: [ - { - model: MicroserviceStatus, - as: 'microserviceStatus', - required: true - }, - { - model: CatalogItem, - as: 'catalogItem', - required: true, - attributes: ['category'] - } - ], - where: where - }, {transaction: transaction}) - } } const instance = new MicroserviceManager(); diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 7beb5d44d..024b9b62c 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -218,11 +218,10 @@ async function deleteMicroservice(microserviceUuid, microserviceData, user, isCL } async function deleteNotRunningMicroservices(transaction) { - const microservices = await MicroserviceManager.findAllWithStatusesAndCategory(transaction); + const microservices = await MicroserviceManager.findAllWithStatuses(transaction); microservices .filter(microservice => microservice.delete) .filter(microservice => microservice.microserviceStatus.status === MicroserviceStates.NOT_RUNNING) - .filter(microservice => microservice.catalogItem.category != "SYSTEM") .forEach(microservice => deleteMicroserviceWithRoutesAndPortMappings(microservice.uuid, transaction)); } From 656416279fa42c03329536688f777cb748548a44 Mon Sep 17 00:00:00 2001 From: dbusel Date: Mon, 28 Jan 2019 17:49:13 +0300 Subject: [PATCH 7/9] fix formating after merge from develop --- src/config/default.json | 2 +- src/config/development.json | 2 +- src/config/production.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/default.json b/src/config/default.json index 6e4990cda..f18f594eb 100644 --- a/src/config/default.json +++ b/src/config/default.json @@ -23,4 +23,4 @@ "Diagnostics": { "DiagnosticDir": "diagnostic" } -} +} \ No newline at end of file diff --git a/src/config/development.json b/src/config/development.json index d7b36c289..1a21cf099 100644 --- a/src/config/development.json +++ b/src/config/development.json @@ -31,4 +31,4 @@ "Diagnostics": { "DiagnosticDir": "diagnostic" } -} +} \ No newline at end of file diff --git a/src/config/production.json b/src/config/production.json index ba72f7189..ef1359bc3 100644 --- a/src/config/production.json +++ b/src/config/production.json @@ -15,4 +15,4 @@ "FogStatusUpdateIntervalSeconds": 120, "FogStatusFrequencySeconds": 60 } -} +} \ No newline at end of file From 8af55199415e3bd6503a01fc975e20c788eeab30 Mon Sep 17 00:00:00 2001 From: dbusel Date: Mon, 28 Jan 2019 17:58:09 +0300 Subject: [PATCH 8/9] fix code review comment --- src/services/microservices-service.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 024b9b62c..b80976668 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -128,9 +128,11 @@ async function updateMicroservice(microserviceUuid, microserviceData, user, isCL userId: user.id }; + const config = _validateMicroserviceConfig(microserviceData.config); + const microserviceToUpdate = { name: microserviceData.name, - config: microserviceData.config ? _validateMicroserviceConfig(microserviceData.config) : null, + config: config, rebuild: microserviceData.rebuild, iofogUuid: microserviceData.iofogUuid, rootHostAccess: microserviceData.rootHostAccess, From d8ce7989f010d7f23ac92e5361681c034f340689 Mon Sep 17 00:00:00 2001 From: dbusel Date: Mon, 28 Jan 2019 18:01:29 +0300 Subject: [PATCH 9/9] fix code review comment --- src/helpers/error-messages.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/error-messages.js b/src/helpers/error-messages.js index 44fd1a071..48b1094c9 100644 --- a/src/helpers/error-messages.js +++ b/src/helpers/error-messages.js @@ -80,7 +80,7 @@ module.exports = { CATALOG_ITEM_IMAGES_IS_FROZEN: 'Can\'t update catalog item images for item used for running microservices', CATALOG_UPDATE_NO_FIELDS: 'Add some parameters which should be updated.', CATALOG_UPDATE_REQUIRES_ID: "Parameter '--item-id' is missing, update requires Catalog id.", - SYSTEM_CATALOG_ITEM_UPDATE: 'Catalog item id {} is systemic and can\'t be updated', - SYSTEM_CATALOG_ITEM_DELETE: 'Catalog item id {} is systemic and can\'t be deleted', - SYSTEM_MICROSERVICE_UPDATE: 'Microservice id {} is systemic and can\'t be updated' + SYSTEM_CATALOG_ITEM_UPDATE: 'Catalog item id {} is system and can\'t be updated', + SYSTEM_CATALOG_ITEM_DELETE: 'Catalog item id {} is system and can\'t be deleted', + SYSTEM_MICROSERVICE_UPDATE: 'Microservice uuid {} is system and can\'t be updated' };