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
19 changes: 12 additions & 7 deletions src/cli/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Catalog extends BaseCLIHandler {
await _executeCase(catalogCommand, constants.CMD_LIST, _listCatalogItems, false);
break;
case constants.CMD_INFO:
await _executeCase(catalogCommand, constants.CMD_INFO, _listCatalogItem, false);
await _executeCase(catalogCommand, constants.CMD_INFO, _getCatalogItem, false);
break;
case constants.CMD_HELP:
default:
Expand Down Expand Up @@ -218,8 +218,9 @@ const _createCatalogItem = async function (obj, user) {
? JSON.parse(fs.readFileSync(obj.file, 'utf8'))
: _createCatalogItemObject(obj);

logger.cliReq('catalog add', {args: item});
const catalogItemIdObject = await CatalogItemService.createCatalogItem(item, user);
logger.info(JSON.stringify({
logger.cliRes(JSON.stringify({
id: catalogItemIdObject.id
}, null, 2));
};
Expand All @@ -233,23 +234,27 @@ const _updateCatalogItem = async function (obj) {
throw new Errors.NotFoundError(ErrorMessages.CATALOG_UPDATE_REQUIRES_ID);
}

logger.cliReq('catalog update', {args: item});
await CatalogItemService.updateCatalogItem(obj.itemId, item, {}, true);
logger.info('Catalog item has been updated successfully.');
logger.cliRes('Catalog item has been updated successfully.');
};

const _deleteCatalogItem = async function (obj) {
logger.cliReq('catalog remove', {args: {itemId: obj.itemId}});
await CatalogItemService.deleteCatalogItem(obj.itemId, {}, true);
logger.info('Catalog item has been removed successfully');
logger.cliRes('Catalog item has been removed successfully');
};

const _listCatalogItems = async function () {
logger.cliReq('catalog list');
const result = await CatalogItemService.listCatalogItems({}, true);
logger.info(JSON.stringify(result, null, 2));
logger.cliRes(JSON.stringify(result, null, 2));
};

const _listCatalogItem = async function (obj) {
const _getCatalogItem = async function (obj) {
logger.cliReq('catalog info', {args: {itemId: obj.itemId}});
const result = await CatalogItemService.getCatalogItem(obj.itemId, {}, true);
logger.info(JSON.stringify(result, null, 2));
logger.cliRes(JSON.stringify(result, null, 2));
};

const _createCatalogItemObject = function (catalogItem) {
Expand Down
10 changes: 5 additions & 5 deletions src/cli/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const _addConfigOption = async function (options) {

if (options.emailPassword) {
config.set('Email:Password', AppHelper.encryptText(options.emailPassword, config.get('Email:Address')));
logger.info('Config option email-password has been updated.');
logger.cliRes('Config option email-password has been updated.');
}

await updateConfig(options.emailService, 'email-service', 'Email:Service', (onSuccess) => {
Expand All @@ -216,10 +216,10 @@ const updateConfig = async function (newConfigValue, cliConfigName, configName,
if (newConfigValue !== oldConfigValue) {
await fn(function () {
const currentConfigValue = config.get(configName);
logger.info(`Config option ${cliConfigName} has been set to ${currentConfigValue}`);
logger.cliRes(`Config option ${cliConfigName} has been set to ${currentConfigValue}`);
});
} else {
logger.info(`Config option ${cliConfigName} is already set to ${newConfigValue}`);
logger.cliRes(`Config option ${cliConfigName} is already set to ${newConfigValue}`);
}
}
};
Expand Down Expand Up @@ -250,7 +250,7 @@ const _listConfigOptions = function () {
const _changeDevModeState = async function (options) {
const enableDevMode = AppHelper.validateBooleanCliOptions(options.on, options.off);
config.set('Server:DevMode', enableDevMode);
logger.info('Dev mode state updated successfully.');
logger.cliRes('Dev mode state updated successfully.');

//example of tracking for other config
const event = Tracking.buildEvent(TrackingEventType.CONFIG_CHANGED, `devMode was set to ${enableDevMode}`);
Expand All @@ -260,7 +260,7 @@ const _changeDevModeState = async function (options) {
const _changeEmailActivationState = function (options) {
const enableEmailActivation = AppHelper.validateBooleanCliOptions(options.on, options.off);
config.set('Email:ActivationEnabled', enableEmailActivation);
logger.info('Email activation state updated successfully.')
logger.cliRes('Email activation state updated successfully.')
};

module.exports = new Config();
18 changes: 11 additions & 7 deletions src/cli/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,41 @@ async function _executeCase(commands, commandName, f, isUserRequired) {

async function _createConnector(obj) {
const connector = _createConnectorObject(obj);
logger.cliReq('connector add', {args: connector});
try {
await ConnectorService.createConnector(connector);
logger.info('Connector has been created successfully.');
logger.cliRes('Connector has been created successfully.');
} catch (e) {
logger.info(e.message)
logger.error(e.message)
}
}

async function _updateConnector(obj) {
const connector = _createConnectorObject(obj);
logger.cliReq('connector update', {args: connector});
try {
await ConnectorService.updateConnector(connector);
logger.info('Connector has been updated successfully.');
logger.cliRes('Connector has been updated successfully.');
} catch (e) {
logger.info(e.message)
logger.error(e.message)
}
}

async function _deleteConnector(obj) {
const connector = _createConnectorObject(obj);
logger.cliReq('connector remove', {args: connector});
try {
await ConnectorService.deleteConnector(connector);
logger.info('Connector has been removed successfully.');
logger.cliRes('Connector has been removed successfully.');
} catch (e) {
logger.info(e.message)
logger.error(e.message)
}
}

async function _getConnectorList() {
logger.cliReq('connector list');
const list = await ConnectorService.getConnectorList();
logger.info(JSON.stringify(list, null, 2));
logger.cliRes(JSON.stringify(list, null, 2));
}

function _createConnectorObject(cliData) {
Expand Down
11 changes: 7 additions & 4 deletions src/cli/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,25 @@ const _executeCase = async function (userCommand, commandName, f, isUserRequired

const _getStatus = async function () {
const response = await ControllerService.statusController(true);
logger.info(JSON.stringify(response, null, 2));
logger.cliRes(JSON.stringify(response, null, 2));
};

const _emailActivation = async function () {
logger.cliReq('controller email-activation');
const response = await ControllerService.emailActivation(true);
logger.info(JSON.stringify(response, null, 2));
logger.cliRes(JSON.stringify(response, null, 2));
};

const _getFogTypes = async function () {
logger.cliReq('controller fog-types');
const response = await ControllerService.getFogTypes(true);
logger.info(JSON.stringify(response, null, 2));
logger.cliRes(JSON.stringify(response, null, 2));
};

const _getVersion = async function () {
logger.cliReq('controller version');
const response = await ControllerService.getVersion(true);
logger.info(response, null, 2);
logger.cliRes(response, null, 2);
};

module.exports = new Controller();
21 changes: 13 additions & 8 deletions src/cli/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,37 @@ const _executeCase = async function (diagnosticCommand, commandName, f, isUserRe

const _changeMicroserviceStraceState = async function (obj) {
const isEnable = AppHelper.validateBooleanCliOptions(obj.enable, obj.disable);
logger.cliReq('diagnostics strace-update', {args: {isEnable: isEnable}});
await DiagnosticService.changeMicroserviceStraceState(obj.microserviceUuid, {enable: isEnable}, {}, true);
const msg = isEnable ? 'Microservice strace has been enabled' : 'Microservice strace has been disabled';
logger.info(msg);
logger.cliRes(msg);
};

const _getMicroserviceStraceData = async function (obj) {
logger.cliReq('diagnostics strace-info', {args: obj});
const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceUuid, {format: obj.format}, {}, true);
logger.info('Strace data:');
logger.info('=============================');
logger.info(result.data);
logger.info('Microservice strace data has been retrieved successfully.');
logger.cliRes('Strace data:');
logger.cliRes('=============================');
logger.cliRes(result.data);
logger.cliRes('Microservice strace data has been retrieved successfully.');
};

const _postMicroserviceStraceDataToFtp = async function (obj) {
logger.cliReq('diagnostics strace-ftp-post', {args: obj});
await DiagnosticService.postMicroserviceStraceDatatoFtp(obj.microserviceUuid, obj, {}, true);
logger.info('Strace data has been posted to FTP successfully.');
logger.cliRes('Strace data has been posted to FTP successfully.');
};

const _postMicroserviceImageSnapshotCreate = async function (obj) {
logger.cliReq('diagnostics image-snapshot-create');
await DiagnosticService.postMicroserviceImageSnapshotCreate(obj.microserviceUuid, {}, true);
logger.info('Microservice image snapshot has been created successfully.');
logger.cliRes('Microservice image snapshot has been created successfully.');
};

const _getMicroserviceImageSnapshot = async function (obj) {
logger.cliReq('diagnostics image-snapshot-get');
const filePath = await DiagnosticService.getMicroserviceImageSnapshot(obj.microserviceUuid, {}, true);
logger.info('Microservice images path = ' + filePath);
logger.cliRes('Microservice images path = ' + filePath);
};

module.exports = new Diagnostics();
19 changes: 10 additions & 9 deletions src/cli/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ const _createFlow = async function (flowData, user) {
const flow = flowData.file
? JSON.parse(fs.readFileSync(flowData.file, 'utf8'))
: _createFlowObject(flowData);

logger.cliReq('flow add', {args: flow});
const createdFlow = await FlowService.createFlow(flow, user, true);
logger.info(JSON.stringify({
logger.cliRes(JSON.stringify({
id: createdFlow.id
}, null, 2));
};
Expand All @@ -159,28 +159,29 @@ const _updateFlow = async function (flowData) {
: _createFlowObject(flowData);

const flowId = flowData.flowId;

logger.cliReq('flow update', {args: flow});
await FlowService.updateFlow(flow, flowId, {}, true);
logger.info('Flow updated successfully.');
logger.cliRes('Flow updated successfully.');
};

const _deleteFlow = async function (flowData) {
const flowId = flowData.flowId;

logger.cliReq('flow remove', {args: {flowId: flowId}});
await FlowService.deleteFlow(flowId, {}, true);
logger.info('Flow removed successfully.');
logger.cliRes('Flow removed successfully.');
};

const _getAllFlows = async function () {
logger.cliReq('flow list');
const flows = await FlowService.getAllFlows(true);
logger.info(JSON.stringify(flows, null, 2));
logger.cliRes(JSON.stringify(flows, null, 2));
};

const _getFlow = async function (flowData) {
const flowId = flowData.flowId;

logger.cliReq('flow info', {args: {flowId: flowId}});
const flow = await FlowService.getFlowWithTransaction(flowId, {}, true);
logger.info(JSON.stringify(flow, null, 2));
logger.cliRes(JSON.stringify(flow, null, 2));
};

function _createFlowObject(data) {
Expand Down
32 changes: 20 additions & 12 deletions src/cli/iofog.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ async function _createFog(obj, user) {
? JSON.parse(fs.readFileSync(obj.file, 'utf8'))
: _createFogObject(obj);

logger.cliReq('fog add', {args: fog});
const result = await FogService.createFog(fog, user, true);
logger.info(JSON.stringify({
logger.cliRes(JSON.stringify({
uuid: result.uuid
}, null, 2));
}
Expand All @@ -302,61 +303,68 @@ async function _updateFog(obj, user) {

fog.uuid = obj.iofogUuid;

logger.cliReq('fog update', {args: fog});
await FogService.updateFog(fog, user, true);
logger.info('ioFog node has been updated successfully.');
logger.cliRes('ioFog node has been updated successfully.');
}

async function _deleteFog(obj, user) {
const fog = _createFogObject(obj);
logger.cliReq('fog remove', {args: fog});
await FogService.deleteFog(fog, user, true);
logger.info('ioFog node has been removed successfully');
logger.cliRes('ioFog node has been removed successfully');
}

async function _getFogList(obj, user) {
logger.cliReq('fog list');
const emptyFilters = [];
const list = await FogService.getFogList(emptyFilters, user, true);
logger.info(JSON.stringify(list, null, 2));
logger.cliRes(JSON.stringify(list, null, 2));
}

async function _getFog(obj, user) {
const fog = _createFogObject(obj);
logger.cliReq('fog info', {args: fog});
const res = await FogService.getFogWithTransaction(fog, user, true);
logger.info(JSON.stringify(res, null, 2));
logger.cliRes(JSON.stringify(res, null, 2));
}

async function _generateProvision(obj, user) {
const fog = _createFogObject(obj);
logger.cliReq('fog provisioning-key', {args: fog});
const response = await FogService.generateProvisioningKey(fog, user, true);
logger.info(JSON.stringify(response), null, 2);
logger.cliRes(JSON.stringify(response), null, 2);
}

async function _setFogRebootCommand(obj, user) {
const fog = _createFogObject(obj);
logger.cliReq('fog reboot', {args: fog});
await FogService.setFogRebootCommand(fog, user, true);
logger.info('ioFog reboot command has been set successfully');
logger.cliRes('ioFog reboot command has been set successfully');
}

async function _setFogVersionCommand(obj, user) {
const fog = {
uuid: obj.iofogUuid,
versionCommand: obj.versionCommand
};
logger.cliReq('fog version', {args: fog});
await FogService.setFogVersionCommand(fog, user, true);
logger.info('ioFog version command has been set successfully');
logger.cliRes('ioFog version command has been set successfully');
}

async function _getHalHardwareInfo(obj) {
const uuidObj = {
uuid: obj.iofogUuid
};

logger.cliReq('fog hal-hw', {args: uuidObj});
const data = await FogService.getHalHardwareInfo(uuidObj, {}, true);
if (data) {
if (data.hasOwnProperty('info')) {
data.info = JSON.parse(data.info);
}

logger.info(JSON.stringify(data, null, 2));
logger.cliRes(JSON.stringify(data, null, 2));
}

}
Expand All @@ -365,14 +373,14 @@ async function _getHalUsbInfo(obj) {
const uuidObj = {
uuid: obj.iofogUuid
};

logger.cliReq('fog hal-usb', {args: uuidObj});
const data = await FogService.getHalUsbInfo(uuidObj, {}, true);
if (data) {
if (data.hasOwnProperty('info')) {
data.info = JSON.parse(data.info);
}

logger.info(JSON.stringify(data, null, 2));
logger.cliRes(JSON.stringify(data, null, 2));
}
}

Expand Down
Loading