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
6 changes: 3 additions & 3 deletions specs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -2874,7 +2874,7 @@ definitions:
type: string
rootHostAccess:
type: boolean
logLimit:
logSize:
type: number
volumeMappings:
type: array
Expand Down
7 changes: 4 additions & 3 deletions src/schemas/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const microserviceCreate = {
"type": "array",
"items": {"type": "string"}}
},
"required": ["name"]
"required": ["name", "flowId", "catalogItemId"]
};

const microserviceUpdate = {
Expand All @@ -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"}
Expand Down Expand Up @@ -75,7 +75,8 @@ const volumeMappings = {
"hostDestination": {"type": "string"},
"containerDestination": {"type": "string"},
"accessMode": {"type": "string"}
}
},
"required": ["hostDestination", "containerDestination", "accessMode"]
};

module.exports = {
Expand Down
51 changes: 30 additions & 21 deletions src/services/microservices-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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)
}
};
Expand All @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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({
Expand All @@ -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) {
Expand All @@ -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)
}
};
Expand Down Expand Up @@ -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
};