Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/helpers/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ module.exports = {
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'
SYSTEM_MICROSERVICE_UPDATE: 'Microservice uuid {} is system and can\'t be updated',
SYSTEM_MICROSERVICE_DELETE: 'Microservice uuid {} is system and can\'t be deleted'
};
12 changes: 9 additions & 3 deletions src/sequelize/managers/microservice-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,19 @@ class MicroserviceManager extends BaseManager {
}, {transaction: transaction})
}

findOneWithStatus(where, transaction) {
findOneWithStatusAndCategory(where, transaction) {
return Microservice.findOne({
include: [
{
model: MicroserviceStatus,
as: 'microserviceStatus',
required: true
required: false
},
{
model: CatalogItem,
as: 'catalogItem',
required: true,
attributes: ['category']
}
],
where: where
Expand All @@ -239,7 +245,7 @@ class MicroserviceManager extends BaseManager {
{
model: MicroserviceStatus,
as: 'microserviceStatus',
required: true
required: false
}
],
where: where
Expand Down
7 changes: 5 additions & 2 deletions src/services/microservices-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@ async function deleteMicroservice(microserviceUuid, microserviceData, user, isCL
userId: user.id
};

const microservice = await MicroserviceManager.findOneWithStatus(where, transaction);
const microservice = await MicroserviceManager.findOneWithStatusAndCategory(where, transaction);
if (!microservice) {
throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid));
}
if (!isCLI && microservice.catalogItem.category === "SYSTEM") {
throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.SYSTEM_MICROSERVICE_DELETE, microserviceUuid))
}

if (microservice.microserviceStatus.status === MicroserviceStates.NOT_RUNNING) {
if (!microservice.microserviceStatus || microservice.microserviceStatus.status === MicroserviceStates.NOT_RUNNING) {
await deleteMicroserviceWithRoutesAndPortMappings(microserviceUuid, transaction);
} else {
await MicroserviceManager.update({
Expand Down
2 changes: 1 addition & 1 deletion test/src/services/microservices-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ describe('Microservices Service', () => {
// def('updateChangeTrackingResponse', () => Promise.resolve());
//
// beforeEach(() => {
// $sandbox.stub(MicroserviceManager, 'findOneWithStatus').returns($findMicroserviceResponse);
// $sandbox.stub(MicroserviceManager, 'findOneWithStatusAndCategory').returns($findMicroserviceResponse);
// $sandbox.stub(MicroservicePortManager, 'findAll').returns($findMicroservicePortResponse);
// $sandbox.stub(MicroservicePortManager, 'delete').returns($deleteMicroservicePortResponse);
// $sandbox.stub(MicroserviceManager, 'update').returns($updateMicroserviceResponse);
Expand Down