Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
06aa871
microservice validation refactoring
Oct 25, 2018
064e9f8
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
6734bf1
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
93622c1
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
eef356d
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
0b7d665
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
248d773
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
c0755e4
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
a71671e
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 25, 2018
1fce81b
cli microservice wip
Oct 26, 2018
f491bb3
cli microservice wip
Oct 26, 2018
16d589f
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 26, 2018
e732b3e
microservices cli wip
Oct 26, 2018
8c295bf
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 26, 2018
d32b759
cli microservices final
Oct 26, 2018
24f4c2b
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 26, 2018
ff17ccf
microservice cli refactoring
Oct 29, 2018
e27899f
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 29, 2018
3219642
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 29, 2018
f662aa9
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 29, 2018
dc9621a
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 29, 2018
231b5ff
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 29, 2018
b3b1547
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 29, 2018
17b8688
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 29, 2018
5ce12d8
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 30, 2018
7dc67a3
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 30, 2018
308c83c
Merge branch 'new-fog-controller' of https://github.com/ioFog/FogCont…
Oct 30, 2018
2fb2215
Merge branch 'develop' of https://github.com/ioFog/FogController into…
Oct 30, 2018
0514066
Merge branch 'develop' of https://github.com/ioFog/FogController into…
Oct 30, 2018
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
179 changes: 90 additions & 89 deletions src/cli/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Microservice extends BaseCLIHandler {
},
{
name: 'microservice-id', alias: 'i', type: String, description: 'Microservice ID',
group: [constants.CMD_UPDATE, constants.CMD_REMOVE, constants.CMD_INFO, constants.CMD_PORT_MAPPING]
group: [constants.CMD_UPDATE, constants.CMD_REMOVE, constants.CMD_INFO, constants.CMD_PORT_MAPPING_CREATE,
constants.CMD_PORT_MAPPING_REMOVE, constants.CMD_PORT_MAPPING_LIST]
},
{
name: 'name', alias: 'n', type: String, description: 'Microservice name',
Expand Down Expand Up @@ -123,28 +124,20 @@ class Microservice extends BaseCLIHandler {
group: [constants.CMD_ADD]
},
{
name: 'routes', alias: 't', type: String, description: 'Microservice route(s) (receiving microservices)', multiple: true,
group: [constants.CMD_ADD]
},
{
name: 'add', alias: 'a', type: String, description: 'Add new route(s)',
group: [constants.CMD_ROUTE]
},
{
name: 'remove', alias: 'm', type: String, description: 'Delete existing route(s)',
group: [constants.CMD_ROUTE]
name: 'mapping', alias: 'P', type: String, description: 'Container port mapping',
group: [constants.CMD_PORT_MAPPING_CREATE]
},
{
name: 'create', alias: 'b', type: String, description: 'Add new port mapping(s)',
group: [constants.CMD_PORT_MAPPING]
name: 'routes', alias: 't', type: String, description: 'Microservice route(s) (receiving microservices)', multiple: true,
group: [constants.CMD_ADD]
},
{
name: 'delete', alias: 'B', type: String, description: 'Delete existing port mapping(s)',
group: [constants.CMD_PORT_MAPPING]
name: 'route', alias: 'T', type: String, description: 'Microservice route (receiving microservices)',
group: [constants.CMD_ROUTE_CREATE, constants.CMD_ROUTE_REMOVE]
},
{
name: 'list', alias: 'G', type: Boolean, description: 'List port mappings',
group: [constants.CMD_PORT_MAPPING]
name: 'internal-port', alias: 'b', type: String, description: 'Internal port',
group: [constants.CMD_PORT_MAPPING_REMOVE]
},
{
name: 'rebuild', alias: 'w', type: Boolean, description: 'Rebuild microservice image on fog agent',
Expand All @@ -165,8 +158,11 @@ class Microservice extends BaseCLIHandler {
[constants.CMD_REMOVE]: 'Delete a microservice.',
[constants.CMD_LIST]: 'List all microservices.',
[constants.CMD_INFO]: 'Get microservice settings.',
[constants.CMD_ROUTE]: 'Add/Remove microservice route.',
[constants.CMD_PORT_MAPPING]: 'Create/Delete/List microservice port mapping.'
[constants.CMD_ROUTE_CREATE]: 'Create microservice route.',
[constants.CMD_ROUTE_REMOVE]: 'Remove microservice route.',
[constants.CMD_PORT_MAPPING_CREATE]: 'Create microservice port mapping.',
[constants.CMD_PORT_MAPPING_REMOVE]: 'Remove microservice port mapping.',
[constants.CMD_PORT_MAPPING_LIST]: 'List microservice port mapping.'
}
}

Expand All @@ -175,25 +171,34 @@ class Microservice extends BaseCLIHandler {

switch (microserviceCommand.command.command) {
case constants.CMD_ADD:
await _executeCase(microserviceCommand, constants.CMD_ADD, _createMicroservice, false);
await _executeCase(microserviceCommand, constants.CMD_ADD, _createMicroservice);
break;
case constants.CMD_UPDATE:
await _executeCase(microserviceCommand, constants.CMD_UPDATE, _updateMicroservice, false);
await _executeCase(microserviceCommand, constants.CMD_UPDATE, _updateMicroservice);
break;
case constants.CMD_REMOVE:
await _executeCase(microserviceCommand, constants.CMD_REMOVE, _removeMicroservice, false);
await _executeCase(microserviceCommand, constants.CMD_REMOVE, _removeMicroservice);
break;
case constants.CMD_LIST:
await _executeCase(microserviceCommand, constants.CMD_LIST, _listMicroservices, false);
await _executeCase(microserviceCommand, constants.CMD_LIST, _listMicroservices);
break;
case constants.CMD_INFO:
await _executeCase(microserviceCommand, constants.CMD_INFO, _getMicroservice, false);
await _executeCase(microserviceCommand, constants.CMD_INFO, _getMicroservice);
break;
case constants.CMD_ROUTE_CREATE:
await _executeCase(microserviceCommand, constants.CMD_ROUTE_CREATE, _createRoute);
break;
case constants.CMD_ROUTE_REMOVE:
await _executeCase(microserviceCommand, constants.CMD_ROUTE_REMOVE, _removeRoute);
break;
case constants.CMD_ROUTE:
await _executeCase(microserviceCommand, constants.CMD_ROUTE, _executeRouteCommand, false);
case constants.CMD_PORT_MAPPING_CREATE:
await _executeCase(microserviceCommand, constants.CMD_PORT_MAPPING_CREATE, _createPortMapping);
break;
case constants.CMD_PORT_MAPPING:
await _executeCase(microserviceCommand, constants.CMD_PORT_MAPPING, _executePortMappingCommand, false);
case constants.CMD_PORT_MAPPING_REMOVE:
await _executeCase(microserviceCommand, constants.CMD_PORT_MAPPING_REMOVE, _removePortMapping);
break;
case constants.CMD_PORT_MAPPING_LIST:
await _executeCase(microserviceCommand, constants.CMD_PORT_MAPPING_LIST, _listPortMappings);
break;
case constants.CMD_HELP:
default:
Expand Down Expand Up @@ -229,100 +234,96 @@ class Microservice extends BaseCLIHandler {
example: '$ iofog-controller microservice add [other required options] --volumes /host_src:/container_src /host_bin:/container_bin',
},
{
desc: '3. Port mapping (internal:external:publicMode)',
desc: '3. Port mapping (80:8080:false - internal port : external port : public mode)',
example: '$ iofog-controller microservice add [other required options] --ports 80:8080:false 443:5443:false',
},
{
desc: '4. Add routes (sourceMicroserviceId:destMicroserviceId)',
example: '$ iofog-controller microservice route --add ABC:DEF',
desc: '4. Add routes (ABC:DEF - source microservice id : dest microservice id)',
example: '$ iofog-controller microservice add [other required options] --routes ABC:DEF RFG:HJK'
},
{
desc: '4. Add route (ABC:DEF - source microservice id : dest microservice id)',
example: '$ iofog-controller microservice route-create --route ABC:DEF',
},
{
desc: '5. Delete route (sourceMicroserviceId:destMicroserviceId)',
example: '$ iofog-controller microservice route --remove ABC:DEF',
desc: '5. Delete route (ABC:DEF - source microservice id : dest microservice id)',
example: '$ iofog-controller microservice route-remove --route ABC:DEF',
},
{
desc: '6. Create port mapping (internal:external:publicMode)',
example: '$ iofog-controller microservice port-mapping --create 80:8080:false -i ABC'
desc: '6. Create port mapping (80:8080:false - internal port : external port : public mode, ABC - microservice)',
example: '$ iofog-controller microservice port-mapping-create --mapping 80:8080:false -i ABC'
},
{
desc: '7. Delete port mapping (internal)',
example: '$ iofog-controller microservice port-mapping --delete 80 -i ABC'
desc: '7. Delete port mapping (80 - internal port, ABC - microservice id)',
example: '$ iofog-controller microservice port-mapping-remove --internal-port 80 -i ABC'
}
],
},
])
}
}

