diff --git a/specs/swagger.yml b/specs/swagger.yml index 06ba3f0b9..2ff37c248 100644 --- a/specs/swagger.yml +++ b/specs/swagger.yml @@ -1222,8 +1222,8 @@ paths: required: true type: string - in: body - name: NetMicroserviceInfo - description: New Microserviced Info + name: NewMicroserviceInfo + description: New Microservice Info required: true schema: $ref: '#/definitions/NewMicroserviceRequest' @@ -2874,7 +2874,7 @@ definitions: type: string rootHostAccess: type: boolean - logLimit: + logSize: type: number volumeMappings: type: array diff --git a/src/schemas/microservice.js b/src/schemas/microservice.js index 20012ed3d..05de1f720 100644 --- a/src/schemas/microservice.js +++ b/src/schemas/microservice.js @@ -23,7 +23,7 @@ const microserviceCreate = { "type": "array", "items": {"type": "string"}} }, - "required": ["name"] + "required": ["name", "flowId", "catalogItemId"] }; const microserviceUpdate = { @@ -38,7 +38,7 @@ const microserviceUpdate = { "rebuild": {"type": "boolean"}, "ioFogNodeId": {"type": "string"}, "rootHostAccess": {"type": "boolean"}, - "logSize": {"type": "integer"}, + "logSize": {"type": "integer", "minimum" : 0}, "volumeMappings": { "type": "array", "items": {"$ref": "/volumeMappings"} @@ -75,7 +75,8 @@ const volumeMappings = { "hostDestination": {"type": "string"}, "containerDestination": {"type": "string"}, "accessMode": {"type": "string"} - } + }, + "required": ["hostDestination", "containerDestination", "accessMode"] }; module.exports = { diff --git a/src/services/microservices-service.js b/src/services/microservices-service.js index 0bd39cdee..31c1bd7ad 100644 --- a/src/services/microservices-service.js +++ b/src/services/microservices-service.js @@ -68,11 +68,11 @@ const _createMicroserviceOnFog = async function (microserviceData, user, isCLI, await _createVolumeMappings(microserviceData.volumeMappings, microservice.uuid, transaction); } - if (microserviceData.routes){ + if (microserviceData.routes) { await _createRoutes(microserviceData.routes, microservice.uuid, user, transaction); } - if(microserviceData.ioFogNodeId) { + if (microserviceData.ioFogNodeId) { await _updateChangeTracking(false, microservice.uuid, microserviceData.ioFogNodeId, user, isCLI, transaction); } @@ -97,7 +97,7 @@ const _createMicroservice = async function (microserviceData, user, isCLI, trans newMicroservice = AppHelper.deleteUndefinedFields(newMicroservice); - await _checkForDuplicateName(newMicroservice.name, {}, transaction); + await _checkForDuplicateName(newMicroservice.name, {}, user.id, transaction); //validate catalog item await CatalogService.getCatalogItem(newMicroservice.catalogItemId, user, isCLI, transaction); @@ -134,7 +134,7 @@ const _createVolumeMappings = async function (volumeMappings, microserviceUuid, }; const _createRoutes = async function (routes, microserviceUuid, user, transaction) { - for (let route of routes){ + for (let route of routes) { await _createRoute(microserviceUuid, route, user, transaction) } }; @@ -160,9 +160,9 @@ const _updateMicroservice = async function (microserviceUuid, microserviceData, updatedBy: user.id }, transaction); - if (microserviceDataUpdate.name) { - await _checkForDuplicateName(microserviceDataUpdate.name, {id: microserviceUuid}, transaction); - } + if (microserviceDataUpdate.name) { + await _checkForDuplicateName(microserviceDataUpdate.name, {id: microserviceUuid}, user.id, transaction); + } //validate fog node if (microserviceDataUpdate.iofogUuid) { @@ -177,7 +177,7 @@ const _updateMicroservice = async function (microserviceUuid, microserviceData, await _updateVolumeMappings(microserviceDataUpdate.volumeMappings, microserviceUuid, transaction); } - if (microserviceDataUpdate.ioFogNodeId){ + if (microserviceDataUpdate.ioFogNodeId) { await _deleteRoutes(microserviceData.routes, microserviceUuid, transaction); await _createRoutes(microserviceData.routes, microserviceUuid, user, transaction); await _updateChangeTracking(false, microserviceUuid, microserviceDataUpdate.ioFogNodeId, user, isCLI, transaction) @@ -206,13 +206,13 @@ const _updateChangeTracking = async function (configUpdated, microserviceUuid, f }; const _deleteMicroservice = async function (microserviceUuid, deleteWithCleanUp, user, isCLI, transaction) { - if (deleteWithCleanUp){ + if (deleteWithCleanUp) { return await MicroserviceManager.update({ - uuid: microserviceUuid - }, - { - deleteWithCleanUp: deleteWithCleanUp - }, transaction); + uuid: microserviceUuid + }, + { + deleteWithCleanUp: deleteWithCleanUp + }, transaction); } const microservice = await MicroserviceManager.findOne({ @@ -230,11 +230,20 @@ const _deleteMicroservice = async function (microserviceUuid, deleteWithCleanUp, await _updateChangeTracking(false, microserviceUuid, microservice.ioFogNodeId, user, isCLI, transaction) }; -const _checkForDuplicateName = async function (name, item, transaction) { +const _checkForDuplicateName = async function (name, item, userId, transaction) { if (name) { const where = item.id - ? {name: name, uuid: {[Op.ne]: item.id}} - : {name: name}; + ? + { + name: name, + uuid: {[Op.ne]: item.id}, + updatedBy: userId + } + : + { + name: name, + updatedBy: userId + }; const result = await MicroserviceManager.findOne(where, transaction); if (result) { @@ -243,8 +252,8 @@ const _checkForDuplicateName = async function (name, item, transaction) { } }; -const _deleteRoutes = async function(routes, microserviceUuid, user, transaction){ - for (let route of routes){ +const _deleteRoutes = async function (routes, microserviceUuid, user, transaction) { + for (let route of routes) { await _deleteRoute(microserviceUuid, route, user, transaction) } }; @@ -793,11 +802,11 @@ module.exports = { getMicroserviceWithTransaction: TransactionDecorator.generateTransaction(_getMicroservice), updateMicroserviceWithTransaction: TransactionDecorator.generateTransaction(_updateMicroservice), deleteMicroserviceWithTransaction: TransactionDecorator.generateTransaction(_deleteMicroservice), - createRouteWithTransaction : TransactionDecorator.generateTransaction(_createRoute), + createRouteWithTransaction: TransactionDecorator.generateTransaction(_createRoute), deleteRouteWithTransaction: TransactionDecorator.generateTransaction(_deleteRoute), createPortMappingWithTransaction: TransactionDecorator.generateTransaction(_createPortMapping), getMicroservicePortMappingListWithTransaction: TransactionDecorator.generateTransaction(_getPortMappingList), deletePortMappingWithTransaction: TransactionDecorator.generateTransaction(_deletePortMapping), getPhysicalConections: getPhysicalConections, - getListMicroservices: _listMicroservices + getListMicroservices: _listMicroservices };