Skip to content
9 changes: 6 additions & 3 deletions src/helpers/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -76,8 +78,9 @@ module.exports = {
INVALID_VERSION_COMMAND_UPGRADE: 'Can\'t upgrade version now. Latest is already installed',
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',
CATALOG_UPDATE_NO_FIELDS: 'Add some parameters which should be updated.',
CATALOG_UPDATE_REQUIRES_ID: "Parameter '--item-id' is missing, update requires Catalog id."
CATALOG_UPDATE_REQUIRES_ID: "Parameter '--item-id' is missing, update requires Catalog id.",
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'
};
14 changes: 14 additions & 0 deletions src/sequelize/managers/microservice-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ 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})
}
}

const instance = new MicroserviceManager();
Expand Down
14 changes: 9 additions & 5 deletions src/services/microservices-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,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);
Expand Down Expand Up @@ -230,7 +234,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
Expand All @@ -239,7 +243,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) {
Expand Down Expand Up @@ -279,7 +283,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
Expand All @@ -288,7 +292,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({
Expand Down