Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epankou/feature microservice removal ewc 306 #312

Merged
merged 10 commits into from
Nov 8, 2018
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ $ iofog-controller catalog <*command*> <*options*> <br>
"config": "string",<br>
"catalogItemId": 0,<br>
"flowId": 0,<br>
"ioFogNodeId": "string",<br>
"iofogUuid": "string",<br>
"rootHostAccess": true,<br>
"logLimit": 0,<br>
"volumeMappings": [<br>
Expand Down Expand Up @@ -558,7 +558,7 @@ $ iofog-controller catalog <*command*> <*options*> <br>
"name": "string",<br>
"config": "string",<br>
"rebuild": true,<br>
"ioFogNodeId": "string",<br>
"iofogUuid": "string",<br>
"rootHostAccess": true,<br>
"logLimit": 0,<br>
"volumeMappings": [<br>
Expand Down
4 changes: 2 additions & 2 deletions specs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2907,7 +2907,7 @@ definitions:
type: integer
flowId:
type: integer
ioFogNodeId:
iofogUuid:
type: string
rootHostAccess:
type: boolean
Expand All @@ -2934,7 +2934,7 @@ definitions:
type: string
rebuild:
type: boolean
ioFogNodeId:
iofogUuid:
type: string
rootHostAccess:
type: boolean
Expand Down
8 changes: 4 additions & 4 deletions src/cli/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const JSON_SCHEMA_ADD = AppHelper.stringifyCliJsonSchema(
config: "string",
catalogItemId: 0,
flowId: 0,
ioFogNodeId: "string",
iofogUuid: "string",
rootHostAccess: true,
logLimit: 0,
volumeMappings: [
Expand Down Expand Up @@ -54,7 +54,7 @@ const JSON_SCHEMA_UPDATE = AppHelper.stringifyCliJsonSchema(
name: "string",
config: "string",
rebuild: true,
ioFogNodeId: "string",
iofogUuid: "string",
rootHostAccess: true,
logLimit: 0,
volumeMappings: [
Expand Down Expand Up @@ -370,7 +370,7 @@ const _updateMicroserviceObject = function (obj) {
const microserviceObj = {
name: obj.name,
config: obj.config,
ioFogNodeId: obj.iofogId,
iofogUuid: obj.iofogId,
rootHostAccess: AppHelper.validateBooleanCliOptions(obj.rootEnable, obj.rootDisable),
logLimit: obj.logLimit,
rebuild: obj.rebuild
Expand All @@ -389,7 +389,7 @@ const _createMicroserviceObject = function (obj) {
config: obj.config,
catalogItemId: parseInt(obj.catalogId),
flowId: parseInt(obj.flowId),
ioFogNodeId: obj.iofogId,
iofogUuid: obj.iofogId,
rootHostAccess: AppHelper.validateBooleanCliOptions(obj.rootEnable, obj.rootDisable),
logLimit: obj.logLimit,
routes: obj.routes
Expand Down
9 changes: 9 additions & 0 deletions src/enums/microservice-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const microserviceState = {
NOT_RUNNING: 'NOT_RUNNING',
RUNNING: 'RUNNING',
RESTARTING: 'RESTARTING',
STUCK_IN_RESTART: 'STUCK_IN_RESTART',
}

module.exports = microserviceState;

4 changes: 2 additions & 2 deletions src/schemas/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const microserviceCreate = {
"config": {"type": "string"},
"catalogItemId": {"type": "integer"},
"flowId": {"type": "integer"},
"ioFogNodeId": {"type": "string"},
"iofogUuid": {"type": "string"},
"rootHostAccess": {"type": "boolean"},
"logSize": {"type": "integer"},
"imageSnapshot": {"type": "string"},
Expand All @@ -36,7 +36,7 @@ const microserviceUpdate = {
},
"config": {"type": "string"},
"rebuild": {"type": "boolean"},
"ioFogNodeId": {"type": "string"},
"iofogUuid": {"type": "string"},
"rootHostAccess": {"type": "boolean"},
"logSize": {"type": "integer", "minimum" : 0},
"volumeMappings": {
Expand Down
26 changes: 26 additions & 0 deletions src/sequelize/managers/microservice-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Flow = models.Flow;
const User = models.User;
const Routing = models.Routing;
const Registry = models.Registry;
const MicroserviceStatus = models.MicroserviceStatus;

class MicroserviceManager extends BaseManager {
getEntity() {
Expand Down Expand Up @@ -194,6 +195,31 @@ class MicroserviceManager extends BaseManager {
}, {transaction: transaction})
}

findOneWithStatus(where, transaction) {
return Microservice.findOne({
include: [
{
model: MicroserviceStatus,
as: 'microserviceStatus',
required: true
}
],
where: where
}, {transaction: transaction})
}

findAllWithStatuses(transaction) {
return Microservice.findAll({
include: [
{
model: MicroserviceStatus,
as: 'microserviceStatus',
required: true
}
]
}, {transaction: transaction})
}

findMicroserviceOnGet(where, transaction) {
return Microservice.findOne({
include: [
Expand Down
25 changes: 25 additions & 0 deletions src/sequelize/managers/microservice-status-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* *******************************************************************************
* * Copyright (c) 2018 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
* * http://www.eclipse.org/legal/epl-2.0
* *
* * SPDX-License-Identifier: EPL-2.0
* *******************************************************************************
*
*/

const BaseManager = require('../managers/base-manager')
const models = require('./../models');
const MicroserviceStatus = models.MicroserviceStatus;

class MicroserviceStatusManager extends BaseManager {
getEntity() {
return MicroserviceStatus;
}
}

const instance = new MicroserviceStatusManager();
module.exports = instance;
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
type: Sequelize.TEXT,
field: 'image_snapshot'
},
deleteWithCleanUp: {
deleteWithCleanup: {
type: Sequelize.BOOLEAN,
field: 'delete_with_cleanup'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('MicroserviceStatuses',
'operating_duration',
Sequelize.BIGINT
)
.then(() => queryInterface.addColumn('MicroserviceStatuses',
'start_time',
Sequelize.BIGINT));
},

down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('MicroserviceStatuses', 'operating_duration')
.then(() => queryInterface.removeColumn('MicroserviceStatuses', 'start_time'));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('Microservices',
'delete',
Sequelize.BOOLEAN
)
},

down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('Microservices', 'delete')
}
};
14 changes: 12 additions & 2 deletions src/sequelize/models/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ module.exports = (sequelize, DataTypes) => {
field: 'image_snapshot',
defaultValue: ""
},
deleteWithCleanUp: {
delete: {
type: DataTypes.BOOLEAN,
field: 'delete',
defaultValue: false
},
deleteWithCleanup: {
type: DataTypes.BOOLEAN,
field: 'delete_with_cleanup',
defaultValue: false
Expand Down Expand Up @@ -112,7 +117,12 @@ module.exports = (sequelize, DataTypes) => {
Microservice.hasMany(models.Routing, {
foreignKey: 'source_microservice_uuid',
as: 'routes'
})
});

Microservice.hasOne(models.MicroserviceStatus, {
foreignKey: 'microservice_uuid',
as: 'microserviceStatus'
});
};
return Microservice;
};
13 changes: 12 additions & 1 deletion src/sequelize/models/microservicestatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ module.exports = (sequelize, DataTypes) => {
},
status: {
type: DataTypes.TEXT,
defaultValue: 'NOT_RUNNING',
field: 'status'
},
operatingDuration: {
type: DataTypes.BIGINT,
defaultValue: 0,
field: 'operating_duration'
},
startTime: {
type: DataTypes.BIGINT,
defaultValue: 0,
field: 'start_time'
},
cpuUsage: {
type: DataTypes.FLOAT,
defaultValue: 0.000,
Expand All @@ -24,6 +35,7 @@ module.exports = (sequelize, DataTypes) => {
},
containerId: {
type: DataTypes.TEXT,
defaultValue: '',
field: 'container_id'
}
}, {
Expand All @@ -32,7 +44,6 @@ module.exports = (sequelize, DataTypes) => {
underscored: true
});
MicroserviceStatus.associate = function (models) {

MicroserviceStatus.belongsTo(models.Microservice, {
foreignKey: {
name: 'microserviceUuid',
Expand Down
34 changes: 29 additions & 5 deletions src/services/agent-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const ChangeTrackingManager = require('../sequelize/managers/change-tracking-man
const FogVersionCommandManager = require('../sequelize/managers/iofog-version-command-manager');
const StraceManager = require('../sequelize/managers/strace-manager');
const RegistryManager = require('../sequelize/managers/registry-manager');
const MicroserviceStatusManager = require('../sequelize/managers/microservice-status-manager')
const Validator = require('../schemas');
const Errors = require('../helpers/errors');
const AppHelper = require('../helpers/app-helper');
Expand Down Expand Up @@ -174,7 +175,7 @@ const getAgentConfigChanges = async function (fog, transaction) {
const updateAgentStatus = async function (agentStatus, fog, transaction) {
await Validator.validate(agentStatus, Validator.schemas.updateAgentStatus);

let update = {
let fogStatus = {
daemonStatus: agentStatus.daemonStatus,
daemonOperatingDuration: agentStatus.daemonOperatingDuration,
daemonLastStart: agentStatus.daemonLastStart,
Expand All @@ -184,7 +185,6 @@ const updateAgentStatus = async function (agentStatus, fog, transaction) {
memoryViolation: agentStatus.memoryViolation,
diskViolation: agentStatus.diskViolation,
cpuViolation: agentStatus.cpuViolation,
microserviceStatus: agentStatus.microserviceStatus,
repositoryCount: agentStatus.repositoryCount,
repositoryStatus: agentStatus.repositoryStatus,
systemTime: agentStatus.systemTime,
Expand All @@ -199,11 +199,34 @@ const updateAgentStatus = async function (agentStatus, fog, transaction) {
isReadyToUpgrade: agentStatus.isReadyToUpgrade,
isReadyToRollback: agentStatus.isReadyToRollback
};
update = AppHelper.deleteUndefinedFields(update);

fogStatus = AppHelper.deleteUndefinedFields(fogStatus);

await FogManager.update({
uuid: fog.uuid
}, update, transaction);
}, fogStatus, transaction);

await _updateMicroserviceStatuses(JSON.parse(agentStatus.microserviceStatus), transaction);
await MicroserviceService.deleteNotRunningMicroservices(transaction);
};


const _updateMicroserviceStatuses = async function (microserviceStatus, transaction) {
for (status of microserviceStatus) {
let microserviceStatus = {
containerId: status.containerId,
status: status.status,
startTime: status.startTime,
operatingDuration: status.operatingDuration,
cpuUsage: status.cpuUsage,
memoryUsage: status.memoryUsage
};
microserviceStatus = AppHelper.deleteUndefinedFields(microserviceStatus);

await MicroserviceStatusManager.update({
microserviceUuid: status.id
}, microserviceStatus, transaction);
}
};

const getAgentMicroservices = async function (fog, transaction) {
Expand All @@ -230,7 +253,8 @@ const getAgentMicroservices = async function (fog, transaction) {
portMappings: microservice.ports,
volumeMappings: microservice.volumeMappings,
imageSnapshot: microservice.imageSnapshot,
deleteWithCleanUp: microservice.deleteWithCleanUp,
delete: microservice.delete,
deleteWithCleanup: microservice.deleteWithCleanup,
routes: routes
};

Expand Down
Loading