Index: src/server/controllers/api/elementController.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP <+>/**\n * @file elementController.js\n * @author Zishan Iqbal\n * @description This file includes the implementation of the end-points that deal with elements\n */\n\nimport async from 'async';\n\n\nimport ChangeTrackingService from '../../services/changeTrackingService';\nimport ElementFogTypeService from '../../services/elementFogTypeService';\nimport ElementService from '../../services/elementService';\nimport ElementInstanceService from '../../services/elementInstanceService';\nimport ElementInstancePortService from '../../services/elementInstancePortService';\nimport ElementInstanceConnectionsService from '../../services/elementInstanceConnectionsService';\nimport ElementInputTypeService from '../../services/elementInputTypeService';\nimport ElementOutputTypeService from '../../services/elementOutputTypeService';\nimport FogTypeService from '../../services/fogTypeService';\nimport NetworkPairingService from '../../services/networkPairingService';\nimport RoutingService from '../../services/routingService';\nimport SatellitePortService from '../../services/satellitePortService';\nimport UserService from '../../services/userService';\nimport AppUtils from '../../utils/appUtils';\nimport logger from '../../utils/winstonLogs';\n\n\n/*********************************************** EndPoints **************************************************************/\n/************ Get Element Details EndPoint (Get: /api/v2/authoring/element/module/details/moduleid/:moduleId) ************/\n const getElementDetailsEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementProps = {\n elementId: 'bodyParams.moduleId',\n setProperty: 'elementData'\n };\n params.bodyParams = req.params;\n params.bodyParams.t = req.query.t;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getElementDetails, elementProps)\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'module', params.elementData, result);\n });\n};\n/************ Create Element For User EndPoint (Post: /api/v2/authoring/element/module/create) ************/\n const createElementForUserEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n fogTypeProps = {\n fogTypeId: 'bodyParams.fabricType',\n setProperty: 'fogTypeData'\n };\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(FogTypeService.getFogTypeDetail, fogTypeProps),\n createElementForUser,\n createElementFogType,\n createElementInputType,\n createElementOutputType\n\n ], function(err, result) {\n let successLabelArr,\n successValueArr,\n elementData = {};\n\n if (params.element && params.elementFogData){\n elementData.id = params.element.id;\n successLabelArr= ['elementFogType', 'module'],\n successValueArr= [params.elementFogData.iofog_type_id, elementData];\n }\n AppUtils.sendMultipleResponse(res, err, successLabelArr, successValueArr, result);\n })\n};\n\n/*************** Create Element EndPoint (Post) *****************/\n const createElementEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n };\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n checkFogTypes,\n createElement,\n createElementFogTypes\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'element', params.element, result);\n })\n};\n\n/*************** Update Element EndPoint (Post) *****************/\n const updateElementEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n \n elementProps = {\n networkElementId: 'bodyParams.id',\n setProperty: 'element'\n },\n\n fogTypeProps = {\n elementId: 'bodyParams.id',\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getNetworkElement, elementProps),\n checkFogTypes,\n updateElement,\n async.apply(ElementFogTypeService.deleteElementFogType, fogTypeProps),\n createElementFogTypes,\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'element', params.bodyParams.id, result);\n })\n};\n\nconst checkFogTypes = function(params, callback) {\n let fogTypeIds = [];\n \n if(params.bodyParams.fabricTypeIds){\n fogTypeIds = params.bodyParams.fabricTypeIds.split(',')\n }\n params.fogTypeIds = fogTypeIds;\n if (fogTypeIds.length) {\n async.eachOfSeries(params.fogTypeIds, function (value, key, cb) {\n let fogTypeProps = {\n fogTypeId: value\n };\n \n FogTypeService.getFogTypeDetails(fogTypeProps, params, cb);\n\n }, function (err) {\n if(!err){\n callback(null, params);\n }else{\n callback('Error', 'Error: Unable to find fogType details');\n }\n });\n }else{\n callback(null, params);\n }\n}\n\nconst createElementFogTypes = function(params, callback) {\n let fogTypeIds = [];\n \n if(params.bodyParams.fabricTypeIds){\n fogTypeIds = params.bodyParams.fabricTypeIds.split(',')\n }\n if (fogTypeIds.length) {\n async.eachOfSeries(fogTypeIds, function (value, key, cb) {\n let elementFogTypeProps = {\n elementType: {\n element_id: params.element.id,\n iofog_type_id: value\n }\n };\n \n ElementFogTypeService.createElementFogType(elementFogTypeProps, params, cb);\n }, function (err) {\n if(!err){\n callback(null, params);\n }else{\n callback('Error', err);\n }\n });\n }else{\n callback(null, params);\n }\n}\n\n/*************** Update Element For User EndPoint (Post: /api/v2/authoring/element/module/update) ***********************/\n const updateElementForUserEndPoint= function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementProps = {\n networkElementId: 'bodyParams.id',\n setProperty: 'element'\n },\n\n fogTypeProps = {\n elementId: 'bodyParams.id',\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getNetworkElement, elementProps),\n updateElement,\n updateElementInputType,\n updateElementOutputType\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, '', '', result);\n })\n};\n\n/*************** Delete Element EndPoint (Post: /api/v2/authoring/organization/element/delete) *****************/\n const deleteElementEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n \n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementProps = {\n elementKey: 'bodyParams.id',\n setProperty: 'elementInstanceData'\n },\n deleteElementProps = {\n elementId: 'bodyParams.id',\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.findElementInstancesByElementKey, elementProps),\n deleteElementInstanceData,\n async.apply(ElementService.deleteElementById, deleteElementProps)\n \n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'elementId', params.bodyParams.id, result);\n })\n};\n\n/*************** Delete Element For User EndPoint (Get: /api/v2/authoring/element/module/delete/moduleid/:moduleId) **************/\n const deleteElementForUserEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n \n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementProps = {\n elementKey: 'bodyParams.moduleId',\n setProperty: 'elementInstanceData'\n },\n elementIdProps = {\n elementId: 'bodyParams.moduleId'\n },\n elementKeyProps = {\n networkElementId: 'bodyParams.moduleId',\n setProperty: 'elementData'\n };\n\n params.bodyParams = req.params;\n params.bodyParams.t = req.query.t;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getNetworkElement, elementKeyProps), \n async.apply(ElementInstanceService.findElementInstancesByElementKey, elementProps),\n deleteElementInstanceData,\n async.apply(ElementFogTypeService.deleteElementFogType, elementIdProps),\n async.apply(ElementInputTypeService.deleteElementInputType, elementProps),\n async.apply(ElementOutputTypeService.deleteElementOutputType, elementProps),\n async.apply(ElementService.deleteElementById, elementIdProps)\n \n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'moduleId', params.bodyParams.moduleId, result);\n });\n};\n\nconst updateFogChangeTracking = function(params, callback){\n let changeTrackingProps = {\n elementInstanceData: 'elementInstancesData',\n field: 'iofog_uuid',\n changeObject: {\n containerList: new Date().getTime()\n }\n }; \n ChangeTrackingService.updateChangeTrackingData(changeTrackingProps, params, callback);\n}\n\n/************* Get Element Catalog EndPoint (Get: api/v2/authoring/element/catalog/get) ***********/\nconst getCatalogOfElements = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n getElementCatalogProps = {\n setProperty: 'elementCatalog'\n };\n \n params.bodyParams = req.params;\n params.bodyParams.t = req.query.t;\n\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getElementCatalog, getElementCatalogProps)\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'elementCatalog', params.elementCatalog, result);\n })\n};\n\n/************* Get Elements For Publishing EndPoint (Get: api/v2/authoring/element/get) ***********/\nconst getElementsForPublishingEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementProps = {\n setProperty: 'elementCatalog'\n };\n \n params.bodyParams = req.params;\n params.bodyParams.t = req.query.t;\n\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getElementForPublish, elementProps)\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'elementCatalog', params.elementCatalog, result);\n })\n};\n\n/*************************************** Extra Functions *************************************************/\nconst createElement = function(params, callback) {\n let elementProps = {\n element : {\n name: params.bodyParams.name,\n description: params.bodyParams.description,\n config: params.bodyParams.config,\n category: params.bodyParams.category,\n containerImage: params.bodyParams.containerImage,\n publisher: params.bodyParams.publisher,\n diskRequired: false,\n ramRequired: false,\n picture: params.bodyParams.picture,\n isPublic: false,\n registry_id: 1\n },\n setProperty: 'element'\n };\n ElementService.createElement(elementProps, params, callback);\n}\n\nconst createElementInputType = function(params, callback) {\n let elementInputTypeProps = {\n elementInputType : {\n elementKey: params.element.id,\n infoType: '',\n infoFormat: ''\n },\n setProperty: 'elementInputType'\n };\n\n ElementInputTypeService.createElementInputType(elementInputTypeProps, params, callback);\n}\n\nconst createElementOutputType = function(params, callback) {\n let elementOutputTypeProps = {\n elementOutputType : {\n elementKey: params.element.id,\n infoType: '',\n infoFormat: ''\n },\n setProperty: 'elementOutputType'\n };\n\n ElementOutputTypeService.createElementOutputType(elementOutputTypeProps, params, callback);\n}\n\nconst createElementForUser = function(params, callback) {\n let elementProps = {\n element : {\n name: '',\n description: '',\n category: '',\n containerImage: '',\n publisher: '',\n config: '',\n diskRequired: false,\n ramRequired: false,\n picture: 'images/shared/default.png',\n isPublic: false,\n registry_id: 1\n },\n setProperty: 'element'\n };\n ElementService.createElement(elementProps, params, callback);\n}\n\nconst createElementFogType = function(params, callback) {\n if (params.bodyParams.fabricType){\n let elementFogTypeProps = {\n elementType: {\n element_id: params.element.id,\n iofog_type_id: params.bodyParams.fabricType\n },\n setProperty: 'elementFogData'\n };\n ElementFogTypeService.createElementFogType(elementFogTypeProps, params, callback);\n }\n}\n\nconst updateElement = function(params, callback) {\n let elementProps = {\n elementId: 'bodyParams.id',\n updatedElement : {\n name: params.bodyParams.name,\n description: params.bodyParams.description,\n config: params.bodyParams.config,\n category: params.bodyParams.category,\n containerImage: params.bodyParams.containerImage,\n publisher: params.bodyParams.publisher,\n diskRequired: params.bodyParams.diskRequired ? params.bodyParams.diskRequired : false,\n ramRequired: params.bodyParams.ramRequired ? params.bodyParams.ramRequired : false,\n picture: params.bodyParams.picture,\n isPublic: false,\n registry_id: 1\n }\n };\n\n ElementService.updateElement(elementProps, params, callback);\n}\n\nconst updateElementInputType = function(params, callback) {\n let elementInputTypeProps = {\n elementKey: 'bodyParams.id',\n updatedData : {\n infoType: params.bodyParams.inputType,\n infoFormat: params.bodyParams.inputFormat,\n }\n };\n\n ElementInputTypeService.updateElementInputType(elementInputTypeProps, params, callback);\n}\n\nconst updateElementOutputType = function(params, callback) {\n let elementOutputTypeProps = {\n elementKey: 'bodyParams.id',\n updatedData : {\n infoType: params.bodyParams.outputType,\n infoFormat: params.bodyParams.outputFormat,\n }\n };\n\n ElementOutputTypeService.updateElementOutputType(elementOutputTypeProps, params, callback);\n}\n\nconst deleteElementInstanceData = function(params, callback) {\n if (params.elementInstanceData.length){\n let elementInstanceDataProps = {\n elementInstanceData: 'elementInstanceData',\n field: 'uuid'\n },\n networkPairingProps = {\n elementInstanceData: 'elementInstanceData',\n field: 'uuid',\n setProperty: 'networkPairingData'\n },\n satellitePortProps = {\n satellitePortIds: 'networkPairingData',\n field: 'satellitePortId'\n },\n deleteNetworkElementInstanceProps = {\n elementInstanceData: 'networkPairingData',\n field1: 'networkElementId1',\n field2: 'networkElementId2'\n };\n\n async.waterfall([\n async.apply(ElementInstancePortService.deleteElementInstancePortsByElementIds, elementInstanceDataProps, params),\n async.apply(NetworkPairingService.findByElementInstanceIds, networkPairingProps),\n async.apply(SatellitePortService.deleteSatellitePortByIds, satellitePortProps),\n async.apply(ElementInstanceService.deleteNetworkElementInstances, deleteNetworkElementInstanceProps),\n async.apply(NetworkPairingService.deleteNetworkPairingByElementId1, networkPairingProps),\n async.apply(ElementInstanceConnectionsService.deleteElementInstanceConnection, elementInstanceDataProps),\n async.apply(RoutingService.deleteByPublishingOrDestinationElementId, elementInstanceDataProps),\n updateFogChangeTracking,\n async.apply(ElementInstanceService.deleteElementInstances, elementInstanceDataProps)\n ], function(err, result) {\n callback(null, params);\n });\n }else{\n callback(null, params);\n }\n}\n\nexport default {\n createElementEndPoint: createElementEndPoint,\n createElementForUserEndPoint: createElementForUserEndPoint,\n updateElementEndPoint: updateElementEndPoint,\n updateElementForUserEndPoint: updateElementForUserEndPoint,\n deleteElementEndPoint: deleteElementEndPoint,\n getCatalogOfElements: getCatalogOfElements,\n getElementsForPublishingEndPoint: getElementsForPublishingEndPoint,\n getElementDetailsEndPoint: getElementDetailsEndPoint,\n deleteElementForUserEndPoint: deleteElementForUserEndPoint\n}; Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/server/controllers/api/elementController.js (revision 699e89aa874329389baccbbbc2a1a80032994925) +++ src/server/controllers/api/elementController.js (date 1520859553000) @@ -372,19 +372,20 @@ /*************************************** Extra Functions *************************************************/ const createElement = function(params, callback) { - let elementProps = { + debugger; + let elementProps = { element : { name: params.bodyParams.name, description: params.bodyParams.description, config: params.bodyParams.config, category: params.bodyParams.category, containerImage: params.bodyParams.containerImage, + registry: params.bodyParams.registry, publisher: params.bodyParams.publisher, diskRequired: false, ramRequired: false, picture: params.bodyParams.picture, - isPublic: false, - registry_id: 1 + isPublic: false }, setProperty: 'element' }; @@ -418,7 +419,7 @@ } const createElementForUser = function(params, callback) { - let elementProps = { + let elementProps = { element : { name: '', description: '', @@ -430,7 +431,7 @@ ramRequired: false, picture: 'images/shared/default.png', isPublic: false, - registry_id: 1 + registryId: 1 }, setProperty: 'element' }; @@ -451,7 +452,8 @@ } const updateElement = function(params, callback) { - let elementProps = { + debugger; + let elementProps = { elementId: 'bodyParams.id', updatedElement : { name: params.bodyParams.name, @@ -459,12 +461,12 @@ config: params.bodyParams.config, category: params.bodyParams.category, containerImage: params.bodyParams.containerImage, + registryId: params.bodyParams.registry, publisher: params.bodyParams.publisher, diskRequired: params.bodyParams.diskRequired ? params.bodyParams.diskRequired : false, ramRequired: params.bodyParams.ramRequired ? params.bodyParams.ramRequired : false, picture: params.bodyParams.picture, - isPublic: false, - registry_id: 1 + isPublic: false } }; Index: src/server/controllers/api/elementInstanceController.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP <+>/**\n * @file elementController.js\n * @author Zishan Iqbal\n * @description This file includes the implementation of the end-points that deal with elements\n */\n\nimport async from 'async';\n\nimport https from 'https';\nimport ChangeTrackingService from '../../services/changeTrackingService';\nimport ComsatService from '../../services/comsatService';\nimport DataTracksService from '../../services/dataTracksService';\nimport ElementService from '../../services/elementService';\nimport ElementInstanceService from '../../services/elementInstanceService';\nimport ElementInstancePortService from '../../services/elementInstancePortService';\nimport ElementInstanceConnectionsService from '../../services/elementInstanceConnectionsService';\nimport ElementAdvertisedPortService from '../../services/elementAdvertisedPortService';\nimport FogService from '../../services/fogService';\nimport FogTypeService from '../../services/fogTypeService';\nimport NetworkPairingService from '../../services/networkPairingService';\nimport RoutingService from '../../services/routingService';\nimport SatellitePortService from '../../services/satellitePortService';\nimport SatelliteService from '../../services/satelliteService';\nimport UserService from '../../services/userService';\n\nimport AppUtils from '../../utils/appUtils';\nimport logger from '../../utils/winstonLogs';\nimport _ from 'underscore';\n\n/*********************************************** EndPoints ******************************************************/\n/***** Get Rebuild Status of Element Instance EndPoint (Get: /api/v2/authoring/element/instance/rebuild/status/elementid/:elementId *****/\n const elementInstanceRebuildStatusEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n\n elementInstanceProps = {\n elementInstanceId: 'bodyParams.elementId',\n setProperty: 'elementInstance'\n };\n\n params.bodyParams = req.params;\n params.bodyParams.t = req.query.t; \n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.getElementInstance, elementInstanceProps)\n\n ], function(err, result) {\n let rebuild = 0;\n if(!err){\n if (params.elementInstance.rebuild){\n rebuild = 1;\n }\n }\n AppUtils.sendResponse(res, err, 'rebuild', rebuild, result);\n });\n};\n\n/***** Track Element List By TrackId EndPoint (Get: /api/v2/authoring/fabric/track/element/list/:trackId) *****/\n const trackElementListEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementInstanceProps = {\n trackId: 'bodyParams.trackId',\n setProperty: 'elementInstance'\n },\n elementAdvertisedProps = {\n elementInstanceData: 'elementInstance',\n field: 'element_key',\n setProperty: 'elementAdvertisedPort'\n },\n elementInstancePortProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty: 'elementInstancePort'\n },\n networkPortProps = {\n elementInstancePortData: 'elementInstancePort',\n field: 'id',\n setProperty: 'networkPairing'\n },\n satellitePortProps = {\n networkData: 'networkPairing',\n field: 'satellitePortId',\n setProperty: 'satellitePort'\n },\n satelliteProps = {\n satellitePortData: 'satellitePort',\n field: 'satellite_id',\n setProperty: 'satellite'\n },\n routingProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty: 'routing'\n },\n outputRoutingProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty: 'outputRouting'\n },\n intraTrackProps = {\n intraTrackData: 'intraRoutingList',\n field: 'publishing_element_id',\n setProperty: 'intraTracks'\n },\n outputIntraTrackProps = {\n intraTrackData: 'outputIntraRoutingList',\n field: 'destination_element_id',\n setProperty: 'outputIntraTracks'\n },\n extraTrackProps = {\n extraTrackData: 'extraRoutingList',\n field: 'publishing_element_id',\n setProperty: 'extraTracks'\n },\n outputExtraTrackProps = {\n extraTrackData: 'outputExtraRoutingList',\n field: 'destination_element_id',\n setProperty: 'outPutExtraTracks'\n },\n otherTrackProps = {\n otherTrackData: 'otherTrackElementIds',\n field: 'elementId1',\n setProperty: 'extraintegrator'\n },\n outputOtherTrackProps = {\n otherTrackData: 'outputOtherTrackElementId2',\n field: 'elementId2',\n setProperty: 'outPutExtraintegrator'\n };\n\n params.bodyParams = req.params;\n params.bodyParams.t = req.query.t;\n\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.findRealElementInstanceByTrackId, elementInstanceProps),\n async.apply(ElementAdvertisedPortService.findElementAdvertisedPortByElementIds, elementAdvertisedProps),\n async.apply(ElementInstancePortService.findElementInstancePortsByElementIds, elementInstancePortProps),\n async.apply(NetworkPairingService.findByElementInstancePortId, networkPortProps),\n async.apply(SatellitePortService.findBySatellitePortIds, satellitePortProps),\n async.apply(SatelliteService.findBySatelliteIds, satelliteProps),\n async.apply(RoutingService.findByElementInstanceUuidsAndRoutingDestination, routingProps),\n RoutingService.extractDifferentRoutingList,\n async.apply(ElementInstanceService.findIntraTrackByUuids, intraTrackProps),\n async.apply(ElementInstanceService.findExtraTrackByUuids, extraTrackProps),\n NetworkPairingService.findOtherTrackByUuids,\n NetworkPairingService.concatNetwotkElementAndNormalElement,\n async.apply(ElementInstanceService.findOtherTrackDetailByUuids, otherTrackProps),\n async.apply(RoutingService.findOutputRoutingByElementInstanceUuidsAndRoutingPublishing, outputRoutingProps),\n RoutingService.extractDifferentOutputRoutingList,\n async.apply(ElementInstanceService.findIntraTrackByUuids, outputIntraTrackProps),\n async.apply(ElementInstanceService.findExtraTrackByUuids, outputExtraTrackProps),\n NetworkPairingService.findOutputOtherElementInfoByUuids,\n NetworkPairingService.concatNetwotkElement2AndNormalElement,\n async.apply(ElementInstanceService.findOtherTrackDetailByUuids, outputOtherTrackProps),\n extractElementsForTrack\n ], function(err, result) { \n AppUtils.sendResponse(res, err, 'elements', result.response, result);\n })\n};\n\n/******** Detailed Element Instance Create EndPoint (Post: /api/v2/authoring/element/instance/create) ************/\n const detailedElementInstanceCreateEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementProps = {\n networkElementId: 'bodyParams.elementKey',\n setProperty: 'element'\n },\n newElementInstanceProps = {\n userId: 'user.id',\n trackId: 'bodyParams.trackId',\n name: 'bodyParams.name',\n logSize: 'bodyParams.logSize',\n config: 'bodyParams.config',\n fogInstanceId: 'bodyParams.fabricInstanceId',\n setProperty: 'newElementInstance'\n }, \n changeTrackingProps = {\n fogInstanceId: 'bodyParams.fabricInstanceId',\n changeObject: {\n containerConfig: new Date().getTime(),\n containerList: new Date().getTime()\n }\n },\n elementAdvertisedProps = {\n elementInstanceData: 'elementInstance',\n field: 'element_key',\n setProperty: 'elementAdvertisedPort'\n },\n elementInstancePortProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty: 'elementInstancePort'\n },\n fogProps = {\n fogId: 'bodyParams.fabricInstanceId',\n setProperty: 'fogInstance'\n },\n networkPortProps = {\n elementInstancePortData: 'elementInstancePort',\n field: 'id',\n setProperty: 'networkPairing'\n },\n satellitePortProps = {\n networkData: 'networkPairing',\n field: 'satellitePortId',\n setProperty: 'satellitePort'\n },\n satelliteProps = {\n satellitePortData: 'satellitePort',\n field: 'satellite_id',\n setProperty: 'satellite'\n },\n routingProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty: 'routing'\n },\n outputRoutingProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty: 'outputRouting'\n },\n intraTrackProps = {\n intraTrackData: 'intraRoutingList',\n field: 'publishing_element_id',\n setProperty: 'intraTracks'\n },\n outputIntraTrackProps = {\n intraTrackData: 'outputIntraRoutingList',\n field: 'destination_element_id',\n setProperty: 'outputIntraTracks'\n },\n extraTrackProps = {\n extraTrackData: 'extraRoutingList',\n field: 'publishing_element_id',\n setProperty: 'extraTracks'\n },\n outputExtraTrackProps = {\n extraTrackData: 'outputExtraRoutingList',\n field: 'destination_element_id',\n setProperty: 'outPutExtraTracks'\n },\n otherTrackProps = {\n otherTrackData: 'otherTrackElementIds',\n field: 'elementId1',\n setProperty: 'extraintegrator'\n },\n outputOtherTrackProps = {\n otherTrackData: 'outputOtherTrackElementId2',\n field: 'elementId2',\n setProperty: 'outPutExtraintegrator'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getNetworkElement, elementProps),\n async.apply(FogService.getFogInstance, fogProps),\n async.apply(ElementInstanceService.createElementInstance, newElementInstanceProps),\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingProps),\n convertToArr,\n async.apply(ElementAdvertisedPortService.findElementAdvertisedPortByElementIds, elementAdvertisedProps),\n async.apply(ElementInstancePortService.findElementInstancePortsByElementIds, elementInstancePortProps),\n async.apply(NetworkPairingService.findByElementInstancePortId, networkPortProps),\n async.apply(SatellitePortService.findBySatellitePortIds, satellitePortProps),\n async.apply(SatelliteService.findBySatelliteIds, satelliteProps),\n async.apply(RoutingService.findByElementInstanceUuidsAndRoutingDestination, routingProps),\n RoutingService.extractDifferentRoutingList,\n async.apply(ElementInstanceService.findIntraTrackByUuids,intraTrackProps),\n async.apply(ElementInstanceService.findExtraTrackByUuids,extraTrackProps),\n NetworkPairingService.findOtherTrackByUuids,\n NetworkPairingService.concatNetwotkElementAndNormalElement,\n async.apply(ElementInstanceService.findOtherTrackDetailByUuids, otherTrackProps),\n async.apply(RoutingService.findOutputRoutingByElementInstanceUuidsAndRoutingPublishing, outputRoutingProps),\n RoutingService.extractDifferentOutputRoutingList,\n async.apply(ElementInstanceService.findIntraTrackByUuids, outputIntraTrackProps),\n async.apply(ElementInstanceService.findExtraTrackByUuids, outputExtraTrackProps),\n NetworkPairingService.findOutputOtherElementInfoByUuids,\n NetworkPairingService.concatNetwotkElement2AndNormalElement,\n async.apply(ElementInstanceService.findOtherTrackDetailByUuids, outputOtherTrackProps),\n getElementDetails\n\n ], function(err, result) {\n let errMsg = 'Internal error: ' + result \n AppUtils.sendResponse(res, err, 'elementDetails', params.elementInstanceDetails, errMsg);\n });\n};\n\n/********** Element Instance Create EndPoint (Post: /api/v2/authoring/build/element/instance/create) **********/\nconst elementInstanceCreateEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n let params = {};\n params.logSize = 10;\n \n let userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n \n elementProps = {\n networkElementId: 'bodyParams.elementKey',\n setProperty: 'element'\n },\n\n elementInstanceProps = {\n userId: 'user.id',\n trackId: 'bodyParams.trackId',\n name: 'bodyParams.name',\n logSize: 'logSize',\n setProperty: 'elementInstance'\n },\n trackProps = {\n trackId: 'bodyParams.trackId',\n setProperty: 'trackData'\n };\n \n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementService.getNetworkElement, elementProps),\n async.apply(DataTracksService.getDataTrackById, trackProps),\n async.apply(ElementInstanceService.createElementInstance, elementInstanceProps),\n processNewElementInstance\n\n ], function(err, result) {\n let errMsg = 'Internal error: There was a problem creating the ioElement instance.' + result;\n AppUtils.sendResponse(res, err, 'elementInstance', params.outputObj, errMsg);\n });\n};\n\nconst processNewElementInstance = function(params, callback) {\n let outputObj = {\n id: params.elementInstance.uuid,\n layoutX: params.bodyParams.layoutX,\n layoutY: params.bodyParams.layoutY\n };\n\n params.outputObj = outputObj;\n callback(null, params); \n}\n\n/*** Element Instance Name/Config Update EndPoint (Post: ['/api/v2/authoring/element/instance/config/update',\n '/api/v2/authoring/element/instance/name/update',]) ***/\nconst elementInstanceConfigUpdateEndPoint = function(req, res) {\nlogger.info(\"Endpoint hit: \"+req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n\n elementInstanceProps = {\n elementInstanceId: 'bodyParams.elementId',\n setProperty: 'elementInstance'\n },\n\n changeTrackingProps = {\n instanceId: 'elementInstance.iofog_uuid',\n setProperty: 'trackingData'\n };\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.getElementInstance, elementInstanceProps),\n updateElementInstanceConfig,\n async.apply(ChangeTrackingService.getChangeTrackingByInstanceId, changeTrackingProps),\n updateConfigTracking\n\n ], function(err, result) {\n let errMsg = 'Internal error: There was a problem updating ioElement instance.' + result\n\n AppUtils.sendResponse(res, err, 'elementInstance', params.bodyParams.elementId, errMsg);\n });\n};\n\n/********* Element Instance Delete EndPoint (Post: '/api/v2/authoring/element/instance/delete') *********/\nconst elementInstanceDeleteEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n \n portPasscodeProps = {\n elementId: 'bodyParams.elementId',\n setProperty: 'portPasscode'\n },\n\n deleteElementProps = {\n elementId: 'bodyParams.elementId'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n params.milliseconds = new Date().getTime();\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstancePortService.deleteElementInstancePort, deleteElementProps),\n async.apply(RoutingService.deleteElementInstanceRouting, deleteElementProps),\n async.apply(RoutingService.deleteNetworkElementRouting, deleteElementProps),\n async.apply(ElementInstanceService.deleteNetworkElementInstance, deleteElementProps),\n async.apply(SatellitePortService.getPasscodeForNetworkElements, portPasscodeProps),\n ComsatService.closePortsOnComsat,\n async.apply(NetworkPairingService.deleteNetworkPairing, deleteElementProps),\n async.apply(SatellitePortService.deletePortsForNetworkElements, deleteElementProps),\n async.apply(ElementInstanceService.deleteElementInstance, deleteElementProps)\n ], function(err, result) {\n let errMsg = 'Internal error: There was a problem deleting ioElement instance.' + result;\n\n AppUtils.sendResponse(res, err, 'element', params.bodyParams.elementId, errMsg);\n });\n};\n\n/** Element Instance Comsat Pipe Create EndPoint (Post: '/api/v2/authoring/element/instance/comsat/pipe/create') **/\nconst elementInstanceComsatPipeCreateEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n let params = {},\n\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n\n fogTypeProps = {\n fogTypeId: 'fogInstance.typeKey',\n setProperty: 'fogType'\n },\n\n elementInstanceProps = {\n elementInstanceId: 'bodyParams.elementId',\n setProperty: 'elementInstance'\n },\n\n elementInstancePortProps = {\n portId: 'bodyParams.portId',\n setProperty: 'elementInstancePort'\n },\n\n networkPairingProps = {\n instanceId1: 'fogInstance.uuid',\n instanceId2: null,\n elementId1: 'streamViewer.uuid',\n elementId2: null,\n networkElementId1: 'networkElementInstance.uuid',\n networkElementId2: null,\n isPublic: true,\n elementPortId: 'elementInstancePort.id',\n satellitePortId: 'satellitePort.id',\n setProperty: 'networkPairingObj'\n },\n\n changeTrackingCLProps = {\n fogInstanceId: 'fogInstance.uuid',\n changeObject: {\n 'containerList': new Date().getTime(),\n 'containerConfig': new Date().getTime()\n }\n },\n\n fogProps = {\n fogId: 'bodyParams.instanceId',\n setProperty: 'fogInstance'\n },\n\n networkElementProps = {\n networkElementId: 'fogType.networkElementKey',\n setProperty: 'networkElement'\n },\n\n networkElementInstanceProps = {\n networkElement: 'networkElement',\n fogInstanceId: 'fogInstance.uuid',\n satellitePort: 'satellitePort.port1',\n satelliteDomain: 'satellite.domain',\n passcode: 'comsatPort.passcode1',\n trackId: null,\n userId: 'user.id',\n networkName: null,\n networkPort: 0,\n isPublic: true,\n setProperty: 'networkElementInstance'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n // elementId is used as params.streamViewer.uuid in NetworkPairingService->createNetworkPairing method\n params.streamViewer = {};\n params.streamViewer.uuid = params.bodyParams.elementId;\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(FogService.getFogInstance, fogProps),\n async.apply(ElementInstanceService.getElementInstance, elementInstanceProps),\n async.apply(FogTypeService.getFogTypeDetail, fogTypeProps),\n async.apply(ElementInstancePortService.getElementInstancePort, elementInstancePortProps),\n ComsatService.openPortOnRadomComsat,\n createSatellitePort,\n async.apply(ElementService.getNetworkElement, networkElementProps),\n createNetworkElementInstance,\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingCLProps),\n async.apply(NetworkPairingService.createNetworkPairing, networkPairingProps)\n ], function(err, result) {\n let errMsg = 'Internal error: There was a problem trying to create the Comsat Pipe.' + result;\n let outputObj;\n if (params.satellite){\n outputObj = {\n 'accessUrl': 'https://' + params.satellite.domain + ':' + params.satellitePort.port2,\n 'networkPairingId': params.networkPairingObj.id\n };\n }\n AppUtils.sendResponse(res, err, 'connection', outputObj, errMsg);\n });\n};\n\n/** Element Instance Comsat Pipe Delete EndPoint (Post: '/api/v2/authoring/element/instance/comsat/pipe/delete') **/\nconst elementInstanceComsatPipeDeleteEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n\n changeTrackingProps = {\n fogInstanceId: 'networkPairing.instanceId1',\n changeObject: {\n 'containerList': new Date().getTime(),\n 'containerConfig': new Date().getTime()\n }\n },\n\n satellitePortProps = {\n satellitePortId: 'networkPairing.satellitePortId',\n setProperty: 'satellitePort'\n },\n\n satelliteProps = {\n satelliteId: 'satellitePort.satellite_id',\n setProperty: 'satellite'\n },\n\n deleteSatelliteProps = {\n satellitePortId: 'satellitePort.id'\n },\n\n networkPairingProps = {\n networkPairingId: 'networkPairing.id'\n },\n\n deleteElementInstanceProps = {\n elementId: 'networkPairing.networkElementId1'\n },\n getNetworkPairingProps = {\n networkPairingId: 'bodyParams.networkPairingId'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(NetworkPairingService.getNetworkPairing, getNetworkPairingProps),\n async.apply(SatellitePortService.getSatellitePort, satellitePortProps),\n async.apply(SatelliteService.getSatelliteById, satelliteProps),\n ComsatService.closePortOnComsat,\n async.apply(SatellitePortService.deleteSatellitePort, deleteSatelliteProps),\n async.apply(ElementInstanceService.deleteElementInstance, deleteElementInstanceProps),\n async.apply(NetworkPairingService.deleteNetworkPairingById, networkPairingProps),\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingProps)\n\n ], function(err, result) {\n let errMsg = 'Internal error: There was a problem trying to delete the Comsat Pipe.' + result;\n\n AppUtils.sendResponse(res, err, 'networkPairingId', params.bodyParams.networkPairingId, errMsg);\n });\n};\n\n/**** Element Instance Port Create EndPoint (Post: '/api/v2/authoring/element/instance/port/create') ****/\nconst elementInstancePortCreateEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n let params = {},\n waterfallMethods = [],\n\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n\n elementInstancePortProps = {\n userId: 'user.id',\n internalPort: 'bodyParams.internalPort',\n externalPort: 'bodyParams.externalPort',\n elementId: 'bodyParams.elementId',\n setProperty: 'elementInstancePort'\n },\n\n elementInstanceProps = {\n elementInstanceId: 'bodyParams.elementId',\n setProperty: 'elementInstance'\n },\n\n elementInstancesProps = {\n fogId: 'fogInstance.uuid',\n setProperty: 'elementInstances'\n },\n\n fogProps = {\n fogId: 'elementInstance.iofog_uuid',\n setProperty: 'fogInstance'\n },\n\n changeTrackingProps = {\n fogInstanceId: 'fogInstance.uuid',\n changeObject: {\n 'containerList': new Date().getTime()\n }\n },\n\n fogTypeProps = {\n fogTypeId: 'fogInstance.typeKey',\n setProperty: 'fogType'\n },\n\n networkPairingProps = {\n instanceId1: 'fogInstance.uuid',\n instanceId2: null,\n elementId1: 'bodyParams.elementId',\n elementId2: null,\n networkElementId1: 'networkElementInstance.uuid',\n networkElementId2: null,\n isPublic: true,\n elementPortId: 'elementInstancePort.id',\n satellitePortId: 'satellitePort.id',\n setProperty: 'networkPairingObj'\n },\n\n changeTrackingCLProps = {\n fogInstanceId: 'fogInstance.uuid',\n changeObject: {\n 'containerList': new Date().getTime(),\n 'containerConfig': new Date().getTime()\n }\n },\n\n networkElementProps = {\n networkElementId: 'fogType.networkElementKey',\n setProperty: 'networkElement'\n },\n elementInstancesPortProps = {\n elementInstanceData: 'elementInstances',\n field: 'uuid',\n setProperty: 'elemntInstancesPortData'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n if (params.bodyParams.publicAccess == 1) {\n waterfallMethods = [\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.getElementInstance, elementInstanceProps),\n async.apply(FogService.getFogInstance, fogProps),\n async.apply(FogTypeService.getFogTypeDetail, fogTypeProps),\n \n async.apply(ElementInstanceService.getElementInstancesByFogId, elementInstancesProps),\n async.apply(ElementInstancePortService.findElementInstancePortsByElementIds, elementInstancesPortProps),\n verifyPorts,\n \n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingProps),\n async.apply(ElementInstancePortService.createElementInstancePort, elementInstancePortProps),\n updateElemInstance,\n ComsatService.openPortOnRadomComsat,\n createSatellitePort,\n async.apply(ElementService.getNetworkElement, networkElementProps),\n createNetworkElementInstance,\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingCLProps),\n async.apply(NetworkPairingService.createNetworkPairing, networkPairingProps),\n getOutputDetails\n ];\n } else {\n waterfallMethods = [\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.getElementInstance, elementInstanceProps),\n async.apply(FogService.getFogInstance, fogProps),\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingProps),\n async.apply(ElementInstancePortService.createElementInstancePort, elementInstancePortProps),\n updateElemInstance,\n getOutputDetails\n ];\n }\n async.waterfall(waterfallMethods, function(err, result) {\n\n AppUtils.sendResponse(res, err, 'port', params.output, result);\n });\n};\n\nconst verifyPorts = function(params, callback){\n let internalPort = params.bodyParams.internalPort,\n externalPort = params.bodyParams.externalPort;\n\n if(AppUtils.isValidPort(internalPort)){\n if(AppUtils.isValidPort(externalPort)){\n if(externalPort != 60400 && externalPort != 60401 && externalPort != 10500 && externalPort != 54321 && externalPort != 55555){\n if(params.elemntInstancesPortData.length){\n async.each(params.elemntInstancesPortData, function(obj, next) {\n if(externalPort == obj.portexternal){\n next('Error', 'Port is already in use.')\n }else{\n next();\n }\n }, function(err) {\n if(!err){\n callback(null, params)\n }else{\n callback('Error', 'Port '+ externalPort +' is already in use on this fog instance!');\n }\n });\n }else{\n callback(null, params);\n }\n }else{\n callback('Error', 'Port '+ externalPort +' is already in use on this fog instance!');\n }\n }else{\n callback('Error', 'You must enter a valid number for both the internal and external ports');\n }\n }else{\n callback('Error', 'You must enter a valid number for both the internal and external ports');\n }\n}\n\nconst createNetworkElementInstance = function (params, callback){\n let networkElementInstanceProps = {\n networkElement: 'networkElement',\n fogInstanceId: 'fogInstance.uuid',\n satellitePort: 'satellitePort.port1',\n satelliteDomain: 'satellite.domain',\n trackId: null,\n userId: 'user.id',\n networkName: 'Network for Element '+ params.elementInstance.uuid,\n networkPort: 0,\n isPublic: true,\n passcode: 'comsatPort.passcode1',\n setProperty: 'networkElementInstance'\n };\n\n ElementInstanceService.createNetworkElementInstance(networkElementInstanceProps, params, callback);\n}\n\n/**** Element Instance Port Delete EndPoint (Post: '/api/v2/authoring/element/instance/port/delete') ****/\nconst elementInstancePortDeleteEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n let params = {},\n waterfallMethods = [],\n\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n\n elementInstancePortProps = {\n portId: 'bodyParams.portId',\n setProperty: 'elementInstancePort'\n },\n\n readElementInstanceProps = {\n elementInstanceId: 'elementInstancePort.elementId',\n setProperty: 'elementInstance'\n },\n\n fogProps = {\n fogId: 'elementInstance.iofog_uuid',\n setProperty: 'fogInstance'\n },\n\n changeTrackingProps = {\n fogInstanceId: 'fogInstance.uuid',\n changeObject: {\n 'containerList': new Date().getTime()\n }\n },\n\n delElementInstancePortProps = {\n elementPortId: 'elementInstancePort.id'\n },\n\n satellitePortProps = {\n satellitePortId: 'networkPairing.satellitePortId',\n setProperty: 'satellitePort'\n },\n\n satelliteProps = {\n satelliteId: 'satellitePort.satellite_id',\n setProperty: 'satellite'\n },\n\n deleteSatelliteProps = {\n satellitePortId: 'satellitePort.id'\n },\n\n networkPairingProps = {\n networkPairingId: 'networkPairing.id'\n },\n\n changeTrackingProps2 = {\n fogInstanceId: 'networkPairing.instanceId1',\n changeObject: {\n 'containerList': new Date().getTime(),\n 'containerConfig': new Date().getTime()\n }\n },\n deleteElementInstanceProps = {\n elementId: 'networkPairing.networkElementId1'\n },\n getNetworkPairingProps = {\n networkPairingId: 'bodyParams.networkPairingId'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n if (params.bodyParams.networkPairingId > 0) {\n waterfallMethods = [\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstancePortService.getElementInstancePort, elementInstancePortProps),\n updateElemInstance,\n async.apply(ElementInstanceService.getElementInstance, readElementInstanceProps),\n async.apply(FogService.getFogInstance, fogProps),\n async.apply(NetworkPairingService.getNetworkPairing, getNetworkPairingProps),\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingProps),\n async.apply(ElementInstancePortService.deleteElementInstancePortById, delElementInstancePortProps),\n async.apply(SatellitePortService.getSatellitePort, satellitePortProps),\n async.apply(SatelliteService.getSatelliteById, satelliteProps),\n ComsatService.closePortOnComsat,\n async.apply(SatellitePortService.deleteSatellitePort, deleteSatelliteProps),\n async.apply(ElementInstanceService.deleteElementInstance, deleteElementInstanceProps),\n async.apply(NetworkPairingService.deleteNetworkPairingById, networkPairingProps),\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingProps2)\n ];\n } else {\n waterfallMethods = [\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstancePortService.getElementInstancePort, elementInstancePortProps),\n updateElemInstance,\n async.apply(ElementInstanceService.getElementInstance, readElementInstanceProps),\n async.apply(FogService.getFogInstance, fogProps),\n async.apply(ChangeTrackingService.updateChangeTracking, changeTrackingProps),\n async.apply(ElementInstancePortService.deleteElementInstancePortById, delElementInstancePortProps)\n ];\n }\n\n async.waterfall(waterfallMethods, function(err, result) {\n AppUtils.sendResponse(res, err, 'portId', params.bodyParams.portId, result);\n });\n};\n\n/***** Get Properties of Element Instance EndPoint (Post: api/v2/authoring/build/properties/panel/get *****/\n const getElementInstancePropertiesEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementInstanceProps = {\n elementInstanceId: 'bodyParams.instanceId',\n setProperty: 'elementInstance'\n },\n elementInstancePortProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty:'elementInstancePort'\n },\n networkPairingProps = {\n elementInstancePortData: 'elementInstancePort',\n field: 'id',\n setProperty:'networkPairing'\n },\n satellitePortProps = {\n networkData: 'networkPairing',\n field: 'satellitePortId',\n setProperty: 'satellitePort'\n },\n satelliteProps = {\n satellitePortData: 'satellitePort',\n field: 'satellite_id',\n setProperty: 'satellite'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.getElementInstanceProperties, elementInstanceProps),\n async.apply(ElementInstancePortService.findElementInstancePortsByElementIds, elementInstancePortProps),\n async.apply(NetworkPairingService.findByElementInstancePortId, networkPairingProps),\n async.apply(SatellitePortService.findBySatellitePortIds, satellitePortProps),\n async.apply(SatelliteService.findBySatelliteIds, satelliteProps),\n getElementInstanceProperties\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'instance', params.response, result);\n });\n};\n\n/***** Create Element Instance Connection EndPoint (Post: /api/v2/authoring/element/connection/create *****/\n const createElementInstanceConnectionEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementInstanceConnectionProps = {\n sourceElementInstanceId: 'bodyParams.sourceElementId',\n destinationElementInstanceId: 'bodyParams.destinationElementId',\n setProperty: 'elementInstanceConnection'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceConnectionsService.findBySourceAndDestinationElementInstance, elementInstanceConnectionProps),\n createElementInstanceConnection\n\n ], function(err, result) {\n let connectionId;\n if(!err){\n if (params.elementInstanceConnection.length){\n connectionId = params.elementInstanceConnection[0].id;\n }else{\n connectionId = params.newElementInstanceConnection.id;\n }\n }\n AppUtils.sendResponse(res, err, 'connection', connectionId, result);\n });\n};\n\n/***** Delete Element Instance Connection EndPoint (Post: /api/v2/authoring/element/connection/delete *****/\n const deleteElementInstanceConnectionEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementInstanceConnectionProps = {\n sourceElementInstanceId: 'bodyParams.sourceElementId',\n destinationElementInstanceId: 'bodyParams.destinationElementId',\n setProperty: 'elementInstanceConnection'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceConnectionsService.deleteBySourceAndDestinationElementInstance, elementInstanceConnectionProps),\n\n ], function(err, result) {\n\n AppUtils.sendResponse(res, err, '', '', result);\n });\n};\n\n/********** Element Instance Update EndPoint (Post: /api/v2/authoring/element/instance/update) **********/\nconst elementInstanceUpdateEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementInstanceProps = {\n elementInstanceId: 'bodyParams.instanceId',\n setProperty: 'elementInstance'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n getFogInstance,\n async.apply(ElementInstanceService.getElementInstance, elementInstanceProps),\n updateElementInstance,\n updateChangeTracking,\n updateChange, \n updateElement \n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'id', params.bodyParams.instanceId, result);\n });\n};\n\nconst getFogInstance = function (params, callback){\n if (params.bodyParams.fabricInstanceId) {\n let fogProps = {\n fogId: 'bodyParams.fabricInstanceId',\n setProperty: 'fogData'\n };\n \n FogService.getFogInstance(fogProps, params, callback);\n }else{\n callback(null, params);\n }\n}\n\n/***** Update Rebuild of Element Instance EndPoint (Post: /api/v2/authoring/element/instance/rebuild *****/\n const elementInstanceRebuildUpdateEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementInstanceProps = {\n elementInstanceId: 'bodyParams.elementId',\n setProperty: 'elementInstance'\n };\n\n params.bodyParams = req.body;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.getElementInstance, elementInstanceProps),\n updateRebuild,\n updateChangeTrackingData\n\n ], function(err, result) {\n\n AppUtils.sendResponse(res, err, 'id', params.bodyParams.elementId, result);\n });\n};\n\n/***** Get Details of Element Instance EndPoint (Get/Post: /api/v2/authoring/element/instance/details/trackid/:trackId *****/\n const getElementInstanceDetailsEndPoint = function(req, res) {\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n userProps = {\n userId: 'bodyParams.t',\n setProperty: 'user'\n },\n elementInstanceProps = {\n trackId: 'bodyParams.trackId',\n setProperty: 'elementInstance'\n },\n elementInstanceConnectionProps = {\n sourceElementInstanceIds: 'elementInstance',\n field: 'uuid',\n setProperty:'elementInstanceConnection'\n },\n elementInstancePortProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty:'elementInstancePort'\n },\n networkPairingProps = {\n elementInstancePortData: 'elementInstancePort',\n field: 'id',\n setProperty:'networkPairing'\n },\n satellitePortProps = {\n networkData: 'networkPairing',\n field: 'satellitePortId',\n setProperty: 'satellitePort'\n },\n satelliteProps = {\n satellitePortData: 'satellitePort',\n field: 'satellite_id',\n setProperty: 'satellite'\n },\n debugProps = {\n elementInstanceData: 'elementInstance',\n fieldOne: 'uuid',\n fieldTwo: 'fogInstanceId',\n setProperty: 'isDebug'\n },\n viewerProps = {\n elementInstanceData: 'elementInstance',\n fieldOne: 'uuid',\n fieldTwo: 'fogInstanceId',\n setProperty: 'isViewer'\n },\n dataTrackProps = {\n elementInstanceData: 'elementInstance',\n field: 'uuid',\n setProperty: 'dataTracks'\n };\n \n params.bodyParams = req.body;\n\n if(req.query.t){\n params.bodyParams.t = req.query.t;\n }\n params.bodyParams.trackId = req.params.trackId;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n\n async.waterfall([\n async.apply(UserService.getUser, userProps, params),\n async.apply(ElementInstanceService.getDetailedElementInstances, elementInstanceProps),\n async.apply(ElementInstanceConnectionsService.findBySourceElementInstance, elementInstanceConnectionProps),\n async.apply(ElementInstancePortService.findElementInstancePortsByElementIds, elementInstancePortProps),\n async.apply(NetworkPairingService.findByElementInstancePortId, networkPairingProps),\n async.apply(SatellitePortService.findBySatellitePortIds, satellitePortProps),\n async.apply(SatelliteService.findBySatelliteIds, satelliteProps),\n async.apply(RoutingService.isDebugging, debugProps),\n async.apply(RoutingService.isViewer, viewerProps),\n async.apply(ElementInstanceService.getDataTrackDetails, dataTrackProps),\n getOpenPorts\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'instance', params.response, result);\n });\n};\n\n/********************************* Extra Functions *****************************************/\nconst getOpenPorts = function(params, callback){\n try{\n let response = [];\n async.eachSeries(params.elementInstance, function(instance, cb){\n let elementInstance = {\n id: instance.uuid,\n elementInstanceName: instance.elementInstanceName,\n config: instance.config,\n fogInstanceId: instance.fogInstanceId != null ? instance.fogInstanceId :'NONE',\n rootHostAccess: instance.rootHostAccess,\n logSize: instance.logSize,\n viewerEnabled: instance.isStreamViewer,\n debugEnabled: instance.isDebugConsole,\n volumeMappings: instance.volumeMappings,\n elementName: instance.elementName,\n picture: instance.elementPicture,\n typeName: instance.Name,\n typeId: instance.ID,\n connections: getConnections(params, instance),\n ports: extractOpenPort(params, instance),\n debug: isDebugging(params, instance),\n viewer: isViewer(params, instance),\n status: instance.daemonStatus == null ? 'UNKNOWN': instance.daemonStatus\n };\n response.push(elementInstance);\n cb();\n },\n function(err) {\n params.response = response;\n callback(null, params);\n });\n }catch(e){\n logger.error(e);\n }\n}\n\nconst isViewer = function(params, elementInstance) {\n let elementInstanceViewer = _.where(params.isViewer, {\n publishing_element_id: elementInstance.uuid\n });\n\n if(elementInstanceViewer.length > 0){\n return 1;\n }else{\n return 0;\n }\n}\n\nconst getConnections = function(params, elementInstance) {\n let connections = [];\n\n let elementInstanceConnection = _.where(params.elementInstanceConnection, {\n sourceElementInstance: elementInstance.uuid\n });\n\n elementInstanceConnection.forEach((instanceConnection, index) => {\n connections.push(instanceConnection.destinationElementInstance);\n });\n return connections;\n}\n\nconst updateChangeTrackingData = function(params, callback) {\n if (params.elementInstance.iofog_uuid){\n let changeTrackingProps = {\n fogInstanceId: 'elementInstance.iofog_uuid',\n changeObject: {\n containerList: new Date().getTime()\n }\n };\n \n ChangeTrackingService.updateChangeTracking(changeTrackingProps, params, callback);\n }else{\n callback(null, params);\n }\n}\n\nconst updateRebuild = function (params, callback) {\n params.elementInstanceName = 'Network for Element ' + params.bodyParams.elementId;\n let elementProps = {\n elementId: 'bodyParams.elementId',\n name: 'elementInstanceName',\n updatedData: {\n rebuild: 1\n }\n };\n\n ElementInstanceService.updateElementInstanceRebuild(elementProps, params, callback);\n}\n\nconst updateElementInstance = function (params, callback) {\n try{\n let data;\n\n if (params.elementInstance.iofog_uuid == params.bodyParams.fabricInstanceId) {\n callback(null, params);\n } \n else {\n let fogInstanceId = null;\n if (params.bodyParams.fabricInstanceId != 'NONE'){\n fogInstanceId = params.bodyParams.fabricInstanceId;\n }\n\n data = {\n iofog_uuid: fogInstanceId\n };\n\n let elementProps = {\n elementId:'bodyParams.instanceId',\n updatedData: data\n };\n ElementInstanceService.updateElemInstance(elementProps, params, callback);\n }\n }catch(e){\n logger.error(e);\n }\n}\n\nconst updateChangeTracking = function(params, callback) {\n\n let lastUpdated = new Date().getTime(),\n updateChangeTracking = {},\n updateChange = {},\n\n updateElementObject = {\n logSize: params.bodyParams.logSize,\n name: params.bodyParams.name,\n config: params.bodyParams.config,\n configLastUpdated: lastUpdated,\n rootHostAccess: params.bodyParams.rootAccess,\n volumeMappings: params.bodyParams.volumes\n };\n\n if (params.elementInstance.config != params.bodyParams.config) {\n updateElementObject.configLastUpdated = new Date().getTime();\n updateChangeTracking.containerConfig = new Date().getTime();\n }\n if (params.elementInstance.iofog_uuid != params.bodyParams.fabricInstanceId) {\n\n updateChangeTracking.containerList = new Date().getTime();\n updateChangeTracking.containerConfig = new Date().getTime();\n\n updateChange.containerConfig = new Date().getTime();\n updateChange.containerList = new Date().getTime();\n\n } else if (params.elementInstance.rootHostAccess != params.bodyParams.rootAccess ||\n params.elementInstance.volumeMappings != params.bodyParams.volumes) {\n updateChange.containerList = new Date().getTime();\n }\n\n params.updateElementObject = updateElementObject;\n params.updateChange = updateChange;\n\n if (updateChangeTracking.containerConfig || updateChangeTracking.containerList){\n let changeTrackingProps = {\n fogInstanceId: 'elementInstance.iofog_uuid',\n changeObject: updateChangeTracking\n };\n \n ChangeTrackingService.updateChangeTracking(changeTrackingProps, params, callback);\n }else{\n callback(null, params);\n }\n}\n\nconst updateChange = function(params, callback) {\n if (params.updateChange.containerConfig || params.updateChange.containerList){\n let changeTrackingProps = {\n fogInstanceId: 'bodyParams.fabricInstanceId',\n changeObject: params.updateChange\n };\n \n ChangeTrackingService.updateChangeTracking(changeTrackingProps, params, callback);\n }else{\n callback(null, params);\n }\n}\n\nconst updateElement = function(params, callback) {\n\n let elementInstanceProps = {\n elementId: 'bodyParams.instanceId',\n updatedData: params.updateElementObject\n };\n ElementInstanceService.updateElemInstance(elementInstanceProps, params, callback);\n}\n\nconst createElementInstanceConnection = function(params, callback) {\n if (params.bodyParams.sourceElementId && params.bodyParams.destinationElementId){\n if (params.elementInstanceConnection == ''){\n let newElementInstanceConnectionProps = {\n newConnectionObj: {\n sourceElementInstance: params.bodyParams.sourceElementId,\n destinationElementInstance: params.bodyParams.destinationElementId\n },\n setProperty: 'newElementInstanceConnection'\n };\n\n ElementInstanceConnectionsService.createElementInstanceConnection(newElementInstanceConnectionProps, params, callback);\n }else{\n callback(null, params);\n }\n }else{\n callback('err', 'sourceElementId and destinationElementId cannot be empty');\n }\n}\n\nconst getElementInstanceProperties = function(params, callback) {\n let response = [];\n params.elementInstance.forEach((instance, index) => {\n\n if (instance.elementKey) {\n\n let elementInstance = {\n id: instance.uuid,\n elementKey: instance.elementKey,\n config: instance.elementInstanceConfig,\n elementInstanceName: instance.elementInstanceName,\n fogInstanceId: instance.fogInstanceId != null ? instance.fogInstanceId :'NONE',\n rebuild: instance.rebuild,\n rootHostAccess: instance.rootHostAccess,\n logSize: instance.logSize,\n elementName: instance.name,\n description: instance.description,\n category: instance.category,\n containerImage: instance.container_image,\n publisher: instance.publisher,\n diskRequired: instance.diskRequired,\n ramRequired: instance.ram_required,\n picture: instance.picture,\n volumeMappings: instance.volumeMappings,\n isPublic: instance.is_public,\n registryId: instance.registry_id,\n typeId: instance.fogTypeID,\n ports: extractOpenPort(params, instance)\n };\n response.push(elementInstance);\n }\n });\n params.response = response;\n callback(null, params);\n}\n\nconst isDebugging = function(params, elementInstance) {\n let elementInstanceDebug = _.where(params.isDebug, {\n publishing_element_id: elementInstance.uuid\n });\n\n if(elementInstanceDebug.length > 0){\n return 1;\n }else{\n return 0;\n }\n}\n\nconst extractOpenPort = function(params, elementInstance) {\n let openports = [];\n let elementInstancePort = _.where(params.elementInstancePort, {\n elementId: elementInstance.uuid\n })\n elementInstancePort.forEach((instancePort, index) => {\n let networkpairing = _.findWhere(params.networkPairing, {\n elemen1PortId: instancePort.id\n })\n let accessurl, networkpairingid;\n\n if (networkpairing != null) {\n\n let satellitePort = _.findWhere(params.satellitePort, {\n id: networkpairing.satellitePortId\n });\n\n let satellite = _.findWhere(params.satellite, {\n id: satellitePort.satellite_id\n });\n\n accessurl = 'https://' + satellite.domain + ':' + satellitePort.port2;\n networkpairingid = networkpairing.id;\n } else {\n accessurl = '';\n networkpairingid = 0;\n }\n\n let openPort = {\n portId: instancePort.id,\n internalPort: instancePort.portinternal,\n externalPort: instancePort.portexternal,\n accessUrl: accessurl,\n networkPairingId: networkpairingid\n }\n\n openports.push(openPort);\n });\n\n return openports;\n}\n\nconst extractElementsForTrack = function(params, callback) {\n let response = [];\n params.elementInstance.forEach((instance, index) => {\n\n if (instance.element_key) {\n\n let elementInstance = {\n elementid: instance.uuid,\n elementkey: instance.element_key,\n config: instance.config,\n name: instance.name,\n elementtypename: instance.element.name,\n category: instance.element.category,\n image: instance.element.containerImage,\n publisher: instance.element.publisher,\n advertisedports: _.where(params.elementAdvertisedPort, {\n element_id: instance.element_key\n }),\n openports: extractOpenPort(params, instance),\n routing: extractRouting(params, instance)\n };\n response.push(elementInstance);\n }\n });\n params.response = response;\n callback(null, params);\n}\n\nconst extractRouting = function(params, elementInstance) {\n\n let inputs, outputs;\n\n let inputIntraTrack = _.where(params.intraTracks, {\n elementid: elementInstance.uuid\n });\n let inputExtraTrack = _.where(params.extraTracks, {\n elementid: elementInstance.uuid\n });\n let inputExtraIntegrator = _.where(params.extraintegrator, {\n elementid: elementInstance.uuid\n });\n\n let outputIntraTrack = _.where(params.outputIntraTracks, {\n elementid: elementInstance.uuid\n });\n let outputExtraTrack = _.where(params.outPutExtraTracks, {\n elementid: elementInstance.uuid\n });\n let outputExtraIntegrator = _.where(params.outPutExtraintegrator, {\n elementid: elementInstance.uuid\n });\n\n return {\n inputs: {\n intratrack: inputIntraTrack,\n extratrack: inputExtraTrack,\n extraintegrator: inputExtraIntegrator,\n },\n outputs: {\n intratrack: outputIntraTrack,\n extratrack: outputExtraTrack,\n extraintegrator: outputExtraIntegrator,\n }\n }\n}\n\nconst convertToArr = function(params, callback) {\n let elementInstance = [];\n\n elementInstance.push(params.newElementInstance);\n params.elementInstance = elementInstance;\n\n callback(null, params);\n}\n\nconst getElementDetails = function(params, callback) {\n\n let elementInstanceDetails = {\n elementId: params.elementInstance[0].uuid,\n elementKey: params.elementInstance[0].element_key,\n config: params.elementInstance[0].config,\n name: params.elementInstance[0].name,\n elementTypeName: params.element.name,\n category: params.element.category,\n image: params.element.containerImage,\n publisher: params.element.publisher,\n advertisedPorts: _.where(params.elementAdvertisedPort, {\n element_id: params.elementInstance[0].element_key\n }),\n openPorts: extractOpenPort(params, params.elementInstance[0]),\n routing: extractRouting(params, params.elementInstance[0])\n };\n\n params.elementInstanceDetails = elementInstanceDetails;\n callback(null, params);\n}\n\nconst updateConfigTracking = function(params, callback){\n if (params.isConfigChanged) {\n let changeTrackingProps = {\n fogInstanceId: 'elementInstance.iofog_uuid',\n changeObject: {\n containerConfig: new Date().getTime()\n }\n };\n ChangeTrackingService.updateChangeTracking(changeTrackingProps, params, callback);\n }else{\n callback(null, params);\n }\n}\n\nconst updateElementInstanceConfig = function(params, callback){\n let updatedData = {};\n\n if (params.bodyParams.config) {\n updatedData.config = params.bodyParams.config;\n updatedData.configLastUpdated = new Date().getTime();\n params.isConfigChanged = true;\n }\n\n if (params.bodyParams.name) {\n updatedData.name = params.bodyParams.name\n }\n\n let updateElementInstanceProps ={\n elementId: 'bodyParams.elementId',\n updatedData: updatedData\n };\n\n ElementInstanceService.updateElemInstance(updateElementInstanceProps, params, callback);\n}\n\nconst createSatellitePort = function(params, callback){\n let satellitePortProps = {\n satellitePortObj: {\n port1: params.comsatPort.port1,\n port2: params.comsatPort.port2,\n maxConnectionsPort1: 60,\n maxConnectionsPort2: 0,\n passcodePort1: params.comsatPort.passcode1,\n passcodePort2: params.comsatPort.passcode2,\n heartBeatAbsenceThresholdPort1: 60000,\n heartBeatAbsenceThresholdPort2: 0,\n satellite_id: params.satellite.id,\n mappingId: params.comsatPort.id\n },\n setProperty: 'satellitePort'\n };\n SatellitePortService.createSatellitePort(satellitePortProps, params, callback);\n}\n\nconst updateElemInstance = function(params, callback) {\n let elementInstanceUpdateProps = {\n elementId: 'bodyParams.elementId',\n updatedData: {\n updatedBy: params.user.id,\n updatedAt: new Date().getTime()\n }\n };\n ElementInstanceService.updateElemInstance(elementInstanceUpdateProps, params, callback);\n}\n\nconst getOutputDetails = function(params, callback) {\n params.output = {\n portId: params.elementInstancePort.id,\n internalPort: params.bodyParams.internalPort,\n externalPort: params.bodyParams.externalPort,\n networkPairingId: ''\n };\n\n if (params.bodyParams.publicAccess == 1) {\n params.output.accessUrl = \"https://\" + params.satellite.domain + \":\" + params.satellitePort.port2;\n params.output.networkPairingId = params.networkPairingObj.id;\n }\n\n callback(null, params);\n}\n\nexport default {\n createElementInstanceConnectionEndPoint:createElementInstanceConnectionEndPoint,\n deleteElementInstanceConnectionEndPoint: deleteElementInstanceConnectionEndPoint,\n detailedElementInstanceCreateEndPoint: detailedElementInstanceCreateEndPoint,\n elementInstanceCreateEndPoint: elementInstanceCreateEndPoint,\n elementInstanceUpdateEndPoint: elementInstanceUpdateEndPoint,\n elementInstanceConfigUpdateEndPoint: elementInstanceConfigUpdateEndPoint,\n elementInstanceDeleteEndPoint: elementInstanceDeleteEndPoint,\n elementInstanceComsatPipeCreateEndPoint: elementInstanceComsatPipeCreateEndPoint,\n elementInstanceComsatPipeDeleteEndPoint: elementInstanceComsatPipeDeleteEndPoint,\n elementInstancePortCreateEndPoint: elementInstancePortCreateEndPoint,\n elementInstancePortDeleteEndPoint: elementInstancePortDeleteEndPoint,\n elementInstanceRebuildStatusEndPoint: elementInstanceRebuildStatusEndPoint,\n elementInstanceRebuildUpdateEndPoint: elementInstanceRebuildUpdateEndPoint,\n getElementInstanceDetailsEndPoint: getElementInstanceDetailsEndPoint,\n getElementInstancePropertiesEndPoint: getElementInstancePropertiesEndPoint,\n trackElementListEndPoint: trackElementListEndPoint\n}; Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/server/controllers/api/elementInstanceController.js (revision 699e89aa874329389baccbbbc2a1a80032994925) +++ src/server/controllers/api/elementInstanceController.js (date 1520859553000) @@ -1369,7 +1369,7 @@ params.elementInstance.forEach((instance, index) => { if (instance.elementKey) { - + debugger let elementInstance = { id: instance.uuid, elementKey: instance.elementKey, @@ -1383,13 +1383,14 @@ description: instance.description, category: instance.category, containerImage: instance.container_image, + registryId: instance.registry, + //registryId: instance.registry_id, publisher: instance.publisher, diskRequired: instance.diskRequired, ramRequired: instance.ram_required, picture: instance.picture, volumeMappings: instance.volumeMappings, isPublic: instance.is_public, - registryId: instance.registry_id, typeId: instance.fogTypeID, ports: extractOpenPort(params, instance) }; @@ -1459,7 +1460,7 @@ params.elementInstance.forEach((instance, index) => { if (instance.element_key) { - + debugger let elementInstance = { elementid: instance.uuid, elementkey: instance.element_key, @@ -1468,6 +1469,7 @@ elementtypename: instance.element.name, category: instance.element.category, image: instance.element.containerImage, + registryId: instance.element.registry, publisher: instance.element.publisher, advertisedports: _.where(params.elementAdvertisedPort, { element_id: instance.element_key @@ -1530,7 +1532,7 @@ } const getElementDetails = function(params, callback) { - + debugger let elementInstanceDetails = { elementId: params.elementInstance[0].uuid, elementKey: params.elementInstance[0].element_key, @@ -1539,6 +1541,7 @@ elementTypeName: params.element.name, category: params.element.category, image: params.element.containerImage, + registryId: params.element.registry, publisher: params.element.publisher, advertisedPorts: _.where(params.elementAdvertisedPort, { element_id: params.elementInstance[0].element_key Index: src/server/controllers/api/instanceContainerListController.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP <+>/**\n * @file instanceContainerListController.js\n * @author Zishan Iqbal\n * @description This file includes the implementation of the instance-containerList end-point\n */\nimport async from 'async';\n\nimport BaseApiController from './baseApiController';\nimport DataTracksService from '../../services/dataTracksService';\nimport ElementService from '../../services/elementService';\nimport ElementInstancePortService from '../../services/elementInstancePortService';\nimport ElementInstanceService from '../../services/elementInstanceService';\nimport AppUtils from '../../utils/appUtils';\nimport logger from '../../utils/winstonLogs';\n\n\n/********************************************* EndPoints ******************************************************/\nconst containerListEndPoint = function(req, res){\n logger.info(\"Endpoint hit: \"+ req.originalUrl);\n\n let params = {},\n dataTrackProps = {\n instanceId: 'bodyParams.ID',\n setProperty: 'elementInstances'\n };\n params.bodyParams = req.params;\n logger.info(\"Parameters:\" + JSON.stringify(params.bodyParams));\n \n async.waterfall([\n async.apply(BaseApiController.checkUserExistance, req, res),\n async.apply(DataTracksService.findContainerListByInstanceId, dataTrackProps, params),\n processContainerList\n\n ], function(err, result) {\n AppUtils.sendResponse(res, err, 'containerlist', params.containerList, result);\n })\n}\n/************************************* Extra Functions **************************************************/\nconst processContainerList = function(params, callback){\n let elementInstances = params.elementInstances;\n params.containerList = [];\n\n async.forEachLimit(elementInstances, 1, function(elementInstance, next){\n\n params.container = elementInstance;\n params.container.ports = [];\n\n let updateElementInstanceProps = {\n elementId: 'container.UUID',\n updatedData: {\n rebuild: 0\n }\n },\n elementProps = {\n elementId: 'container.element_key',\n setProperty: 'elementData'\n },\n elementPortProps = {\n elementPortId: 'container.UUID',\n setProperty: 'elementInstancePort'\n };\n\n async.waterfall([\n async.apply(ElementInstanceService.updateElemInstance, updateElementInstanceProps, params),\n async.apply(ElementService.findElementAndRegistryById, elementProps),\n processContainerData,\n async.apply(ElementInstancePortService.getPortsByElementId, elementPortProps),\n processContainerPorts\n ], function(err, result) {\n if (err){\n callback(err, result);\n }\n else{\n next(null, params);\n }\n })\n }, function(err, result) {\n callback(null, params);\n });\n}\nconst processContainerData = function(params, callback) {\n let newContainerItem = {\n id: params.container.UUID,\n lastmodified: Date.parse(params.container.updated_at),\n rebuild: params.container.rebuild > 0,\n roothostaccess: params.container.root_host_access > 0,\n logsize: parseFloat(params.container.log_size),\n imageid: params.elementData.containerImage,\n registryurl: params.elementData.registry.url,\n volumemappings: params.container.volume_mappings\n };\n params.newContainerItem = newContainerItem;\n callback(null, params);\n}\nconst processContainerPorts = function(params, callback) {\ntry{\n for (let j = 0; j < params.elementInstancePort.length; j++) {\n let outputPortItem = {\n outsidecontainer: (params.elementInstancePort[j].portexternal).toString(),\n insidecontainer: (params.elementInstancePort[j].portinternal).toString()\n };\n params.container.ports.push(outputPortItem);\n }\n params.newContainerItem.portmappings = params.container.ports;\n\n params.containerList.push(params.newContainerItem);\n callback(null, params);\n}catch(e){\n logger.error(e);\n}\n}\nexport default {\n containerListEndPoint: containerListEndPoint\n}; Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/server/controllers/api/instanceContainerListController.js (revision 699e89aa874329389baccbbbc2a1a80032994925) +++ src/server/controllers/api/instanceContainerListController.js (date 1520859553000) @@ -79,7 +79,8 @@ }); } const processContainerData = function(params, callback) { - let newContainerItem = { + debugger; + let newContainerItem = { id: params.container.UUID, lastmodified: Date.parse(params.container.updated_at), rebuild: params.container.rebuild > 0, Index: src/server/services/elementService.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP <+>import ElementManager from '../managers/elementManager';\nimport AppUtils from '../utils/appUtils';\n\nconst createElement = function(props, params, callback) {\n ElementManager\n .create(props.element)\n .then(AppUtils.onCreate.bind(null, params, props.setProperty, 'Unable to create Element object.', callback));\n}\n\nconst deleteElementById = function(props, params, callback) {\n let elementId = AppUtils.getProperty(params, props.elementId);\n\n ElementManager\n .deleteElementById(elementId)\n .then(AppUtils.onDelete.bind(null, params, 'Unable to delete Element', callback));\n}\n\nconst getElementDetails = function(props, params, callback) {\n let elementId = AppUtils.getProperty(params, props.elementId);\n\n ElementManager\n .getElementDetails(elementId)\n .then(AppUtils.onFind.bind(null, params, props.setProperty, 'Unable to find Element details', callback));\n}\n\nconst findElementAndRegistryById = function(props, params, callback) {\n let elementId = AppUtils.getProperty(params, props.elementId);\n\n ElementManager\n .findElementAndRegistryById(elementId)\n .then(AppUtils.onFind.bind(null, params, props.setProperty, 'Unable to find Element object with id ' + elementId, callback));\n}\n\nconst getElementCatalog = function(props, params, callback) {\n\n ElementManager\n .getElementCatalog()\n .then(AppUtils.onFind.bind(null, params, props.setProperty, 'Error: Element catalog not found', callback));\n}\n\nconst getElementForPublish = function(props, params, callback) {\n\n ElementManager\n .getElementForPublish()\n .then(AppUtils.onFind.bind(null, params, props.setProperty, 'Error: Element catalog not found', callback));\n}\n\nconst getNetworkElement = function(props, params, callback) {\n let networkElementId = AppUtils.getProperty(params, props.networkElementId);\n\n ElementManager\n .findElementById(networkElementId)\n .then(AppUtils.onFind.bind(null, params, props.setProperty, 'Unable to find Element object with id ' + networkElementId, callback));\n}\n\nconst updateElement = function(props, params, callback) {\n let elementId = AppUtils.getProperty(params, props.elementId);\n\n ElementManager\n .updateElementById(elementId, props.updatedElement)\n .then(AppUtils.onUpdate.bind(null, params, 'Unable to update Element object', callback));\n}\n\nexport default {\n createElement: createElement,\n deleteElementById: deleteElementById,\n findElementAndRegistryById: findElementAndRegistryById,\n getElementCatalog: getElementCatalog,\n getElementDetails: getElementDetails,\n getElementForPublish: getElementForPublish,\n getNetworkElement: getNetworkElement,\n updateElement: updateElement\n}; Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/server/services/elementService.js (revision 699e89aa874329389baccbbbc2a1a80032994925) +++ src/server/services/elementService.js (date 1520859553000) @@ -2,6 +2,7 @@ import AppUtils from '../utils/appUtils'; const createElement = function(props, params, callback) { + debugger; ElementManager .create(props.element) .then(AppUtils.onCreate.bind(null, params, props.setProperty, 'Unable to create Element object.', callback));