UNPKG

fog-controller

Version:

Fog Controller project @ iotracks.com

1,130 lines (987 loc) 63.6 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _async = require('async'); var _async2 = _interopRequireDefault(_async); var _https = require('https'); var _https2 = _interopRequireDefault(_https); var _changeTrackingService = require('../../services/changeTrackingService'); var _changeTrackingService2 = _interopRequireDefault(_changeTrackingService); var _comsatService = require('../../services/comsatService'); var _comsatService2 = _interopRequireDefault(_comsatService); var _dataTracksService = require('../../services/dataTracksService'); var _dataTracksService2 = _interopRequireDefault(_dataTracksService); var _elementService = require('../../services/elementService'); var _elementService2 = _interopRequireDefault(_elementService); var _elementInstanceService = require('../../services/elementInstanceService'); var _elementInstanceService2 = _interopRequireDefault(_elementInstanceService); var _elementInstancePortService = require('../../services/elementInstancePortService'); var _elementInstancePortService2 = _interopRequireDefault(_elementInstancePortService); var _elementInstanceConnectionsService = require('../../services/elementInstanceConnectionsService'); var _elementInstanceConnectionsService2 = _interopRequireDefault(_elementInstanceConnectionsService); var _elementAdvertisedPortService = require('../../services/elementAdvertisedPortService'); var _elementAdvertisedPortService2 = _interopRequireDefault(_elementAdvertisedPortService); var _fogService = require('../../services/fogService'); var _fogService2 = _interopRequireDefault(_fogService); var _fogTypeService = require('../../services/fogTypeService'); var _fogTypeService2 = _interopRequireDefault(_fogTypeService); var _networkPairingService = require('../../services/networkPairingService'); var _networkPairingService2 = _interopRequireDefault(_networkPairingService); var _routingService = require('../../services/routingService'); var _routingService2 = _interopRequireDefault(_routingService); var _satellitePortService = require('../../services/satellitePortService'); var _satellitePortService2 = _interopRequireDefault(_satellitePortService); var _satelliteService = require('../../services/satelliteService'); var _satelliteService2 = _interopRequireDefault(_satelliteService); var _userService = require('../../services/userService'); var _userService2 = _interopRequireDefault(_userService); var _appUtils = require('../../utils/appUtils'); var _appUtils2 = _interopRequireDefault(_appUtils); var _winstonLogs = require('../../utils/winstonLogs'); var _winstonLogs2 = _interopRequireDefault(_winstonLogs); var _underscore = require('underscore'); var _underscore2 = _interopRequireDefault(_underscore); var _architectureUtils = require('../../utils/architectureUtils'); var _architectureUtils2 = _interopRequireDefault(_architectureUtils); var _baseApiController = require('./baseApiController'); var _baseApiController2 = _interopRequireDefault(_baseApiController); var _elementInstanceToCleanUpService = require('../../services/elementInstanceToCleanUpService'); var _elementInstanceToCleanUpService2 = _interopRequireDefault(_elementInstanceToCleanUpService); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /*********************************************** EndPoints ******************************************************/ /***** Get Rebuild Status of Element Instance EndPoint (Get: /api/v2/authoring/element/instance/rebuild/status/elementid/:elementId *****/ var elementInstanceRebuildStatusEndPoint = function elementInstanceRebuildStatusEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceProps = { elementInstanceId: 'bodyParams.elementId', setProperty: 'elementInstance' }; params.bodyParams = req.params; params.bodyParams.t = req.query.t; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.getElementInstance, elementInstanceProps)], function (err, result) { var rebuild = 0; if (!err) { if (params.elementInstance.rebuild) { rebuild = 1; } } _appUtils2.default.sendResponse(res, err, 'rebuild', rebuild, result); }); }; /***** Track Element List By TrackId EndPoint (Get: /api/v2/authoring/fabric/track/element/list/:trackId) *****/ /** * @file elementController.js * @author Zishan Iqbal * @description This file includes the implementation of the end-points that deal with elements */ var trackElementListEndPoint = function trackElementListEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceProps = { trackId: 'bodyParams.trackId', setProperty: 'elementInstance' }, elementAdvertisedProps = { elementInstanceData: 'elementInstance', field: 'element_key', setProperty: 'elementAdvertisedPort' }, elementInstancePortProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'elementInstancePort' }, networkPortProps = { elementInstancePortData: 'elementInstancePort', field: 'id', setProperty: 'networkPairing' }, satellitePortProps = { networkData: 'networkPairing', field: 'satellitePortId', setProperty: 'satellitePort' }, satelliteProps = { satellitePortData: 'satellitePort', field: 'satellite_id', setProperty: 'satellite' }, routingProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'routing' }, outputRoutingProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'outputRouting' }, intraTrackProps = { intraTrackData: 'intraRoutingList', field: 'publishing_element_id', setProperty: 'intraTracks' }, outputIntraTrackProps = { intraTrackData: 'outputIntraRoutingList', field: 'destination_element_id', setProperty: 'outputIntraTracks' }, extraTrackProps = { extraTrackData: 'extraRoutingList', field: 'publishing_element_id', setProperty: 'extraTracks' }, outputExtraTrackProps = { extraTrackData: 'outputExtraRoutingList', field: 'destination_element_id', setProperty: 'outPutExtraTracks' }, otherTrackProps = { otherTrackData: 'otherTrackElementIds', field: 'elementId1', setProperty: 'extraintegrator' }, outputOtherTrackProps = { otherTrackData: 'outputOtherTrackElementId2', field: 'elementId2', setProperty: 'outPutExtraintegrator' }; params.bodyParams = req.params; params.bodyParams.t = req.query.t; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.findRealElementInstanceByTrackId, elementInstanceProps), _async2.default.apply(_elementAdvertisedPortService2.default.findElementAdvertisedPortByElementIds, elementAdvertisedProps), _async2.default.apply(_elementInstancePortService2.default.findElementInstancePortsByElementIds, elementInstancePortProps), _async2.default.apply(_networkPairingService2.default.findByElementInstancePortId, networkPortProps), _async2.default.apply(_satellitePortService2.default.findBySatellitePortIds, satellitePortProps), _async2.default.apply(_satelliteService2.default.findBySatelliteIds, satelliteProps), _async2.default.apply(_routingService2.default.findByElementInstanceUuidsAndRoutingDestination, routingProps), _routingService2.default.extractDifferentRoutingList, _async2.default.apply(_elementInstanceService2.default.findIntraTrackByUuids, intraTrackProps), _async2.default.apply(_elementInstanceService2.default.findExtraTrackByUuids, extraTrackProps), _networkPairingService2.default.findOtherTrackByUuids, _networkPairingService2.default.concatNetwotkElementAndNormalElement, _async2.default.apply(_elementInstanceService2.default.findOtherTrackDetailByUuids, otherTrackProps), _async2.default.apply(_routingService2.default.findOutputRoutingByElementInstanceUuidsAndRoutingPublishing, outputRoutingProps), _routingService2.default.extractDifferentOutputRoutingList, _async2.default.apply(_elementInstanceService2.default.findIntraTrackByUuids, outputIntraTrackProps), _async2.default.apply(_elementInstanceService2.default.findExtraTrackByUuids, outputExtraTrackProps), _networkPairingService2.default.findOutputOtherElementInfoByUuids, _networkPairingService2.default.concatNetwotkElement2AndNormalElement, _async2.default.apply(_elementInstanceService2.default.findOtherTrackDetailByUuids, outputOtherTrackProps), extractElementsForTrack], function (err, result) { _appUtils2.default.sendResponse(res, err, 'elements', result.response, result); }); }; /******** Detailed Element Instance Create EndPoint (Post: /api/v2/authoring/element/instance/create) ************/ var detailedElementInstanceCreateEndPoint = function detailedElementInstanceCreateEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementProps = { networkElementId: 'bodyParams.elementKey', setProperty: 'element' }, newElementInstanceProps = { userId: 'user.id', trackId: 'bodyParams.trackId', name: 'bodyParams.name', logSize: 'bodyParams.logSize', config: 'bodyParams.config', fogInstanceId: 'bodyParams.fabricInstanceId', setProperty: 'newElementInstance' }, changeTrackingProps = { fogInstanceId: 'bodyParams.fabricInstanceId', changeObject: { containerConfig: new Date().getTime(), containerList: new Date().getTime() } }, elementAdvertisedProps = { elementInstanceData: 'elementInstance', field: 'element_key', setProperty: 'elementAdvertisedPort' }, elementInstancePortProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'elementInstancePort' }, fogProps = { fogId: 'bodyParams.fabricInstanceId', setProperty: 'fogInstance' }, networkPortProps = { elementInstancePortData: 'elementInstancePort', field: 'id', setProperty: 'networkPairing' }, satellitePortProps = { networkData: 'networkPairing', field: 'satellitePortId', setProperty: 'satellitePort' }, satelliteProps = { satellitePortData: 'satellitePort', field: 'satellite_id', setProperty: 'satellite' }, routingProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'routing' }, outputRoutingProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'outputRouting' }, intraTrackProps = { intraTrackData: 'intraRoutingList', field: 'publishing_element_id', setProperty: 'intraTracks' }, outputIntraTrackProps = { intraTrackData: 'outputIntraRoutingList', field: 'destination_element_id', setProperty: 'outputIntraTracks' }, extraTrackProps = { extraTrackData: 'extraRoutingList', field: 'publishing_element_id', setProperty: 'extraTracks' }, outputExtraTrackProps = { extraTrackData: 'outputExtraRoutingList', field: 'destination_element_id', setProperty: 'outPutExtraTracks' }, otherTrackProps = { otherTrackData: 'otherTrackElementIds', field: 'elementId1', setProperty: 'extraintegrator' }, outputOtherTrackProps = { otherTrackData: 'outputOtherTrackElementId2', field: 'elementId2', setProperty: 'outPutExtraintegrator' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementService2.default.getNetworkElement, elementProps), _async2.default.apply(_fogService2.default.getFogInstance, fogProps), _async2.default.apply(_elementInstanceService2.default.createElementInstance, newElementInstanceProps), _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps), convertToArr, _async2.default.apply(_elementAdvertisedPortService2.default.findElementAdvertisedPortByElementIds, elementAdvertisedProps), _async2.default.apply(_elementInstancePortService2.default.findElementInstancePortsByElementIds, elementInstancePortProps), _async2.default.apply(_networkPairingService2.default.findByElementInstancePortId, networkPortProps), _async2.default.apply(_satellitePortService2.default.findBySatellitePortIds, satellitePortProps), _async2.default.apply(_satelliteService2.default.findBySatelliteIds, satelliteProps), _async2.default.apply(_routingService2.default.findByElementInstanceUuidsAndRoutingDestination, routingProps), _routingService2.default.extractDifferentRoutingList, _async2.default.apply(_elementInstanceService2.default.findIntraTrackByUuids, intraTrackProps), _async2.default.apply(_elementInstanceService2.default.findExtraTrackByUuids, extraTrackProps), _networkPairingService2.default.findOtherTrackByUuids, _networkPairingService2.default.concatNetwotkElementAndNormalElement, _async2.default.apply(_elementInstanceService2.default.findOtherTrackDetailByUuids, otherTrackProps), _async2.default.apply(_routingService2.default.findOutputRoutingByElementInstanceUuidsAndRoutingPublishing, outputRoutingProps), _routingService2.default.extractDifferentOutputRoutingList, _async2.default.apply(_elementInstanceService2.default.findIntraTrackByUuids, outputIntraTrackProps), _async2.default.apply(_elementInstanceService2.default.findExtraTrackByUuids, outputExtraTrackProps), _networkPairingService2.default.findOutputOtherElementInfoByUuids, _networkPairingService2.default.concatNetwotkElement2AndNormalElement, _async2.default.apply(_elementInstanceService2.default.findOtherTrackDetailByUuids, outputOtherTrackProps), getElementDetails], function (err, result) { var errMsg = 'Internal error: ' + result; _appUtils2.default.sendResponse(res, err, 'elementDetails', params.elementInstanceDetails, errMsg); }); }; /********** Element Instance Create EndPoint (Post: /api/v2/authoring/build/element/instance/create) **********/ var elementInstanceCreateEndPoint = function elementInstanceCreateEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}; params.logSize = 10; var userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementProps = { networkElementId: 'bodyParams.elementKey', setProperty: 'element' }, elementInstanceProps = { userId: 'user.id', trackId: 'bodyParams.trackId', name: 'bodyParams.name', logSize: 'logSize', setProperty: 'elementInstance' }, trackProps = { trackId: 'bodyParams.trackId', setProperty: 'trackData' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementService2.default.getNetworkElement, elementProps), _async2.default.apply(_dataTracksService2.default.getDataTrackById, trackProps), _async2.default.apply(_elementInstanceService2.default.createElementInstance, elementInstanceProps), processNewElementInstance], function (err, result) { var errMsg = 'Internal error: There was a problem creating the ioElement instance.' + result; _appUtils2.default.sendResponse(res, err, 'elementInstance', params.outputObj, errMsg); }); }; var processNewElementInstance = function processNewElementInstance(params, callback) { var outputObj = { id: params.elementInstance.uuid, layoutX: params.bodyParams.layoutX, layoutY: params.bodyParams.layoutY }; params.outputObj = outputObj; callback(null, params); }; /*** Element Instance Name/Config Update EndPoint (Post: ['/api/v2/authoring/element/instance/config/update', '/api/v2/authoring/element/instance/name/update',]) ***/ var elementInstanceConfigUpdateEndPoint = function elementInstanceConfigUpdateEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceProps = { elementInstanceId: 'bodyParams.elementId', setProperty: 'elementInstance' }, changeTrackingProps = { instanceId: 'elementInstance.iofog_uuid', setProperty: 'trackingData' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.getElementInstance, elementInstanceProps), updateElementInstanceConfig, _async2.default.apply(_changeTrackingService2.default.getChangeTrackingByInstanceId, changeTrackingProps), updateConfigTracking], function (err, result) { var errMsg = 'Internal error: There was a problem updating ioElement instance.' + result; _appUtils2.default.sendResponse(res, err, 'elementInstance', params.bodyParams.elementId, errMsg); }); }; /********* Element Instance Delete EndPoint (Post: '/api/v2/authoring/element/instance/delete') *********/ var elementInstanceDeleteEndPoint = function elementInstanceDeleteEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, portPasscodeProps = { elementId: 'bodyParams.elementId', setProperty: 'portPasscode' }, deleteElementProps = { elementId: 'bodyParams.elementId', iofogUUID: 'elementInstance.iofog_uuid', withCleanUp: 'bodyParams.withCleanUp' }, elementInstanceProps = { setProperty: 'elementInstance', elementInstanceId: 'bodyParams.elementId' }, changeTrackingProps = { fogInstanceId: 'elementInstance.iofog_uuid', changeObject: { 'containerList': new Date().getTime() } }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); params.milliseconds = new Date().getTime(); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstancePortService2.default.deleteElementInstancePort, deleteElementProps), _async2.default.apply(_routingService2.default.deleteElementInstanceRouting, deleteElementProps), _async2.default.apply(_routingService2.default.deleteNetworkElementRouting, deleteElementProps), _async2.default.apply(_elementInstanceService2.default.deleteNetworkElementInstance, deleteElementProps), _async2.default.apply(_satellitePortService2.default.getPasscodeForNetworkElements, portPasscodeProps), _comsatService2.default.closePortsOnComsat, _async2.default.apply(_networkPairingService2.default.deleteNetworkPairing, deleteElementProps), _async2.default.apply(_satellitePortService2.default.deletePortsForNetworkElements, deleteElementProps), _async2.default.apply(_elementInstanceService2.default.getElementInstance, elementInstanceProps), _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps), _async2.default.apply(_elementInstanceService2.default.deleteElementInstanceWithCleanUp, deleteElementProps)], function (err, result) { var errMsg = 'Internal error: There was a problem deleting ioElement instance.' + result; _appUtils2.default.sendResponse(res, err, 'element', params.bodyParams.elementId, errMsg); }); }; /** Element Instance Comsat Pipe Create EndPoint (Post: '/api/v2/authoring/element/instance/comsat/pipe/create') **/ var elementInstanceComsatPipeCreateEndPoint = function elementInstanceComsatPipeCreateEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, fogTypeProps = { fogTypeId: 'fogInstance.typeKey', setProperty: 'fogType' }, elementInstanceProps = { elementInstanceId: 'bodyParams.elementId', setProperty: 'elementInstance' }, elementInstancePortProps = { portId: 'bodyParams.portId', setProperty: 'elementInstancePort' }, networkPairingProps = { instanceId1: 'fogInstance.uuid', instanceId2: null, elementId1: 'streamViewer.uuid', elementId2: null, networkElementId1: 'networkElementInstance.uuid', networkElementId2: null, isPublic: true, elementPortId: 'elementInstancePort.id', satellitePortId: 'satellitePort.id', setProperty: 'networkPairingObj' }, changeTrackingCLProps = { fogInstanceId: 'fogInstance.uuid', changeObject: { 'containerList': new Date().getTime(), 'containerConfig': new Date().getTime() } }, fogProps = { fogId: 'bodyParams.instanceId', setProperty: 'fogInstance' }, networkElementProps = { networkElementId: 'fogType.networkElementKey', setProperty: 'networkElement' }, networkElementInstanceProps = { networkElement: 'networkElement', fogInstanceId: 'fogInstance.uuid', satellitePort: 'satellitePort.port1', satelliteDomain: 'satellite.domain', passcode: 'comsatPort.passcode1', trackId: null, userId: 'user.id', networkName: null, networkPort: 0, isPublic: true, setProperty: 'networkElementInstance' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); // elementId is used as params.streamViewer.uuid in NetworkPairingService->createNetworkPairing method params.streamViewer = {}; params.streamViewer.uuid = params.bodyParams.elementId; _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_fogService2.default.getFogInstance, fogProps), _async2.default.apply(_elementInstanceService2.default.getElementInstance, elementInstanceProps), _async2.default.apply(_fogTypeService2.default.getFogTypeDetail, fogTypeProps), _async2.default.apply(_elementInstancePortService2.default.getElementInstancePort, elementInstancePortProps), _comsatService2.default.openPortOnRadomComsat, createSatellitePort, _async2.default.apply(_elementService2.default.getNetworkElement, networkElementProps), createNetworkElementInstance, _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingCLProps), _async2.default.apply(_networkPairingService2.default.createNetworkPairing, networkPairingProps)], function (err, result) { var errMsg = 'Internal error: There was a problem trying to create the Comsat Pipe.' + result; var outputObj = void 0; if (params.satellite) { outputObj = { 'accessUrl': 'https://' + params.satellite.domain + ':' + params.satellitePort.port2, 'networkPairingId': params.networkPairingObj.id }; } _appUtils2.default.sendResponse(res, err, 'connection', outputObj, errMsg); }); }; /** Element Instance Comsat Pipe Delete EndPoint (Post: '/api/v2/authoring/element/instance/comsat/pipe/delete') **/ var elementInstanceComsatPipeDeleteEndPoint = function elementInstanceComsatPipeDeleteEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, changeTrackingProps = { fogInstanceId: 'networkPairing.instanceId1', changeObject: { 'containerList': new Date().getTime(), 'containerConfig': new Date().getTime() } }, satellitePortProps = { satellitePortId: 'networkPairing.satellitePortId', setProperty: 'satellitePort' }, satelliteProps = { satelliteId: 'satellitePort.satellite_id', setProperty: 'satellite' }, deleteSatelliteProps = { satellitePortId: 'satellitePort.id' }, networkPairingProps = { networkPairingId: 'networkPairing.id' }, deleteElementInstanceProps = { elementId: 'networkPairing.networkElementId1' }, getNetworkPairingProps = { networkPairingId: 'bodyParams.networkPairingId' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_networkPairingService2.default.getNetworkPairing, getNetworkPairingProps), _async2.default.apply(_satellitePortService2.default.getSatellitePort, satellitePortProps), _async2.default.apply(_satelliteService2.default.getSatelliteById, satelliteProps), _comsatService2.default.closePortOnComsat, _async2.default.apply(_satellitePortService2.default.deleteSatellitePort, deleteSatelliteProps), _async2.default.apply(_elementInstanceService2.default.deleteElementInstance, deleteElementInstanceProps), _async2.default.apply(_networkPairingService2.default.deleteNetworkPairingById, networkPairingProps), _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps)], function (err, result) { var errMsg = 'Internal error: There was a problem trying to delete the Comsat Pipe.' + result; _appUtils2.default.sendResponse(res, err, 'networkPairingId', params.bodyParams.networkPairingId, errMsg); }); }; /**** Element Instance Port Create EndPoint (Post: '/api/v2/authoring/element/instance/port/create') ****/ var elementInstancePortCreateEndPoint = function elementInstancePortCreateEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, waterfallMethods = [], userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstancePortProps = { userId: 'user.id', internalPort: 'bodyParams.internalPort', externalPort: 'bodyParams.externalPort', elementId: 'bodyParams.elementId', setProperty: 'elementInstancePort' }, elementInstanceProps = { elementInstanceId: 'bodyParams.elementId', setProperty: 'elementInstance' }, elementInstancesProps = { fogId: 'fogInstance.uuid', setProperty: 'elementInstances' }, fogProps = { fogId: 'elementInstance.iofog_uuid', setProperty: 'fogInstance' }, changeTrackingProps = { fogInstanceId: 'fogInstance.uuid', changeObject: { 'containerList': new Date().getTime() } }, fogTypeProps = { fogTypeId: 'fogInstance.typeKey', setProperty: 'fogType' }, networkPairingProps = { instanceId1: 'fogInstance.uuid', instanceId2: null, elementId1: 'bodyParams.elementId', elementId2: null, networkElementId1: 'networkElementInstance.uuid', networkElementId2: null, isPublic: true, elementPortId: 'elementInstancePort.id', satellitePortId: 'satellitePort.id', setProperty: 'networkPairingObj' }, changeTrackingCLProps = { fogInstanceId: 'fogInstance.uuid', changeObject: { 'containerList': new Date().getTime(), 'containerConfig': new Date().getTime() } }, networkElementProps = { networkElementId: 'fogType.networkElementKey', setProperty: 'networkElement' }, elementInstancesPortProps = { elementInstanceData: 'elementInstances', field: 'uuid', setProperty: 'elemntInstancesPortData' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); if (params.bodyParams.publicAccess == 1) { waterfallMethods = [_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.getElementInstance, elementInstanceProps), _async2.default.apply(_fogService2.default.getFogInstance, fogProps), _async2.default.apply(_fogTypeService2.default.getFogTypeDetail, fogTypeProps), _async2.default.apply(_elementInstanceService2.default.getElementInstancesByFogId, elementInstancesProps), _async2.default.apply(_elementInstancePortService2.default.findElementInstancePortsByElementIds, elementInstancesPortProps), verifyPorts, _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps), _async2.default.apply(_elementInstancePortService2.default.createElementInstancePort, elementInstancePortProps), updateElemInstance, _comsatService2.default.openPortOnRadomComsat, createSatellitePort, _async2.default.apply(_elementService2.default.getNetworkElement, networkElementProps), createNetworkElementInstance, _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingCLProps), _async2.default.apply(_networkPairingService2.default.createNetworkPairing, networkPairingProps), getOutputDetails]; } else { waterfallMethods = [_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.getElementInstance, elementInstanceProps), _async2.default.apply(_fogService2.default.getFogInstance, fogProps), _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps), _async2.default.apply(_elementInstancePortService2.default.createElementInstancePort, elementInstancePortProps), updateElemInstance, getOutputDetails]; } _async2.default.waterfall(waterfallMethods, function (err, result) { _appUtils2.default.sendResponse(res, err, 'port', params.output, result); }); }; var verifyPorts = function verifyPorts(params, callback) { var internalPort = params.bodyParams.internalPort, externalPort = params.bodyParams.externalPort; if (_appUtils2.default.isValidPort(internalPort)) { if (_appUtils2.default.isValidPort(externalPort)) { if (externalPort != 60400 && externalPort != 60401 && externalPort != 10500 && externalPort != 54321 && externalPort != 55555) { if (params.elemntInstancesPortData.length) { _async2.default.each(params.elemntInstancesPortData, function (obj, next) { if (externalPort == obj.portexternal) { next('Error', 'Port is already in use.'); } else { next(); } }, function (err) { if (!err) { callback(null, params); } else { callback('Error', 'Port ' + externalPort + ' is already in use on this fog instance!'); } }); } else { callback(null, params); } } else { callback('Error', 'Port ' + externalPort + ' is already in use on this fog instance!'); } } else { callback('Error', 'You must enter a valid number for both the internal and external ports'); } } else { callback('Error', 'You must enter a valid number for both the internal and external ports'); } }; var createNetworkElementInstance = function createNetworkElementInstance(params, callback) { var networkElementInstanceProps = { networkElement: 'networkElement', fogInstanceId: 'fogInstance.uuid', satellitePort: 'satellitePort.port1', satelliteDomain: 'satellite.domain', satelliteCertificate: 'satellite.cert', trackId: null, userId: 'user.id', networkName: 'Network for Element ' + params.elementInstance.uuid, networkPort: 'bodyParams.externalPort', isPublic: true, passcode: 'comsatPort.passcode1', setProperty: 'networkElementInstance' }; _elementInstanceService2.default.createNetworkElementInstance(networkElementInstanceProps, params, callback); }; /**** Element Instance Port Delete EndPoint (Post: '/api/v2/authoring/element/instance/port/delete') ****/ var elementInstancePortDeleteEndPoint = function elementInstancePortDeleteEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, waterfallMethods = [], userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstancePortProps = { portId: 'bodyParams.portId', setProperty: 'elementInstancePort' }, readElementInstanceProps = { elementInstanceId: 'elementInstancePort.elementId', setProperty: 'elementInstance' }, fogProps = { fogId: 'elementInstance.iofog_uuid', setProperty: 'fogInstance' }, changeTrackingProps = { fogInstanceId: 'fogInstance.uuid', changeObject: { 'containerList': new Date().getTime() } }, delElementInstancePortProps = { elementPortId: 'elementInstancePort.id' }, satellitePortProps = { satellitePortId: 'networkPairing.satellitePortId', setProperty: 'satellitePort' }, satelliteProps = { satelliteId: 'satellitePort.satellite_id', setProperty: 'satellite' }, deleteSatelliteProps = { satellitePortId: 'satellitePort.id' }, networkPairingProps = { networkPairingId: 'networkPairing.id' }, changeTrackingProps2 = { fogInstanceId: 'networkPairing.instanceId1', changeObject: { 'containerList': new Date().getTime(), 'containerConfig': new Date().getTime() } }, deleteElementInstanceProps = { elementId: 'networkPairing.networkElementId1' }, getNetworkPairingProps = { networkPairingId: 'bodyParams.networkPairingId' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); if (params.bodyParams.networkPairingId > 0) { waterfallMethods = [_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstancePortService2.default.getElementInstancePort, elementInstancePortProps), updateElemInstance, _async2.default.apply(_elementInstanceService2.default.getElementInstance, readElementInstanceProps), _async2.default.apply(_fogService2.default.getFogInstance, fogProps), _async2.default.apply(_networkPairingService2.default.getNetworkPairing, getNetworkPairingProps), _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps), _async2.default.apply(_elementInstancePortService2.default.deleteElementInstancePortById, delElementInstancePortProps), _async2.default.apply(_satellitePortService2.default.getSatellitePort, satellitePortProps), _async2.default.apply(_satelliteService2.default.getSatelliteById, satelliteProps), _comsatService2.default.closePortOnComsat, _async2.default.apply(_satellitePortService2.default.deleteSatellitePort, deleteSatelliteProps), _async2.default.apply(_elementInstanceService2.default.deleteElementInstance, deleteElementInstanceProps), _async2.default.apply(_networkPairingService2.default.deleteNetworkPairingById, networkPairingProps), _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps2)]; } else { waterfallMethods = [_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstancePortService2.default.getElementInstancePort, elementInstancePortProps), updateElemInstance, _async2.default.apply(_elementInstanceService2.default.getElementInstance, readElementInstanceProps), _async2.default.apply(_fogService2.default.getFogInstance, fogProps), _async2.default.apply(_changeTrackingService2.default.updateChangeTracking, changeTrackingProps), _async2.default.apply(_elementInstancePortService2.default.deleteElementInstancePortById, delElementInstancePortProps)]; } _async2.default.waterfall(waterfallMethods, function (err, result) { _appUtils2.default.sendResponse(res, err, 'portId', params.bodyParams.portId, result); }); }; /***** Get Properties of Element Instance EndPoint (Post: api/v2/authoring/build/properties/panel/get *****/ var getElementInstancePropertiesEndPoint = function getElementInstancePropertiesEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceProps = { elementInstanceId: 'bodyParams.instanceId', setProperty: 'elementInstance' }, elementInstancePortProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'elementInstancePort' }, networkPairingProps = { elementInstancePortData: 'elementInstancePort', field: 'id', setProperty: 'networkPairing' }, satellitePortProps = { networkData: 'networkPairing', field: 'satellitePortId', setProperty: 'satellitePort' }, satelliteProps = { satellitePortData: 'satellitePort', field: 'satellite_id', setProperty: 'satellite' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.getElementInstanceProperties, elementInstanceProps), _async2.default.apply(_elementInstancePortService2.default.findElementInstancePortsByElementIds, elementInstancePortProps), _async2.default.apply(_networkPairingService2.default.findByElementInstancePortId, networkPairingProps), _async2.default.apply(_satellitePortService2.default.findBySatellitePortIds, satellitePortProps), _async2.default.apply(_satelliteService2.default.findBySatelliteIds, satelliteProps), getElementInstanceProperties], function (err, result) { _appUtils2.default.sendResponse(res, err, 'instance', params.response, result); }); }; /***** Create Element Instance Connection EndPoint (Post: /api/v2/authoring/element/connection/create *****/ var createElementInstanceConnectionEndPoint = function createElementInstanceConnectionEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceConnectionProps = { sourceElementInstanceId: 'bodyParams.sourceElementId', destinationElementInstanceId: 'bodyParams.destinationElementId', setProperty: 'elementInstanceConnection' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceConnectionsService2.default.findBySourceAndDestinationElementInstance, elementInstanceConnectionProps), createElementInstanceConnection], function (err, result) { var connectionId = void 0; if (!err) { if (params.elementInstanceConnection.length) { connectionId = params.elementInstanceConnection[0].id; } else { connectionId = params.newElementInstanceConnection.id; } } _appUtils2.default.sendResponse(res, err, 'connection', connectionId, result); }); }; /***** Delete Element Instance Connection EndPoint (Post: /api/v2/authoring/element/connection/delete *****/ var deleteElementInstanceConnectionEndPoint = function deleteElementInstanceConnectionEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceConnectionProps = { sourceElementInstanceId: 'bodyParams.sourceElementId', destinationElementInstanceId: 'bodyParams.destinationElementId', setProperty: 'elementInstanceConnection' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceConnectionsService2.default.deleteBySourceAndDestinationElementInstance, elementInstanceConnectionProps)], function (err, result) { _appUtils2.default.sendResponse(res, err, '', '', result); }); }; /********** Element Instance Update EndPoint (Post: /api/v2/authoring/element/instance/update) **********/ var elementInstanceUpdateEndPoint = function elementInstanceUpdateEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceProps = { elementInstanceId: 'bodyParams.instanceId', setProperty: 'elementInstance' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), getFogInstance, _async2.default.apply(_elementInstanceService2.default.getElementInstanceWithImages, elementInstanceProps), updateElementInstance, updateChangeTracking, updateChange, updateElement], function (err, result) { _appUtils2.default.sendResponse(res, err, 'id', params.bodyParams.instanceId, result); }); }; var getFogInstance = function getFogInstance(params, callback) { if (params.bodyParams.fabricInstanceId) { var fogProps = { fogId: 'bodyParams.fabricInstanceId', setProperty: 'fogData' }; _fogService2.default.getFogInstance(fogProps, params, callback); } else { callback(null, params); } }; /***** Update Rebuild of Element Instance EndPoint (Post: /api/v2/authoring/element/instance/rebuild *****/ var elementInstanceRebuildUpdateEndPoint = function elementInstanceRebuildUpdateEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceProps = { elementInstanceId: 'bodyParams.elementId', setProperty: 'elementInstance' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.getElementInstance, elementInstanceProps), updateRebuild, updateChangeTrackingData], function (err, result) { _appUtils2.default.sendResponse(res, err, 'id', params.bodyParams.elementId, result); }); }; /***** Get Details of Element Instance EndPoint (Get/Post: /api/v2/authoring/element/instance/details/trackid/:trackId *****/ var getElementInstanceDetailsEndPoint = function getElementInstanceDetailsEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, elementInstanceProps = { trackId: 'bodyParams.trackId', setProperty: 'elementInstance' }, elementInstanceConnectionProps = { sourceElementInstanceIds: 'elementInstance', field: 'uuid', setProperty: 'elementInstanceConnection' }, elementInstancePortProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'elementInstancePort' }, networkPairingProps = { elementInstancePortData: 'elementInstancePort', field: 'id', setProperty: 'networkPairing' }, satellitePortProps = { networkData: 'networkPairing', field: 'satellitePortId', setProperty: 'satellitePort' }, satelliteProps = { satellitePortData: 'satellitePort', field: 'satellite_id', setProperty: 'satellite' }, debugProps = { elementInstanceData: 'elementInstance', fieldOne: 'uuid', fieldTwo: 'fogInstanceId', setProperty: 'isDebug' }, viewerProps = { elementInstanceData: 'elementInstance', fieldOne: 'uuid', fieldTwo: 'fogInstanceId', setProperty: 'isViewer' }, dataTrackProps = { elementInstanceData: 'elementInstance', field: 'uuid', setProperty: 'dataTracks' }; params.bodyParams = req.body; if (req.query.t) { params.bodyParams.t = req.query.t; } params.bodyParams.trackId = req.params.trackId; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_elementInstanceService2.default.getDetailedElementInstances, elementInstanceProps), _async2.default.apply(_elementInstanceConnectionsService2.default.findBySourceElementInstance, elementInstanceConnectionProps), _async2.default.apply(_elementInstancePortService2.default.findElementInstancePortsByElementIds, elementInstancePortProps), _async2.default.apply(_networkPairingService2.default.findByElementInstancePortId, networkPairingProps), _async2.default.apply(_satellitePortService2.default.findBySatellitePortIds, satellitePortProps), _async2.default.apply(_satelliteService2.default.findBySatelliteIds, satelliteProps), _async2.default.apply(_routingService2.default.isDebugging, debugProps), _async2.default.apply(_routingService2.default.isViewer, viewerProps), _async2.default.apply(_elementInstanceService2.default.getDataTrackDetails, dataTrackProps), getOpenPorts], function (err, result) { _appUtils2.default.sendResponse(res, err, 'instance', params.response, result); }); }; /********************************* Extra Functions *****************************************/ var getOpenPorts = function getOpenPorts(params, callback) { try { var response = []; _async2.default.eachSeries(params.elementInstance, function (instance, cb) { var elementInstance = { id: instance.uuid, elementInstanceName: instance.elementInstanceName, config: instance.config, fogInstanceId: instance.fogInstanceId != null ? instance.fogInstanceId : 'NONE', rootHostAccess: instance.rootHostAccess, logSize: instance.logSize, viewerEnabled: instance.isStreamViewer, debugEnabled: instance.isDebugConsole, volumeMappings: instance.volumeMappings, elementName: instance.elementName, picture: instance.elementPicture, images: instance.elementImages, connections: getConnections(params, instance), ports: extractOpenPort(params, instance), debug: isDebugging(params, instance), viewer: isViewer(params, instance), status: instance.daemonStatus == null ? 'UNKNOWN' : instance.daemonStatus }; response.push(elementInstance); cb(); }, function (err) { params.response = response; callback(null, params); }); } catch (e) { _winstonLogs2.default.error(e); } }; var isViewer = function isViewer(params, elementInstance) { var elementInstanceViewer = _underscore2.default.where(params.isViewer, { publishing_element_id: elementInstance.uuid }); if (elementInstanceViewer.length > 0) { return 1; } else { return 0; } }; var getConnections = function getConnections(params, elementInstance) { var connections = []; var elementInstanceConnection = _underscore2.default.where(params.elementInstanceConnection, { sourceElementInstance: elementInstance.uuid }); elementInstanceConnection.forEach(function (instanceConnection, index) { connections.push(instanceConnection.destinationElementInstance); }); return connections; }; var updateChangeTrackingData = function updateChangeTrackingData(params, callback) { if (params.elementInstance.iofog_uuid) { var changeTrackingProps = { fogInstanceId: 'elementInstance.iofog_uuid', changeObject: { containerList: new Date().getTime() } }; _changeTrackingService2.default.updateChangeTracking(changeTrackingProps, params, callback); } else { callback(null, params); } }; var updateRebuild = function updateRebuild(params, callback) { params.elementInstanceName = 'Network for Element ' + params.bodyParams.elementId; var elementProps = { elementId: 'bodyParams.elementId', name: 'elementInstanceName', updatedData: { rebuild: 1 } }; _elementInstanceService2.default.updateElementInstanceRebuild(elementProps, params, callback); }; var updateElementInstance = function updateElementInstance(params, callback) { try { var data = void 0; if (params.elementInstance.iofog_uuid == params.bodyParams.fabricInstanceId) { callback(null, params); } else { var fogInstanceId = null; if (params.bodyParams.fabricInstanceId != 'NONE') { fogInstanceId = params.bodyParams.fabricInstanceId; } if (!_architectureUtils2.default.isExistsImageForFogType(params.fogData.typeKey, params.elementInstance.elementImages)) { callback('error', "no container image for this fog type"); return; } data = { iofog_uuid: fogInstanceId }; var elementProps = { elementId: 'bodyParams.instanceId', updatedData: data }; _elementInstanceService2.default.updateElemInstance(elementProps, params, callback); } } catch (e) { _winstonLogs2.default.error(e); } }; var updateChangeTracking = function updateChangeTracking(params, callback) { var lastUpdated = new Date().getTime(), updateChangeTracking = {}, updateChange = {