const _executeCase = async function (microserviceCommand, commandName, f, isUserRequired) {
const _executeCase = async function (microserviceCommand, commandName, f) {
try {
const item = microserviceCommand[commandName] || {};

if (isUserRequired) {
const decoratedFunction = AuthDecorator.prepareUserById(f);
await decoratedFunction(item);
} else {
await f(item);
}
await f(item);
} catch (error) {
logger.error(error.message);
}
};

const _executeRouteCommand = async function (obj) {
const _createRoute = async function (obj) {
logger.info(JSON.stringify(obj));
if (obj.add) {
try {
const arr = obj.add.split(':');
const sourceMicroserviceId = arr[0];
const destMicroserviceId = arr[1];
await MicroserviceService.createRouteWithTransaction(sourceMicroserviceId, destMicroserviceId, {}, true);
logger.info(`Microservice route with source microservice ${sourceMicroserviceId} and dest microservice
try {
const arr = obj.route.split(':');
const sourceMicroserviceId = arr[0];
const destMicroserviceId = arr[1];
await MicroserviceService.createRouteWithTransaction(sourceMicroserviceId, destMicroserviceId, {}, true);
logger.info(`Microservice route with source microservice ${sourceMicroserviceId} and dest microservice
${destMicroserviceId} has been created successfully.`)
} catch (e) {
logger.error(ErrorMessages.CLI.INVALID_ROUTE);
}
} else if (obj.remove) {
try {
const arr = obj.add.split(':');
const sourceMicroserviceId = arr[0];
const destMicroserviceId = arr[1];
await MicroserviceService.deleteRouteWithTransaction(sourceMicroserviceId, destMicroserviceId, {}, true);
logger.info(`Microservice route with source microservice ${obj.sourceMicroserviceId} and dest microservice
} catch (e) {
logger.error(ErrorMessages.CLI.INVALID_ROUTE);
}
};

const _removeRoute = async function (obj) {
logger.info(JSON.stringify(obj));
try {
const arr = obj.route.split(':');
const sourceMicroserviceId = arr[0];
const destMicroserviceId = arr[1];
await MicroserviceService.deleteRouteWithTransaction(sourceMicroserviceId, destMicroserviceId, {}, true);
logger.info(`Microservice route with source microservice ${obj.sourceMicroserviceId} and dest microservice
${obj.destMicroserviceId} has been removed successfully.`);
} catch (e) {
logger.error(ErrorMessages.CLI.INVALID_ROUTE);
}
} else if (obj.add && obj.remove) {
logger.info('Please specify either "add" or "remove" operation');
} else {
logger.info('No operation specified');
} catch (e) {
logger.error(ErrorMessages.CLI.INVALID_ROUTE);
}
};

const _executePortMappingCommand = async function (obj) {
const _createPortMapping = async function (obj) {
logger.info(JSON.stringify(obj));
const mapping = parsePortMappingObject(obj.mapping, ErrorMessages.CLI.INVALID_PORT_MAPPING);
await MicroserviceService.createPortMappingWithTransaction(obj.microserviceId, mapping, {}, true);
logger.info('Port mapping has been create successfully');
};

if (obj.create) {
const mapping = parsePortMappingObject(obj.create, ErrorMessages.CLI.INVALID_PORT_MAPPING);
await MicroserviceService.createPortMappingWithTransaction(obj.microserviceId, mapping, {}, true);
logger.info('Port mapping has been create successfully');
} else if (obj.delete) {
try {
const internalPort = parseInt(obj.delete);
await MicroserviceService.deletePortMappingWithTransaction(obj.microserviceId, internalPort, {}, true);
logger.info('Port mapping has been deleted successfully');
} catch(e) {
logger.error(ErrorMessages.CLI.INVALID_INTERNAL_PORT);
}
} else if (obj.list) {
await MicroserviceService.getMicroservicePortMappingListWithTransaction(obj.microserviceId, {}, true);
logger.info('Port mappings have been retrieved successfully');
} else {
logger.info('Incorrect command usage. Please specify only one command at once');
const _removePortMapping = async function (obj) {
logger.info(JSON.stringify(obj));
try {
const internalPort = parseInt(obj.internalPort);
await MicroserviceService.deletePortMappingWithTransaction(obj.microserviceId, internalPort, {}, true);
logger.info('Port mapping has been deleted successfully');
} catch(e) {
logger.error(ErrorMessages.CLI.INVALID_INTERNAL_PORT);
}
};

const _listPortMappings = async function (obj) {
const result = await MicroserviceService.getMicroservicePortMappingListWithTransaction(obj.microserviceId, {}, true);
logger.info(JSON.stringify(result));
logger.info('Port mappings have been retrieved successfully');
};

const _removeMicroservice = async function (obj) {
logger.info(JSON.stringify(obj));
await MicroserviceService.deleteMicroserviceWithTransaction(obj.microserviceId, obj.cleanUp, {}, true);
Expand All @@ -331,7 +332,7 @@ const _removeMicroservice = async function (obj) {

const _listMicroservices = async function () {
const result = await MicroserviceService.listMicroservicesWithTransaction({}, {}, true);
logger.info(JSON.stringify(result, null, 2));
logger.info(JSON.stringify(result));
logger.info('Microservices have been retrieved successfully.');
};

Expand Down
7 changes: 5 additions & 2 deletions src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ module.exports = {
CMD_CATALOG: 'catalog',
CMD_FLOW: 'flow',
CMD_MICROSERVICE: 'microservice',
CMD_ROUTE: 'route',
CMD_PORT_MAPPING: 'port-mapping',
CMD_ROUTE_CREATE: 'route-create',
CMD_ROUTE_REMOVE: 'route-remove',
CMD_PORT_MAPPING_CREATE: 'port-mapping-create',
CMD_PORT_MAPPING_REMOVE: 'port-mapping-remove',
CMD_PORT_MAPPING_LIST: 'port-mapping-list',
CMD_REGISTRY: 'registry',
CMD_ACTIVATE: 'activate',
CMD_SUSPEND: 'suspend',
Expand Down
18 changes: 18 additions & 0 deletions src/sequelize/managers/flow-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,30 @@
const BaseManager = require('./base-manager');
const models = require('./../models');
const Flow = models.Flow;
const Microservice = models.Microservice;
const sequelize = require('sequelize');

class FlowManager extends BaseManager {
getEntity() {
return Flow
}

async findFlowMicroservices(where, transaction) {
return Flow.findOne({
include: [
{
model: Microservice,
as: 'microservice',
required: false,
attributes: ['iofogUuid']
}
],
where: where,
attributes: ['id']
}, {transaction: transaction})
}
}


const instance = new FlowManager();
module.exports = instance;
Loading