From 09762dc92a06fb885f7055796db390a3a1baa535 Mon Sep 17 00:00:00 2001 From: "Kotagiri, Ramprasad (rp5662)" Date: Fri, 7 Aug 2020 15:54:10 -0400 Subject: CCSDK DCAE dashboard feature changes Issue-ID: DCAEGEN2-1857 Issue-ID: DCAEGEN2-2074 Issue-ID: DCAEGEN2-2364 Change-Id: I97f5ec4599512ed848136971b11d4c2a137a4999 Signed-off-by: Kotagiri, Ramprasad (rp5662) --- .../src/main/webapp/WEB-INF/oom-app.hbm.xml | 49 - .../app/ccsdk/cloudify/blueprint-controllers.js | 464 ---- .../webapp/app/ccsdk/cloudify/blueprint-service.js | 114 - .../app/ccsdk/cloudify/blueprint_popups.html | 187 -- .../webapp/app/ccsdk/cloudify/blueprint_table.html | 98 - .../app/ccsdk/cloudify/deployment-controllers.js | 2352 +++++++++++++++++-- .../app/ccsdk/cloudify/deployment-service.js | 97 +- .../app/ccsdk/cloudify/deployment_popups.html | 201 +- .../app/ccsdk/cloudify/deployment_table.html | 426 +++- .../webapp/app/ccsdk/cloudify/execution-service.js | 27 +- .../webapp/app/ccsdk/cloudify/plugin-service.js | 31 + .../app/ccsdk/cloudify/plugin-table-controller.js | 64 + .../webapp/app/ccsdk/cloudify/plugin_table.html | 77 + .../app/ccsdk/cloudify/tosca-table-controller.js | 106 - .../webapp/app/ccsdk/cloudify/tosca_table.html | 87 - .../main/webapp/app/ccsdk/consul/node_table.html | 4 +- .../app/ccsdk/consul/service_health_table.html | 6 +- .../app/ccsdk/external/angular-local-storage.js | 592 +++++ .../src/main/webapp/app/ccsdk/external/select.css | 362 +++ .../src/main/webapp/app/ccsdk/external/select.js | 2427 ++++++++++++++++++++ .../src/main/webapp/app/ccsdk/home/api_doc.html | 26 - .../src/main/webapp/app/ccsdk/home/appDS2.js | 32 +- .../webapp/app/ccsdk/home/controller-service.js | 159 +- .../webapp/app/ccsdk/home/controller_table.html | 85 - .../webapp/app/ccsdk/home/ecd_popup_templates.html | 65 + .../app/ccsdk/home/executions-view-controller.js | 45 - .../webapp/app/ccsdk/home/executions_view.html | 5 - .../main/webapp/app/ccsdk/home/http-interceptor.js | 29 - .../app/ccsdk/home/oom-instances-controller.js | 70 - .../src/main/webapp/app/ccsdk/home/oom-router.js | 97 - .../src/main/webapp/app/ccsdk/home/oom-style.css | 301 --- .../webapp/app/ccsdk/home/oom_instances_popup.html | 86 - .../webapp/app/ccsdk/home/oom_popup_templates.html | 65 - .../src/main/webapp/app/ccsdk/home/oom_spa.html | 164 -- .../webapp/app/ccsdk/home/tree-view-controller.js | 113 - .../webapp/app/ccsdk/home/tree-view-directive.js | 165 -- .../main/webapp/app/ccsdk/home/tree-view-style.css | 132 -- .../src/main/webapp/app/ccsdk/home/tree_view.html | 24 - .../app/ccsdk/inventory/blueprint-controllers.js | 2300 +++++++++++-------- .../app/ccsdk/inventory/blueprint-service.js | 91 +- .../app/ccsdk/inventory/deployment-controllers.js | 1352 ----------- .../app/ccsdk/inventory/deployment-service.js | 160 +- .../app/ccsdk/inventory/execution-service.js | 58 + .../inventory/inventory_blueprint_popups.html | 108 +- .../ccsdk/inventory/inventory_blueprint_table.html | 470 ++-- .../inventory/inventory_deployment_popups.html | 1378 +++++------ .../inventory/inventory_deployment_table.html | 148 -- .../inventory/inventory_execution_popups.html | 520 +++-- .../src/main/webapp/app/ccsdk/ops/dbcl_view.html | 6 - .../webapp/app/ccsdk/ops/tabs-view-controller.js | 271 --- .../src/main/webapp/app/ccsdk/ops/tabs_view.html | 131 -- 51 files changed, 9328 insertions(+), 7099 deletions(-) delete mode 100644 ccsdk-app-overlay/src/main/webapp/WEB-INF/oom-app.hbm.xml delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-controllers.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-service.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_popups.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_table.html create mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/plugin-service.js create mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/plugin-table-controller.js create mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/plugin_table.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/tosca-table-controller.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/tosca_table.html create mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/external/angular-local-storage.js create mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/external/select.css create mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/external/select.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/api_doc.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/controller_table.html create mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/ecd_popup_templates.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions-view-controller.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions_view.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/http-interceptor.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-instances-controller.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-router.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-style.css delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_instances_popup.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_popup_templates.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_spa.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-controller.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-directive.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-style.css delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree_view.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-controllers.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_deployment_table.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/dbcl_view.html delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs-view-controller.js delete mode 100644 ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs_view.html (limited to 'ccsdk-app-overlay/src/main') diff --git a/ccsdk-app-overlay/src/main/webapp/WEB-INF/oom-app.hbm.xml b/ccsdk-app-overlay/src/main/webapp/WEB-INF/oom-app.hbm.xml deleted file mode 100644 index b302346..0000000 --- a/ccsdk-app-overlay/src/main/webapp/WEB-INF/oom-app.hbm.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - seq_ecd_component - - - - - - - FROM EcdComponent - - - diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-controllers.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-controllers.js deleted file mode 100644 index c764165..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-controllers.js +++ /dev/null @@ -1,464 +0,0 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - *******************************************************************************/ -appDS2.controller('blueprintTableController', function($rootScope, $scope, $log, $modal, modalService, BlueprintService) { - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - // models for controls on screen - $scope.ecdapp.tableData = []; - $scope.ecdapp.currentPageNum = 1; - $scope.ecdapp.viewPerPage = 10; - // other - $scope.ecdapp.errMsg = null; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isRequestFailed = false; - - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.loadTable = function() { - $scope.ecdapp.isDataLoading = true; - BlueprintService.getBlueprints($scope.ecdapp.currentPageNum, $scope.ecdapp.viewPerPage) - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("blueprintController.loadTable failed: " + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - if (debug) - $log.debug("bluePrintController.loadTable succeeded, size " + jsonObj.data.length); - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - $scope.ecdapp.tableData = jsonObj.items; - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $log.error("blueprintController.loadTable failed: " + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - }); - }; - - /** - * Invoked at first page load AND when - * user clicks on the B2B pagination control. - */ - $scope.pageChangeHandler = function(page) { - // console.log('pageChangeHandler: current is ' + $scope.ecdapp.currentPageNum + ' new is ' + page); - $scope.ecdapp.currentPageNum = page; - $scope.ecdapp.loadTable(); - } - - /** - * Shows a modal pop-up with blueprint content. - * Passes data in via an object named "message". - */ - $scope.ecdapp.viewBlueprintModalPopup = function(blueprint) { - $scope.ecdapp.editBlueprint = null; - var modalInstance = $modal.open({ - templateUrl : 'blueprint_view_popup.html', - controller : 'blueprintViewCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-medium', - resolve : { - message : function() { - var dataForPopup = { - blueprint : blueprint - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function() { - // No response. - }); - }; - - /** - * Shows a modal pop-up to upload a blueprint. - * Passes data in via an object named "message". - * On success, updates the table. - */ - $scope.ecdapp.uploadBlueprintModalPopup = function() { - $scope.ecdapp.editBlueprint = null; - var modalInstance = $modal.open({ - templateUrl : 'blueprint_upload_popup.html', - controller : 'blueprintUploadCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-small', - resolve : { - message : function() { - var dataForPopup = { - blueprint : $scope.ecdapp.editBlueprint, - blueprintList : $scope.ecdapp.tableData - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - if (debug) - $log.debug('uploadBlueprintModalPopup: response: ' + JSON.stringify(response)); - if (response == null) { - // $log.debug('user closed dialog'); - } - else { - if (response.error != null) { - $log.error('uploadBlueprintModalPopup failed: ' + response.error); - alert('Failed to upload blueprint:\n' + response.error); - } - else { - // success, get the updated list. - $scope.ecdapp.loadTable(); - } - } - }); - }; - - /** - * Shows a modal pop-up to create a deployment from a blueprint. - * Passes data in via an object named "message". - */ - $scope.ecdapp.deployBlueprintModalPopup = function(blueprint) { - var modalInstance = $modal.open({ - templateUrl : 'blueprint_deploy_popup.html', - controller : 'blueprintDeployCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-medium', - resolve : { - message : function() { - var dataForPopup = { - blueprint : blueprint - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - if (debug) - $log.debug('deployBlueprintModalPopup: response: ' + JSON.stringify(response)); - if (response == null) { - if (debug) - $log.debug('user closed dialog'); - } - else { - if (response.error != null) { - $log.error('deployBlueprintModalPopup failed: ' + response.error); - alert('Failed to deploy blueprint:\n' + response.error); - // No need to update THIS table. - // Must switch to deployments page to see result? Awkward. - } - } - }); - }; - - /** - * Shows a modal pop-up to confirm deletion. - * On successful completion, updates the table. - */ - $scope.ecdapp.deleteBlueprintModalPopup = function(blueprint) { - modalService.popupConfirmWin("Confirm", "Delete blueprint with ID '" - + blueprint.id + "'?", function() { - BlueprintService.deleteBlueprint(blueprint.id).then( - function(response) { - if (debug) - $log.debug('deleteBlueprintModalPopup: response: ' + JSON.stringify(response)); - if (response && response.error) { - // $log.error('deleteBlueprint failed: ' + response.error); - alert('Failed to delete blueprint:\n' + response.error); - } - else { - // No response body on success. - $scope.ecdapp.loadTable(); - } - }, - function(error) { - $log.error('BlueprintService.deleteBlueprint failed: ' + error); - alert('Service failed to delete blueprint:\n' + error); - }); - }); - }; - - // Populate the table on load. Note that the b2b selector code - // sets the page-number value, and the change event calls load table. - // Do not call this here to avoid double load: - // $scope.ecdapp.loadTable(); - -}); - -/*************************************************************************/ - -appDS2.controller('blueprintUploadCtrl', function( - $scope, $log, $modalInstance, message, BlueprintService) { - - 'use strict'; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Upload Blueprint'; - $scope.ecdapp.uploadRequest = - { - blueprint_id : '', - blueprint_filename : '', - zip_url : '' - }; - - /** - * Validates content of user-editable fields. - * Uses the list in message.feedList - * Returns null if all is well, - * a descriptive error message otherwise. - */ - $scope.ecdapp.validateRequest = function(uploadRequest) { - if (uploadRequest == null) - return "No data found.\nPlease enter some values."; - if (uploadRequest.blueprint_id == null || uploadRequest.blueprint_id.trim() === '') - return "ID is required.\nPlease enter a value."; - if (uploadRequest.blueprint_filename == null || uploadRequest.blueprint_filename.trim() === '') - return "File name is required.\nPlease enter a value."; - if (uploadRequest.blueprint_filename.toLowerCase().substr(-4) !== 'yaml') - return "File name must end with YAML.\nPlease use that suffix."; - if (uploadRequest.zip_url == null || uploadRequest.zip_url.trim() === '') - return "Zip file URL is required.\nPlease enter a value."; - return null; - } - - $scope.ecdapp.uploadBlueprint = function(uploadRequest) { - var validateMsg = $scope.ecdapp.validateRequest(uploadRequest); - if (validateMsg != null) { - alert('Invalid upload request:\n' + validateMsg); - return; - } - BlueprintService.uploadBlueprint(uploadRequest) - .then(function(response) { - // $log.debug('blueprintPopupCtrl: response: ' + response); - if (response.error) - alert('Failed to upload blueprint:\n' + response.error); - else - $modalInstance.close(response); - }, - function (error) { - $log.error('blueprintUploadCtrl: error while uploading: ' + error); - alert('Server rejected upload request:\n' + error); - } - ); - - }; - -}); - -/*************************************************************************/ - -appDS2.controller('blueprintViewCtrl', function( - $scope, $log, message, BlueprintService) { - - 'use strict'; - - var debug = false; - - if (debug) - $log.debug("blueprintViewCtrl.message: " + JSON.stringify(message)); - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.blueprintId = message.blueprint.id; - - $scope.ecdapp.label = 'View Blueprint ' + message.blueprint.id; - - // Fetch the blueprint - $scope.ecdapp.isDataLoading = true; - BlueprintService.viewBlueprint(message.blueprint.id).then(function(jsonObj) { - if (debug) - $log.debug("blueprintViewCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed'; - } - else { - $scope.ecdapp.blueprint = jsonObj.content; - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $scope.ecdapp.isDataLoading = false; - alert('Failed to get blueprint. Please retry.'); - $log.error("blueprintViewCtrl failed: " + error); - }); - -}); - - -/*************************************************************************/ - -appDS2.controller('blueprintDeployCtrl', function( - $scope, $log, $modalInstance, message, DeploymentService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Deploy Blueprint'; - - // Cache the input parameter names for validation - if (debug) - $log.debug('blueprintDeployCtrl: inputs: ' + JSON.stringify(message.blueprint.plan.inputs)); - $scope.ecdapp.inputsDict = message.blueprint.plan.inputs; - - // Copy the input parameter names and default values - let inputsAndDefaults = {}; - for (var pkey in message.blueprint.plan.inputs) { - if (debug) - $log.debug('blueprintDeployCtrl: checking key ' + pkey); - let dval = message.blueprint.plan.inputs[pkey].default; - if (! dval) - dval = ''; - inputsAndDefaults[pkey] = dval; - } - if (debug) - $log.debug('blueprintDeployCtrl: inputsAndDefaults: ' + JSON.stringify(inputsAndDefaults)); - - // Create an object for edit - $scope.ecdapp.editRequest = { - deployment_id : '', - blueprint_id : message.blueprint.id, - fileModel : null, - parmFileDict : inputsAndDefaults - }; - - /** - * Handler for file-read event reads file, parses YAML, validates content. - */ - var fileReader = new FileReader(); - fileReader.onload = function(event) { - let yamlString = fileReader.result; - if (debug) - $log.debug('fileReader.onload: read: ' + yamlString); - let ydict = {}; - try { - ydict = YAML.parse(yamlString); - } - catch (ex) { - alert('Failed to parse file as YAML:\n' + ex); - } - // Process the file - for (var ykey in ydict) { - let yval = ydict[ykey]; - if (debug) - $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); - // Allow only expected keys with scalar values - if (! (ykey in $scope.ecdapp.editRequest.parmFileDict)) - alert('Unexpected file content:\nKey not defined by blueprint:\n' + ykey); - else if (typeof yval !== 'string' && typeof yval !== 'number') - alert('Unexpected file content:\nNot a simple key-value pair:\n' + ykey); - else - $scope.ecdapp.editRequest.parmFileDict[ykey] = yval; - } - if (debug) - $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.editRequest.parmFileDict)); - - // Update table in all cases - $scope.$apply(); - } - - // Handler for file-select event - $scope.handleFileSelect = function() { - if (debug) - $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); - fileReader.readAsText($scope.ecdapp.editRequest.fileModel); - }; - - /** - * Validates content of user-editable fields. - * Returns null if all is well, - * a descriptive error message otherwise. - */ - $scope.ecdapp.validateRequest = function(editRequest) { - if (editRequest == null) - return 'No data found.\nPlease enter some values.'; - if (editRequest.deployment_id == null || editRequest.deployment_id.trim() == '') - return 'Deployment ID is required.\nPlease enter a value.'; - if (editRequest.blueprint_id == null || editRequest.blueprint_id.trim() == '') - return 'Blueprint ID is required.\nPlease enter a value.'; - // Check that every file parameter is defined by blueprint - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) { - // Defined in blueprint? - if (! $scope.ecdapp.inputsDict[pkey]) - return 'Unexpected input parameter\n' + pkey; - // Populated? - let parmVal = $scope.ecdapp.editRequest.parmFileDict[pkey]; - if (parmVal == null || (typeof (parmVal) === 'string' && parmVal.trim().length == 0)) - return 'Missing value for parameter\n' + pkey; - } - // Check that a value is supplied for every expected input - for (var bkey in $scope.ecdapp.inputsDict) { - if (! $scope.ecdapp.editRequest.parmFileDict[bkey]) - return 'Missing input parameter\n' + bkey; - } - return null; - } - - $scope.ecdapp.deployBlueprint = function(editRequest) { - if (debug) - $log.debug('deployBlueprint: editRequest is ' + JSON.stringify($scope.ecdapp.editRequest)); - var validateMsg = $scope.ecdapp.validateRequest(editRequest); - if (validateMsg != null) { - alert('Invalid Request:\n' + validateMsg); - return; - } - // Create request with key:value parameters dictionary - let deployRequest = { - deployment_id : editRequest.deployment_id, - blueprint_id : editRequest.blueprint_id, - parameters : {} - }; - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) - deployRequest.parameters[pkey] = $scope.ecdapp.editRequest.parmFileDict[pkey]; - if (debug) - $log.debug('deployBlueprint: deployRequest is ' + JSON.stringify(deployRequest)); - - DeploymentService.deployBlueprint(deployRequest) - .then(function(response) { - if (response.error) - alert('Failed to deploy blueprint:\n' + response.error); - else - $modalInstance.close(response); - }, - function (error) { - $log.error('blueprintDeployCtrl: error while deploying: ' + error); - alert('Server rejected deployment request:\n' + error); - } - ); - - }; - -}); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-service.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-service.js deleted file mode 100644 index f058b09..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint-service.js +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - *******************************************************************************/ -appDS2.factory('BlueprintService', function ($http, $q, $log) { - return { - /** - * Gets one page of blue prints objects. - * @param {Number} pageNum - page number; e.g., 1 - * @param {Number} viewPerPage - number of items per page; e.g., 25 - * @return {JSON} Response object from remote side - */ - getBlueprints: function(pageNum,viewPerPage) { - // cache control for IE - let cc = "&cc=" + new Date().getTime().toString(); - let url = 'blueprints?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + cc; - return $http({ - method: 'GET', - url: url, - cache: false, - responseType: 'json' - }).then(function(response) { - if (response.data == null || typeof response.data != 'object') - return $q.reject('BlueprintService.getBlueprints: response.data null or not object'); - else - return response.data; - }, - function(error) { - $log.error('BlueprintService.getBlueprints failed: ' + JSON.stringify(error)); - return $q.reject(error.statusText); - }); - }, - - /** - * Gets blueprint content. - * @return {JSON} Response object from remote side - */ - viewBlueprint: function(id) { - // cache control for IE - let url = 'viewblueprints/' + id; - return $http({ - method: 'GET', - url: url, - cache: false, - responseType: 'json' - }).then(function(response) { - if (response.data == null || typeof response.data != 'object') - return $q.reject('BlueprintService.viewBlueprint: response.data null or not object'); - else - return response.data; - }, - function(error) { - $log.error('BlueprintService.viewBlueprint failed: ' + JSON.stringify(error)); - return $q.reject(error.statusText); - }); - }, - - uploadBlueprint: function(uploadRequest) { - let url = 'blueprints'; - return $http({ - method: 'POST', - url: url, - data: uploadRequest, - responseType: 'json' - }).then(function(response) { - if (response.data == null || typeof response.data != 'object') - return $q.reject('BlueprintService.uploadBlueprint: response.data null or not object'); - else - return response.data; - }, - function(error) { - $log.error('BlueprintService.uploadBlueprint failed: ' + JSON.stringify(error)); - return $q.reject(error.statusText); - }); - }, - - deleteBlueprint: function(id) { - let url = 'blueprints/' + id; - return $http({ - method: 'DELETE', - url: url, - cache: false, - responseType: 'json' - }).then(function(response) { - // This is called on response code 200..299. - // On success, response.data is null. - // On failure, response.data has an error message. - return response.data; - }, - function(error) { - $log.error('BlueprintService.deleteBlueprint failed: ' + JSON.stringify(error)); - return $q.reject(error.statusText); - }); - } - - }; -}); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_popups.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_popups.html deleted file mode 100644 index ee92d84..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_popups.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_table.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_table.html deleted file mode 100644 index 3ce60b9..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/blueprint_table.html +++ /dev/null @@ -1,98 +0,0 @@ -
- -

Blueprints

- - -
-
- - Please wait while the content loads. -
-
- -
- -
- -
-
- -
-
-
- -
- {{ecdapp.errMsg}} -
- -
- -
- - - - - - - - - - - - - - - - - - - -
IDFile NameDescriptionCreated DateUpdated Date
- - - - - -
- -
-
- -
-
- -
-
-
- -
-
- -
- -
- -
- -
diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-controllers.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-controllers.js index 1e80082..f89ce76 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-controllers.js +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-controllers.js @@ -1,26 +1,6 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - *******************************************************************************/ appDS2.controller('deploymentTableController', function( - $rootScope, $scope, $log, $modal, DeploymentService) { + $rootScope, $scope, $log, $modal, $routeParams, DeploymentService, ControllerService, + InventoryDeploymentService, localStorageService, $interval) { 'use strict'; @@ -36,17 +16,469 @@ appDS2.controller('deploymentTableController', function( // other $scope.ecdapp.errMsg = null; $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.useCache = true; + $scope.ecdapp.groupByTenant = false; + $scope.ecdapp.filterByUser = true; + $scope.ecdapp.cache_switch = { + value: true + }; + $scope.ecdapp.getTenants = function() { + ControllerService.getTenants() + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("blueprintController.getTenants failed: " + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + var tenants = []; + for (var tenIndx = 0; tenIndx < jsonObj.items.length; tenIndx++) { + tenants.push(jsonObj.items[tenIndx].name); + } + $scope.ecdapp.availableTenants = tenants; + if ($scope.ecdapp.availableTenants != undefined) { + $scope.ecdapp.selectedTenant = $scope.ecdapp.availableTenants[0]; + } + localStorageService.set('tenants', JSON.stringify(tenants)); + } + }, function(error) { + $log.error("blueprintController.getTenants failed: " + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + }); + }; + + $scope.ecdapp.availableTenants = JSON.parse(localStorageService.get('tenants')); + if ($scope.ecdapp.availableTenants == undefined) { + $scope.ecdapp.getTenants(); + } else { + //$scope.ecdapp.selectedTenant = $scope.ecdapp.availableTenants[0]; + $scope.ecdapp.selectedTenant = ''; + } + // searching + $scope.ecdapp.searchBy = $routeParams.depId; + if ($scope.ecdapp.searchBy == undefined) { + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + + "cache:" + $scope.ecdapp.useCache + ";" +"owner:" + $scope.userId + ";"; + //+ "user:" + $scope.ecdapp.filterByUser + ";"; + } else { + if ($scope.ecdapp.searchBy.includes("owner")) { + if ($scope.ecdapp.searchBy.split(":")[1] === "group") { + $scope.ecdapp.filterByUser = false; + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + + "cache:" + $scope.ecdapp.useCache + ";"; + } + } else { + $scope.ecdapp.selectedTenant = $scope.ecdapp.searchBy.split(";")[0].split(":")[1] + } + } + //$scope.ecdapp.selectedTenant = "default_tenant"; + //if ($scope.ecdapp.availableTenants != undefined) { + // $scope.ecdapp.selectedTenant = $scope.ecdapp.availableTenants[0]; + //} + + // sorting + $scope.ecdapp.sortBy = null; + + $scope.ecdapp.isDisabled = false; + $scope.ecdapp.isDetailView = false; + $scope.ecdapp.isHelmType = false; + $scope.ecdapp.aafUsernameString; + $scope.ecdapp.dcaeTargetTypeString; + $scope.ecdapp.selectedSrvc; + $scope.ecdapp.usingAafFilter = false; + $scope.ecdapp.usingDcaeTargetTypeFilter = false; + $scope.ecdapp.selectedOwner; + $scope.ecdapp.availableServices; // = JSON.parse(localStorageService.get('deplNames')); + $scope.ecdapp.selectedServices; + $scope.ecdapp.bpOwners = JSON.parse(localStorageService.get('bpOwners')); + + $scope.ecdapp.availableStatus = + ['pending','started','cancelling','force_cancelling','cancelled','terminated','failed']; + $scope.ecdapp.selectedStatus; + + $scope.ecdapp.showingMoreFilters = false; + + $scope.ecdapp.toggleMoreFilters = function() { + $scope.ecdapp.showingMoreFilters = !$scope.ecdapp.showingMoreFilters; + }; + + + // Handler for disabling non aaf/dcae target type search fields + $scope.ecdapp.handleDisableOtherFields = function() { + //If using aaf filter, disable others + //and clear the dcae target type field + if ($scope.ecdapp.aafUsernameString == '' || typeof $scope.ecdapp.aafUsernameString == "undefined") + $scope.ecdapp.usingAafFilter = false; + else { + $scope.ecdapp.usingAafFilter = true; + $scope.ecdapp.dcaeTargetTypeString = ''; + } + + //If using dcae target type filter, disable others + //and clear the aaf filter field + if ($scope.ecdapp.dcaeTargetTypeString == '' || typeof $scope.ecdapp.dcaeTargetTypeString == "undefined") + $scope.ecdapp.usingDcaeTargetTypeFilter = false; + else { + $scope.ecdapp.usingDcaeTargetTypeFilter = true; + $scope.ecdapp.aafUsernameString = ''; + } + }; + + // get the blueprints summary list + $scope.ecdapp.bp = []; + $scope.ecdapp.getAllAuthBpList = function() { + InventoryBlueprintService.getBlueprintsSummary() + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryDeploymentUpdateCtrl.loadTable failed: " + jsonObj.error); + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.bp = []; + } else { + $scope.ecdapp.errMsg = null; + $scope.ecdapp.bp = jsonObj; + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $log.error("inventoryDeploymentUpdateCtrl.loadTable failed: " + error); + $scope.ecdapp.errMsg = error; + $scope.ecdapp.bp = []; + $scope.ecdapp.isDataLoading = false; + }); + }; + + $scope.ecdapp.getDeploymentsList = function() { + InventoryDeploymentService.getDeploymentList($scope.ecdapp.searchBy).then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryDeploymentController.getDeploymentList failed: " + + jsonObj.error); + $scope.ecdapp.availableServices = []; + } else { + //localStorageService.set('deplNames', JSON.stringify(jsonObj)); + $scope.ecdapp.availableServices = jsonObj; + //JSON.parse(localStorageService.get('deplNames')); + } + }, + function(error) { + $log.error("inventoryDeploymentController.getDeploymentList failed: " + + error); + $scope.ecdapp.availableServices = []; + }); + }; + + $scope.ecdapp.reloadTable = function() { + $scope.ecdapp.currentPageNum = 1; + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + +"cache:" + $scope.ecdapp.useCache + ";"; + //+ "user:" + $scope.ecdapp.filterByUser + ";"; + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy += "owner:" + $scope.userId + ";"; + } + $scope.ecdapp.searchString = ''; + $scope.ecdapp.resetFilters(); + $scope.ecdapp.loadTable(); + }; + + $scope.ecdapp.resetFilters = function() { + $scope.ecdapp.selectedServices = ''; + $scope.ecdapp.selectedTenants = ''; + $scope.ecdapp.selectedStatus = ''; + $scope.ecdapp.selectedOwner = ''; + $scope.ecdapp.isHelmType = false; + $scope.ecdapp.searchString = ''; + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + +"cache:" + $scope.ecdapp.useCache + ";"; + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy += "owner:" + $scope.userId + ";"; + } + /* + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + +"cache:" + $scope.ecdapp.useCache + ";"+ "user:" + $scope.ecdapp.filterByUser + ";"; + */ + }; + $scope.ecdapp.filterBySvc = function() { + if ( typeof $scope.ecdapp.searchString != "undefined" && + $scope.ecdapp.searchString != '') { + if ($scope.ecdapp.searchString.includes("serviceRef:") || + $scope.ecdapp.searchString.includes("tenant:") || + $scope.ecdapp.searchString.includes("status:") || + $scope.ecdapp.searchString.includes("helm:")) { + $scope.ecdapp.searchBy = $scope.ecdapp.searchString +";cache:" + $scope.ecdapp.useCache + ";"; + // + "user:" + $scope.ecdapp.filterByUser + ";"; + } else { + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + $scope.ecdapp.searchBy += 'serviceRef:' + $scope.ecdapp.searchString +";cache:" + $scope.ecdapp.useCache + ";"; + //+ "user:" + $scope.ecdapp.filterByUser + ";"; + } + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy += "owner:" + $scope.userId + ";"; + } + $scope.ecdapp.searchTable(); + } + }; + + $scope.ecdapp.extendedfilterSrch = function() { + /* + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + + "cache:" + $scope.ecdapp.useCache + ";" + "user:" + $scope.ecdapp.filterByUser + ";"; + * + */ + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + + "cache:" + $scope.ecdapp.useCache + ";"; + + if ( typeof $scope.ecdapp.selectedServices != "undefined" && + $scope.ecdapp.selectedServices != '') { + var svcFilterStr = 'serviceRef:' + $scope.ecdapp.selectedServices.toString(); + $scope.ecdapp.searchBy += svcFilterStr + ";" + } + if ( typeof $scope.ecdapp.selectedOwner != "undefined" && + $scope.ecdapp.selectedOwner != '') { + var ownerFilterStr = 'owner:' + $scope.ecdapp.selectedOwner.toString(); + $scope.ecdapp.searchBy += ownerFilterStr + ';' + } + if ( typeof $scope.ecdapp.selectedStatus != "undefined" && + $scope.ecdapp.selectedStatus != '') { + var statusFilterStr = 'status:' + $scope.ecdapp.selectedStatus.toString(); + $scope.ecdapp.searchBy += statusFilterStr + ';' + } + if ( typeof $scope.ecdapp.isHelmType != "undefined" && + $scope.ecdapp.isHelmType == true) { + var helmFilterStr = 'helm:' + $scope.ecdapp.isHelmType; + $scope.ecdapp.searchBy += helmFilterStr + ';' + } + + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy += "owner:" + $scope.userId + ";"; + } + //If using AAF username filter, ignore other fields and do filtered search. + if ($scope.ecdapp.usingAafFilter) { + var aafFilterStr = 'aafUsername:' + $scope.ecdapp.aafUsernameString.toString(); + $scope.ecdapp.searchBy = $scope.ecdapp.aafUsernameString.toString(); + $scope.ecdapp.searchString = aafFilterStr + ';'; + $scope.ecdapp.searchTableAafFilter(); + } + else if ($scope.ecdapp.usingDcaeTargetTypeFilter) { + var dcaeTargetTypeFilterStr = 'dcaeTargetType:' + $scope.ecdapp.dcaeTargetTypeString.toString(); + $scope.ecdapp.searchBy = $scope.ecdapp.dcaeTargetTypeString.toString(); + $scope.ecdapp.searchString = dcaeTargetTypeFilterStr + ';'; + $scope.ecdapp.searchTableDcaeTargetTypeFilter(); + } + else { + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + $scope.ecdapp.searchTable(); + } + }; + + $scope.ecdapp.sortTable = function(sortBy) { + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.sortBy = sortBy; + DeploymentService.getDeployments($scope.ecdapp.currentPageNum, + $scope.ecdapp.viewPerPage, $scope.ecdapp.sortBy, $scope.ecdapp.searchBy).then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("DeploymentController.sortTable failed: " + + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + $scope.ecdapp.tableData = jsonObj.items; + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error("DeploymentController.sortTable failed: " + + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + }); + }; + /** + * Loads the table. Interprets the remote controller's response and copies + * to scope variables. The response is either a list to be assigned to + * tableData, or an error to be shown. + */ + $scope.ecdapp.searchTable = function() { + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.showingMoreFilters = false; + if ($scope.ecdapp.currentPageNum != 1) { + $scope.ecdapp.currentPageNum = 1; + } else { + $scope.ecdapp.stopLoading(); + DeploymentService.getDeployments($scope.ecdapp.currentPageNum, + $scope.ecdapp.viewPerPage, $scope.ecdapp.sortBy, $scope.ecdapp.searchBy).then( + function(jsonObj) { + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 180000, 100, false); + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + if (jsonObj.error) { + $log.error("DeploymentController.loadTable failed: " + + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + $scope.ecdapp.tableData = jsonObj.items; + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + $scope.ecdapp.searchBy = ''; + $log.error("DeploymentController.loadTable failed: " + + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + }); + } + }; + + /** + * Loads the table with AAF Filter. Interprets the remote controller's response and copies + * to scope variables. The response is either a list to be assigned to + * tableData, or an error to be shown. + */ + $scope.ecdapp.searchTableAafFilter = function() { + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.showingMoreFilters = false; + if ($scope.ecdapp.currentPageNum != 1) { + $scope.ecdapp.currentPageNum = 1; + } else { + $scope.ecdapp.stopLoading(); + InventoryDeploymentService.getDeploymentsAafFilter($scope.ecdapp.currentPageNum, + $scope.ecdapp.viewPerPage, $scope.ecdapp.searchBy).then( + function(jsonObj) { + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 180000, 100, false); + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + if (jsonObj.error) { + $log.error("inventoryDeploymentController.loadTable failed: " + + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + $scope.ecdapp.tableData = jsonObj.items; + //$scope.ecdapp.updateTable(); + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + $scope.ecdapp.searchBy = ''; + $log.error("inventoryDeploymentController.loadTable failed: " + + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + }); + } + }; + + /** + * Loads the table with Dcae target type Filter. Interprets the remote controller's response and copies + * to scope variables. The response is either a list to be assigned to + * tableData, or an error to be shown. + */ + $scope.ecdapp.searchTableDcaeTargetTypeFilter = function() { + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.showingMoreFilters = false; + if ($scope.ecdapp.currentPageNum != 1) { + $scope.ecdapp.currentPageNum = 1; + } else { + $scope.ecdapp.stopLoading(); + InventoryDeploymentService.getDeploymentsDcaeTargetTypeFilter($scope.ecdapp.currentPageNum, + $scope.ecdapp.viewPerPage, $scope.ecdapp.searchBy).then( + function(jsonObj) { + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 180000, 100, false); + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + if (jsonObj.error) { + $log.error("inventoryDeploymentController.loadTable failed: " + + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + $scope.ecdapp.tableData = jsonObj.items; + //$scope.ecdapp.updateTable(); + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + $scope.ecdapp.searchBy = ''; + $log.error("inventoryDeploymentController.loadTable failed: " + + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + }); + } + }; + $scope.ecdapp.stopLoading = function() { + if (angular.isDefined(stop)) { + $interval.cancel(stop); + stop = undefined; + } + }; + + $scope.ecdapp.toggleRefresh = function() { + if ($scope.ecdapp.useCache === true) { + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 180000, 100, false); + } else { + $scope.ecdapp.stopLoading(); + } + }; + + if ($scope.ecdapp.useCache === true) { + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 180000, 100, false); + } + + $scope.ecdapp.toggleUserFilt = function() { + if ($scope.ecdapp.filterByUser === true) { + $scope.ecdapp.groupByTenant = false; + $scope.ecdapp.selectedTenant = ''; + } else { + $scope.ecdapp.searchString = ''; + } + $scope.ecdapp.reloadTable(); + } + + $scope.ecdapp.toggleTenantFilt = function() { + if ($scope.ecdapp.groupByTenant === false) { + $scope.ecdapp.selectedTenant = ''; + } + } /** * Loads the table. Interprets the remote controller's response and copies * to scope variables. The response is either a list to be assigned to * tableData, or an error to be shown. */ - $scope.ecdapp.loadTable = function() { + $scope.ecdapp.loadTable = function(sortBy, searchBy) { $scope.ecdapp.isDataLoading = true; + //$scope.ecdapp.searchString = ''; + $scope.ecdapp.sortBy = sortBy; DeploymentService.getDeployments($scope.ecdapp.currentPageNum, - $scope.ecdapp.viewPerPage).then( + $scope.ecdapp.viewPerPage, $scope.ecdapp.sortBy, $scope.ecdapp.searchBy).then( function(jsonObj) { if (jsonObj.error) { $log.error("deploymentController.loadTable failed: " @@ -69,7 +501,13 @@ appDS2.controller('deploymentTableController', function( $scope.ecdapp.errMsg = error; $scope.ecdapp.tableData = []; $scope.ecdapp.isDataLoading = false; + var loc = location.pathname; + var loc1 = loc.replace("/", ""); + var loc2 = loc1.replace("/ecd", "/login.htm"); + alert("Session expired - Sign in again"); + location.replace("/"+loc2); }); + $scope.ecdapp.getDeploymentsList(); }; /** @@ -79,9 +517,186 @@ appDS2.controller('deploymentTableController', function( $scope.pageChangeHandler = function(page) { // console.log('pageChangeHandler: current is ' + $scope.ecdapp.currentPageNum + ' new is ' + page); $scope.ecdapp.currentPageNum = page; - $scope.ecdapp.loadTable(); + //$scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";"; + $scope.ecdapp.loadTable($scope.ecdapp.sortBy, $scope.ecdapp.searchBy); } + $scope.ecdapp.tenantChangeHandler = function() { + $scope.ecdapp.currentPageNum = 1; + $scope.ecdapp.searchBy = "tenant:" + $scope.ecdapp.selectedTenant + ";" + +"cache:" + $scope.ecdapp.useCache + ";"; + //+ "user:" + $scope.ecdapp.filterByUser + ";"; + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy += "owner:" + $scope.userId + ";"; + } + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + $scope.ecdapp.loadTable($scope.ecdapp.sortBy, $scope.ecdapp.searchBy); + } + + //$scope.ecdapp.getTenants(); + + /** + * modal pop-up for app reconfig operation + * + */ + $scope.ecdapp.reconfigDeploymentModalPopup = function(deployment) { + var modalInstance = $modal.open({ + templateUrl : 'app_reconfig_view_popup.html', + controller : 'appReconfigCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + deployment : deployment + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + // No response. + }); + }; + + /** + * Shows a modal pop-up to confirm deletion. + * On successful completion, updates the table. + */ + $scope.ecdapp.deleteDeploymentModalPopup = function(deployment) { + deployment.onlyLatest = true; + var modalInstance = $modal.open({ + templateUrl : 'inventory_deployment_delete_popup.html', + controller : 'deploymentDeleteCtrl', + sizeClass: 'modal-small', + resolve : { + message : function() { + var dataForPopup = { + deployment : deployment, + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + if (debug) + $log.debug('deleteDeploymentPopup: response: ' + JSON.stringify(response)); + if (response == null) { + // $log.debug('user closed dialog'); + } + else { + if (response.error != null) { + $log.error('deleteDeploymentModalPopup failed: ' + response.error); + alert('Failed to delete deployment:\n' + response.error); + } + else { + $scope.ecdapp.viewDeploymentExecutionsModalPopup(deployment); + } + } + }); + }; + + /** + * Shows a modal pop-up with executions for a deployment. + * Passes data in via an object named "deployment". + */ + $scope.ecdapp.viewDeploymentExecutionsModalPopup = function(deployment) { + var modalInstance = $modal.open({ + templateUrl : 'inventory_execution_view_popup.html', + controller : 'deploymentExecutionsViewCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + deployment : deployment + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + // No response. + }); + }; + + + $scope.ecdapp.viewDeploymentInputsModalPopup = function(deployment) { + var modalInstance = $modal.open({ + templateUrl : 'inventory_deployment_inputs_view_popup.html', + controller : 'deploymentInputsViewCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + deployment : deployment + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + // No response. + }); + }; + + /** + * Shows a modal pop-up to initiate update blueprint for a deployment + */ + $scope.ecdapp.updateDeploymentModalPopup = function(deployment) { + var modalInstance = $modal.open({ + templateUrl: 'inventory_deployment_update_popup.html', + controller: 'deploymentUpdateCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve: { + message: function() { + var dataForPopup = { + deployment : deployment + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + if (response != null) { + if (response.error != null) { + $log.error('updateDeploymentModalPopup failed: ' + response.error); + alert('Failed to update deployment:\n' + response.error); + } + else { + $scope.ecdapp.viewDeploymentExecutionsModalPopup(deployment); + } + } + }); + }; + + /** + * Shows a modal pop-up with blueprint content. + * Passes data in via an object named "message". + */ + $scope.ecdapp.getBlueprintDataModal = function(deployment) { + var modalInstance = $modal.open({ + templateUrl : 'blueprint_content_popup.html', + controller : 'deployBlueprintContentCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + blueprint : deployment, + tenant_name: $scope.ecdapp.selectedTenant + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + }); + }; + + /** * Shows a modal pop-up to create an execution from a deployment. * Passes data in via an object named "message". @@ -96,7 +711,7 @@ appDS2.controller('deploymentTableController', function( resolve : { message : function() { var dataForPopup = { - deployment : deployment + deployment : deployment, }; return dataForPopup; } @@ -119,253 +734,1480 @@ appDS2.controller('deploymentTableController', function( }); }; - /** - * Shows a modal pop-up to confirm deletion. - * On successful completion, updates the table. - */ - $scope.ecdapp.deleteDeploymentModalPopup = function(deployment) { - var modalInstance = $modal.open({ - templateUrl : 'deployment_delete_popup.html', - controller : 'deploymentDeleteCtrl', - sizeClass: 'modal-small', - resolve : { - message : function() { - var dataForPopup = { - deployment : deployment - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - if (debug) - $log.debug('deleteDeploymentPopup: response: ' + JSON.stringify(response)); - if (response == null) { - // $log.debug('user closed dialog'); - } - else { - if (response.error != null) { - $log.error('deleteDeploymentModalPopup failed: ' + response.error); - alert('Failed to delete deployment:\n' + response.error); - } - else { - // success, get the updated list. - $scope.ecdapp.loadTable() - } - } - }); - }; + $scope.ecdapp.checkHelmStatus = function(deployment) { + var selTenant = deployment.tenant_name; + if ( typeof selTenant === "undefined" ) { + selTenant = "default_tenant"; + } + deployment.onlyLatest = true; + + // This object holds data for this operation + $scope.ecdapp.helmStatusRequest = { + "deployment_id": deployment.id, + "workflow_name": "status", + "tenant": selTenant + }; + InventoryDeploymentService.helmStatusFlow($scope.ecdapp.helmStatusRequest).then(function(jsonObj) { + if (debug) + $log.debug("checkHelmStatus response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; + $scope.ecdapp.updatingDeployment = false; + $scope.ecdapp.isDataLoading = false; + alert('Request Failed: ' + jsonObj.error); + } else { + console.log('%c POSTED helm status request', 'color: magenta; font-weight: bold;'); + $scope.ecdapp.viewDeploymentExecutionsModalPopup(deployment); + } + }, function(error) { + $log.error('helmStatusFlow failed: ' + error); + alert('helmStatusFlow failed: ' + error); + }); + + }; + + /** + * Shows a modal pop-up to initiate helm upgrade for a deployment + */ + $scope.ecdapp.upgradeDeploymentModalPopup = function(deployment) { + //console.log(deployment); + var modalInstance = $modal.open({ + templateUrl: 'inventory_deployment_upgrade_popup.html', + controller: 'deploymentUpgradeCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve: { + message: function() { + var dataForPopup = { + deployment : deployment + }; + return dataForPopup; + } + } + }); + }; + + /** + * Shows a modal pop-up to initiate helm rollback for a deployment + */ + $scope.ecdapp.rollbackDeploymentModalPopup = function(deployment) { + var modalInstance = $modal.open({ + templateUrl: 'inventory_deployment_rollback_popup.html', + controller: 'deploymentRollbackCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve: { + message: function() { + var dataForPopup = { + deployment : deployment + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + // No response. + }); + }; + $scope.$on('$destroy', function() { + // Make sure that the interval is destroyed too + $scope.ecdapp.stopLoading(); + }); + }); /*************************************************************************/ appDS2.controller('deploymentDeleteCtrl', function( - $scope, $log, $modalInstance, message, DeploymentService) { + $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { - 'use strict'; - - // Controls logging in this controller - var debug = false; + 'use strict'; - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Delete Deployment'; - $scope.ecdapp.deploymentId = message.deployment.id; - $scope.ecdapp.ignoreLiveNodes = false; - - $scope.ecdapp.deleteDeploymentById = function(){ - DeploymentService.deleteDeployment($scope.ecdapp.deploymentId, $scope.ecdapp.ignoreLiveNodes).then( - function(response) { - if (debug) - $log.debug('deploymentDeleteCtrl.deleteDeployment: ' + JSON.stringify(response)); - if (response && response.error) { - $log.error('DeploymentService.deleteDeployment failed: ' + response.error); - alert('Failed to delete deployment:\n' + response.error); - } - else { - // Delete service returns null on success. - $modalInstance.close("success"); - } - }, - function(error) { - $log.error('DeploymentService.deleteDeployment failed: ' + error); - alert('Service failed to delete deployment:\n' + error); - }); - } + // Controls logging in this controller + var debug = false; + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'Undeploy?'; + $scope.ecdapp.deploymentRef = message.deployment.id; + var selTenant = message.deployment.tenant_name; + $scope.ecdapp.ui_tenant = selTenant; + $scope.ecdapp.tenant = selTenant; + + $scope.ecdapp.deleteDeploymentById = function(){ + $scope.ecdapp.isDisabled = true; + InventoryDeploymentService.deleteDeployment($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then( + function(response) { + if (debug) + $log.debug('inventoryDeploymentDeleteCtrl.deleteDeployment: ' + JSON.stringify(response)); + if (response && response.error) { + $log.error('InventoryDeploymentService.deleteDeployment failed: ' + response.error); + alert('Failed to delete deployment:\n' + response.error); + } + else { + // Delete service returns null on success. + $modalInstance.close("success"); + } + }, + function(error) { + $log.error('InventoryDeploymentService.deleteDeployment failed: ' + error); + alert('Service failed to delete deployment:\n' + error); + }); + } }); /*************************************************************************/ -appDS2.controller('deploymentExecuteCtrl', function( - $scope, $log, $modalInstance, message, ExecutionService) { +appDS2.controller('deploymentExecutionsViewCtrl', function( + $scope, $rootScope, $interval, $log, $modalInstance, message, modalService, InventoryExecutionService, ExecutionService) { - 'use strict'; - - // Controls logging in this controller - var debug = false; + 'use strict'; - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Execute Deployment'; - - // Cache the input parameter names for validation - $scope.ecdapp.inputsDict = {}; - if (debug) - $log.debug('DeploymentXeqCtrl: inputsDict is ' + JSON.stringify($scope.ecdapp.inputsDict)); - - // Copy the input names and values - // (different structure than blueprint) - /*for (var pkey in message.deployment.inputs) { - let dval = message.deployment.inputs[pkey]; - inputsAndValues[pkey] = dval; - }*/ - - // Gather workflow names as a simple list - var workflowList = []; - for (var i = 0; i < message.deployment.workflows.length; i++) - workflowList.push(message.deployment.workflows[i].name); - if (debug) - $log.debug('DeploymentXeqCtrl: workflowList is ' + JSON.stringify(workflowList)); - - // Create an object for edit. - $scope.ecdapp.editRequest = { - deployment_id : message.deployment.id, - allow_custom_parameter : false, - force : false, - // Has title and value objects - workflow_name: { value : '' }, - workflow_list : workflowList, - fileModel : null, - parmFileDict : {} - }; - - $scope.selectWorkflowName = function(){ - var workflows = message.deployment.workflows; - let inputsAndValues = {}; - var res = workflows.filter(function(d){ - if(d.name == $scope.ecdapp.editRequest.workflow_name.value){ - return d - } - }); - for(var key in res[0].parameters){ - inputsAndValues[key] = typeof (res[0].parameters[key].default) === 'string' ? res[0].parameters[key].default : null; - } - $scope.ecdapp.inputsDict = inputsAndValues; - $scope.ecdapp.editRequest.parmFileDict = inputsAndValues; - }; - - if (debug) - $log.debug('DeploymentXeqCtrl: editRequest is ' + JSON.stringify($scope.ecdapp.editRequest)); + var debug = false; - /** - * Handler for file-read event reads file, parses YAML, validates content. - */ - var fileReader = new FileReader(); - fileReader.onload = function(event) { - let yamlString = fileReader.result; - if (debug) - $log.debug('fileReader.onload: read: ' + yamlString); - let ydict = {}; - try { - ydict = YAML.parse(yamlString); - } - catch (ex) { - alert('Failed to parse file as YAML:\n' + ex); - } - for (var ykey in ydict) { - let yval = ydict[ykey]; - if (debug) - $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); - // Only accept valid, expected key-value pairs - if (typeof yval !== 'string' && typeof yval!=='number') - alert('Unexpected file content:\nNot a simple key-value pair:\n' + ykey); - else if (! (ykey in $scope.ecdapp.editRequest.parmFileDict)) - alert('Unexpected file content:\nKey not defined by deployment:\n' + ykey); - else - $scope.ecdapp.editRequest.parmFileDict[ykey] = yval; - } - if (debug) - $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.editRequest.parmFileDict)); - - // Update table in all cases - $scope.$apply(); - } + if (debug) + $log.debug("inventoryDeploymentsExecutionsViewCtrl.message: " + JSON.stringify(message)); - // Handler for file-select event - $scope.handleFileSelect = function() { - if (debug) - $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); - fileReader.readAsText($scope.ecdapp.editRequest.fileModel); - }; + // this object holds all app data and functions + $scope.ecdapp = {}; + // models for controls on screen + $scope.ecdapp.label = 'Deployment ' + message.deployment.id + ' Executions'; + $scope.ecdapp.tableData = []; + $scope.ecdapp.logTableData = []; + $scope.ecdapp.currentPageNum = 1; + $scope.ecdapp.viewPerPage = 10; + $scope.ecdapp.currentLogPageNum = 1; + $scope.ecdapp.selectedRow = null; - /** - * Validates content of user-editable fields. - * Returns null if all is well, - * a descriptive error message otherwise. - */ - var validateRequest = function(editRequest) { - if (debug) - $log.debug('validateRequest: editRequest is ' + JSON.stringify(editRequest)); - if (editRequest == null) - return "No data found.\nPlease enter some values."; - if (editRequest.deployment_id == null || editRequest.deployment_id.trim() == '') - return "Deployment ID is required.\nPlease enter a value."; - if (editRequest.workflow_name.value == null || editRequest.workflow_name.value.trim() == '') - return "Workflow name is required.\nPlease select a workflow."; - // Check that every file parameter is defined by blueprint - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) { - // Defined in blueprint? - if (! $scope.ecdapp.inputsDict[pkey]) - return 'Unexpected input parameter\n' + pkey; - // Populated? - let parmVal = $scope.ecdapp.editRequest.parmFileDict[pkey]; - if (parmVal.trim().length == 0) - return 'Missing value for parameter ' + pkey; - } - // Check that a value is supplied for every expected input - for (var bkey in $scope.ecdapp.inputsDict) { - if (! $scope.ecdapp.editRequest.parmFileDict[bkey]) - return 'Missing input parameter\n' + bkey; - } - return null; - } - - $scope.ecdapp.executeDeployment = function(editRequest) { - var validateMsg = validateRequest(editRequest); - if (validateMsg != null) { - alert('Invalid execution request:\n' + validateMsg); - return; - } - - // Create request with key:value parameters dictionary - let executeRequest = { - deployment_id : editRequest.deployment_id, - workflow_name : editRequest.workflow_name.value, - allow_custom_parameter : editRequest.allow_custom_parameter, - force : editRequest.force, - parameters : {} - }; - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) - executeRequest.parameters[pkey] = $scope.ecdapp.editRequest.parmFileDict[pkey]; - if (debug) - $log.debug('executeDeployment: executeRequest is ' + JSON.stringify(executeRequest)); - - ExecutionService.executeDeployment(executeRequest) - .then(function(response) { - if (response.error) - alert('Failed to create execution:\n' + response.error); - else - $modalInstance.close(response); - }, - function (error) { - $log.error('deploymentExecuteCtrl: error while creating execution: ' + error); - alert('Server rejected execute request:\n' + error); - } - ); + // other + $scope.ecdapp.errMsg = null; + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.isEventLogQuery = false; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.isLastExecution = message.deployment.onlyLatest; + $scope.ecdapp.isLogType = true; + $scope.ecdapp.refresh_switch = { + value: true + }; + $scope.ecdapp.options = { + "on":"On", + "off":"Off" + } + var selTenant = message.deployment.tenant_name; - }; + $scope.ecdapp.ui_tenant = selTenant; + $scope.ecdapp.tenant = selTenant; + $scope.ecdapp.execId = ""; + $scope.ecdapp.deplRef = message.deployment.id; + var stop; + /** + * Loads the table. Interprets the remote controller's response and copies + * to scope variables. The response is either a list to be assigned to + * tableData, or an error to be shown. + */ + $scope.ecdapp.loadTable = function() { + $scope.ecdapp.isDataLoading = true; + InventoryExecutionService.getExecutionsByDeployment($scope.ecdapp.deplRef, + $scope.ecdapp.tenant, + $scope.ecdapp.currentPageNum, + $scope.ecdapp.viewPerPage).then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("deploymentExecutionsViewCtrl.loadTable failed: " + + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + if (jsonObj.error.includes("404")) { + $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; + } + $scope.ecdapp.tableData = []; + $scope.ecdapp.stopLoading(); + } else { + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + var resultLen = jsonObj.items.length; + if (resultLen != undefined && resultLen > 0) { + var exec_id = jsonObj.items[resultLen-1].id; + $scope.ecdapp.execId = exec_id; + $scope.ecdapp.selectedRow = resultLen-1; + if ($scope.ecdapp.isLastExecution) { + $scope.ecdapp.tableData = []; + $scope.ecdapp.tableData.push(jsonObj.items[resultLen-1]); + } else { + $scope.ecdapp.tableData = jsonObj.items; + } + $scope.ecdapp.getExecutionLogs($scope.ecdapp.selectedRow, exec_id, $scope.ecdapp.tenant); + } + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error("inventoryDeploymentExecutionsViewCtrl.loadTable failed: " + + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + $scope.ecdapp.stopLoading(); + }); + }; + $scope.$watch('ecdapp.refresh_switch["value"]', function(newValue,oldValue,scope) { + if (newValue != oldValue) { + if (newValue === true) { + $scope.ecdapp.loadTable(); + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 30000, 100, false); + } else { + $scope.ecdapp.stopLoading(); + } + } + }, true); + + if ($scope.ecdapp.refresh_switch.value === true) { + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 30000, 100, false); + } + + $scope.ecdapp.stopLoading = function() { + if (angular.isDefined(stop)) { + $interval.cancel(stop); + stop = undefined; + } + }; + $scope.ecdapp.copyStringToClipboard = function(str) { + // Create new element + var el = document.createElement('textarea'); + // Set value (string to be copied) + el.value = str; + // Set non-editable to avoid focus and move outside of view + el.setAttribute('readonly', ''); + el.style = {position: 'absolute', left: '-9999px'}; + document.body.appendChild(el); + // Select text inside element + el.select(); + // Copy text to clipboard + document.execCommand('copy'); + // Remove temporary element + document.body.removeChild(el); + }; + + $scope.ecdapp.cancelExecutionModalPopup = function(execution, tenant) { + modalService.popupConfirmWin("Confirm", "Cancel execution with ID '" + + execution.id + "'?", function() { + $scope.ecdapp.isCancelOn = true; + // TODO: gather action from user + InventoryExecutionService.cancelExecution(execution.id, execution.deployment_id, "force-cancel", tenant).then( + function(response) { + if (debug) + $log.debug("Controller.cancelExecutionModalPopup: " + JSON.stringify(response)); + if (response && response.error) { + // $log.error('cancelExectuion failed: ' + response.error); + alert('Failed to cancel execution:\n' + response.error); + $scope.ecdapp.isCancelOn = false; + } + else { + // No response body on success. + $scope.ecdapp.isCancelOn = false; + $scope.ecdapp.loadTable(); + } + }, + function(error) { + $scope.ecdapp.isCancelOn = false; + $log.error('ExecutionService.cancelExecution failed: ' + error); + alert('Service failed to cancel execution:\n' + error); + }); + }) + }; + + /** + * Invoked at first page load AND when + * user clicks on the B2B pagination control. + */ + $scope.pageChangeHandler = function(page) { + if (debug) + console.log('pageChangeHandler: current is ' + $scope.ecdapp.currentPageNum + ' new is ' + page); + $scope.ecdapp.currentPageNum = page; + $scope.ecdapp.loadTable(); + + } + $scope.pageChangeHandlerEvent = function(page) { + if (debug) + console.log('pageChangeHandlerEvent: current is ' + $scope.ecdapp.currentLogPageNum + ' new is ' + page); + if (page != $scope.ecdapp.currentLogPageNum ) { + $scope.ecdapp.currentLogPageNum = page; + $scope.ecdapp.getExecutionLogs($scope.ecdapp.selectedRow, $scope.ecdapp.execId, $scope.ecdapp.tenant); + } + } + + $scope.ecdapp.setClickedRow = function(index){ //function that sets the value of selectedRow to current index + $scope.ecdapp.selectedRow = index; + } + $scope.ecdapp.selected = false; + $scope.ecdapp.toggleStatusDefinitions = function() { + $scope.ecdapp.selected = $scope.ecdapp.selected ? false :true; + } + + /** + * Shows a modal pop-up with the error. + */ + $scope.ecdapp.viewErrorModalPopup = function(row) { + $modalInstance.dismiss('cancel'); + modalService.showFailure('Error Details', row.error, function() { } ); + }; + + $scope.ecdapp.getExecutionLogs = function(rowIdx, id, tenant) { + $scope.ecdapp.setClickedRow(rowIdx); + $scope.ecdapp.execId = id; + $scope.ecdapp.isEventLogQuery = false; + InventoryExecutionService.getEventsByExecution(id , $scope.ecdapp.isLogType, tenant, + $scope.ecdapp.currentLogPageNum, $scope.ecdapp.viewPerPage ).then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryDeploymentExecutionsViewCtrl.getExecutionLogs failed: " + + jsonObj.error); + $scope.ecdapp.isEventLogQuery = false; + $scope.ecdapp.evtErrMsg = jsonObj.error; + $scope.ecdapp.logTableData = []; + } else { + $scope.ecdapp.isEventLogQuery = true; + $scope.ecdapp.evtErrMsg = null; + $scope.ecdapp.totalLogPages = jsonObj.totalPages; + $scope.ecdapp.logTableData = jsonObj.items; + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error("inventoryDeploymentExecutionsViewCtrl.getExecutionLogs failed: " + + error); + $scope.ecdapp.evtErrMsg = error; + $scope.ecdapp.logTableData = []; + $scope.ecdapp.isDataLoading = false; + }); + } + + $scope.$on('$destroy', function() { + // Make sure that the interval is destroyed too + $scope.ecdapp.stopLoading(); + }); +}); + + +/*************************************************************************/ +appDS2.controller('deploymentInputsViewCtrl', function( + $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'Deployment Inputs'; + $scope.ecdapp.deploymentRef = message.deployment.id; + $scope.ecdapp.serviceId = message.deployment.serviceId; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.isRequestFailed = false; + var selTenant = message.deployment.tenant_name; + if ( typeof selTenant === "undefined" ) { + selTenant = "default_tenant"; + } + $scope.ecdapp.ui_tenant = selTenant; + $scope.ecdapp.tenant = selTenant; + let inputsAndDescriptions = {}; + let inputsAndDefaults = {}; + // Get associated blueprint for inputs info + InventoryDeploymentService.getBlueprint($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then(function(blueprint) { + if (debug) + $log.debug("inventoryDeploymentInputsViewCtrl.getBlueprint response: " + JSON.stringify(blueprint)); + if (!blueprint.error) { + for (var pkey in blueprint.items[0].plan.inputs) { + let description = blueprint.items[0].plan.inputs[pkey].description; + if ( typeof description === "undefined" ) { + description = ''; + } + inputsAndDescriptions[pkey] = description; + } + $scope.ecdapp.deployment.descriptionDict = inputsAndDescriptions; + } + }, + function(error) { + $log.error('InventoryDeploymentService.getBlueprint failed: ' + JSON.stringify(error)); + }); + + InventoryDeploymentService.getDeployment($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then(function(deployment) { + if (deployment.items.length == 0) { + $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; + $log.error("InventoryDeploymentSerice.getDeployment failed: " + + $scope.ecdapp.errMsg); + $scope.ecdapp.isRequestFailed = true; + } + // Deployment IDs are unique, so this will always return exactly one item! + // retrieve blueprintId and inputs of deployment. + else { + $scope.ecdapp.errMsg = null; + //$scope.ecdapp.deployment = deployment.items[0]; + let ydict = deployment.items[0].inputs; + for (var ykey in ydict) { + let yval = ydict[ykey]; + if (yval.constructor === {}.constructor) + inputsAndDefaults[ykey] = JSON.stringify(yval, undefined, 2); + else + inputsAndDefaults[ykey] = yval; + } + $scope.ecdapp.isRequestFailed = false; + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeployment failed: ' + JSON.stringify(error)); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.isDataLoading = false; + }); + $scope.ecdapp.deployment = { + parmFileDict : inputsAndDefaults, + descriptionDict : inputsAndDescriptions + }; }); +/*************************************************************************/ + +appDS2.controller('deployBlueprintContentCtrl', function( + $scope, $log, message, DeploymentService) { + + 'use strict'; + + var debug = false; + + if (debug) + $log.debug("deployBlueprintContentCtrl.message: " + JSON.stringify(message)); + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'View Blueprint ' + message.blueprint.blueprint_id; + // Fetch the blueprint + $scope.ecdapp.isDataLoading = true; + DeploymentService.getBlueprintContent(message.blueprint.blueprint_id, message.tenant_name).then(function(jsonObj) { + if (debug) + $log.debug("deployBlueprintContentCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed'; + } + else { + $scope.ecdapp.typeName = message.blueprint.blueprint_id; + $scope.ecdapp.blueprint = jsonObj.data; + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $scope.ecdapp.isDataLoading = false; + alert('Failed to get blueprint. Please retry.'); + $log.error("deployBlueprintContentCtrl failed: " + error); + }); +}); + + + /*************************************************************************/ + appDS2.controller('deploymentUpdateCtrl', function( + $scope, $log, $modalInstance, message, InventoryBlueprintService, InventoryDeploymentService) { + + 'use strict'; + + var debug = false; + if (debug) + $log.debug("inventoryDeploymentUpdateCtrl.message: " + JSON.stringify(message)); + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.deploymentInProgress = false; + $scope.ecdapp.serviceTypeComplete = false; + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.label = 'Update ' + message.deployment.id; + $scope.ecdapp.deploymentRef = message.deployment.id; + var selTenant = message.deployment.tenant_name; + if ( typeof selTenant === "undefined" ) { + selTenant = "default_tenant"; + } + $scope.ecdapp.tenant = selTenant; + $scope.ecdapp.ui_tenant = selTenant; + $scope.ecdapp.updateBp = ''; + $scope.ecdapp.typeName = ''; + $scope.ecdapp.typeId = ''; + $scope.ecdapp.inputsDict = {}; + $scope.ecdapp.nodeInst = []; + $scope.ecdapp.selectedNodeInst; + $scope.ecdapp.editRequest = { + deployment_id : $scope.ecdapp.deploymentRef, + type_id : '', + fileModel : null, + parmFileDict : {}, + descriptionDict : {}, + tenant : $scope.ecdapp.tenant + }; + $scope.ecdapp.install_flow = { + value: true + }; + + $scope.ecdapp.uninstall_flow = { + value: true + }; + + $scope.ecdapp.reinstall_flow = { + value: true + }; + + $scope.ecdapp.install_first_flow_flag = { + value: false + }; + + $scope.ecdapp.force_flag = { + value: false + }; + + $scope.ecdapp.ignore_failure_flag = { + value: false + }; + + $scope.ecdapp.skip_install = false; + $scope.ecdapp.skip_uninstall = false; + $scope.ecdapp.skip_reinstall = false; + $scope.ecdapp.install_first_flow = false; + $scope.ecdapp.force = false; + $scope.ecdapp.ignore_failure = false; + + $scope.$watch('ecdapp.install_flow["value"]', function(newValue,oldValue,scope) { + if (newValue != oldValue) { + console.log("toggled install flow: " + newValue); + $scope.ecdapp.skip_install = oldValue; + } + }, true); + + $scope.$watch('ecdapp.uninstall_flow["value"]', function(newValue,oldValue,scope) { + if (newValue != oldValue) { + console.log("toggled uninstall flow: " + newValue); + $scope.ecdapp.skip_uninstall = oldValue; + } + }, true); + + $scope.$watch('ecdapp.reinstall_flow["value"]', function(newValue,oldValue,scope) { + if (newValue != oldValue) { + console.log("toggled reinstall flow: " + newValue); + $scope.ecdapp.skip_reinstall = oldValue; + } + }, true); + + $scope.$watch('ecdapp.install_first_flow_flag["value"]', function(newValue,oldValue,scope) { + if (newValue != oldValue) { + console.log("toggled install first flow: " + newValue); + $scope.ecdapp.install_first_flow = newValue; + } + }, true); + + $scope.$watch('ecdapp.force_flag["value"]', function(newValue,oldValue,scope) { + if (newValue != oldValue) { + console.log("toggled force flag: " + newValue); + $scope.ecdapp.force = newValue; + } + }, true); + + $scope.$watch('ecdapp.ignore_failure_flag["value"]', function(newValue,oldValue,scope) { + if (newValue != oldValue) { + console.log("toggled ignore_failure flow: " + newValue); + $scope.ecdapp.ignore_failure = newValue; + } + }, true); + + // deployment node instances + InventoryDeploymentService.getNodeInstances($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant) + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryDeploymentUpdateCtrl.getNodeInstances failed: " + jsonObj.error); + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.nodeInst = []; + } else { + $scope.ecdapp.errMsg = null; + for (var nodeIndx = 0; nodeIndx < jsonObj.items.length; nodeIndx++) { + $scope.ecdapp.nodeInst.push(jsonObj.items[nodeIndx].id); + } + } + }, function(error) { + $log.error("inventoryDeploymentUpdateCtrl.getNodeInstances failed: " + error); + $scope.ecdapp.errMsg = error; + $scope.ecdapp.nodeInst = []; + $scope.ecdapp.isDataLoading = false; + }); + + // current blueprint +/* var typeLink = message.deployment.typeLink.href; + var n = typeLink.lastIndexOf("/"); + var typeId = typeLink.substring(n+1); + // Fetch the blueprint + $scope.ecdapp.isDataLoading = true; + InventoryBlueprintService.viewBlueprint(typeId).then(function(jsonObj) { + if (debug) + $log.debug("inventoryDeploymentUpdateCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed'; + } + else { + $scope.ecdapp.typeName = jsonObj.typeName; + $scope.ecdapp.typeId = jsonObj.typeId; + $scope.ecdapp.bp.push(jsonObj); + $scope.ecdapp.getBlueprint(); + } + //$scope.ecdapp.isDataLoading = false; + }, function(error) { + $scope.ecdapp.isDataLoading = false; + alert('Failed to get blueprint. Please retry.'); + $log.error("blueprintViewCtrl failed: " + error); + });*/ + + // get the blueprints from inventory matching deployment reference filter + $scope.ecdapp.bp = []; + InventoryBlueprintService.getBlueprintsSummary() + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryDeploymentUpdateCtrl.loadTable failed: " + jsonObj.error); + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.bp = []; + } else { + $scope.ecdapp.errMsg = null; + $scope.ecdapp.bp = jsonObj; + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $log.error("inventoryDeploymentUpdateCtrl.loadTable failed: " + error); + $scope.ecdapp.errMsg = error; + $scope.ecdapp.bp = []; + $scope.ecdapp.isDataLoading = false; + }); + $scope.ecdapp.getBlueprint = function() { + $scope.ecdapp.isDataLoading = true; + InventoryBlueprintService.viewBlueprint($scope.ecdapp.typeId).then(function(jsonObj) { + if (debug) + $log.debug("inventoryDeploymentUpdateCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed'; + $scope.ecdapp.serviceTypeComplete = false; + $scope.ecdapp.isDataLoading = false; + } + else { + $scope.ecdapp.typeName = jsonObj.typeName; + $scope.ecdapp.typeVersion = jsonObj.typeVersion; + $scope.ecdapp.inputsDict = jsonObj.blueprintInputs; + // query the current deployment inputs + InventoryDeploymentService.getDeployment($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then(function(deployment) { + if (deployment.items.length == 0) { + $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; + $log.error("InventoryDeploymentSerice.getDeployment failed: " + + $scope.ecdapp.errMsg); + //$scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.serviceTypeComplete = true; + } + // Deployment IDs are unique, so this will always return exactly one item!. + // retrieve inputs of deployment. + else { + $scope.ecdapp.errMsg = null; + $scope.ecdapp.deployment = deployment.items[0]; + // Copy the input parameter names and default values + let inputsAndDefaults = {}; + let inputsAndDescriptions = {}; + let ydict = deployment.items[0].inputs; + for (var ykey in ydict) { + let yval = ydict[ykey]; + if (yval.constructor === {}.constructor) + inputsAndDefaults[ykey] = JSON.stringify(yval, undefined, 2); + else + //$scope.ecdapp.deployment.inputs[ykey] = yval; + inputsAndDefaults[ykey] = yval; + } + for (var pkey in $scope.ecdapp.inputsDict) { + //$scope.ecdapp.deployment = deployment.items[0]; + let description = $scope.ecdapp.inputsDict[pkey].description; + if ( typeof description === "undefined" ) + description = ''; + inputsAndDescriptions[pkey] = description; + } + + $scope.ecdapp.editRequest.parmFileDict = inputsAndDefaults; + $scope.ecdapp.editRequest.descriptionDict = inputsAndDescriptions; + $scope.ecdapp.editRequest.type_id = $scope.ecdapp.typeId; + if (debug) + $log.debug('inventoryBlueprintDeployCtrl: inputsAndDefaults: ' + JSON.stringify(inputsAndDefaults)); + + $scope.ecdapp.serviceTypeComplete = true; + //$scope.$apply(); + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeployment failed: ' + JSON.stringify(error)); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.isDataLoading = false; + }); + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $scope.ecdapp.isDataLoading = false; + $scope.ecdapp.serviceTypeComplete = false; + alert('Failed to get blueprint. Please retry with valid blueprint ID.'); + $log.error("inventoryDeploymentUpdateCtrl failed: " + error); + }); + }; + + /** + * Handler for file-read event reads file, parses JSON, validates content. + */ + var fileReader = new FileReader(); + fileReader.onload = function(event) { + let jsonString = fileReader.result; + if (debug) + $log.debug('fileReader.onload: read: ' + jsonString); + let ydict = {}; + try { + ydict = JSON.parse(jsonString); + } + catch (ex) { + alert('Failed to parse file as JSON:\n' + ex); + } + // Process the file + for (var ykey in ydict) { + let yval = ydict[ykey]; + if (debug) + $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); + // Allow only expected keys with scalar values + if (! (ykey in $scope.ecdapp.editRequest.parmFileDict)) + alert('Unexpected file content:\nKey not defined by blueprint:\n' + ykey); + if (yval.constructor === {}.constructor) + $scope.ecdapp.editRequest.parmFileDict[ykey] = angular.toJson(yval); + else + $scope.ecdapp.editRequest.parmFileDict[ykey] = yval; + } + if (debug) + $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.editRequest.parmFileDict)); + + // Update table in all cases + $scope.$apply(); + } + + // Handler for file-select event + $scope.handleFileSelect = function() { + if (debug) + $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); + fileReader.readAsText($scope.ecdapp.editRequest.fileModel); + }; + + $scope.ecdapp.validateRequest = function(editRequest) { + if (editRequest == null) + return 'No data found.\nPlease enter some values.'; + if (editRequest.deployment_id == null || editRequest.deployment_id.trim() == '') + return 'Deployment ID is required.\nPlease enter a value.'; + if (editRequest.type_id == null || editRequest.type_id.trim() == '') + return 'Type ID is required.\nPlease enter a value.'; + // Check that every file parameter is defined by blueprint + for (var pkey in $scope.ecdapp.editRequest.parmFileDict) { + // Defined in blueprint? + if (! $scope.ecdapp.inputsDict[pkey]) + return 'Unexpected input parameter\n' + pkey; + } + return null; + } + + $scope.ecdapp.updateDeployment = function(editRequest) { + if (debug) + $log.debug('deployBlueprint: editRequest is ' + JSON.stringify($scope.ecdapp.editRequest)); + var validateMsg = $scope.ecdapp.validateRequest(editRequest); + if (validateMsg != null) { + alert('Invalid Request:\n' + validateMsg); + $scope.ecdapp.errMsg = validateMsg; + return; + } + // Create request with key:value parameters dictionary + let deploymentRequestObject = { + deploymentId : editRequest.deployment_id, + serviceTypeId : editRequest.type_id, + inputs : {}, + tenant : editRequest.tenant, + method : "update", + reinstall_list : $scope.ecdapp.selectedNodeInst, + skip_install : $scope.ecdapp.skip_install, + skip_uninstall : $scope.ecdapp.skip_uninstall, + skip_reinstall : $scope.ecdapp.skip_reinstall, + force : $scope.ecdapp.force, + ignore_failure : $scope.ecdapp.ignore_failure, + install_first : $scope.ecdapp.install_first_flow + }; + + for (var pkey in $scope.ecdapp.editRequest.parmFileDict) + try { + deploymentRequestObject.inputs[pkey] = angular.fromJson($scope.ecdapp.editRequest.parmFileDict[pkey]); + } catch (error) { + deploymentRequestObject.inputs[pkey] = $scope.ecdapp.editRequest.parmFileDict[pkey]; + } + if (debug) + $log.debug('deployBlueprint: deploymentRequestObject is ' + JSON.stringify(deployRequestObject)); + + $scope.ecdapp.deploymentInProgress = true; + InventoryDeploymentService.deployBlueprint(deploymentRequestObject) + .then(function(response) { + $scope.ecdapp.deploymentInProgress = false; + if (response.error) { + alert('Failed to deploy blueprint:\n' + response.error); + $scope.ecdapp.errMsg = response.error; + } else { + alert('Deployment update request sent successfully, query the execution status for final outcome'); + $modalInstance.close(response); + } + }, + function (error) { + $log.error('inventoryBlueprintDeployCtrl: error while deploying: ' + error); + alert('Server rejected deployment request:\n' + error); + $scope.ecdapp.deploymentInProgress = false; + } + ); + }; + + }); + + /*************************************************************************/ + appDS2.controller('deploymentRollbackCtrl', function( + $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'Deployment Rollback'; + $scope.ecdapp.revisions = []; + $scope.ecdapp.deploymentRef = message.deployment.id; + $scope.ecdapp.serviceId = message.deployment.serviceId; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.updatingDeployment = false; + var selTenant = message.deployment.tenant_name; + if ( typeof selTenant === "undefined" ) { + selTenant = "default_tenant"; + } + $scope.ecdapp.tenant = selTenant; + $scope.ecdapp.ui_tenant = selTenant; + $scope.ecdapp.local_revisions = []; + // This object holds data for this operation + $scope.ecdapp.rollbackRequest = { + "deployment_id": message.deployment.deploymentRef, + "workflow_name": "rollback", + "tenant": selTenant, + "revision": 1 + }; + + InventoryDeploymentService.getNodeInstanceVersions($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then(function(nodeRunTime) { + if (nodeRunTime == null) { + $scope.ecdapp.errMsg = "Failed to retrieve Node instance runtime information"; + $log.error("InventoryDeploymentSerice.getNodeInstanceVersions failed: " + + $scope.ecdapp.errMsg); + $scope.ecdapp.isRequestFailed = true; + } else { + $scope.ecdapp.errMsg = null; + $scope.ecdapp.revisions = nodeRunTime.items[0].runtime_properties['helm-history']; + if (Array.isArray($scope.ecdapp.revisions) ) { + var dLen = $scope.ecdapp.revisions.length; + + for (var i = 1; i < dLen; i++) { + var str = $scope.ecdapp.revisions[i].replace(/\s+/g, ' '); + var itemStrArr = str.split(" "); + var itemLen = itemStrArr.length; + var revObj = {}; + revObj.revision = itemStrArr[0].trim(); + revObj.updated = itemStrArr.slice(1,5).toString().replace(/,/g, ' '); + revObj.status = itemStrArr[6].trim(); + revObj.chart = itemStrArr[7].trim(); + revObj.description = itemStrArr.slice(8,itemLen).toString().replace(/,/g, ' '); + revObj.name = itemStrArr[0].trim(); + revObj.checked = false; + $scope.ecdapp.local_revisions.push(revObj); + } + } + console.log($scope.ecdapp.local_revisions); + $scope.ecdapp.isRequestFailed = false; + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error('InventoryDeploymentService.getNodeInstanceVersions failed: ' + JSON.stringify(error)); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.isDataLoading = false; + }); + $scope.ecdapp.updateSelection = function(position) { + $scope.ecdapp.rollbackRequest.revision = position; + angular.forEach($scope.ecdapp.local_revisions, function(item, index) { + if (position != index+1) + item.checked = false; + }); + } + /** + * rollback deployment based on parameters user enters/adjusts in modal popup + * First retrieves the node-id using the blueprintId + * Using the node-id and deploymentId, retrieves the node-instance-id + * Calls the update resource API, passing object with deploymentId, and changed parameters + */ + $scope.ecdapp.rollbackWorkflow = function(revision) { + $scope.ecdapp.updatingDeployment = true; + $scope.ecdapp.isDataLoading = true; + InventoryDeploymentService.rollbackFlow($scope.ecdapp.rollbackRequest).then(function(jsonObj) { + if (debug) + $log.debug("inventoryDeploymentRollbackCtrl.rollbackWorkflow response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; + $scope.ecdapp.updatingDeployment = false; + $scope.ecdapp.isDataLoading = false; + } else { + console.log('%c ROLLBACK RESOURCES COMPLETED', 'color: magenta; font-weight: bold;'); + alert('Rollback request for ' + $scope.ecdapp.deploymentRef + ' successfully went through to Cloudiy. Rollback is now pending'); + $scope.ecdapp.updatingDeployment = false; + $scope.ecdapp.isDataLoading = false; + } + }, function(error) { + $scope.ecdapp.updatingDeployment = false; + $log.error('inventoryDeploymentRollbackCtrl failed: ' + error); + alert('Failed to rollback Deployment ' + $scope.ecdapp.deploymentRef + '. Please retry.'); + $scope.ecdapp.isDataLoading = false; + }); + } + }); + + /*************************************************************************/ + appDS2.controller('appReconfigCtrl', function( + $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService, DeploymentService) { + + 'use strict'; + + var debug = true; + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.tenant = message.deployment.tenant_name; + $scope.ecdapp.deploymentId = message.deployment.id; + $scope.ecdapp.bpId = message.deployment.blueprint_id; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.updatingDeployment = false; + $scope.ecdapp.parmFileDict = {}; + $scope.ecdapp.parmCurrFileDict = {}; + $scope.ecdapp.app_config_from_bp = {}; + $scope.ecdapp.app_config_new = {}; + $scope.ecdapp.app_config_bakup = {}; + $scope.ecdapp.app_config_inputs = []; + $scope.ecdapp.app_config_bp_str =''; + $scope.ecdapp.app_config_latest_str =''; + $scope.ecdapp.descriptionDict = {}; + $scope.ecdapp.appConfigOverride = {}; + $scope.ecdapp.app_config_input_map = {}; + + $scope.ecdapp.reconfigRequest = { + deployment_id: $scope.ecdapp.deploymentId, + workflow_id: 'execute_operation', + parameters: {}, + tenant: $scope.ecdapp.tenant + }; + $scope.ecdapp.reconfigRequest.parameters.operation = + 'dcae.interfaces.lifecycle.Reconfiguration'; + $scope.ecdapp.reconfigRequest.parameters.operation_kwargs = {}; + $scope.ecdapp.reconfigRequest.parameters.operation_kwargs.type = 'app_reconfig'; + $scope.ecdapp.reconfigRequest.parameters.operation_kwargs.application_config = {}; + $scope.ecdapp.reconfigRequest.parameters.allow_kwargs_override = true; + $scope.ecdapp.reconfigRequest.parameters.type_names = + ['dcae.nodes.DockerContainerForComponents', 'dcae.nodes.DockerContainerForComponentsUsingDmaap', + 'dcae.nodes.ContainerizedServiceComponent', 'dcae.nodes.ContainerizedServiceComponentUsingDmaap']; + + // get the BP object from cloudify + // get the depl object from cloudify + // get the node instance data from cloudify + // parse the application_config from BP node properties + // parse the inputs from deployment + // display FORM with current input fields that are referred in the appl + // config object + // display application_config on the screen and setup data binding to the + // input FORM + // create POST request body for start execution to cloudify + // invoke service method to send POST request to cloudify + InventoryDeploymentService.getBlueprint($scope.ecdapp.bpId, + $scope.ecdapp.tenant).then(function(blueprint) { + if (debug) + $log.debug("appReconfigCtrl.getBlueprint response: " + JSON.stringify(blueprint)); + if (blueprint.error) { + $scope.ecdapp.errMsg = 'Request Failed: ' + blueprint.error; + $scope.ecdapp.updatingDeployment = false; + $scope.ecdapp.isRequestFailed = true; + } + else { + $scope.ecdapp.isRequestFailed = false; + if (Array.isArray(blueprint.items) && blueprint.items.length > 0) { + var foundNode = blueprint.items[0].plan.nodes.find(function checkAppConfig(node) { + if (Object.keys(node.properties).includes("application_config")) { + return true; + } + }); + if (foundNode != undefined && foundNode.properties != undefined ) { + $scope.ecdapp.app_config_from_bp = foundNode.properties.application_config; + $scope.ecdapp.app_config_bp_str = + JSON.stringify($scope.ecdapp.app_config_from_bp, undefined, 4); + + $scope.ecdapp.checkType = function(key1, value1) { + if (value1 instanceof Object && !Array.isArray(value1)) { + for (let [key2, value2] of Object.entries(value1)) { + if (key2 == "get_input") { + $scope.ecdapp.app_config_inputs.push(value2); + $scope.ecdapp.app_config_input_map[key1] = value2; + } else { + $scope.ecdapp.checkType(key2, value2); + } + } + } + }; + + for (let [key1, value1] of + Object.entries($scope.ecdapp.app_config_from_bp)) + { + $scope.ecdapp.checkType(key1, value1); + } + } + + let inputsAndDescriptions = {}; + for (var pkey in blueprint.items[0].plan.inputs) { + let description = blueprint.items[0].plan.inputs[pkey].description; + if ( typeof description === "undefined" ) { + description = ''; + } + inputsAndDescriptions[pkey] = description; + } + $scope.ecdapp.descriptionDict = inputsAndDescriptions; + + InventoryDeploymentService.getDeployment($scope.ecdapp.deploymentId, + $scope.ecdapp.tenant).then(function(deployment) { + if (deployment.items.length == 0) { + $scope.ecdapp.errMsg = "404 - Deployment " + $scope.ecdapp.deploymentId + " Not Found!"; + $log.error("InventoryDeploymentSerice.getDeployment failed: " + + $scope.ecdapp.errMsg); + $scope.ecdapp.isRequestFailed = true; + } + else { + $scope.ecdapp.errMsg = null; + $scope.ecdapp.deployment = deployment.items[0]; + $scope.ecdapp.isRequestFailed = false; + if (Array.isArray(deployment.items) && deployment.items.length > 0) { + var deplInputs = deployment.items[0].inputs; + $scope.ecdapp.app_config_inputs.forEach(function findMatch(value, index, array) { + for (let [key, val] of Object.entries(deplInputs)) { + if (value == key) { + $scope.ecdapp.parmFileDict[key] = val; + } + } + }); + } + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeployment failed: ' + JSON.stringify(error)); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.isDataLoading = false; + }); + + InventoryDeploymentService.getNodeInstanceData($scope.ecdapp.deploymentId, + $scope.ecdapp.tenant).then(function(nodeInstances) { + if (Array.isArray(nodeInstances.items) && nodeInstances.items.length > 0) { + var foundNode = nodeInstances.items.find(function checkAppConfig(item) { + if (Object.keys(item.runtime_properties).includes("application_config")) { + return true; + } + }); + if (foundNode != undefined) { + $scope.ecdapp.app_config_new = foundNode.runtime_properties.application_config; + $scope.ecdapp.app_config_latest_str = + JSON.stringify($scope.ecdapp.app_config_new, undefined, 4); + for (let [key, value] of + Object.entries(foundNode.runtime_properties.application_config)) + { + if (value.constructor === {}.constructor) + $scope.ecdapp.appConfigOverride[key] = angular.toJson(value); + else + $scope.ecdapp.appConfigOverride[key] = value; + } + $scope.ecdapp.app_config_inputs.forEach(function findMatch(value, index, array) { + for (let [key, val] of Object.entries($scope.ecdapp.appConfigOverride)) { + if (value == key) { + $scope.ecdapp.parmCurrFileDict[key] = val; + } + } + }); + } + } + }, + function(error) { + $log.error('InventoryDeploymentService.getNodeInstances failed: ' + JSON.stringify(error)); + }); + } + $scope.ecdapp.isDataLoading = false; + } + }, + function(error) { + $log.error('InventoryDeploymentService.getBlueprint failed: ' + JSON.stringify(error)); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.isDataLoading = false; + }); + + $scope.ecdapp.refreshAppConfig = function(newInputs) { + angular.copy($scope.ecdapp.app_config_from_bp, $scope.ecdapp.app_config_bakup); + for (let [input_key, input_val] of Object.entries(newInputs)) { + $scope.ecdapp.replaceNewInput(input_key, input_val, $scope.ecdapp.app_config_from_bp); + } + angular.copy($scope.ecdapp.app_config_from_bp, $scope.ecdapp.app_config_new); + angular.copy($scope.ecdapp.app_config_bakup, $scope.ecdapp.app_config_from_bp); + + $scope.ecdapp.app_config_latest_str = + JSON.stringify($scope.ecdapp.app_config_new, undefined, 4); + }; + + var fileReader = new FileReader(); + fileReader.onload = function(event) { + let jsonString = fileReader.result; + let ydict = {}; + try { + ydict = JSON.parse(jsonString); + } + catch (ex) { + alert('Failed to parse file as JSON:\n' + ex); + } + // Process the file + for (var ykey in ydict) { + let yval = ydict[ykey]; + // Allow only expected keys with scalar values + if (ykey in $scope.ecdapp.parmFileDict) + { + // alert('Unexpected file content:\nKey not defined by blueprint:\n' + + // ykey); + if (yval.constructor === {}.constructor) + $scope.ecdapp.parmFileDict[ykey] = angular.toJson(yval); + else + $scope.ecdapp.parmFileDict[ykey] = yval; + } + } + $scope.ecdapp.refreshAppConfig($scope.ecdapp.parmFileDict); + $scope.$apply(); + }; + // Handler for file-select event + $scope.handleFileSelect = function() { + if (debug) + $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); + fileReader.readAsText($scope.ecdapp.editRequest.fileModel); + }; + $scope.ecdapp.replaceNewInput = function(input_key, input_val, src) { + var itemFound = false; + for (let [key, value] of Object.entries(src)) { + if (value instanceof Object && !Array.isArray(value)) { + for (let [key2, value2] of Object.entries(value)) { + if (key2 == "get_input" && value2 == input_key) { + src[key] = input_val; + itemFound = true; + break; + } else { + $scope.ecdapp.replaceNewInput(input_key, input_val, value2); + } + } + } + if (itemFound) { + break; + } + } + }; + + $scope.ecdapp.reconfigDeploymentById = function(newInputs) { + $scope.ecdapp.updatingDeployment = true; + angular.copy($scope.ecdapp.app_config_from_bp, $scope.ecdapp.app_config_bakup); + for (let [input_key, input_val] of Object.entries(newInputs)) { + $scope.ecdapp.replaceNewInput(input_key, input_val, + $scope.ecdapp.app_config_from_bp); + } + angular.copy($scope.ecdapp.app_config_from_bp, $scope.ecdapp.app_config_new); + angular.copy($scope.ecdapp.app_config_bakup, $scope.ecdapp.app_config_from_bp); + $scope.ecdapp.app_config_latest_str = + JSON.stringify($scope.ecdapp.app_config_new, undefined, 4); + + $scope.ecdapp.reconfigRequest.parameters.operation_kwargs.application_config = + $scope.ecdapp.app_config_new; + + DeploymentService.reconfigFlow($scope.ecdapp.reconfigRequest).then(function(jsonObj) { + if (debug) + $log.debug("appReconfigCtrl.reconfigFlow response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; + $scope.ecdapp.updatingDeployment = false; + } + else { + $scope.ecdapp.updatingDeployment = false; + alert('application reconfig request for ' + $scope.ecdapp.deploymentId + ' successfully went through to Cloudify. Reconfig is now pending'); + $modalInstance.dismiss('cancel'); + } + }, function(error) { + $scope.ecdapp.updatingDeployment = false; + alert('Failed to perform reconfig for Deployment Id ' + $scope.ecdapp.deploymentId); + $log.error('appReconfigCtrl.reconfigFlow failed: ' + error); + }); + + }; + }); + + /*************************************************************************/ + appDS2.controller('deploymentUpgradeCtrl', function( + $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'Deployment Upgrade'; + $scope.ecdapp.deployment = null; + $scope.ecdapp.deploymentRef = message.deployment.id; //THIS IS THE BLUEPRINT ID + $scope.ecdapp.bpId = message.deployment.blueprint_id; + $scope.ecdapp.serviceId = message.deployment.serviceId; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.updatingDeployment = false; + var selTenant = message.deployment.tenant_name; + if ( typeof selTenant === "undefined" ) { + selTenant = "default_tenant"; + } + $scope.ecdapp.tenant = selTenant; + $scope.ecdapp.ui_tenant = selTenant; + $scope.ecdapp.parmFileDict = {}; + + // This object holds data for editing the input parameters + $scope.ecdapp.editRequest = { + deployment_id: '', + type_id: '', + fileModel: null, + resourceConstants: {}, + resourceDefinitionChanges: {} + }; + //First get the blueprintId associated with the deployment, along with the inputs of the deployment + InventoryDeploymentService.getDeployment($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then(function(deployment) { + if (deployment.items.length == 0) { + $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; + $log.error("InventoryDeploymentSerice.getDeployment failed: " + + $scope.ecdapp.errMsg); + $scope.ecdapp.isRequestFailed = true; + } + // Deployment IDs are unique, so this will always return exactly one item! + else { + $scope.ecdapp.errMsg = null; + $scope.ecdapp.deployment = deployment.items[0]; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.editRequest.type_id = deployment.items[0].blueprint_id; + $scope.ecdapp.parmFileDict = deployment.items[0].inputs; + Object.keys($scope.ecdapp.parmFileDict).map(function(key, index) { + if (key == 'config-format' || key == 'config-url' || key == 'chart-version' || key == 'chart-repo-url' || key == 'config-set') { + $scope.ecdapp.editRequest.resourceDefinitionChanges[key] = $scope.ecdapp.parmFileDict[key]; + } else { + $scope.ecdapp.editRequest.resourceConstants[key] = $scope.ecdapp.parmFileDict[key]; + } + //$scope.ecdapp.editRequest.resourceDefinitionChanges['config_set'] = ''; + }); + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeployment failed: ' + JSON.stringify(error)); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.isDataLoading = false; + }); + + /** + * Validates content of user-editable fields. + * Returns null if all is well, + * a descriptive error message otherwise. + */ + + $scope.ecdapp.validateRequest = function(editRequest) { + if (editRequest == null) + return 'No data found.\nPlease enter some values.'; + if (editRequest["chart-version"] == null || editRequest["chart-version"].trim() == '') + return 'Chart version is required.\nPlease enter a value.'; + if (!editRequest["config-format"] || editRequest["config-format"].trim() == '') { + return 'config format is required.\nPlease enter a value.'; + } + if ((!editRequest["config-url"] || editRequest["config-url"].trim() == '') && + (!editRequest["config_set"] || editRequest["config_set"].trim() == '')) { + return 'Config URL or Config set is required.\nPlease enter either of these input values'; + } + return null; + }; + + /** + * Helm upgrade for deployment based on parameters user enters in modal popup + * First retrieves the node-id using the blueprintId + * Using the node-id and deploymentId, retrieves the node-instance-id + * Calls the start execution API, passing object with deploymentId, and changed parameters + */ + + $scope.ecdapp.upgradeWorkflow = function(resourceDefinitionChanges) { + $scope.ecdapp.updatingDeployment = true; + let nodeId = ''; + + // validate request + var validateMsg = $scope.ecdapp.validateRequest(resourceDefinitionChanges); + if (validateMsg != null) { + alert('Invalid Request:\n' + validateMsg); + $scope.ecdapp.updatingDeployment = false; + return; + } + //get node id from blueprint + InventoryDeploymentService.getBlueprint($scope.ecdapp.bpId, $scope.ecdapp.tenant).then(function(blueprint) { + if (debug) + $log.debug("inventoryDeploymentUpgradeCtrl.getBlueprint response: " + JSON.stringify(blueprint)); + if (blueprint.error) { + $scope.ecdapp.errMsg = 'Request Failed: ' + blueprint.error; + $scope.ecdapp.updatingDeployment = false; + } + else { + //console.log('returned blueprint:' + blueprint); + let count = 0; + //console.log("number of node objects in array: " + blueprint.items[0].plan.nodes.length); + //console.log(JSON.stringify(blueprint)); + blueprint.items[0].plan.nodes.map(function(node) { + if (node.type == 'onap.nodes.component') { + //want to get FIRST node with type 'cloudify.kubernetes.resources.Deployment' so only set nodeID for first matching type + if (count < 1) { + nodeId = node.id; + } + count = count + 1; + } + }); + //if no node has type 'cloudify.kubernetes.resources.Deployment', return message saying no deployment exists and exit (ie nodeId still is '') + if (nodeId == '') { + alert('Failed to retrieve Node Id. No matching deployment found (no deployment exists)'); + $scope.ecdapp.updatingDeployment = false; + return; + } + //found node id. now need to retrieve node-instance-id + console.log('%c RETRIEVED NODE ID: ' + nodeId, 'color: orange; font-weight: bold;'); + let nodeInstanceId = ''; + InventoryDeploymentService.getNodeInstanceId($scope.ecdapp.deploymentRef, nodeId, $scope.ecdapp.tenant).then(function(jsonObj) { + if (debug) + $log.debug("inventoryDeploymentUpgradeCtrl.getNodeInstanceId response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; + $scope.ecdapp.updatingDeployment = false; + } + else { + //if nodeInstanceId is still '' then it wasn't found, stop flow) + if (jsonObj.items[0].id == '') { + alert('Failed to retrieve Node Instance Id for Node Id' + nodeId); + $scope.ecdapp.updatingDeployment = false; + return; + } + //found node-instance-id. now need to update resources + nodeInstanceId = jsonObj.items[0].id; + console.log('%c RETRIEVED NODE INSTANCE ID:' + nodeInstanceId, 'color: green; font-weight: bold;'); + //console.log(resourceDefinitionChanges); + InventoryDeploymentService.upgradeFlow($scope.ecdapp.deploymentRef, nodeInstanceId, resourceDefinitionChanges, $scope.ecdapp.tenant).then(function(jsonObj) { + if (debug) + $log.debug("inventoryDeploymentUpgradeCtrl.updateResources response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; + $scope.ecdapp.updatingDeployment = false; + } + else { + console.log('%c UPDATE RESOURCES COMPLETED', 'color: magenta; font-weight: bold;'); + //console.log(jsonObj); + $scope.ecdapp.updatingDeployment = false; + alert('Helm Upgrade request for ' + $scope.ecdapp.deploymentRef + ' successfully went through to Cloudiy. Upgrade is now pending'); $modalInstance.dismiss('cancel'); + } + }, function(error) { + $scope.ecdapp.updatingDeployment = false; + alert('Failed to perform upgrade for Deployment Id ' + $scope.ecdapp.deploymentRef + ' and Node Instance Id ' + nodeInstanceId + '. Please retry.'); + $log.error('inventoryDeploymentUpgradeCtrl failed: ' + error); + }); + } + }, function(error) { + $scope.ecdapp.updatingDeployment = false; + alert('Failed to get Node Instance Id for deploymentId ' + $scope.ecdapp.deploymentRef + ' and Node Id ' + nodeId + '. Please retry.'); + $log.error('inventoryDeploymentUpgradeCtrl failed: ' + error); + }); + + } + }, function(error) { + $scope.ecdapp.updatingDeployment = false; + alert('Failed to get blueprint for blueprintId ' + $scope.ecdapp.deploymentRef + '. Please retry.'); + $log.error('inventoryDeploymentUpgradeCtrl failed: ' + error); + }); + }; + + /** + * Handler for file-read event reads file, parses JSON, validates content. + */ + + var fileReader = new FileReader(); + fileReader.onload = function(event) { + let jsonString = fileReader.result; + if (debug) + $log.debug('fileReader.onload: read: ' + jsonString); + let ydict = {}; + try { + ydict = JSON.parse(jsonString); + } + catch (ex) { + alert('Failed to parse file as JSON:\n' + ex); + } + // Process the file + for (var ykey in ydict) { + let yval = ydict[ykey]; + if (debug) + $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); + // Allow only expected keys with scalar values + if (! (ykey in $scope.ecdapp.parmFileDict)) + alert('Unexpected file content:\nKey not defined by blueprint:\n' + ykey); + if (yval.constructor === {}.constructor) + $scope.ecdapp.parmFileDict[ykey] = angular.toJson(yval); + else + $scope.ecdapp.parmFileDict[ykey] = yval; + } + if (debug) + $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.parmFileDict)); + + // Update table in all cases + //$scope.ecdapp.setResourceDefinitionChanges($scope.ecdapp.editRequest.resourceDefinitionChanges, $scope.ecdapp.editRequest.parmFileDict); + Object.keys($scope.ecdapp.parmFileDict).map(function(key, index) { + + if (key == 'config-format' || key == 'config-url' || key == 'chart-version' || key == 'chart-repo-url' || key == 'config-set') { + $scope.ecdapp.editRequest.resourceDefinitionChanges[key] = $scope.ecdapp.parmFileDict[key]; + } else { + $scope.ecdapp.editRequest.resourceConstants[key] = $scope.ecdapp.parmFileDict[key]; + } + }); + //$scope.$apply(); + }; + + // Handler for file-select event + $scope.handleFileSelect = function() { + if (debug) + $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); + fileReader.readAsText($scope.ecdapp.editRequest.fileModel); + }; + + }); + diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-service.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-service.js index cee83c3..f7f9db3 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-service.js +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment-service.js @@ -1,24 +1,3 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - *******************************************************************************/ appDS2.factory('DeploymentService', function ($http, $q, $log) { return { /** @@ -27,10 +6,19 @@ appDS2.factory('DeploymentService', function ($http, $q, $log) { * @param {Number} viewPerPage - number of items per page; e.g., 25 * @return {JSON} Response object from remote side */ - getDeployments: function(pageNum,viewPerPage) { + getDeployments: function(pageNum,viewPerPage,sortBy,searchBy) { // cache control for IE let cc = "&cc=" + new Date().getTime().toString(); - let url = 'deployments?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + cc; + let url = null; + if (sortBy && searchBy) { + url = 'deployments?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&sortBy=' + sortBy + '&searchBy=' + searchBy + cc; + } else if (sortBy) { + url = 'deployments?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&sortBy=' + sortBy + cc; + } else if (searchBy) { + url = 'deployments?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&searchBy=' + searchBy + cc; + } else { + url = 'deployments?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage +cc; + } return $http({ method: 'GET', url: url, @@ -84,6 +72,69 @@ appDS2.factory('DeploymentService', function ($http, $q, $log) { $log.error('DeploymentService.deleteDeployment failed: ' + JSON.stringify(error)); return $q.reject(error.statusText); }); + }, + + getBlueprintContent: function(id, tenant) { + let url ='blueprints/' + id + '/archive?tenant=' + tenant; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'yaml' + }).then(function(response) { + // This is called on response code 200..299. + // On success, response.data is null. + // On failure, response.data has an error message. +/* var contentType = "application/octet-stream"; + var data = response.data + var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL; + if (urlCreator) { + var blob = new Blob([data], { type: contentType }); + var url = urlCreator.createObjectURL(blob); + var a = document.createElement("a"); + document.body.appendChild(a); + a.style = "display: none"; + a.href = url; + a.download = "blueprint.yaml"; //you may assign this value from header as well + a.click(); + window.URL.revokeObjectURL(url); + }*/ + return response; + }, + function(error) { + $log.error('DeploymentService.getBlueprintContent failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + reconfigFlow: function(reconfigRequest) { + let body = { + "deployment_id": reconfigRequest.deployment_id, + "workflow_id": reconfigRequest.workflow_id, + "allow_custom_parameters": true, + "force": true, + "tenant": reconfigRequest.tenant, + "parameters": reconfigRequest.parameters + }; + let urlStr = 'executions'; + return $http({ + method: 'POST', + url: urlStr, + data: body, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null) + return $q.reject('DeploymentService.reconfigFlow: response.data null or not object'); + else { + console.log(response); + return response.data; + } + }, + function(error) { + $log.error('DeploymentService.reconfigFlow failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); } }; }); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment_popups.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment_popups.html index f4a4cdd..d051495 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment_popups.html +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/cloudify/deployment_popups.html @@ -1,3 +1,43 @@ + - + + + + \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions-view-controller.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions-view-controller.js deleted file mode 100644 index 2491e50..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions-view-controller.js +++ /dev/null @@ -1,45 +0,0 @@ -appDS2.controller('executionsViewController', function($scope, $rootScope, ControllerService, $modal, ExecutionService, $log) { - - $scope.parent = { 'blueprint_id': 'Root', 'parent': 'parent' }; - $scope.ecdapp = {}; - $scope.ecdapp.isDataLoading = false; - $scope.ecdapp.appLabel = ""; - $rootScope.tenantList = { - tenant: '', - data: {} - }; - var debug = false; - - var getTenants = function() { - ControllerService.getTenants() - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("executionsViewController.getTenants failed: " + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - $rootScope.tenantList.data = jsonObj.items; - $rootScope.tenantList.tenant = jsonObj.items[0].name; - } - }, function(error) { - $log.error("executionsViewController.loadTable failed: " + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - }); - }; - - var getAppLabel = function() { - ControllerService.getAppLabel().then(function(jsonObj) { - if (debug) - $log.debug("Controller.getAppLabel succeeded: " + JSON.stringify(jsonObj)); - $scope.ecdapp.appLabel = jsonObj; - }, function(error) { - $log.error("Controller.getAppLabel failed: " + error); - }); - }; - // Initialize the page - getAppLabel(); - getTenants(); - -}); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions_view.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions_view.html deleted file mode 100644 index 5623b1c..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/executions_view.html +++ /dev/null @@ -1,5 +0,0 @@ -
- -

DCAE Dashboard

-
- diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/http-interceptor.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/http-interceptor.js deleted file mode 100644 index 0f5410d..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/http-interceptor.js +++ /dev/null @@ -1,29 +0,0 @@ -appDS2.factory('httpInterceptor', function ($q, $rootScope, $location) { - return { - 'request': function (config) { - return config; - }, - /* - 'requestError': function (rejection) { - }, - */ - 'response': function (response) { - if (response.data == null) { - var loc = location.pathname; - console.log("location path name: " + loc); - var loc1 = loc.replace("/", ""); - var loc2 = loc1.replace("/ecd", "/login.htm"); - console.log("location url: " + loc2); - alert("Your session has expired. Please log in again..."); - location.replace("/"+loc2); - } - return response; - }, - // optional method - 'responseError': function (rejection) { - } - }; - }) - .config(function($httpProvider) { - $httpProvider.interceptors.push('httpInterceptor'); - }); \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-instances-controller.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-instances-controller.js deleted file mode 100644 index f07d1b3..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-instances-controller.js +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - *******************************************************************************/ -appDS2.controller('selectEcompcController', function( - $scope, $rootScope, $log, $modalInstance, message, ControllerService) { - - // message brings the table items - - 'use strict'; - - // Set to true for verbose output - var debug = false; - - // this object holds data and functions - $scope.ecdapp = {}; - $scope.ecdapp.tableData = message.items; - - // Populate the model that drives the radio buttons. - // Radio buttons require a model with the value of the button - // that is selected. The data comes across with a boolean - // indicator on each row, selected or not, which is useless - // for driving the radio buttons. This model uses the URL - // as the unique value. - $scope.ecdapp.radiobutton = { - url : null - }; - for (var rowNum in message.items) { - let row = message.items[rowNum]; - if (debug) - $log.debug('selectEcompcController: row is ' + JSON.stringify(row)); - if (row.selected) - $scope.ecdapp.radiobutton.url = row.url; - } - - /** - * Handles a click on radio button to select a controller. - */ - $scope.ecdapp.selectController = function(row) { - if (debug) - $log.debug('selectController: row is ' + JSON.stringify(row)); - if (row == null || row.url == null) - $log.error('selectController invoked with bad argument'); - else - ControllerService.setControllerSelection(row).then(function(data) { - $rootScope.$broadcast('controllerChange', {name: row.name}) - }, - function(error) { - $log.error('selectController failed: ' + error); - }); - }; - -}); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-router.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-router.js deleted file mode 100644 index 0b43341..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-router.js +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * =============LICENSE_START========================================================= - * - * ================================================================================= - * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ -appDS2.config(function($routeProvider) { - $routeProvider - .when('/api', { - templateUrl: 'app/ccsdk/home/api_doc.html', - controller : '' - }) - .when('/api-spec', { - templateUrl: 'app/ccsdk/home/rest-api-spec.html', - controller : 'apiDocsController' - }) - .when('/ibp', { - templateUrl: 'app/ccsdk/inventory/inventory_blueprint_table.html', - controller : 'inventoryBlueprintTableController' - }) - .when('/idep', { - templateUrl: 'app/ccsdk/inventory/inventory_deployment_table.html', - controller : 'inventoryDeploymentTableController' - }) - .when('/idep/:depId', { - templateUrl: 'app/ccsdk/inventory/inventory_deployment_table.html', - controller : 'inventoryDeploymentTableController' - }) - .when('/sh', { - templateUrl: 'app/ccsdk/consul/service_health_table.html', - controller : 'serviceHealthTableController' - }) - .when('/nh', { - templateUrl: 'app/ccsdk/consul/node_table.html', - controller : 'nodeTableController' - }) - .when('/dc', { - templateUrl: 'app/ccsdk/consul/datacenter_table.html', - controller : 'datacenterTableController' - }) - .when('/profile/:profileId', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/self_profile.html', - controller: 'selfProfileController' - }) - .when('/profile_search', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/profile_searchDS2.html', - controller : "profileSearchCtrlDS2" - }) - .when('/post_search', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/post.html', - controller: 'postController' - }) - .when('/self_profile', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/self_profile.html', - controller: 'selfProfileController' - }) - .when('/role_list', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-admin/role_list.html', - controller : 'adminController' - }) - .when('/role_function_list', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-admin/role-function.html', - controller : "adminController" - }) - .when('/jcs_admin', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-admin/jcs_admin.html', - controller: 'adminController' - }) - .when('/admin_menu_edit', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-admin/admin-menu-edit.html', - controller: 'AdminMenuEditController' - }) - .when('/usage_list', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-admin/usage.html', - controller: 'usageListControllerDS2' - }) - .otherwise({ - templateUrl: 'app/ccsdk/home/executions_view.html', - controller : 'executionsViewController' - }) - ; - -}); \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-style.css b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-style.css deleted file mode 100644 index a4e9a97..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom-style.css +++ /dev/null @@ -1,301 +0,0 @@ -/* Styles for ECOMP Controller Dashboard */ - -.content-container { - min-height: 650px; - width: calc(100% - 50px); -} - -.ecd-error-message { - font-size: 14px; - font-weight: bold; - color: red; -} - -.ecd-icon-display { - font-size: 18px; -} - -.ecd-icon-action { - font-size: 18px; -} - -.ecd-icon-action:hover { - color: red; - text-decoration: none; -} - -.selected { - background-color:black; - color:white; - font-weight:bold; -} -.red-background { - background-color: #ff0000b3; - } -.green-background { - background-color: #bbf0bb; - } -.td-error { - border-top: 5px dotted red; - border-bottom: 5px dotted red; - } -.menu { - display: none; - z-index: 1000; - border: 1px dotted; - border-radius: 5px; - padding: 10px; - width: 50%; - background: azure; - position: fixed; - overflow: scroll; -} - -.show-menu { - z-index: 800; -} - -#show-menu { - display: none; -} - -#show-menu:checked ~ .menu { - display: block; -} - -#show-menu:checked ~ .show-menu { - color: blue; -} - -.menu-off { - position: fixed; - left: 0; - right: 0; - top: 0; - bottom: 0; - z-index: 700; - display: none; -} - -.menu-off { - display: none; -} - -#show-menu:checked ~ .menu-off { - display: block; -} - -#show-menu:checked ~ .show-menu { - display: none; -} - -.menu-off input[type=checkbox]:checked ~ .menu { - display: none; -} - -.menu-off input[type=checkbox]:checked ~ .show-menu { - display: block; -} - -td > .btn-group { - min-width: 0; - width: auto; -} - -.dropup, -.dropdown { - position: relative; -} -.dropdown-toggle:focus { - outline: 0; -} -.dropdown-menu { - position: absolute; - top: 100%; - left: 0; - z-index: 1000; - display: none; - float: left; - min-width: 160px; - padding: 5px 0; - margin: 2px 0 0; - font-size: 14px; - text-align: left; - list-style: none; - background-color: #fff; - -webkit-background-clip: padding-box; - background-clip: padding-box; - border: 1px solid #ccc; - border: 1px solid rgba(0, 0, 0, .15); - border-radius: 4px; - -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175); - box-shadow: 0 6px 12px rgba(0, 0, 0, .175); -} -.dropdown-menu.pull-right { - right: 0; - left: auto; -} -.dropdown-menu .divider { - height: 1px; - margin: 9px 0; - overflow: hidden; - background-color: #e5e5e5; -} -.dropdown-menu > li > a { - display: block; - padding: 3px 20px; - clear: both; - font-weight: normal; - line-height: 1.42857143; - color: #333; - white-space: nowrap; -} -.dropdown-menu > li > a:hover, -.dropdown-menu > li > a:focus { - color: #262626; - text-decoration: none; - background-color: #f5f5f5; -} -.dropdown-menu > .active > a, -.dropdown-menu > .active > a:hover, -.dropdown-menu > .active > a:focus { - color: #fff; - text-decoration: none; - background-color: #337ab7; - outline: 0; -} -.dropdown-menu > .disabled > a, -.dropdown-menu > .disabled > a:hover, -.dropdown-menu > .disabled > a:focus { - color: #777; -} -.dropdown-menu > .disabled > a:hover, -.dropdown-menu > .disabled > a:focus { - text-decoration: none; - cursor: not-allowed; - background-color: transparent; - background-image: none; - filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); -} -.open > .dropdown-menu { - display: block; -} -.open > a { - outline: 0; -} -.dropdown-menu-right { - right: 0; - left: auto; -} -.dropdown-menu-left { - right: auto; - left: 0; -} -.dropdown-header { - display: block; - padding: 3px 20px; - font-size: 12px; - line-height: 1.42857143; - color: #777; - white-space: nowrap; -} -.dropdown-backdrop { - position: fixed; - top: 0; - right: 0; - bottom: 0; - left: 0; - z-index: 990; -} -.pull-right > .dropdown-menu { - right: 0; - left: auto; -} -.dropup .caret, -.navbar-fixed-bottom .dropdown .caret { - content: ""; - border-top: 0; - border-bottom: 4px dashed; - border-bottom: 4px solid \9; -} -.dropup .dropdown-menu, -.navbar-fixed-bottom .dropdown .dropdown-menu { - top: auto; - bottom: 100%; - margin-bottom: 2px; -} -@media (min-width: 768px) { - .navbar-right .dropdown-menu { - right: 0; - left: auto; - } - .navbar-right .dropdown-menu-left { - right: auto; - left: 0; - } -} - -.dropdown-menu li { - margin-bottom: 10px; -} - -.dropdown-menu li div { - padding-left: 5px; -} - -.dropdown-menu li div i { - margin-right: 5px; -} - -td > .btn-group > .btn { - min-width: 0; - color: #0568ae; -} - -td > .btn-group > .btn> i { - font-size: 30px; -} - -li > a.active { - font-weight: bolder; - outline: thin dotted #666; -} - -tr:hover { - background-color: #f2f2f2; -} - -tr:focus { - background-color: #f2f2f2; -} - -.modalwrapper.modal-docked .modal-jumbo { - max-height: 100%; - height: 100%; - overflow: hidden; - top: 0; - width: 100%; - max-width: 100%; -} - -#addAppDiv { - padding-left: 10px; - background: lightgray; - border-radius: 5px; - padding-bottom: 15px; -} - -.field-group.error .error-msg { - color: red; - display: block; - font-size: 14px; - line-height: 14px; - font-family: "Omnes-ATT-W02-Medium"; - position: relative; - padding-left: 18px; - margin-top: 10px; -} - -.heading-page { - margin-bottom: 20px; -} diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_instances_popup.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_instances_popup.html deleted file mode 100644 index bc523aa..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_instances_popup.html +++ /dev/null @@ -1,86 +0,0 @@ - diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_popup_templates.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_popup_templates.html deleted file mode 100644 index fe4d505..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_popup_templates.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_spa.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_spa.html deleted file mode 100644 index fabb450..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/oom_spa.html +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - - - DCAE Dashboard - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
-
-
-
- - -
- - - diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-controller.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-controller.js deleted file mode 100644 index 99005fb..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-controller.js +++ /dev/null @@ -1,113 +0,0 @@ -appDS2.controller('treeViewController',function( - $scope, $rootScope, $log, $modal, ExecutionService, ControllerService){ - - 'use strict'; - - // Set to true for verbose output - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.isDataLoading = false; - $scope.ecdapp.isRequestFailed = false; - $scope.orgChart = true; - $scope.status = ''; - var selectedItem = { - name: '' - }; - // Initial data as eye candy - $scope.orgChartData = [ { 'blueprint_id': 'Root', 'parent': 'parent' } ]; - var controllersList = []; - - var getControllers = function(){ - ControllerService.getControllers().then(function(jsonObj) { - if (debug) - $log.debug("treeViewController.getControllers succeeded: " + JSON.stringify(jsonObj)); - // Empty - controllersList.length = 0; - // Refill - jsonObj.filter(function(d) { - controllersList.push(d); - if (d.selected) - selectedItem = d; - return; - }); - $scope.ecdapp.loadTable(); - }, function(error) { - alert('Failed to load controllers. Please retry.'); - $log.error("treeViewController.getControllers failed: " + error); - }); - } - - /** - * Called from the directive when user picks a status value. - */ - $scope.ecdapp.loadTable = function(status) { - $scope.ecdapp.isDataLoading = true; - $scope.status = status; - // Empty list and create the root controller item - $scope.orgChartData.length = 0; - $scope.orgChartData.push({ - "blueprint_id": selectedItem.name, - "parent": "parent" - }); - ExecutionService.getExecutionsByStatus(status).then( - function(jsonObj) { - if (jsonObj.error) { - $log.error("treeViewController.loadTable failed: " - + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - } else { - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - for (var i=0; i < jsonObj.items.length; i++) { - $scope.orgChartData.push(jsonObj.items[i]); - } - $scope.$broadcast('listenEvent', {data: $scope.orgChartData} ); - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error("treeViewController.loadTable failed: " - + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.isDataLoading = false; - }); - }; - - // Listens for change of the selected controller - $rootScope.$on('controllerChange', function(e, d){ - $scope.orgChartData[0].blueprint_id = d.name; - $scope.$broadcast('listenEvent', {data: $scope.orgChartData}); - }) - - // Shows popup with list of controllers - $scope.ecdapp.showEcompCInstancesModalPopup = function() { - var modalInstance = $modal.open({ - templateUrl : 'ecompc_instances_popup.html', - controller : 'selectEcompcController', - windowClass: 'modal-docked', - sizeClass: 'modal-medium', - resolve : { - message : function() { - return { items: controllersList } - } - } - }); - modalInstance.result.then(function(response) { - // Always reload the table - // $log.debug('modalInstance: reloading controllers'); - getControllers('active'); - }, - function(error) { - // Should never happen - $log.error('modalInstance: ERROR!?'); - }); - }; - - // Populate the table on load. - getControllers('active'); - -}); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-directive.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-directive.js deleted file mode 100644 index 834026b..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-directive.js +++ /dev/null @@ -1,165 +0,0 @@ -(function() { - 'use strict'; - - appDS2.directive("orgChart", supervisorOrgChart); - supervisorOrgChart.$inject = ['$http', '$templateCache', 'ExecutionService']; - - function supervisorOrgChart($http, $templateCache, ExecutionService) { - return { - restrict: 'E', - scope: { - data: '=', - getCall: '&', - modalCall: '&', - status: '=' - }, - - link: function(scope, elem, attrs) { - - scope.$on('listenEvent', function(event, data) { - data = data.data; - scope.data = data; - $('.jOrgChart').remove(); - drawOrgChart(data); - }); - - - var items = [], - mCheck = []; - var currentZoom = 100; - var data = scope.data; - var selectedStatus = scope.status; - function statusSelectoin(status){ - $('#statusclick li').removeClass('active'); - scope.getCall()(status); - } - - function drawOrgChart(data, supervisorOrg) { - items = []; - var itemHtml = ""; - for(var i=0; i" + - "
" + - ""+ - ""+ - ""+ - "" + root.blueprint_id + ""+ - ""+ - "

"+ - "
"+ - "
'); - var listElem = $("
    ", { - "class": "org", - "style": "float:right;", - html: items.join("") - }).appendTo(elem); - - var opts = { - chartElement: elem, - rowcolor: false - }; - //elem.html(''); - $(elem).find(".org").jOrgChart(opts); - listElem.remove(); - - setTimeout(function(){ - $('.dropdown .dropdown-toggle').on("click", function(e){ - var cls = '.'+ e.target.id; - var subcls = cls + ' a.test'; - if($(cls).hasClass('open')){ - $(cls).removeClass('open'); - $(subcls).next('ul').css({display: 'none'}); - } else{ - $(cls).addClass('open'); - } - }); - - $('.dropdown-submenu a.test').on("mouseover", function(e){ - console.log("hi"); - $('#'+e.target.id).next('ul').toggle(); - }); - - $('#statusclick li').click(function(event){ - statusSelectoin(event.target.id); - }) - - $('.openmodal').click(function(event){ - openModal(); - }) - - $(document).on('click','.expandBtn', function(event, data) { - event.stopImmediatePropagation() - var $this = $(this); - var $tr = $this.closest("tr"); - if ($tr.hasClass('contracted')) { - $(this).addClass('fa-minus').removeClass('fa-plus'); - $tr.removeClass('contracted').addClass('expanded'); - $tr.nextAll("tr").css('visibility', ''); - } else { - $(this).addClass('fa-plus').removeClass('fa-minus'); - $tr.removeClass('expanded').addClass('contracted'); - $tr.nextAll("tr").css('visibility', 'hidden'); - } - }); - - var selectedStatus = scope.status; - if(selectedStatus){ - $('#'+selectedStatus).addClass('active'); - } - - function openModal(){ - scope.modalCall()(); - } - - },0); - } - - drawOrgChart(data); - - }, - }; - }; -})(); \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-style.css b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-style.css deleted file mode 100644 index 5a3e056..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree-view-style.css +++ /dev/null @@ -1,132 +0,0 @@ -/* Basic styling */ - -::-webkit-scrollbar -{ - width: 12px; /* for vertical scrollbars */ - height: 7px; /* for horizontal scrollbars */ -} - -::-webkit-scrollbar-track -{ - background: rgba(0, 0, 0, 0.1); -} - -::-webkit-scrollbar-thumb -{ - background: rgba(0, 0, 0, 0.5); -} - -.orgChart .label_node{ - padding-bottom: 5px; -} - -.orgChart .icon-span{ - float:left;width:25px; - padding-top: 3px; -} -.orgChart .title-span{ - width:110px;float:left; font-size:14px; - padding-top: 3px; -} - -/* Draw the lines */ -.jOrgChart{ - position: relative; - /* left: 245px; */ - width:100%; - min-width: 100%; - overflow-x: auto; - -} -.jOrgChart .line { - height : 20px; - width : 4px; -} - -.jOrgChart .down { - background-color : black; - margin : 0px auto; -} - -.jOrgChart .top { - border-top : 3px solid black; -} - -.jOrgChart button{ - min-width : 20px; - width : 20px; - height : 20px; - padding : 0; -} - -.jOrgChart .dropdown{ - display: inline-block; -} - -.jOrgChart .downloadIcon{ - position: relative; - left: 1px; - float:left; -} - -.jOrgChart .ddIcon{ - position: relative; - float: right; - top: 6px; -} - -.jOrgChart .left { - border-right : 2px solid black; -} - -.jOrgChart .right { - border-left : 2px solid black; -} - -/* node cell */ -.jOrgChart td { - text-align : center; - vertical-align : top; - padding : 0 !important; - border : none; - border-bottom : 1px solid white; -} - -/* The node */ -.jOrgChart .node { - background-color : #efefef; - display : inline-block; - width : 180px; - height : 200px; - z-index : 10; - margin : 0 2px; -} - -.expandBtn { - background-color: #efefef; - padding-top:9px; -} - -/* jQuery drag 'n drop */ - -.drag-active { - border-style : dotted !important; -} - -.drop-hover { - border-style : solid !important; - border-color : #E05E00 !important; -} - -#statusclick{ - padding: 0 !important -} - -#statusclick li { - padding :5px; -} - -#statusclick li.active{ - background: #337ab7; - color: white; -} \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree_view.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree_view.html deleted file mode 100644 index d5364e8..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/home/tree_view.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - -
    - - - -
    -
    - - Please wait while the content loads. -
    -
    -
    -
    - No components found -
    -
    -
    - {{ecdapp.errMsg}} -
    - -
    diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-controllers.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-controllers.js index fceab0e..b474348 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-controllers.js +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-controllers.js @@ -1,1037 +1,1329 @@ appDS2.controller('inventoryBlueprintTableController', function( - $rootScope, $scope, $log, $modal, modalService, InventoryBlueprintService, InventoryDeploymentService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - // models for controls on screen - $scope.ecdapp.tableData = []; - $scope.ecdapp.currentPageNum = 1; - $scope.ecdapp.viewPerPage = 10; - // other - $scope.ecdapp.errMsg = null; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isRequestFailed = false; - // sorting - $scope.ecdapp.sortBy = null; - // searching - $scope.ecdapp.searchBy = null; - - $scope.ecdapp.trackBpRowIndex = function(indx) { - $scope.ecdapp.tableData[indx].expanded = !$scope.ecdapp.tableData[indx].expanded; - }; - - $scope.ecdapp.updateTable = function() { - $scope.ecdapp.isSrvcDataLoading = true; - var srvcTypIds = []; - var srvcIds = []; - var bpDepls =[]; - var cloneGrid = $scope.ecdapp.tableData; - angular.forEach($scope.ecdapp.tableData, function(item, index) { - angular.forEach(item, function(value, key) { - if (key === "typeId") { - srvcTypIds.push(value); - } - }); - }); - - InventoryBlueprintService.getDeploymentForBp(srvcTypIds) - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryBlueprintController.updateTable failed: " + jsonObj.error); - } else { - bpDepls = jsonObj; - for (var typIndx = 0; typIndx < bpDepls.length; typIndx++) { - srvcIds.push(bpDepls[typIndx].serviceRefList); - } - angular.forEach(cloneGrid, function(item, index) { - item.deployments = srvcIds[index]; - item.expanded = false; - }); - $scope.ecdapp.tableData = cloneGrid; - } - $scope.ecdapp.isSrvcDataLoading = false; - }, function(error) { - $log.error("inventoryBlueprintController.updateTable failed: " + error); - bpDepls = []; - $scope.ecdapp.isSrvcDataLoading = false; - }); - - } - - $scope.ecdapp.JSONToCSVConverter = function(blueprint) - { - var array = typeof blueprint != 'object' ? JSON.parse(blueprint) : blueprint; - var str = ''; - for (var i = 0; i < array.length; i++) { - var line = ''; - - for (var index in array[i]) { - line += array[i][index] + ','; + $rootScope, $scope, $log, $modal, modalService, ControllerService, $interval, $routeParams, + InventoryBlueprintService, InventoryDeploymentService, localStorageService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + var stop; + + // this object holds all app data and functions + $scope.ecdapp = {}; + // models for controls on screen + $scope.ecdapp.tableData = []; + $scope.ecdapp.currentPage = 1; + $scope.ecdapp.viewPerPage = 10; + // other + $scope.ecdapp.errMsg = null; + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.filterByUser = true; + // sorting + $scope.ecdapp.sortBy = null; + + // searching + $scope.ecdapp.searchBy = $routeParams.bpId; + if ($scope.ecdapp.searchBy == undefined) { + $scope.ecdapp.searchBy = "owner:" + $scope.userId + ";"; + } else { + if ($scope.ecdapp.searchBy.includes("owner")) { + if ($scope.ecdapp.searchBy.split(":")[1] === "group") { + $scope.ecdapp.filterByUser = false; + $scope.ecdapp.searchBy = undefined; + } + } + } + + $scope.ecdapp.searchString; + $scope.ecdapp.availableTenants = JSON.parse(localStorageService.get('tenants')); + $scope.ecdapp.isInternal = localStorageService.get('internal'); + if ($scope.ecdapp.isInternal) { + $scope.ecdapp.components = JSON.parse(localStorageService.get('appComponents')); + $scope.ecdapp.apps = JSON.parse(localStorageService.get('apps')); + $scope.ecdapp.selectedApp; + $scope.ecdapp.selectedComp; + $scope.ecdapp.availableComp = JSON.parse(localStorageService.get('components')); + } + $scope.ecdapp.selectedBp; + $scope.ecdapp.availableBp = JSON.parse(localStorageService.get('bpNames')); + + $scope.ecdapp.selectedOwner; + + $scope.ecdapp.showingMoreFilters = false; + + $scope.ecdapp.toggleMoreFilters = function() { + $scope.ecdapp.showingMoreFilters = !$scope.ecdapp.showingMoreFilters; + }; + + $scope.ecdapp.trackBpRowIndex = function(indx) { + $scope.ecdapp.tableData[indx].expanded = !$scope.ecdapp.tableData[indx].expanded; + }; + + $scope.ecdapp.updateTable = function() { + $scope.ecdapp.isSrvcDataLoading = true; + var srvcTypIds = []; + var srvcIds = []; + var bpDepls =[]; + var cloneGrid = $scope.ecdapp.tableData; + angular.forEach($scope.ecdapp.tableData, function(item, index) { + angular.forEach(item, function(value, key) { + if (key === "typeId") { + srvcTypIds.push(value); + } + }); + }); + + InventoryBlueprintService.getDeploymentForBp(srvcTypIds) + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryBlueprintController.updateTable failed: " + jsonObj.error); + } else { + bpDepls = jsonObj; + for (var typIndx = 0; typIndx < bpDepls.length; typIndx++) { + srvcIds.push(bpDepls[typIndx].serviceRefList); + } + angular.forEach(cloneGrid, function(item, index) { + item.deployments = srvcIds[index]; + item.expanded = false; + }); + $scope.ecdapp.tableData = cloneGrid; + } + $scope.ecdapp.isSrvcDataLoading = false; + }, function(error) { + $log.error("inventoryBlueprintController.updateTable failed: " + error); + bpDepls = []; + $scope.ecdapp.isSrvcDataLoading = false; + }); + } + + $scope.ecdapp.JSONToCSVConverter = function(blueprint) { + var array = typeof blueprint != 'object' ? JSON.parse(blueprint) : blueprint; + var str = ''; + for (var i = 0; i < array.length; i++) { + var line = ''; + for (var index in array[i]) { + line += array[i][index] + ','; + } + line.slice(0, line.Length - 1); + str += line + '\r\n'; + } + + var uri = 'data:text/csv;charset=utf-8,' + escape(str); + var fileName = 'exported'; + + var link = document.createElement("a"); + link.href= uri; + + link.style = "visibility:hidden"; + link.download = fileName + ".csv"; + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }; + + $scope.ecdapp.createcsv = function(blueprint) { + var bpArr =[]; + bpArr.push(blueprint); + $scope.ecdapp.JSONToCSVConverter(bpArr); + }; + + $scope.ecdapp.exportJson = function(blueprint) { + var bpExportObj = {}; + bpExportObj.application = blueprint.application; + bpExportObj.component = blueprint.component; + bpExportObj.typeName = blueprint.typeName; + bpExportObj.typeVersion = blueprint.typeVersion; + bpExportObj.blueprintTemplate = blueprint.blueprintTemplate; + + var bpStr = JSON.stringify(bpExportObj); + var uri = 'data:text/json;charset=utf-8,' + escape(bpStr); + var fileName = blueprint.application + '_' + blueprint.component + + '_' + blueprint.typeName + '_' + blueprint.typeVersion; + + var link = document.createElement("a"); + link.href= uri; + + link.style = "visibility:hidden"; + link.download = fileName + ".json"; + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }; + + $scope.ecdapp.getTenants = function() { + ControllerService.getTenants() + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("blueprintController.getTenants failed: " + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + var tenants = []; + for (var tenIndx = 0; tenIndx < jsonObj.items.length; tenIndx++) { + tenants.push(jsonObj.items[tenIndx].name); } + localStorageService.set('tenants', JSON.stringify(tenants)); + $scope.ecdapp.availableTenants = JSON.parse(localStorageService.get('tenants')); + } + }, function(error) { + $log.error("blueprintController.getTenants failed: " + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + }); + }; + + $scope.ecdapp.getOwnersList = function() { + $scope.ecdapp.bpOwners = JSON.parse(localStorageService.get('bpOwners')); + if ($scope.ecdapp.bpOwners == null) { + InventoryBlueprintService.getOwnersList().then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("bpCtlr.getOwnersList failed: " + + jsonObj.error); + $scope.ecdapp.bpOwners = []; + } else { + $scope.ecdapp.bpOwners = jsonObj; + localStorageService.set('bpOwners', JSON.stringify(jsonObj)); + } + }, + function(error) { + $log.error("inventoryDeploymentController.getOwnersList failed: " + + error); + $scope.ecdapp.bpOwners = []; + }); + } + }; + + $scope.ecdapp.getBlueprintsList = function() { + $scope.ecdapp.availableBp = JSON.parse(localStorageService.get('bpNames')); + if ($scope.ecdapp.availableBp == null) { + InventoryBlueprintService.getBlueprintsList().then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("execViewCtlr.getBlueprintsList failed: " + + jsonObj.error); + $scope.ecdapp.availableBp = []; + } else { + $scope.ecdapp.availableBp = jsonObj.items; + localStorageService.set('bpNames', JSON.stringify(jsonObj.items)); + //$scope.ecdapp.availableBp = JSON.parse(localStorageService.get('bpNames')); + } + }, + function(error) { + $log.error("inventoryDeploymentController.getDeploymentList failed: " + + error); + $scope.ecdapp.availableBp = []; + }); + } + }; + + /** + * Get the components from database + * + */ + $scope.ecdapp.getAppComponents = function() { + InventoryBlueprintService.getComponents() + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryBlueprintController.loadComponents failed: " + jsonObj.error); + $scope.ecdapp.components = []; + } else { + if (debug) + $log.debug("inventoryBlueprintController.loadComponents succeeded, size " + jsonObj.data.length); + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.components = jsonObj; + if (Array.isArray($scope.ecdapp.components) ) { + angular.forEach($scope.ecdapp.components, function(item, index) { + angular.forEach(item, function(value, key) { + if (key === "app") { + $scope.ecdapp.apps.push(value); + } else { + angular.forEach(value, function(item, index) { + angular.forEach(item, function(value, key) { + if (key === "cname") { + if (!$scope.ecdapp.availableComp.includes(value)) { + $scope.ecdapp.availableComp.push(value); + } + } + }); + }); + } + }); + }); + } + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $log.error("inventoryBlueprintController.loadComponents failed: " + error); + $scope.ecdapp.components = []; + }); + }; + + /** + * Loads the table. Interprets the remote controller's response and copies + * to scope variables. The response is either list to be assigned to + * tableData, or an error to be shown. + */ + $scope.ecdapp.loadTable = function(sortBy, searchBy) { + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.sortBy = sortBy; + //$scope.ecdapp.searchBy = searchBy; + InventoryBlueprintService.getBlueprints($scope.ecdapp.currentPage, $scope.ecdapp.viewPerPage, $scope.ecdapp.sortBy, $scope.ecdapp.searchBy) + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryBlueprintController.loadTable failed: " + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + //if (debug) + //$log.debug("inventoryBlueprintController.loadTable succeeded, size " + jsonObj.data.length); + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + $scope.ecdapp.tableData = jsonObj.items; + //$scope.ecdapp.updateTable(); + $scope.ecdapp.getBlueprintsList(); + $scope.ecdapp.getOwnersList(); + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $log.error("inventoryBlueprintController.loadTable failed: " + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + var loc = location.pathname; + var loc1 = loc.replace("/", ""); + var loc2 = loc1.replace("/ecd", "/login.htm"); + alert("Session expired - Sign in again"); + location.replace("/"+loc2); + }); + }; + + stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 300000, 100, false); + + $scope.ecdapp.stopLoading = function() { + if (angular.isDefined(stop)) { + $interval.cancel(stop); + stop = undefined; + } + }; + + /** + * Loads the table. Interprets the remote controller's response and copies + * to scope variables. The response is either list to be assigned to + * tableData, or an error to be shown. + */ + $scope.ecdapp.sortTable = function(sortBy) { + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.sortBy = sortBy; + InventoryBlueprintService.getBlueprints($scope.ecdapp.currentPage, $scope.ecdapp.viewPerPage, sortBy, $scope.ecdapp.searchBy) + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryBlueprintController.loadTable failed: " + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + if (debug) + $log.debug("inventoryBlueprintController.loadTable succeeded, size " + jsonObj.data.length); + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + $scope.ecdapp.tableData = jsonObj.items; + //$scope.ecdapp.updateTable(); + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $log.error("inventoryBlueprintController.loadTable failed: " + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + }); + }; - line.slice(0, line.Length - 1); + $scope.ecdapp.filterBySvc = function() { + if ( typeof $scope.ecdapp.searchString != "undefined" && + $scope.ecdapp.searchString != '') { + if ($scope.ecdapp.searchString.includes("serviceRef:") || + $scope.ecdapp.searchString.includes("app:") || + $scope.ecdapp.searchString.includes("comp:")) { + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy = $scope.ecdapp.searchString + ";" + "owner:" + $scope.userId + ";" + ";"; + } else { + $scope.ecdapp.searchBy = $scope.ecdapp.searchString; + } + } else { + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy = 'contains:' + $scope.ecdapp.searchString + ";" + "owner:" + $scope.userId + ";"; + } else { + $scope.ecdapp.searchBy = 'contains:' + $scope.ecdapp.searchString; + } + } + $scope.ecdapp.searchTable(); + } + }; - str += line + '\r\n'; + $scope.ecdapp.extendedfilterSrch = function() { + if ( typeof $scope.ecdapp.selectedBp != "undefined" && + $scope.ecdapp.selectedBp != '') { + var svcFilterStr = 'serviceRef:' + $scope.ecdapp.selectedBp.toString(); + $scope.ecdapp.searchBy = svcFilterStr + ';' + if ( typeof $scope.ecdapp.selectedApp != "undefined" && + $scope.ecdapp.selectedApp != '') { + var appFilterStr = 'app:' + $scope.ecdapp.selectedApp.toString(); + $scope.ecdapp.searchBy += appFilterStr + ';' + } + if ( typeof $scope.ecdapp.selectedComp != "undefined" && + $scope.ecdapp.selectedComp != '') { + var compFilterStr = 'comp:' + $scope.ecdapp.selectedComp.toString(); + $scope.ecdapp.searchBy += compFilterStr + ';' } + if ( typeof $scope.ecdapp.selectedOwner != "undefined" && + $scope.ecdapp.selectedOwner != '') { + var ownerFilterStr = 'owner:' + $scope.ecdapp.selectedOwner.toString(); + $scope.ecdapp.searchBy += ownerFilterStr + ';' + } + } else { + if ( typeof $scope.ecdapp.selectedApp != "undefined" && + $scope.ecdapp.selectedApp != '') { + var appFilterStr = 'app:' + $scope.ecdapp.selectedApp.toString(); + $scope.ecdapp.searchBy = appFilterStr + ';' + if ( typeof $scope.ecdapp.selectedComp != "undefined" && + $scope.ecdapp.selectedComp != '' ) { + var compFilterStr = 'comp:' + $scope.ecdapp.selectedComp.toString(); + $scope.ecdapp.searchBy += compFilterStr + ';' + } + if ( typeof $scope.ecdapp.selectedOwner != "undefined" && + $scope.ecdapp.selectedOwner != '') { + var ownerFilterStr = 'owner:' + $scope.ecdapp.selectedOwner.toString(); + $scope.ecdapp.searchBy += ownerFilterStr + ';' + } + } else { + if ( typeof $scope.ecdapp.selectedComp != "undefined" && + $scope.ecdapp.selectedComp != '') { + var compFilterStr = 'comp:' + $scope.ecdapp.selectedComp.toString(); + $scope.ecdapp.searchBy = compFilterStr + ';' + if ( typeof $scope.ecdapp.selectedOwner != "undefined" && + $scope.ecdapp.selectedOwner != '') { + var ownerFilterStr = 'owner:' + $scope.ecdapp.selectedOwner.toString(); + $scope.ecdapp.searchBy += ownerFilterStr + ';' + } + } else { + if ( typeof $scope.ecdapp.selectedOwner != "undefined" && + $scope.ecdapp.selectedOwner != '') { + var ownerFilterStr = 'owner:' + $scope.ecdapp.selectedOwner.toString(); + $scope.ecdapp.searchBy = ownerFilterStr + ';' + } + } + + } + } + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy += "owner:" + $scope.userId + ";"; + } + $scope.ecdapp.searchString = $scope.ecdapp.searchBy; + $scope.ecdapp.searchTable(); + }; + + /** + * Loads the table. Interprets the remote controller's response and copies + * to scope variables. The response is either list to be assigned to + * tableData, or an error to be shown. + */ + $scope.ecdapp.searchTable = function() { + $scope.ecdapp.isDataLoading = true; + $scope.ecdapp.showingMoreFilters = false; + if ($scope.ecdapp.currentPage != 1) { + $scope.ecdapp.currentPage = 1; + } else { + InventoryBlueprintService.getBlueprints($scope.ecdapp.currentPage, $scope.ecdapp.viewPerPage, $scope.ecdapp.sortBy, $scope.ecdapp.searchBy) + .then(function(jsonObj) { + if (jsonObj.error) { + $log.error("inventoryBlueprintController.loadTable failed: " + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + if (debug) + $log.debug("inventoryBlueprintController.loadTable succeeded, size " + jsonObj.data.length); + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.totalPages = jsonObj.totalPages; + $scope.ecdapp.tableData = jsonObj.items; + //$scope.ecdapp.updateTable(); + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $log.error("inventoryBlueprintController.loadTable failed: " + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + var loc = location.pathname; + var loc1 = loc.replace("/", ""); + var loc2 = loc1.replace("/ecd", "/login.htm"); + alert("Session expired - Sign in again"); + location.replace("/"+loc2); + }); + } + }; + + $scope.ecdapp.resetFilters = function() { + $scope.ecdapp.selectedBp = ''; + $scope.ecdapp.selectedApp = ''; + $scope.ecdapp.selectedComp = ''; + $scope.ecdapp.selectedOwner = ''; + $scope.ecdapp.searchString = ''; + }; + + $scope.ecdapp.reloadTable = function() { + $scope.ecdapp.currentPage = 1; + if ($scope.ecdapp.filterByUser) { + $scope.ecdapp.searchBy = "owner:" + $scope.userId + ";"; + } else { + $scope.ecdapp.searchBy = ''; + } + $scope.ecdapp.searchString = ''; + $scope.ecdapp.resetFilters(); + $scope.ecdapp.loadTable(); + }; + + $scope.ecdapp.toggleUserFilt = function() { + $scope.ecdapp.reloadTable(); + /* + if ($scope.ecdapp.filterByUser === false) { + $scope.ecdapp.searchString = ''; + } + */ + } + /** + * Invoked at first page load AND when + * user clicks on the B2B pagination control. + */ + $scope.pageChangeHandler = function(page) { + $scope.ecdapp.currentPage = page; + $scope.ecdapp.loadTable($scope.ecdapp.sortBy, $scope.ecdapp.searchBy); + } + + /** + * Shows a modal pop-up to update a blueprint. + * Passes data in via an object named "message". + * On success, updates the table. + */ + $scope.ecdapp.updateBlueprintModalPopup = function(blueprint) { + $scope.ecdapp.editBlueprint = null; + var modalInstance = $modal.open({ + templateUrl : 'inventory_blueprint_update_popup.html', + controller : 'inventoryBlueprintUpdateCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + blueprint : blueprint + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + + if (debug) + $log.debug('updateBlueprintModalPopup: response: ' + JSON.stringify(response)); + if (response == null) { + if (debug) + $log.debug('user closed dialog'); + } + else { + if (response.error != null) { + $log.error('updateBlueprintModalPopup failed: ' + response.error); + alert('Failed to update blueprint:\n' + response.error); + } + else { + // success, get the updated list. + $scope.ecdapp.loadTable() + } + } + }); + }; + + /** + * Shows a modal pop-up with blueprint content. + * Passes data in via an object named "message". + */ + $scope.ecdapp.viewBlueprintModalPopup = function(blueprint) { + $scope.ecdapp.editBlueprint = null; + var modalInstance = $modal.open({ + templateUrl : 'inventory_blueprint_view_popup.html', + controller : 'inventoryBlueprintViewCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + blueprint : blueprint + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + // No response. + }); + }; - var uri = 'data:text/csv;charset=utf-8,' + escape(str); - var fileName = 'exported'; - - var link = document.createElement("a"); - link.href= uri; - - link.style = "visibility:hidden"; - link.download = fileName + ".csv"; - - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - }; - - $scope.ecdapp.createcsv = function(blueprint) - { - var bpArr =[]; - bpArr.push(blueprint); - $scope.ecdapp.JSONToCSVConverter(bpArr); - }; - - $scope.ecdapp.exportJson = function(blueprint) - { - var bpExportObj = {}; - bpExportObj.application = blueprint.application; - bpExportObj.component = blueprint.component; - bpExportObj.typeName = blueprint.typeName; - bpExportObj.typeVersion = blueprint.typeVersion; - bpExportObj.blueprintTemplate = blueprint.blueprintTemplate; - - var bpStr = JSON.stringify(bpExportObj); - var uri = 'data:text/json;charset=utf-8,' + escape(bpStr); - var fileName = blueprint.application + '_' + blueprint.component + - '_' + blueprint.typeName + '_' + blueprint.typeVersion; - - var link = document.createElement("a"); - link.href= uri; - - link.style = "visibility:hidden"; - link.download = fileName + ".json"; - - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - }; - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.loadTable = function(sortBy, searchBy) { - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.sortBy = sortBy; - $scope.ecdapp.searchBy = searchBy; - InventoryBlueprintService.getBlueprints($scope.ecdapp.currentPageNum, $scope.ecdapp.viewPerPage, sortBy, searchBy) - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryBlueprintController.loadTable failed: " + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - //if (debug) - //$log.debug("inventoryBlueprintController.loadTable succeeded, size " + jsonObj.data.length); - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - $scope.ecdapp.tableData = jsonObj.items; - $scope.ecdapp.updateTable(); - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $log.error("inventoryBlueprintController.loadTable failed: " + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - }); - }; - - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.sortTable = function(sortBy) { - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.sortBy = sortBy; - InventoryBlueprintService.getBlueprints($scope.ecdapp.currentPageNum, $scope.ecdapp.viewPerPage, sortBy, $scope.ecdapp.searchBy) - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryBlueprintController.loadTable failed: " + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - if (debug) - $log.debug("inventoryBlueprintController.loadTable succeeded, size " + jsonObj.data.length); - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - $scope.ecdapp.tableData = jsonObj.items; - $scope.ecdapp.updateTable(); - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $log.error("inventoryBlueprintController.loadTable failed: " + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - }); - }; - - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.searchTable = function(searchBy) { - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.searchBy = searchBy; - InventoryBlueprintService.getBlueprints($scope.ecdapp.currentPageNum, $scope.ecdapp.viewPerPage, $scope.ecdapp.sortBy, searchBy) - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryBlueprintController.loadTable failed: " + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - if (debug) - $log.debug("inventoryBlueprintController.loadTable succeeded, size " + jsonObj.data.length); - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - $scope.ecdapp.tableData = jsonObj.items; - $scope.ecdapp.updateTable(); - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $log.error("inventoryBlueprintController.loadTable failed: " + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - }); - }; - - /** - * Invoked at first page load AND when - * user clicks on the B2B pagination control. - */ - $scope.pageChangeHandler = function(page) { - // console.log('pageChangeHandler: current is ' + $scope.ecdapp.currentPageNum + ' new is ' + page); - $scope.ecdapp.currentPageNum = page; - $scope.ecdapp.loadTable($scope.ecdapp.sortBy, $scope.ecdapp.searchBy); - } - - /** - * Shows a modal pop-up to update a blueprint. - * Passes data in via an object named "message". - * On success, updates the table. - */ - $scope.ecdapp.updateBlueprintModalPopup = function(blueprint) { - $scope.ecdapp.editBlueprint = null; - var modalInstance = $modal.open({ - templateUrl : 'inventory_blueprint_update_popup.html', - controller : 'inventoryBlueprintUpdateCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - blueprint : blueprint - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - - if (debug) - $log.debug('updateBlueprintModalPopup: response: ' + JSON.stringify(response)); - if (response == null) { - if (debug) - $log.debug('user closed dialog'); - } - else { - if (response.error != null) { - $log.error('updateBlueprintModalPopup failed: ' + response.error); - alert('Failed to update blueprint:\n' + response.error); - } - else { - // success, get the updated list. - $scope.ecdapp.loadTable() - } - } - }); - }; - - /** - * Shows a modal pop-up with blueprint content. - * Passes data in via an object named "message". - */ - $scope.ecdapp.viewBlueprintModalPopup = function(blueprint) { - $scope.ecdapp.editBlueprint = null; - var modalInstance = $modal.open({ - templateUrl : 'inventory_blueprint_view_popup.html', - controller : 'inventoryBlueprintViewCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - blueprint : blueprint - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - // No response. - }); - }; - - /** - * Shows a modal pop-up to upload a blueprint. - * Passes data in via an object named "message". - * On success, updates the table. - */ - $scope.ecdapp.uploadBlueprintModalPopup = function() { - $scope.ecdapp.editBlueprint = null; - var modalInstance = $modal.open({ - templateUrl : 'inventory_blueprint_upload_popup.html', - controller : 'inventoryBlueprintUploadCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - blueprint : $scope.ecdapp.editBlueprint, - blueprintList : $scope.ecdapp.tableData, - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - if (debug) - $log.debug('uploadBlueprintModalPopup: response: ' + JSON.stringify(response)); - if (response == null) { - if (debug) - $log.debug('user closed dialog'); - } - else { - if (response.error != null) { - $log.error('uploadBlueprintModalPopup failed: ' + response.error); - alert('Failed to upload blueprint:\n' + response.error); - } - else { - // success, get the updated list. - $scope.ecdapp.loadTable() - } - } - }); - }; - - /** - * Shows a modal pop-up to create a deployment from a blueprint. - * Passes data in via an object named "message". - */ - $scope.ecdapp.deployBlueprintModalPopup = function(blueprint) { - var modalInstance = $modal.open({ - templateUrl : 'inventory_blueprint_deploy_popup.html', - controller : 'inventoryBlueprintDeployCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - blueprint : blueprint, - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - if (debug) - $log.debug('deployBlueprintModalPopup: response: ' + JSON.stringify(response)); - if (response == null) { - if (debug) - $log.debug('user closed dialog'); - } - else { - if (response.error != null) { - $log.error('deployBlueprintModalPopup failed: ' + response.error); - alert('Failed to deploy blueprint:\n' + response.error); - // No need to update THIS table. - // Must switch to deployments page to see result? Awkward. - } - } - }); - }; - - /** - * Shows a modal pop-up to confirm deletion. - * On successful completion, updates the table. - */ - $scope.ecdapp.deleteBlueprintModalPopup = function(blueprint) { - modalService.popupConfirmWin("Confirm", "Delete blueprint with name '" - + blueprint.typeName + "'?", function() { - InventoryBlueprintService.deleteBlueprint(blueprint.typeId).then( - function(response) { - if (debug) - $log.debug('deleteBlueprintModalPopup: response: ' + JSON.stringify(response)); - if (response && response.error) { - // $log.error('deleteBlueprint failed: ' + response.error); - alert('Failed to delete blueprint:\n' + response.error); - } - else { - // No response body on success. - $scope.ecdapp.loadTable(); - } - }, - function(error) { - $log.error('InventoryBlueprintService.deleteBlueprint failed: ' + error); - alert('Service failed to delete blueprint:\n' + error); - }); - }) - }; + /** + * Shows a modal pop-up to upload a blueprint. + * Passes data in via an object named "message". + * On success, updates the table. + */ + $scope.ecdapp.uploadBlueprintModalPopup = function() { + $scope.ecdapp.editBlueprint = null; + var modalInstance = $modal.open({ + templateUrl : 'inventory_blueprint_upload_popup.html', + controller : 'inventoryBlueprintUploadCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + apps : $scope.ecdapp.apps, + appComps: $scope.ecdapp.components + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + if (debug) + $log.debug('uploadBlueprintModalPopup: response: ' + JSON.stringify(response)); + if (response == null) { + if (debug) + $log.debug('user closed dialog'); + } + else { + if (response.error != null) { + $log.error('uploadBlueprintModalPopup failed: ' + response.error); + alert('Failed to upload blueprint:\n' + response.error); + } + else { + // success, get the updated list. + $scope.ecdapp.loadTable() + } + } + }); + }; + + /** + * Shows a modal pop-up to create a deployment from a blueprint. + * Passes data in via an object named "message". + */ + $scope.ecdapp.deployBlueprintModalPopup = function(blueprint) { + var modalInstance = $modal.open({ + templateUrl : 'inventory_blueprint_deploy_popup.html', + controller : 'inventoryBlueprintDeployCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + blueprint : blueprint, + tenantList : $scope.ecdapp.availableTenants + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + if (debug) + $log.debug('deployBlueprintModalPopup: response: ' + JSON.stringify(response)); + if (response == null) { + if (debug) + $log.debug('user closed dialog'); + } + else { + if (response.error != null) { + $log.error('deployBlueprintModalPopup failed: ' + response.error); + alert('Failed to deploy blueprint:\n' + response.error); + // No need to update THIS table. + // Must switch to deployments page to see result? Awkward. + } + } + }); + }; + /** + * Shows a modal pop-up to confirm deletion. + * On successful completion, updates the table. + */ + $scope.ecdapp.deleteBlueprintModalPopup = function(blueprint) { + modalService.popupConfirmWin("Confirm", "Delete blueprint with name '" + + blueprint.typeName + "'?", function() { + InventoryBlueprintService.deleteBlueprint(blueprint.typeId).then( + function(response) { + if (debug) + $log.debug('deleteBlueprintModalPopup: response: ' + JSON.stringify(response)); + if (response && response.error) { + // $log.error('deleteBlueprint failed: ' + response.error); + alert('Failed to delete blueprint:\n' + response.error); + } + else { + // No response body on success. + $scope.ecdapp.loadTable(); + } + }, + function(error) { + $log.error('InventoryBlueprintService.deleteBlueprint failed: ' + error); + alert('Service failed to delete blueprint:\n' + error); + }); + }) + }; + + $scope.ecdapp.getTenants(); + + $scope.$on('$destroy', function() { + // Make sure that the interval is destroyed too + $scope.ecdapp.stopLoading(); + }); + }); /*************************************************************************/ appDS2.controller('inventoryBlueprintUpdateCtrl', function( - $scope, $log, $modalInstance, message, InventoryBlueprintService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Update Blueprint'; - $scope.ecdapp.updateInProgress = false; - // Create a ServiceTypeRequest object for edit - $scope.ecdapp.serviceType = angular.copy(message.blueprint); - - /** - * Validates content of user-editable fields. - * Returns null if all is well, - * a descriptive error message otherwise. - */ - $scope.ecdapp.validateRequest = function(serviceType) { - if (serviceType == null) - return 'No data found.\nPlease enter some values.'; - if (serviceType.blueprintTemplate == null || serviceType.blueprintTemplate.trim() == '') - return 'Blueprint Template is required.\nPlease enter a value.'; - let blueprintTemplate = {}; - try { - blueprintTemplate = YAML.parse(serviceType.blueprintTemplate); - } - catch (ex) { - return ('Blueprint template is not in YAML format:\n' + ex); - } - return null; - } - - $scope.ecdapp.updateBlueprint = function(serviceType) { - $scope.ecdapp.updateInProgress = true; - if (debug) - $log.debug('updateBlueprint: serviceType is ' + JSON.stringify($scope.ecdapp.serviceType)); - var validateMsg = $scope.ecdapp.validateRequest(serviceType); - if (validateMsg != null) { - alert('Invalid Request:\n' + validateMsg); - return; - } - - InventoryBlueprintService.updateBlueprint(serviceType) - .then(function(response) { - if (debug) - $log.debug('inventoryBlueprintUpdateCtrl.updateBlueprint: ' + JSON.stringify(response)); - if (response && response.error) { - $log.error('InventoryBlueprintService.updateBlueprint failed: ' + response.error); - alert('Failed to update blueprint:\n' + response.error); - } - else { - // Delete service returns null on success. - $modalInstance.close("success"); - } - $scope.ecdapp.updateInProgress = false; - }, - function(error) { - $log.error('InventoryBlueprintService.updateBlueprint failed: ' + error); - $scope.ecdapp.updateInProgress = false; - alert('Service failed to update blueprint:\n' + error); - }); - - }; + $scope, $log, $modalInstance, message, InventoryBlueprintService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'Update Blueprint'; + $scope.ecdapp.updateInProgress = false; + // Create a ServiceTypeRequest object for edit + $scope.ecdapp.serviceTypeRequest = angular.copy(message.blueprint); + + $scope.ecdapp.serviceType = + { + asdcResourceId : '', + asdcServiceId : '', + asdcServiceURL : '', + blueprintTemplate : '', + owner : $scope.ecdapp.serviceTypeRequest.owner, + serviceIds : [], + serviceLocations : [], + typeName : $scope.ecdapp.serviceTypeRequest.typeName, + typeVersion : $scope.ecdapp.serviceTypeRequest.typeVersion, + vnfTypes : [], + application: $scope.ecdapp.serviceTypeRequest.application, + component: $scope.ecdapp.serviceTypeRequest.component + }; + + // Fetch the blueprint + $scope.ecdapp.isDataLoading = true; + InventoryBlueprintService.viewBlueprint(message.blueprint.typeId).then(function(jsonObj) { + if (debug) + $log.debug("inventoryBlueprintViewCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed'; + } + else { + $scope.ecdapp.serviceType.blueprintTemplate = jsonObj.blueprintTemplate; + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $scope.ecdapp.isDataLoading = false; + $log.error("blueprintViewCtrl failed: " + error); + }); + + /** + * Validates content of user-editable fields. + * Returns null if all is well, + * a descriptive error message otherwise. + */ + $scope.ecdapp.validateRequest = function(serviceType) { + if (serviceType == null) + return 'No data found.\nPlease enter some values.'; + if (serviceType.blueprintTemplate == null || serviceType.blueprintTemplate.trim() == '') + return 'Blueprint Template is required.\nPlease enter a value.'; + let blueprintTemplate = {}; + try { + blueprintTemplate = YAML.parse(serviceType.blueprintTemplate); + } + catch (ex) { + return ('Blueprint template is not in YAML format:\n' + ex); + } + return null; + } + + $scope.ecdapp.updateBlueprint = function(serviceType) { + $scope.ecdapp.updateInProgress = true; + if (debug) + $log.debug('updateBlueprint: serviceType is ' + JSON.stringify($scope.ecdapp.serviceType)); + var validateMsg = $scope.ecdapp.validateRequest(serviceType); + if (validateMsg != null) { + alert('Invalid Request:\n' + validateMsg); + return; + } + + InventoryBlueprintService.updateBlueprint(serviceType) + .then(function(response) { + if (debug) + $log.debug('inventoryBlueprintUpdateCtrl.updateBlueprint: ' + JSON.stringify(response)); + if (response && response.error) { + $log.error('InventoryBlueprintService.updateBlueprint failed: ' + response.error); + alert('Failed to update blueprint:\n' + response.error); + } + else { + $modalInstance.close("success"); + } + $scope.ecdapp.updateInProgress = false; + }, + function(error) { + $log.error('InventoryBlueprintService.updateBlueprint failed: ' + error); + $scope.ecdapp.updateInProgress = false; + alert('Service failed to update blueprint:\n' + error); + }); + + }; }); appDS2.controller('inventoryBlueprintUploadCtrl', function( - $scope, $log, $modalInstance, message, InventoryBlueprintService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Upload Blueprint'; - $scope.ecdapp.uploadInProgress = false; - $scope.ecdapp.serviceTypeRequest = - { - asdcResourceId : '', - asdcServiceId : '', - asdcServiceURL : '', - blueprintTemplate : '', - owner : $scope.userId, - serviceIds : '', - serviceLocations : '', - typeName : '', - typeVersion : '', - vnfTypes : '', - application: '', - component: '' - }; - $scope.ecdapp.writeRole = false; - $scope.ecdapp.newCompName = ""; - $scope.ecdapp.newCompDisplayName = ""; - $scope.ecdapp.newCompId = null; - $scope.ecdapp.enableAppForm = false; - $scope.ecdapp.apps = []; - $scope.ecdapp.comps = []; - $scope.ecdapp.validAppl = false; - $scope.ecdapp.validComp = false; - $scope.ecdapp.isImport = false; - - /** - * Handler for file-read event reads file, parses JSON, validates content. - */ - var importFileReader = new FileReader(); - importFileReader.onload = function(event) { - let jsonString = importFileReader.result; - if (debug) - $log.debug('fileReader.onload: read: ' + jsonString); - let ydict = {}; - try { - ydict = JSON.parse(jsonString); - } - catch (ex) { - alert('Failed to parse file as JSON:\n' + ex); - } - // Process the file - for (var ykey in ydict) { - let yval = ydict[ykey]; - if (debug) - $log.debug('importFileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); - - if (ykey === "application") { - $scope.ecdapp.serviceTypeRequest.application = yval; - $scope.ecdapp.validAppl = true; - } else if (ykey === "component") { - $scope.ecdapp.serviceTypeRequest.component = yval; - $scope.ecdapp.validComp = true; - } else if (ykey === "typeName") { - $scope.ecdapp.serviceTypeRequest.typeName = yval; - } else if (ykey === "typeVersion") { - $scope.ecdapp.serviceTypeRequest.typeVersion = yval; - } else if (ykey === "blueprintTemplate") { - $scope.ecdapp.serviceTypeRequest.blueprintTemplate = yval; - } - } - } - - $scope.ecdapp.handleImportCb = function($event) { - var checkbox = $event.target; - var action = (checkbox.checked ? 'import' : 'regular'); - if (action === 'import') { - $scope.ecdapp.serviceTypeRequest.application = ''; - $scope.ecdapp.serviceTypeRequest.component = ''; - $scope.ecdapp.isImport = true; - } - if (action === 'regular') { - $scope.ecdapp.serviceTypeRequest.application = 'Select Application'; - $scope.ecdapp.serviceTypeRequest.component = 'Select Component'; - $scope.ecdapp.isImport = false; - } - } - // Handler for file-select event - $scope.ecdapp.handleImportFile = function() { - if (debug) - $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.serviceTypeRequest.fileModel.name); - importFileReader.readAsText($scope.ecdapp.serviceTypeRequest.fileModel); - }; - - /** - * Get the components from database - * - */ - InventoryBlueprintService.getComponents() - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryBlueprintController.loadComponents failed: " + jsonObj.error); - $scope.ecdapp.components = []; - } else { - if (debug) - $log.debug("inventoryBlueprintController.loadComponents succeeded, size " + jsonObj.data.length); - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.components = jsonObj; - if (Array.isArray($scope.ecdapp.components) ) { - angular.forEach($scope.ecdapp.components, function(item, index) { - angular.forEach(item, function(value, key) { - if (key === "app") { - $scope.ecdapp.apps.push(value); - } - }); - }); - } - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $log.error("inventoryBlueprintController.loadComponents failed: " + error); - $scope.ecdapp.components = []; - }); - - //$scope.ecdapp.components = [{"ECOMPC":[{"compId":1,"cname":"controller","dname":"CONTROLLER"},{"compId":2,"cname":"mso","dname":"MSO"},{"compId":3,"cname":"appc","dname":"APP-C"},{"compId":4,"cname":"clamp","dname":"CLAMP"},{"compId":5,"cname":"ecompscheduler","dname":"ECOMP SCHEDULER"},{"compId":6,"cname":"policy","dname":"POLICY"},{"compId":7,"cname":"eipam","dname":"EIPAM"},{"compId":181,"cname":"pdasms","dname":"PDAS-MS"},{"cname":"true"}]}, - // {"DCAE": [{"compId":8,"cname":"dcae","dname":"DCAE"}]}]; - $scope.ecdapp.selectAppComp = function(appName) { - if(appName === "Select Application"){ - $scope.ecdapp.validAppl = false; - } else { - $scope.ecdapp.validAppl = true; - for (var appIndx = 0; appIndx < $scope.ecdapp.components.length; appIndx++) { - if ($scope.ecdapp.components[appIndx].app === appName) { - $scope.ecdapp.comps = $scope.ecdapp.components[appIndx].comps; - break; - } - } - } - } - $scope.ecdapp.validateComp = function(appName) { - if($scope.ecdapp.serviceTypeRequest.component === "Select Component"){ - $scope.ecdapp.validComp = false; - } else { - $scope.ecdapp.validComp = true; - } - } - var fileReader = new FileReader(); - fileReader.onload = function(event) { - let yamlString = fileReader.result; - $scope.ecdapp.serviceTypeRequest.blueprintTemplate = yamlString; - } - $scope.ecdapp.enableAddApp = function() { - if ($scope.ecdapp.enableAppForm) { - $scope.ecdapp.enableAppForm = false; - } else { - $scope.ecdapp.enableAppForm = true; - } - } - $scope.ecdapp.addApplication = function(appName, compId, compName, compDisplayName) { - // save new application to database, reload components list - if (compName.trim().length < 1 || compDisplayName.trim().length < 1) { - alert("Must enter value for Component name and display name"); - return; + $scope, $log, $modalInstance, message, InventoryBlueprintService, localStorageService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'Upload Blueprint'; + $scope.ecdapp.uploadInProgress = false; + + $scope.ecdapp.serviceTypeRequest = + { + asdcResourceId : '', + asdcServiceId : '', + asdcServiceURL : '', + blueprintTemplate : '', + owner : $scope.userId, + serviceIds : '', + serviceLocations : '', + typeName : '', + typeVersion : '', + vnfTypes : '', + application: '', + component: '' + }; + + if (!$scope.ecdapp.isInternal) { + $scope.ecdapp.serviceTypeRequest.application = 'DCAE'; + $scope.ecdapp.serviceTypeRequest.component = 'dcae'; + } + $scope.ecdapp.writeRole = false; + $scope.ecdapp.isImport = false; + + /** + * Handler for file-read event reads file, parses JSON, validates content. + */ + var importFileReader = new FileReader(); + importFileReader.onload = function(event) { + let jsonString = importFileReader.result; + if (debug) + $log.debug('fileReader.onload: read: ' + jsonString); + let ydict = {}; + try { + ydict = JSON.parse(jsonString); + } + catch (ex) { + alert('Failed to parse file as JSON:\n' + ex); + } + // Process the file + for (var ykey in ydict) { + let yval = ydict[ykey]; + if (debug) + $log.debug('importFileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); + + if (ykey === "application") { + $scope.ecdapp.serviceTypeRequest.application = yval; + $scope.ecdapp.validAppl = true; + } else if (ykey === "component") { + $scope.ecdapp.serviceTypeRequest.component = yval; + $scope.ecdapp.validComp = true; + } else if (ykey === "typeName") { + $scope.ecdapp.serviceTypeRequest.typeName = yval; + } else if (ykey === "typeVersion") { + $scope.ecdapp.serviceTypeRequest.typeVersion = yval; + } else if (ykey === "blueprintTemplate") { + $scope.ecdapp.serviceTypeRequest.blueprintTemplate = yval; + } + } + } + + $scope.ecdapp.handleImportCb = function($event) { + var checkbox = $event.target; + var action = (checkbox.checked ? 'import' : 'regular'); + if (action === 'import' && $scope.ecdapp.isInternal) { + $scope.ecdapp.serviceTypeRequest.application = ''; + $scope.ecdapp.serviceTypeRequest.component = ''; + $scope.ecdapp.isImport = true; + } + if (action === 'regular' && $scope.ecdapp.isInternal) { + $scope.ecdapp.serviceTypeRequest.application = 'Select Application'; + $scope.ecdapp.serviceTypeRequest.component = 'Select Component'; + $scope.ecdapp.isImport = false; + } + } + // Handler for file-select event + $scope.ecdapp.handleImportFile = function() { + if (debug) + $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.serviceTypeRequest.fileModel.name); + importFileReader.readAsText($scope.ecdapp.serviceTypeRequest.fileModel); + }; + + + //$scope.ecdapp.components = [{"ECOMPC":[{"compId":1,"cname":"controller","dname":"CONTROLLER"},{"compId":2,"cname":"mso","dname":"MSO"},{"compId":3,"cname":"appc","dname":"APP-C"},{"compId":4,"cname":"clamp","dname":"CLAMP"},{"compId":5,"cname":"ecompscheduler","dname":"ECOMP SCHEDULER"},{"compId":6,"cname":"policy","dname":"POLICY"},{"compId":7,"cname":"eipam","dname":"EIPAM"},{"compId":181,"cname":"pdasms","dname":"PDAS-MS"},{"cname":"true"}]}, + // {"DCAE": [{"compId":8,"cname":"dcae","dname":"DCAE"}]}]; + $scope.ecdapp.selectAppComp = function(appName) { + if(appName === "Select Application") { + $scope.ecdapp.validAppl = false; + } else { + $scope.ecdapp.comps = []; + $scope.ecdapp.serviceTypeRequest.component = ""; + $scope.ecdapp.validAppl = true; + for (var appIndx = 0; appIndx < $scope.ecdapp.components.length; appIndx++) { + if ($scope.ecdapp.components[appIndx].app === appName) { + $scope.ecdapp.comps = $scope.ecdapp.components[appIndx].comps; + break; } - //console.log("Saving " + applicationName + " to components list"); - InventoryBlueprintService.insertComponent(compName, compDisplayName.toUpperCase()).then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryBlueprintController.loadComponents failed: " + jsonObj.error); - } else { - if (debug) - $log.debug("inventoryBlueprintController.loadComponents succeeded, size " + jsonObj.data.length); - //console.log(jsonObj); - InventoryBlueprintService.getComponents().then(function(jsonObj) { - /* - $scope.ecdapp.newApplicationName = ""; - $scope.ecdapp.newApplicationDisplayName = ""; - $scope.ecdapp.selectedOption = $scope.ecdapp.components[0]; - */ - $scope.ecdapp.components = jsonObj; - $scope.ecdapp.enableAppForm = false; - $scope.ecdapp.selectAppComp(appName); - }); - } - }, function(error) { - $log.error("inventoryBlueprintController.addApplication failed: " + error); - }); - }; - - // Handler for file-select event - $scope.handleFileSelect = function() { - if (debug) - $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.serviceTypeRequest.fileModel.name); - fileReader.readAsText($scope.ecdapp.serviceTypeRequest.fileModel); - }; - // Convert serviceIds, serviceLocations, and vnfTypes to JSON Array - $scope.ecdapp.convertStringsToArrays = function(serviceTypeRequest) { - if (serviceTypeRequest.serviceIds || serviceTypeRequest.serviceIds.trim() != '') { - try { - serviceTypeRequest.serviceIds = angular.fromJson(serviceTypeRequest.serviceIds.split(",")); - } catch (error) { - return 'Service Ids is not in the correct format.'; - } - } else { - serviceTypeRequest.serviceIds = []; - } - - if (serviceTypeRequest.serviceLocations || serviceTypeRequest.serviceLocations.trim() != '') { - try { - serviceTypeRequest.serviceLocations = angular.fromJson(serviceTypeRequest.serviceLocations.split(",")); - } catch (error) { - return 'Service Locations is not in the correct format.'; - } - } else { - serviceTypeRequest.serviceLocations = []; - } - - if (serviceTypeRequest.vnfTypes || serviceTypeRequest.vnfTypes.trim() != '') { - try { - serviceTypeRequest.vnfTypes = angular.fromJson(serviceTypeRequest.vnfTypes.split(",")); - } catch (error) { - return 'VNF Types is not in the correct format.'; - } - } else { - serviceTypeRequest.vnfTypes = []; - } - - try { - if (isNaN(serviceTypeRequest.typeVersion)) { - serviceTypeRequest.typeVersion = serviceTypeRequest.typeVersion.replace(/\./gi, ""); - serviceTypeRequest.typeVersion = angular.fromJson(serviceTypeRequest.typeVersion); - } - } catch (error) { - return 'typeVersion is not in the correct format.'; - } - - return null; - } - - /** - * Validates content of user-editable fields. - * Returns null if all is well, - * a descriptive error message otherwise. - */ - $scope.ecdapp.validateRequest = function(serviceTypeRequest) { - if (!serviceTypeRequest) - return 'No data found.\nPlease enter some values.'; - if (!serviceTypeRequest.owner || serviceTypeRequest.owner.trim() == '') { - return 'Application/Owner is required.\nPlease enter a value.'; - } - if (!serviceTypeRequest.typeName || serviceTypeRequest.typeName.trim() == '') { - return 'Type Name is required.\nPlease enter a value.'; - } - if (!serviceTypeRequest.typeVersion ) { - //|| serviceTypeRequest.typeVersion.trim() == '') { - return 'Type Version is required.\nPlease enter a value.'; - } - if (!serviceTypeRequest.blueprintTemplate || serviceTypeRequest.blueprintTemplate.trim() == '') - return 'Blueprint Template is required.\nPlease enter a value.'; - - return null; - } - - $scope.ecdapp.uploadBlueprint = function(serviceTypeRequest) { - if (debug) - $log.debug('uploadBlueprint: serviceType is ' + JSON.stringify(serviceTypeRequest)); - $scope.ecdapp.uploadInProgress = true; - var validateMsg = $scope.ecdapp.validateRequest(serviceTypeRequest); - if (validateMsg != null) { - editServiceType = angular.copy(serviceTypeRequest); - alert('Invalid Request:\n' + validateMsg); - $scope.ecdapp.uploadInProgress = false; - return; - } - //var authUser = $scope.userId; - //serviceTypeRequest.owner = serviceTypeRequest.owner + ':' + authUser; - // Create a editServiceTypeRequest object for edit - var editServiceType = angular.copy(serviceTypeRequest); - var convertMsg = $scope.ecdapp.convertStringsToArrays(editServiceType); - if (convertMsg != null) { - editServiceType = angular.copy(serviceTypeRequest); - alert('Invalid Request:\n' + convertMsg); - return; - } - - InventoryBlueprintService.uploadBlueprint(editServiceType) - .then(function(response) { - if (debug) - $log.debug('inventoryBlueprintUploadCtrl.uploadBlueprint: ' + JSON.stringify(response)); - if (response && response.error) { - $log.error('InventoryBlueprintService.uploadBlueprint failed: ' + response.error); - alert('Failed to upload blueprint:\n' + response.error); - } - else { - // Upload service returns null on success. - $modalInstance.close("success"); - } - $scope.ecdapp.uploadInProgress = false; - }, - function(error) { - $log.error('InventoryBlueprintService.uploadBlueprint failed: ' + error); - $scope.ecdapp.uploadInProgress = false; - alert('Service failed to upload blueprint:\n' + error); - }); - - }; + } + } + } + + $scope.ecdapp.validateComp = function(appName) { + if($scope.ecdapp.serviceTypeRequest.component === "Select Component"){ + $scope.ecdapp.validComp = false; + } else { + $scope.ecdapp.validComp = true; + } + } + var fileReader = new FileReader(); + fileReader.onload = function(event) { + let yamlString = fileReader.result; + $scope.ecdapp.serviceTypeRequest.blueprintTemplate = yamlString; + } + + // Handler for file-select event + $scope.handleFileSelect = function() { + if (debug) + $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.serviceTypeRequest.fileModel.name); + fileReader.readAsText($scope.ecdapp.serviceTypeRequest.fileModel); + }; + // Convert serviceIds, serviceLocations, and vnfTypes to JSON Array + + $scope.ecdapp.convertStringsToArrays = function(serviceTypeRequest) { + if (serviceTypeRequest.serviceIds || serviceTypeRequest.serviceIds.trim() != '') { + try { + serviceTypeRequest.serviceIds = angular.fromJson(serviceTypeRequest.serviceIds.split(",")); + } catch (error) { + return 'Service Ids is not in the correct format.'; + } + } else { + serviceTypeRequest.serviceIds = []; + } + + if (serviceTypeRequest.serviceLocations || serviceTypeRequest.serviceLocations.trim() != '') { + try { + serviceTypeRequest.serviceLocations = angular.fromJson(serviceTypeRequest.serviceLocations.split(",")); + } catch (error) { + return 'Service Locations is not in the correct format.'; + } + } else { + serviceTypeRequest.serviceLocations = []; + } + + if (serviceTypeRequest.vnfTypes || serviceTypeRequest.vnfTypes.trim() != '') { + try { + serviceTypeRequest.vnfTypes = angular.fromJson(serviceTypeRequest.vnfTypes.split(",")); + } catch (error) { + return 'VNF Types is not in the correct format.'; + } + } else { + serviceTypeRequest.vnfTypes = []; + } + return null; + } + + $scope.ecdapp.isInt = function(value) { + return !isNaN(value) && + parseInt(Number(value)) == value && + !isNaN(parseInt(value, 10)); + } + /** + * Validates content of user-editable fields. + * Returns null if all is well, + * a descriptive error message otherwise. + */ + $scope.ecdapp.validateRequest = function(serviceTypeRequest) { + if (!serviceTypeRequest) + return 'No data found.\nPlease enter some values.'; + if (!serviceTypeRequest.owner || serviceTypeRequest.owner.trim() == '') { + return 'Application/Owner is required.\nPlease enter a value.'; + } + if (!serviceTypeRequest.typeName || serviceTypeRequest.typeName.trim() == '') { + return 'Type Name is required.\nPlease enter a value.'; + } + if (!serviceTypeRequest.typeVersion ) { + //|| serviceTypeRequest.typeVersion.trim() == '') { + return 'Type Version is required.\nPlease enter a value.'; + } + if (!$scope.ecdapp.isInt(serviceTypeRequest.typeVersion) ) { + //|| serviceTypeRequest.typeVersion.trim() == '') { + return 'Type Version should be a valid Integer.'; + } + if (!serviceTypeRequest.blueprintTemplate || serviceTypeRequest.blueprintTemplate.trim() == '') + return 'Blueprint Template is required.\nPlease enter a value.'; + + return null; + } + + $scope.ecdapp.uploadBlueprint = function(serviceTypeRequest) { + if (debug) + $log.debug('uploadBlueprint: serviceType is ' + JSON.stringify(serviceTypeRequest)); + $scope.ecdapp.uploadInProgress = true; + var validateMsg = $scope.ecdapp.validateRequest(serviceTypeRequest); + if (validateMsg != null) { + editServiceType = angular.copy(serviceTypeRequest); + alert('Invalid Request:\n' + validateMsg); + $scope.ecdapp.uploadInProgress = false; + return; + } + //var authUser = $scope.userId; + //serviceTypeRequest.owner = serviceTypeRequest.owner + ':' + authUser; + // Create a editServiceTypeRequest object for edit + var editServiceType = angular.copy(serviceTypeRequest); + var convertMsg = $scope.ecdapp.convertStringsToArrays(editServiceType); + if (convertMsg != null) { + editServiceType = angular.copy(serviceTypeRequest); + alert('Invalid Request:\n' + convertMsg); + return; + } + + InventoryBlueprintService.uploadBlueprint(editServiceType) + .then(function(response) { + if (debug) + $log.debug('inventoryBlueprintUploadCtrl.uploadBlueprint: ' + JSON.stringify(response)); + if (response && response.error) { + $log.error('InventoryBlueprintService.uploadBlueprint failed: ' + response.error); + alert('Failed to upload blueprint:\n' + response.error); + } + else { + // Upload service returns null on success. + $modalInstance.close("success"); + } + $scope.ecdapp.uploadInProgress = false; + }, + function(error) { + $log.error('InventoryBlueprintService.uploadBlueprint failed: ' + error); + $scope.ecdapp.uploadInProgress = false; + alert('Service failed to upload blueprint:\n' + error); + }); + + }; }); /*************************************************************************/ appDS2.controller('inventoryBlueprintViewCtrl', function( - $scope, $log, message, InventoryBlueprintService) { - - 'use strict'; - - var debug = false; - - if (debug) - $log.debug("inventoryBlueprintViewCtrl.message: " + JSON.stringify(message)); - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.blueprintId = message.blueprint.typeId; - - $scope.ecdapp.label = 'View Blueprint ' + message.blueprint.typeName; - - // Fetch the blueprint - $scope.ecdapp.isDataLoading = true; - InventoryBlueprintService.viewBlueprint(message.blueprint.typeId).then(function(jsonObj) { - if (debug) - $log.debug("inventoryBlueprintViewCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed'; - } - else { - $scope.ecdapp.blueprint = jsonObj.blueprintTemplate; - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $scope.ecdapp.isDataLoading = false; - alert('Failed to get blueprint. Please retry.'); - $log.error("blueprintViewCtrl failed: " + error); - }); - + $scope, $log, message, InventoryBlueprintService) { + + 'use strict'; + + var debug = false; + + if (debug) + $log.debug("inventoryBlueprintViewCtrl.message: " + JSON.stringify(message)); + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.blueprintId = message.blueprint.typeId; + + $scope.ecdapp.label = 'View Blueprint ' + message.blueprint.typeName; + + // Fetch the blueprint + $scope.ecdapp.isDataLoading = true; + InventoryBlueprintService.viewBlueprint(message.blueprint.typeId).then(function(jsonObj) { + if (debug) + $log.debug("inventoryBlueprintViewCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed'; + } + else { + $scope.ecdapp.blueprint = jsonObj.blueprintTemplate; + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $scope.ecdapp.isDataLoading = false; + alert('Failed to get blueprint. Please retry.'); + $log.error("blueprintViewCtrl failed: " + error); + }); + }); +appDS2.directive('json', function() { + return { + restrict: 'A', // only activate on element attribute + require: 'ngModel', // get a hold of NgModelController + link: function(scope, element, attrs, ngModelCtrl) { + function toUser(object) { + if (typeof object === 'object') { + return angular.toJson(object, true); + } else { + return object; + } + } + ngModelCtrl.$formatters.push(toUser); + // $watch(attrs.ngModel) wouldn't work if this directive created a new scope; + // see http://stackoverflow.com/questions/14693052/watch-ngmodel-from-inside-directive-using-isolate-scope how to do it then + scope.$watch(attrs.ngModel, function(newValue, oldValue) { + if (newValue != oldValue) { + ngModelCtrl.$setViewValue(toUser(newValue)); + // TODO avoid this causing the focus of the input to be lost.. + ngModelCtrl.$render(); + } + }, true); // MUST use objectEquality (true) here, for some reason.. + } + }; +}); /*************************************************************************/ appDS2.controller('inventoryBlueprintDeployCtrl', function( - $scope, $rootScope, $log, $modal, $modalInstance, message, InventoryDeploymentService, InventoryBlueprintService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Deploy Blueprint'; - $scope.ecdapp.errMsg = ''; - - // deployment in progress - $scope.ecdapp.deploymentInProgress = false; - $scope.ecdapp.isDataLoading = false; - $scope.ecdapp.tenant = $rootScope.tenantList.tenant; - $scope.ecdapp.validTenant = false; - - // Cache the input parameter names for validation - if (debug) - $log.debug('inventoryBlueprintDeployCtrl: inputs: ' + JSON.stringify(message.blueprint.blueprintInputs)); - $scope.ecdapp.inputsDict = message.blueprint.blueprintInputs; - - // Copy the input parameter names and default values - let inputsAndDefaults = {}; - for (var pkey in message.blueprint.blueprintInputs) { - if (debug) - $log.debug('inventoryBlueprintDeployCtrl: checking key ' + pkey); - let dval = message.blueprint.blueprintInputs[pkey].defaultValue; - if ( typeof dval === "undefined" ) - dval = ''; - inputsAndDefaults[pkey] = dval; - } - if (debug) - $log.debug('inventoryBlueprintDeployCtrl: inputsAndDefaults: ' + JSON.stringify(inputsAndDefaults)); - - // Create an object for edit - //var genDeployId = message.blueprint.component + "_" + message.blueprint.typeName; - $scope.ecdapp.editRequest = { - deployment_id : '', - type_id : message.blueprint.typeId, - fileModel : null, - parmFileDict : inputsAndDefaults, - tenant : '', - component: message.blueprint.component, - tag : message.blueprint.typeName - }; - $scope.ecdapp.validateTenant = function(){ - if($scope.ecdapp.editRequest.tenant === "Select Tenant"){ - $scope.ecdapp.validTenant = false; - }else{ - $scope.ecdapp.validTenant = true; - } + $scope, $rootScope, $log, $modal, $modalInstance, message, InventoryDeploymentService, InventoryBlueprintService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + + // this object holds all app data and functions + $scope.ecdapp = {}; + $scope.ecdapp.label = 'Deploy Blueprint'; + $scope.ecdapp.errMsg = ''; + $scope.ecdapp.availableTenants = message.tenantList; + + $scope.ecdapp.deploymentInProgress = false; + $scope.ecdapp.validTenant = false; + let inputsAndDefaults = {}; + let inputsAndDescriptions = {}; + + // Create an object for edit + $scope.ecdapp.editRequest = { + deployment_id : '', + type_id : message.blueprint.typeId, + fileModel : null, + parmFileDict : inputsAndDefaults, + descriptionDict : inputsAndDescriptions, + tenant : '', + component: message.blueprint.component, + tag : message.blueprint.typeName + }; + // Fetch the blueprint + $scope.ecdapp.isDataLoading = true; + InventoryBlueprintService.viewBlueprint(message.blueprint.typeId).then(function(jsonObj) { + if (debug) + $log.debug("inventoryBlueprintViewCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); + if (jsonObj.error) { + $scope.ecdapp.errMsg = 'Request Failed'; + } + else { + $scope.ecdapp.inputsDict = jsonObj.blueprintInputs; + for (var pkey in $scope.ecdapp.inputsDict) { + if (debug) + $log.debug('inventoryBlueprintDeployCtrl: checking key ' + pkey); + let dval = $scope.ecdapp.inputsDict[pkey].defaultValue; + let description = $scope.ecdapp.inputsDict[pkey].description; + if ( typeof dval === "undefined" ) + dval = ''; + if ( typeof description === "undefined" ) + description = ''; + inputsAndDefaults[pkey] = dval; + inputsAndDescriptions[pkey] = description; + if (debug) + $log.debug('inventoryBlueprintDeployCtrl: inputsAndDefaults: ' + JSON.stringify(inputsAndDefaults)); + } + } + $scope.ecdapp.isDataLoading = false; + }, function(error) { + $scope.ecdapp.isDataLoading = false; + alert('Failed to get blueprint. Please retry.'); + $log.error("blueprintViewCtrl failed: " + error); + }); + + $scope.ecdapp.validateTenant = function(){ + if($scope.ecdapp.editRequest.tenant === "Select Tenant"){ + $scope.ecdapp.validTenant = false; + }else{ + $scope.ecdapp.validTenant = true; + } + } + /** + * Handler for file-read event reads file, parses JSON, validates content. + */ + var fileReader = new FileReader(); + fileReader.onload = function(event) { + let jsonString = fileReader.result; + if (debug) + $log.debug('fileReader.onload: read: ' + jsonString); + let ydict = {}; + try { + ydict = JSON.parse(jsonString); + } + catch (ex) { + alert('Failed to parse file as JSON:\n' + ex); } - /** - * Handler for file-read event reads file, parses JSON, validates content. - */ - var fileReader = new FileReader(); - fileReader.onload = function(event) { - let jsonString = fileReader.result; - if (debug) - $log.debug('fileReader.onload: read: ' + jsonString); - let ydict = {}; - try { - ydict = JSON.parse(jsonString); - } - catch (ex) { - alert('Failed to parse file as JSON:\n' + ex); - } - // Process the file - for (var ykey in ydict) { - let yval = ydict[ykey]; - if (debug) - $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); - // Allow only expected keys with scalar values - if (! (ykey in $scope.ecdapp.editRequest.parmFileDict)) - alert('Unexpected file content:\nKey not defined by blueprint:\n' + ykey); - /* + // Process the file + for (var ykey in ydict) { + let yval = ydict[ykey]; + if (debug) + $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); + // Allow only expected keys with scalar values + if (! (ykey in $scope.ecdapp.editRequest.parmFileDict)) + alert('Unexpected file content:\nKey not defined by blueprint:\n' + ykey); + /* else if (typeof yval !== 'string' && typeof yval !== 'number') alert('Unexpected file content:\nNot a simple key-value pair:\n' + ykey); - */ - if (yval.constructor === {}.constructor) - $scope.ecdapp.editRequest.parmFileDict[ykey] = angular.toJson(yval); - else - $scope.ecdapp.editRequest.parmFileDict[ykey] = yval; - } - if (debug) - $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.editRequest.parmFileDict)); - - // Update table in all cases - $scope.$apply(); - } - - // Handler for file-select event - $scope.handleFileSelect = function() { - if (debug) - $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); - fileReader.readAsText($scope.ecdapp.editRequest.fileModel); - }; - - /** - * Validates content of user-editable fields. - * Returns null if all is well, - * a descriptive error message otherwise. - */ - $scope.ecdapp.validateRequest = function(editRequest) { - if (editRequest == null) - return 'No data found.\nPlease enter some values.'; - if (editRequest.deployment_id == null || editRequest.deployment_id.trim() == '') - return 'Deployment ID is required.\nPlease enter a value.'; - if (editRequest.type_id == null || editRequest.type_id.trim() == '') - return 'Type ID is required.\nPlease enter a value.'; - if (editRequest.tag == null || editRequest.tag.trim() == '') - return 'Deployment tag is required.\nPlease enter a value.'; - if (editRequest.tenant == null || editRequest.tenant.trim() == '') - return 'Tenant name is required.\nPlease enter a value.'; - // Check that every file parameter is defined by blueprint - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) { - // Defined in blueprint? - if (! $scope.ecdapp.inputsDict[pkey]) - return 'Unexpected input parameter\n' + pkey; - return null; - } - }; - - $scope.ecdapp.viewDeploymentExecutionsModalPopup = function(deployment) { - var modalInstance = $modal.open({ - templateUrl : 'inventory_execution_view_popup.html', - controller : 'inventoryDeploymentExecutionsViewCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - deployment : deployment - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - // No response. - }); - }; - $scope.ecdapp.deployBlueprint = function(editRequest) { - //editRequest.tenant = $rootScope.tenantList.tenant; - $scope.ecdapp.errMsg = ''; - editRequest.deployment_id = editRequest.component + "_" + editRequest.tag; - if (debug) - $log.debug('deployBlueprint: editRequest is ' + JSON.stringify($scope.ecdapp.editRequest)); - var validateMsg = $scope.ecdapp.validateRequest(editRequest); - if (validateMsg != null) { - alert('Invalid Request:\n' + validateMsg); - return; - } - // Create request with key:value parameters dictionary - let deploymentRequestObject = { - deploymentId : editRequest.deployment_id, - serviceTypeId : editRequest.type_id, - inputs : {}, - tenant : editRequest.tenant, - method : "create" - }; - let deploymentExecObj = { - deploymentRef : editRequest.deployment_id, - tenant : editRequest.tenant - } - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) - try { - deploymentRequestObject.inputs[pkey] = angular.fromJson($scope.ecdapp.editRequest.parmFileDict[pkey]); - } catch (error) { - deploymentRequestObject.inputs[pkey] = $scope.ecdapp.editRequest.parmFileDict[pkey]; - } - if (debug) - $log.debug('deployBlueprint: deploymentRequestObject is ' + JSON.stringify(deployRequestObject)); - - $scope.ecdapp.deploymentInProgress = true; - InventoryDeploymentService.deployBlueprint(deploymentRequestObject) - .then(function(response) { - $scope.ecdapp.deploymentInProgress = false; - if (response.error) { - $scope.ecdapp.errMsg = 'Failed to deploy blueprint: ' + response.error; - alert('Failed to deploy blueprint:\n' + response.error); - } - else { - $modalInstance.close(response); - // launch the view executions modal - $scope.ecdapp.viewDeploymentExecutionsModalPopup(deploymentExecObj); - } - }, - function (error) { - $log.error('inventoryBlueprintDeployCtrl: error while deploying: ' + error); - $scope.ecdapp.errMsg = 'Server rejected deployment request: ' + error; - alert('Server rejected deployment request:\n' + error); - $scope.ecdapp.deploymentInProgress = false; - } - ); - }; + */ + if (yval.constructor === {}.constructor) + $scope.ecdapp.editRequest.parmFileDict[ykey] = angular.toJson(yval); + else + $scope.ecdapp.editRequest.parmFileDict[ykey] = yval; + } + if (debug) + $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.editRequest.parmFileDict)); + + // Update table in all cases + $scope.$apply(); + } + + // Handler for file-select event + $scope.handleFileSelect = function() { + if (debug) + $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); + fileReader.readAsText($scope.ecdapp.editRequest.fileModel); + }; + + /** + * Validates content of user-editable fields. + * Returns null if all is well, + * a descriptive error message otherwise. + */ + $scope.ecdapp.validateRequest = function(editRequest) { + if (editRequest == null) + return 'No data found.\nPlease enter some values.'; + if (editRequest.deployment_id == null || editRequest.deployment_id.trim() == '') + return 'Deployment ID is required.\nPlease enter a value.'; + if (editRequest.type_id == null || editRequest.type_id.trim() == '') + return 'Type ID is required.\nPlease enter a value.'; + if (editRequest.tag == null || editRequest.tag.trim() == '') + return 'Deployment tag is required.\nPlease enter a value.'; + if (editRequest.tenant == null || editRequest.tenant.trim() == '') + return 'Tenant name is required.\nPlease enter a value.'; + // Check that every file parameter is defined by blueprint + for (var pkey in $scope.ecdapp.editRequest.parmFileDict) { + // Defined in blueprint? + if (! $scope.ecdapp.inputsDict[pkey]) + return 'Unexpected input parameter\n' + pkey; + return null; + } + }; + + $scope.ecdapp.viewDeploymentExecutionsModalPopup = function(deployment) { + var modalInstance = $modal.open({ + templateUrl : 'inventory_execution_view_popup.html', + controller : 'inventoryDeploymentExecutionsViewCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-jumbo', + resolve : { + message : function() { + var dataForPopup = { + deployment : deployment + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + // No response. + }); + }; + $scope.ecdapp.deployBlueprint = function(editRequest) { + //editRequest.tenant = $rootScope.tenantList.tenant; + $scope.ecdapp.errMsg = ''; + editRequest.deployment_id = editRequest.component + "_" + editRequest.tag; + if (debug) + $log.debug('deployBlueprint: editRequest is ' + JSON.stringify($scope.ecdapp.editRequest)); + var validateMsg = $scope.ecdapp.validateRequest(editRequest); + if (validateMsg != null) { + alert('Invalid Request:\n' + validateMsg); + return; + } + // Create request with key:value parameters dictionary + let deploymentRequestObject = { + deploymentId : editRequest.deployment_id, + serviceTypeId : editRequest.type_id, + inputs : {}, + tenant : editRequest.tenant, + method : "create" + }; + let deploymentExecObj = { + deploymentRef : editRequest.deployment_id, + tenant : editRequest.tenant + } + for (var pkey in $scope.ecdapp.editRequest.parmFileDict) + try { + deploymentRequestObject.inputs[pkey] = angular.fromJson($scope.ecdapp.editRequest.parmFileDict[pkey]); + } catch (error) { + deploymentRequestObject.inputs[pkey] = $scope.ecdapp.editRequest.parmFileDict[pkey]; + } + if (debug) + $log.debug('deployBlueprint: deploymentRequestObject is ' + JSON.stringify(deployRequestObject)); + + $scope.ecdapp.deploymentInProgress = true; + + InventoryDeploymentService.deployBlueprint(deploymentRequestObject) + .then(function(response) { + $scope.ecdapp.deploymentInProgress = false; + if (response.error) { + $scope.ecdapp.errMsg = 'Failed to deploy blueprint: ' + response.error; + alert('Failed to deploy blueprint:\n' + response.error); + InventoryDeploymentService.deleteBlueprint(editRequest.deployment_id, editRequest.tenant); + } + else { + $modalInstance.close(response); + // launch the view executions modal + $scope.ecdapp.viewDeploymentExecutionsModalPopup(deploymentExecObj); + } + }, + function (error) { + $log.error('inventoryBlueprintDeployCtrl: error while deploying: ' + error); + $scope.ecdapp.errMsg = 'Server rejected deployment request: ' + error; + alert('Server rejected deployment request:\n' + error); + $scope.ecdapp.deploymentInProgress = false; + } + ); + }; }); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-service.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-service.js index b553c9e..02709d3 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-service.js +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-service.js @@ -35,11 +35,92 @@ appDS2.factory('InventoryBlueprintService', function ($http, $q, $log) { return $q.reject(error.statusText); }); }, + getBlueprintsSummary: function() { + // cache control for IE + let cc = "&cc=" + new Date().getTime().toString(); + let url = null; + url = 'inventory/dcae-service-types?_include=typeName,typeVersion,typeId' + cc; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryBlueprintService.getBlueprintsSummary: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryBlueprintService.getBlueprintsSummary failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getOwnersList: function() { + let url = 'inventory/owners'; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryBlueprintService.getOwnersList: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryBlueprintService.getOwnersList failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getBlueprintsList: function() { + let url = 'inventory/service-type-list'; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryBlueprintService.getBlueprintsList: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryBlueprintService.getBlueprintsList failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getBlueprintIdsList: function(searchBy) { + let url = ''; + if (searchBy) { + url = 'inventory/service-type-id-list?searchBy=' + searchBy; + } else { + url = 'inventory/service-type-id-list'; + } + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryBlueprintService.getBlueprintIdsList: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryBlueprintService.getBlueprintIdsList failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, /** * get deployments for a blueprint */ getDeploymentForBp: function(bpArr) { - let url = 'inventory/dcae-services/typeIds'; + let url = 'deployment_blueprint_map'; + //let url = 'inventory/dcae-services/typeIds'; return $http({ method: 'POST', url: url, @@ -49,7 +130,6 @@ appDS2.factory('InventoryBlueprintService', function ($http, $q, $log) { if (response.data == null) return $q.reject('InventoryBlueprintService.getDeploymentForBp: response.data null or not object'); else { - console.log(response.data); return response.data; } }, @@ -166,7 +246,6 @@ appDS2.factory('InventoryBlueprintService', function ($http, $q, $log) { if (response.data == null) return $q.reject('InventoryBlueprintService.viewBlueprint: response.data null or not object'); else { - console.log(response.data); return response.data; } }, @@ -281,6 +360,12 @@ appDS2.factory('InventoryBlueprintService', function ($http, $q, $log) { }, */ deleteBlueprint: function(typeId) { + /*var typeId = blueprint.typeId; + var deploymentItems = blueprint.deployments.items; + var deplIdList = []; + for (var i=0; i < deploymentItems.length; i++) { + deplIdList.push(deploymentItems.id); + }*/ let url = 'inventory/dcae-service-types/' + typeId; return $http({ method: 'DELETE', diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-controllers.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-controllers.js deleted file mode 100644 index e17dcae..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-controllers.js +++ /dev/null @@ -1,1352 +0,0 @@ -appDS2.controller('inventoryDeploymentTableController', function( - $rootScope, $scope, $routeParams, $route, - $interval, $log, $modal, modalService, - InventoryDeploymentService, InventoryBlueprintService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - // models for controls on screen - $scope.ecdapp.tableData = []; - $scope.ecdapp.currentPageNum = 1; - $scope.ecdapp.viewPerPage = 10; - // other - $scope.ecdapp.errMsg = null; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isRequestFailed = false; - // sorting - $scope.ecdapp.sortBy = null; - // searching - $scope.ecdapp.searchBy = $routeParams.depId; - $scope.ecdapp.selectedRow = null; // initialize our variable to null - $scope.ecdapp.setClickedRow = function(index){ //function that sets the value of selectedRow to current index - $scope.ecdapp.selectedRow = index; - } - - $scope.ecdapp.updateTable = function() { - $scope.ecdapp.isSrvcDataLoading = true; - var srvcIds = []; - var cloneGrid = $scope.ecdapp.tableData; - angular.forEach($scope.ecdapp.tableData, function(item, index) { - angular.forEach(item, function(value, key) { - if (key === "deploymentRef") { - srvcIds.push(value); - } - }); - }); - - InventoryDeploymentService.getDeploymentStatus(srvcIds) - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryDeploymentTableController.updateTable failed: " + jsonObj.error); - } else { - for (var indx = 0; indx < jsonObj.length; indx++) { - if (jsonObj[indx].status === "terminated") { - jsonObj[indx].status = "completed"; - jsonObj[indx].statusImg = "static/fusion/images/active.png"; - } else { - jsonObj[indx].statusImg = "static/fusion/images/inactive.png"; - } - cloneGrid[indx].statusInfo = jsonObj[indx]; - } - $scope.ecdapp.tableData = cloneGrid; - } - $scope.ecdapp.isSrvcDataLoading = false; - }, function(error) { - $log.error("inventoryBlueprintController.updateTable failed: " + error); - $scope.ecdapp.isSrvcDataLoading = false; - }); - } - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either a list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.loadTable = function(sortBy, searchBy) { - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.sortBy = sortBy; - $scope.ecdapp.searchBy = searchBy; - InventoryDeploymentService.getDeployments($scope.ecdapp.currentPageNum, - $scope.ecdapp.viewPerPage, sortBy, searchBy).then( - function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryDeploymentController.loadTable failed: " - + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - $scope.ecdapp.tableData = jsonObj.items; - $scope.ecdapp.updateTable(); - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error("inventoryDeploymentController.loadTable failed: " - + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - }); - }; - - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either a list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.sortTable = function(sortBy) { - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.sortBy = sortBy; - InventoryDeploymentService.getDeployments($scope.ecdapp.currentPageNum, - $scope.ecdapp.viewPerPage, sortBy, $scope.ecdapp.searchBy).then( - function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryDeploymentController.loadTable failed: " - + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - $scope.ecdapp.tableData = jsonObj.items; - $scope.ecdapp.updateTable(); - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error("inventoryDeploymentController.loadTable failed: " - + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - }); - }; - - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either a list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.searchTable = function(searchBy) { - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.searchBy = searchBy; - InventoryDeploymentService.getDeployments($scope.ecdapp.currentPageNum, - $scope.ecdapp.viewPerPage, $scope.ecdapp.sortBy, searchBy).then( - function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryDeploymentController.loadTable failed: " - + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.tableData = []; - } else { - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - $scope.ecdapp.tableData = jsonObj.items; - $scope.ecdapp.updateTable(); - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error("inventoryDeploymentController.loadTable failed: " - + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - }); - }; - - $scope.ecdapp.checkHelmStatus = function(deployment) { - var selTenant = deployment.statusInfo.tenant_name; - if ( typeof selTenant === "undefined" ) { - selTenant = "default_tenant"; - } - deployment.onlyLatest = true; - - // This object holds data for this operation - $scope.ecdapp.helmStatusRequest = { - "deployment_id": deployment.deploymentRef, - "workflow_name": "status", - "tenant": selTenant - }; - InventoryDeploymentService.helmStatusFlow($scope.ecdapp.helmStatusRequest).then(function(jsonObj) { - if (debug) - $log.debug("checkHelmStatus response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; - $scope.ecdapp.updatingDeployment = false; - $scope.ecdapp.isDataLoading = false; - } else { - console.log('%c POSTED helm status request', 'color: magenta; font-weight: bold;'); - } - }, function(error) { - $log.error('helmStatusFlow failed: ' + error); - }); - $scope.ecdapp.viewDeploymentExecutionsModalPopup(deployment); - }; - /** - * Shows a modal pop-up with blueprint content. - * Passes data in via an object named "message". - */ - $scope.ecdapp.viewBlueprintDataModal = function(deployment) { - var modalInstance = $modal.open({ - templateUrl : 'blueprint_data_view_popup.html', - controller : 'deployBlueprintViewCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - blueprint : deployment - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - }); - }; - - /** - * Invoked at first page load AND when - * user clicks on the B2B pagination control. - */ - $scope.pageChangeHandler = function(page) { - // console.log('pageChangeHandler: current is ' + $scope.ecdapp.currentPageNum + ' new is ' + page); - $scope.ecdapp.currentPageNum = page; - $scope.ecdapp.loadTable($scope.ecdapp.sortBy, $scope.ecdapp.searchBy); - } - - /** - * Shows a modal pop-up to confirm deletion. - * On successful completion, updates the table. - */ - $scope.ecdapp.deleteDeploymentModalPopup = function(deployment) { - deployment.onlyLatest = true; - var modalInstance = $modal.open({ - templateUrl : 'inventory_deployment_delete_popup.html', - controller : 'inventoryDeploymentDeleteCtrl', - sizeClass: 'modal-small', - resolve : { - message : function() { - var dataForPopup = { - deployment : deployment, - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - if (debug) - $log.debug('deleteDeploymentPopup: response: ' + JSON.stringify(response)); - if (response == null) { - // $log.debug('user closed dialog'); - } - else { - if (response.error != null) { - $log.error('deleteDeploymentModalPopup failed: ' + response.error); - alert('Failed to delete deployment:\n' + response.error); - } - else { - $scope.ecdapp.viewDeploymentExecutionsModalPopup(deployment); - } - } - }); - }; - - /** - * Shows a modal pop-up with executions for a deployment. - * Passes data in via an object named "deployment". - */ - $scope.ecdapp.viewDeploymentExecutionsModalPopup = function(deployment) { - var modalInstance = $modal.open({ - templateUrl : 'inventory_execution_view_popup.html', - controller : 'inventoryDeploymentExecutionsViewCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - deployment : deployment - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - // No response. - }); - }; - - /** - * Shows a modal pop-up with executions for a deployment. - * Passes data in via an object named "deployment". - */ - $scope.ecdapp.viewDeploymentInputsModalPopup = function(deployment) { - var modalInstance = $modal.open({ - templateUrl : 'inventory_deployment_inputs_view_popup.html', - controller : 'inventoryDeploymentInputsViewCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve : { - message : function() { - var dataForPopup = { - deployment : deployment - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - // No response. - }); - }; - - /** - * Shows a modal pop-up to initiate helm upgrade for a deployment - */ - $scope.ecdapp.upgradeDeploymentModalPopup = function(deployment) { - //console.log(deployment); - var modalInstance = $modal.open({ - templateUrl: 'inventory_deployment_upgrade_popup.html', - controller: 'inventoryDeploymentUpgradeCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve: { - message: function() { - var dataForPopup = { - deployment : deployment - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - // No response. - }); - }; - - /** - * Shows a modal pop-up to initiate helm rollback for a deployment - */ - $scope.ecdapp.rollbackDeploymentModalPopup = function(deployment) { - var modalInstance = $modal.open({ - templateUrl: 'inventory_deployment_rollback_popup.html', - controller: 'inventoryDeploymentRollbackCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve: { - message: function() { - var dataForPopup = { - deployment : deployment - }; - return dataForPopup; - } - } - }); - modalInstance.result.then(function(response) { - // No response. - }); - }; - - /** - * Shows a modal pop-up to initiate update blueprint for a deployment - */ - $scope.ecdapp.updateDeploymentModalPopup = function(deployment) { - var modalInstance = $modal.open({ - templateUrl: 'inventory_deployment_update_popup.html', - controller: 'inventoryDeploymentUpdateCtrl', - windowClass: 'modal-docked', - sizeClass: 'modal-jumbo', - resolve: { - message: function() { - var dataForPopup = { - deployment : deployment - }; - return dataForPopup; - } - } - }); - }; - - /** - * Shows a modal pop-up to confirm service deletion. - * On successful completion, updates the table. - */ - $scope.ecdapp.deleteServiceModalPopup = function(service) { - modalService.popupConfirmWin("Confirm", "Delete Service with ID '" - + service.serviceId + "'?", function() { - InventoryDeploymentService.deleteService(service.serviceId).then( - function(response) { - if (debug) - $log.debug('deleteServiceModalPopup: response: ' + JSON.stringify(response)); - if (response && response.error) { - alert('Failed to delete service:\n' + response.error); - } - else { - // No response body on success. - $scope.ecdapp.loadTable(); - } - }, - function(error) { - $log.error('InventoryDeploymentService.deleteService failed: ' + error); - alert('Service failed to delete service:\n' + error); - }); - }) - }; -}); - -/*************************************************************************/ - -appDS2.controller('inventoryDeploymentDeleteCtrl', function( - $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Undeploy?'; - $scope.ecdapp.deploymentRef = message.deployment.deploymentRef; - var selTenant = message.deployment.statusInfo.tenant_name; - $scope.ecdapp.ui_tenant = selTenant; - $scope.ecdapp.tenant = selTenant; - - $scope.ecdapp.deleteDeploymentById = function(){ - InventoryDeploymentService.deleteDeployment($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then( - function(response) { - if (debug) - $log.debug('inventoryDeploymentDeleteCtrl.deleteDeployment: ' + JSON.stringify(response)); - if (response && response.error) { - $log.error('InventoryDeploymentService.deleteDeployment failed: ' + response.error); - alert('Failed to delete deployment:\n' + response.error); - } - else { - // Delete service returns null on success. - $modalInstance.close("success"); - } - }, - function(error) { - $log.error('InventoryDeploymentService.deleteDeployment failed: ' + error); - alert('Service failed to delete deployment:\n' + error); - }); - } - -}); - -/*************************************************************************/ - -appDS2.controller('inventoryDeploymentExecutionsViewCtrl', function( - $scope, $rootScope, $interval, $log, $modalInstance, message, modalService, InventoryExecutionService, ExecutionService) { - - 'use strict'; - - var debug = false; - - if (debug) - $log.debug("inventoryDeploymentsExecutionsViewCtrl.message: " + JSON.stringify(message)); - - // this object holds all app data and functions - $scope.ecdapp = {}; - // models for controls on screen - $scope.ecdapp.label = 'Deployment Executions'; - $scope.ecdapp.tableData = []; - $scope.ecdapp.logTableData = []; - $scope.ecdapp.currentPageNum = 1; - $scope.ecdapp.viewPerPage = 50; - $scope.ecdapp.currentLogPageNum = 1; - - // other - $scope.ecdapp.errMsg = null; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isEventLogQuery = false; - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.isLastExecution = message.deployment.onlyLatest; - $scope.ecdapp.isLogType = true; - $scope.ecdapp.refresh_switch = { - value: true - }; - $scope.ecdapp.options = { - "on":"On", - "off":"Off" - } - var selTenant = 'default_tenant'; - - if (typeof message.deployment.statusInfo === "undefined") { - selTenant = message.deployment.tenant; - } else { - selTenant = message.deployment.statusInfo.tenant_name; - } - - $scope.ecdapp.ui_tenant = selTenant; - $scope.ecdapp.tenant = selTenant; - $scope.ecdapp.deplRef = message.deployment.deploymentRef; - var stop; - /** - * Loads the table. Interprets the remote controller's response and copies - * to scope variables. The response is either a list to be assigned to - * tableData, or an error to be shown. - */ - $scope.ecdapp.loadTable = function() { - $scope.ecdapp.isDataLoading = true; - InventoryExecutionService.getExecutionsByDeployment(message.deployment.deploymentRef, - $scope.ecdapp.tenant, - $scope.ecdapp.currentPageNum, - $scope.ecdapp.viewPerPage).then( - function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryDeploymentExecutionsViewCtrl.loadTable failed: " - + jsonObj.error); - $scope.ecdapp.isRequestFailed = true; - if (jsonObj.error.includes("404")) { - $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; - } - $scope.ecdapp.tableData = []; - $scope.ecdapp.stopLoading(); - } else { - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.totalPages = jsonObj.totalPages; - var resultLen = jsonObj.items.length; - if (resultLen != undefined && resultLen > 0) { - var exec_id = jsonObj.items[resultLen-1].id; - if ($scope.ecdapp.isLastExecution) { - $scope.ecdapp.tableData = []; - $scope.ecdapp.tableData.push(jsonObj.items[resultLen-1]); - } else { - $scope.ecdapp.tableData = jsonObj.items; - } - $scope.ecdapp.getExecutionLogs(exec_id, $scope.ecdapp.tenant); - } - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error("inventoryDeploymentExecutionsViewCtrl.loadTable failed: " - + error); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.tableData = []; - $scope.ecdapp.isDataLoading = false; - $scope.ecdapp.stopLoading(); - }); - }; - $scope.$watch('ecdapp.refresh_switch["value"]', function(newValue,oldValue,scope) { - if (newValue != oldValue) { - if (newValue === true) { - $scope.ecdapp.loadTable(); - stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 30000, 100, false); - } else { - $scope.ecdapp.stopLoading(); - } - } - }, true); - - if ($scope.ecdapp.refresh_switch.value === true) { - stop = $interval( function(){ $scope.ecdapp.loadTable(); }, 30000, 100, false); - } - - $scope.ecdapp.stopLoading = function() { - if (angular.isDefined(stop)) { - $interval.cancel(stop); - stop = undefined; - } - }; - - $scope.ecdapp.cancelExecutionModalPopup = function(execution, tenant) { - modalService.popupConfirmWin("Confirm", "Cancel execution with ID '" - + execution.id + "'?", function() { - $scope.ecdapp.isCancelOn = true; - // TODO: gather action from user - InventoryExecutionService.cancelExecution(execution.id, execution.deployment_id, "force-cancel", tenant).then( - function(response) { - if (debug) - $log.debug("Controller.cancelExecutionModalPopup: " + JSON.stringify(response)); - if (response && response.error) { - // $log.error('cancelExectuion failed: ' + response.error); - alert('Failed to cancel execution:\n' + response.error); - $scope.ecdapp.isCancelOn = false; - } - else { - // No response body on success. - $scope.ecdapp.isCancelOn = false; - $scope.ecdapp.loadTable(); - } - }, - function(error) { - $scope.ecdapp.isCancelOn = false; - $log.error('ExecutionService.cancelExecution failed: ' + error); - alert('Service failed to cancel execution:\n' + error); - }); - }) - }; - - /** - * Invoked at first page load AND when - * user clicks on the B2B pagination control. - */ - $scope.pageChangeHandler = function(page) { - if (debug) - console.log('pageChangeHandler: current is ' + $scope.ecdapp.currentPageNum + ' new is ' + page); - $scope.ecdapp.currentPageNum = page; - $scope.ecdapp.loadTable(); - - } - - $scope.ecdapp.selected = false; - $scope.ecdapp.toggleStatusDefinitions = function() { - $scope.ecdapp.selected = $scope.ecdapp.selected ? false :true; - } - - /** - * Shows a modal pop-up with the error. - */ - $scope.ecdapp.viewErrorModalPopup = function(row) { - $modalInstance.dismiss('cancel'); - modalService.showFailure('Error Details', row.error, function() { } ); - }; - - $scope.ecdapp.getExecutionLogs = function(id, tenant) { - $scope.ecdapp.executionId = id; - $scope.ecdapp.isEventLogQuery = false; - InventoryExecutionService.getEventsByExecution(id , $scope.ecdapp.isLogType, tenant, - $scope.ecdapp.currentLogPageNum, $scope.ecdapp.viewPerPage ).then( - function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryDeploymentExecutionsViewCtrl.getExecutionLogs failed: " - + jsonObj.error); - $scope.ecdapp.isEventLogQuery = false; - $scope.ecdapp.evtErrMsg = jsonObj.error; - $scope.ecdapp.logTableData = []; - } else { - $scope.ecdapp.isEventLogQuery = true; - $scope.ecdapp.evtErrMsg = null; - $scope.ecdapp.totalLogPages = jsonObj.totalPages; - $scope.ecdapp.logTableData = jsonObj.items; - /* - if ($scope.ecdapp.isLogType) { - $scope.ecdapp.logTableData = jsonObj.items; - } else { - $scope.ecdapp.logTableData = []; - angular.forEach(jsonObj.items, function(item, index) { - angular.forEach(item, function(value, key) { - if (key === "type" && value != "cloudify_log") { - $scope.ecdapp.logTableData.push(item); - } - }); - }); - } - */ - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error("inventoryDeploymentExecutionsViewCtrl.getExecutionLogs failed: " - + error); - $scope.ecdapp.evtErrMsg = error; - $scope.ecdapp.logTableData = []; - $scope.ecdapp.isDataLoading = false; - }); - } - - $scope.$on('$destroy', function() { - // Make sure that the interval is destroyed too - $scope.ecdapp.stopLoading(); - }); -}); - -/*************************************************************************/ -appDS2.controller('inventoryDeploymentInputsViewCtrl', function( - $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Deployment Inputs'; - $scope.ecdapp.deployment = null; - $scope.ecdapp.deploymentRef = message.deployment.deploymentRef; - $scope.ecdapp.serviceId = message.deployment.serviceId; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isRequestFailed = false; - var selTenant = message.deployment.statusInfo.tenant_name; - if ( typeof selTenant === "undefined" ) { - selTenant = "default_tenant"; - } - $scope.ecdapp.ui_tenant = selTenant; - $scope.ecdapp.tenant = selTenant; - - InventoryDeploymentService.getDeployment(message.deployment.deploymentRef, $scope.ecdapp.tenant).then(function(deployment) { - if (deployment.items.length == 0) { - $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; - $log.error("InventoryDeploymentSerice.getDeployment failed: " - + $scope.ecdapp.errMsg); - $scope.ecdapp.isRequestFailed = true; - } - // Deployment IDs are unique, so this will always return exactly one item! - // retrieve blueprintId and inputs of deployment. - else { - $scope.ecdapp.errMsg = null; - $scope.ecdapp.deployment = deployment.items[0]; - $scope.ecdapp.isRequestFailed = false; - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error('InventoryDeploymentService.getDeployment failed: ' + JSON.stringify(error)); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.isDataLoading = false; - }); -}); - -/*************************************************************************/ -appDS2.controller('inventoryDeploymentUpdateCtrl', function( - $scope, $log, $modalInstance, message, InventoryBlueprintService, InventoryDeploymentService) { - - 'use strict'; - - var debug = false; - if (debug) - $log.debug("inventoryDeploymentUpdateCtrl.message: " + JSON.stringify(message)); - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.deploymentInProgress = false; - $scope.ecdapp.serviceTypeComplete = false; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.label = 'Update Deployment: ' + message.deployment.deploymentRef; - $scope.ecdapp.deploymentRef = message.deployment.deploymentRef; - var selTenant = message.deployment.statusInfo.tenant_name; - if ( typeof selTenant === "undefined" ) { - selTenant = "default_tenant"; - } - $scope.ecdapp.tenant = selTenant; - $scope.ecdapp.ui_tenant = selTenant; - $scope.ecdapp.typeName = ''; - $scope.ecdapp.typeId = ''; - $scope.ecdapp.inputsDict = {}; - $scope.ecdapp.editRequest = { - deployment_id : message.deployment.deploymentRef, - type_id : '', - fileModel : null, - parmFileDict : {}, - tenant : $scope.ecdapp.tenant - }; - - // get the blueprints from inventory matching deployment reference filter - $scope.ecdapp.bp = []; - var sortBy = ''; - var searchBy = message.deployment.deploymentRef.split("_", 1); - searchBy = searchBy[0]; - InventoryBlueprintService.getBlueprints(1, 100, sortBy, searchBy) - .then(function(jsonObj) { - if (jsonObj.error) { - $log.error("inventoryDeploymentUpdateCtrl.loadTable failed: " + jsonObj.error); - $scope.ecdapp.errMsg = jsonObj.error; - $scope.ecdapp.bp = []; - } else { - $scope.ecdapp.errMsg = null; - $scope.ecdapp.bp = jsonObj.items; - if (Array.isArray($scope.ecdapp.bp) ) { - angular.forEach($scope.ecdapp.bp, function(item, index) { - item.checked = false; - }); - } - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $log.error("inventoryDeploymentUpdateCtrl.loadTable failed: " + error); - $scope.ecdapp.errMsg = error; - $scope.ecdapp.bp = []; - $scope.ecdapp.isDataLoading = false; - }); - $scope.ecdapp.updateSelection = function(position) { - $scope.ecdapp.typeId = position; - $scope.ecdapp.editRequest.type_id = position; - angular.forEach($scope.ecdapp.bp, function(item, index) { - if (position != index+1) - item.checked = false; - }); - } - $scope.ecdapp.getBlueprint = function() { - $scope.ecdapp.isDataLoading = true; - InventoryBlueprintService.viewBlueprint($scope.ecdapp.typeId).then(function(jsonObj) { - if (debug) - $log.debug("inventoryDeploymentUpdateCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed'; - $scope.ecdapp.serviceTypeComplete = false; - $scope.ecdapp.isDataLoading = false; - } - else { - $scope.ecdapp.typeName = jsonObj.typeName; - $scope.ecdapp.typeVersion = jsonObj.typeVersion; - $scope.ecdapp.inputsDict = jsonObj.blueprintInputs; - // query the current deployment inputs - InventoryDeploymentService.getDeployment(message.deployment.deploymentRef, $scope.ecdapp.tenant).then(function(deployment) { - if (deployment.items.length == 0) { - $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; - $log.error("InventoryDeploymentSerice.getDeployment failed: " - + $scope.ecdapp.errMsg); - //$scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.serviceTypeComplete = true; - } - // Deployment IDs are unique, so this will always return exactly one item! - // retrieve inputs of deployment. - else { - $scope.ecdapp.errMsg = null; - $scope.ecdapp.deployment = deployment.items[0]; - // Copy the input parameter names and default values - let inputsAndDefaults = {}; - for (var pkey in $scope.ecdapp.inputsDict) { - if (debug) - $log.debug('inventoryDeploymentUpdateCtrl: checking key ' + pkey); - let dval = $scope.ecdapp.deployment.inputs[pkey]; - //$scope.ecdapp.inputsDict[pkey].defaultValue; - if (dval === undefined || dval === null) { - dval = ''; - } - inputsAndDefaults[pkey] = dval; - } - $scope.ecdapp.editRequest.parmFileDict = inputsAndDefaults; - $scope.ecdapp.editRequest.type_id = $scope.ecdapp.typeId; - if (debug) - $log.debug('inventoryBlueprintDeployCtrl: inputsAndDefaults: ' + JSON.stringify(inputsAndDefaults)); - - $scope.ecdapp.serviceTypeComplete = true; - //$scope.$apply(); - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error('InventoryDeploymentService.getDeployment failed: ' + JSON.stringify(error)); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.isDataLoading = false; - }); - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $scope.ecdapp.isDataLoading = false; - $scope.ecdapp.serviceTypeComplete = false; - alert('Failed to get blueprint. Please retry with valid blueprint ID.'); - $log.error("inventoryDeploymentUpdateCtrl failed: " + error); - }); - }; - - /** - * Handler for file-read event reads file, parses JSON, validates content. - */ - var fileReader = new FileReader(); - fileReader.onload = function(event) { - let jsonString = fileReader.result; - if (debug) - $log.debug('fileReader.onload: read: ' + jsonString); - let ydict = {}; - try { - ydict = JSON.parse(jsonString); - } - catch (ex) { - alert('Failed to parse file as JSON:\n' + ex); - } - // Process the file - for (var ykey in ydict) { - let yval = ydict[ykey]; - if (debug) - $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); - // Allow only expected keys with scalar values - if (! (ykey in $scope.ecdapp.editRequest.parmFileDict)) - alert('Unexpected file content:\nKey not defined by blueprint:\n' + ykey); - if (yval.constructor === {}.constructor) - $scope.ecdapp.editRequest.parmFileDict[ykey] = angular.toJson(yval); - else - $scope.ecdapp.editRequest.parmFileDict[ykey] = yval; - } - if (debug) - $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.editRequest.parmFileDict)); - - // Update table in all cases - $scope.$apply(); - } - - // Handler for file-select event - $scope.handleFileSelect = function() { - if (debug) - $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); - fileReader.readAsText($scope.ecdapp.editRequest.fileModel); - }; - - $scope.ecdapp.validateRequest = function(editRequest) { - if (editRequest == null) - return 'No data found.\nPlease enter some values.'; - if (editRequest.deployment_id == null || editRequest.deployment_id.trim() == '') - return 'Deployment ID is required.\nPlease enter a value.'; - if (editRequest.type_id == null || editRequest.type_id.trim() == '') - return 'Type ID is required.\nPlease enter a value.'; - // Check that every file parameter is defined by blueprint - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) { - // Defined in blueprint? - if (! $scope.ecdapp.inputsDict[pkey]) - return 'Unexpected input parameter\n' + pkey; - } - return null; - } - - $scope.ecdapp.updateDeployment = function(editRequest) { - if (debug) - $log.debug('deployBlueprint: editRequest is ' + JSON.stringify($scope.ecdapp.editRequest)); - var validateMsg = $scope.ecdapp.validateRequest(editRequest); - if (validateMsg != null) { - alert('Invalid Request:\n' + validateMsg); - $scope.ecdapp.errMsg = validateMsg; - return; - } - // Create request with key:value parameters dictionary - let deploymentRequestObject = { - deploymentId : editRequest.deployment_id, - serviceTypeId : editRequest.type_id, - inputs : {}, - tenant : editRequest.tenant, - method : "update" - }; - for (var pkey in $scope.ecdapp.editRequest.parmFileDict) - try { - deploymentRequestObject.inputs[pkey] = angular.fromJson($scope.ecdapp.editRequest.parmFileDict[pkey]); - } catch (error) { - deploymentRequestObject.inputs[pkey] = $scope.ecdapp.editRequest.parmFileDict[pkey]; - } - if (debug) - $log.debug('deployBlueprint: deploymentRequestObject is ' + JSON.stringify(deployRequestObject)); - - $scope.ecdapp.deploymentInProgress = true; - InventoryDeploymentService.deployBlueprint(deploymentRequestObject) - .then(function(response) { - $scope.ecdapp.deploymentInProgress = false; - if (response.error) { - alert('Failed to deploy blueprint:\n' + response.error); - $scope.ecdapp.errMsg = response.error; - } else { - alert('Deployment update request sent successfully, query the execution status for final outcome'); - $modalInstance.close(response); - } - }, - function (error) { - $log.error('inventoryBlueprintDeployCtrl: error while deploying: ' + error); - alert('Server rejected deployment request:\n' + error); - $scope.ecdapp.deploymentInProgress = false; - } - ); - }; - -}); - - -/*************************************************************************/ - -appDS2.controller('deployBlueprintViewCtrl', function( - $scope, $log, message, InventoryBlueprintService) { - - 'use strict'; - - var debug = false; - - if (debug) - $log.debug("deployBlueprintViewCtrl.message: " + JSON.stringify(message)); - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'View Blueprint ' + message.blueprint.deploymentRef; - - var typeLink = message.blueprint.typeLink.href; - var n = typeLink.lastIndexOf("/"); - var typeId = typeLink.substring(n+1); - // Fetch the blueprint - $scope.ecdapp.isDataLoading = true; - InventoryBlueprintService.viewBlueprint(typeId).then(function(jsonObj) { - if (debug) - $log.debug("deployBlueprintViewCtrl.viewBlueprint response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed'; - } - else { - $scope.ecdapp.typeName = jsonObj.typeName; - $scope.ecdapp.blueprint = jsonObj.blueprintTemplate; - } - $scope.ecdapp.isDataLoading = false; - }, function(error) { - $scope.ecdapp.isDataLoading = false; - alert('Failed to get blueprint. Please retry.'); - $log.error("blueprintViewCtrl failed: " + error); - }); -}); - -/*************************************************************************/ -appDS2.controller('inventoryDeploymentRollbackCtrl', function( - $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Deployment Rollback'; - $scope.ecdapp.revisions = []; - $scope.ecdapp.deploymentRef = message.deployment.deploymentRef; - $scope.ecdapp.serviceId = message.deployment.serviceId; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.updatingDeployment = false; - var selTenant = message.deployment.statusInfo.tenant_name; - if ( typeof selTenant === "undefined" ) { - selTenant = "default_tenant"; - } - $scope.ecdapp.tenant = selTenant; - $scope.ecdapp.ui_tenant = selTenant; - $scope.ecdapp.local_revisions = []; - // This object holds data for this operation - $scope.ecdapp.rollbackRequest = { - "deployment_id": message.deployment.deploymentRef, - "workflow_name": "rollback", - "tenant": selTenant, - "revision": 1 - }; - - InventoryDeploymentService.getNodeInstanceVersions($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then(function(nodeRunTime) { - if (nodeRunTime == null) { - $scope.ecdapp.errMsg = "Failed to retrieve Node instance runtime information"; - $log.error("InventoryDeploymentSerice.getNodeInstanceVersions failed: " - + $scope.ecdapp.errMsg); - $scope.ecdapp.isRequestFailed = true; - } else { - $scope.ecdapp.errMsg = null; - $scope.ecdapp.revisions = nodeRunTime.items[0].runtime_properties['helm-history']; - if (Array.isArray($scope.ecdapp.revisions) ) { - var dLen = $scope.ecdapp.revisions.length; - - for (var i = 1; i < dLen; i++) { - var str = $scope.ecdapp.revisions[i].replace(/\s+/g, ' '); - var itemStrArr = str.split(" "); - var itemLen = itemStrArr.length; - var revObj = {}; - revObj.revision = itemStrArr[0].trim(); - revObj.updated = itemStrArr.slice(1,5).toString().replace(/,/g, ' '); - revObj.status = itemStrArr[6].trim(); - revObj.chart = itemStrArr[7].trim(); - revObj.description = itemStrArr.slice(8,itemLen).toString().replace(/,/g, ' '); - revObj.name = itemStrArr[0].trim(); - revObj.checked = false; - $scope.ecdapp.local_revisions.push(revObj); - } - } - console.log($scope.ecdapp.local_revisions); - $scope.ecdapp.isRequestFailed = false; - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error('InventoryDeploymentService.getNodeInstanceVersions failed: ' + JSON.stringify(error)); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.isDataLoading = false; - }); - $scope.ecdapp.updateSelection = function(position) { - $scope.ecdapp.rollbackRequest.revision = position; - angular.forEach($scope.ecdapp.local_revisions, function(item, index) { - if (position != index+1) - item.checked = false; - }); - } - /** - * rollback deployment based on parameters user enters/adjusts in modal popup - * First retrieves the node-id using the blueprintId - * Using the node-id and deploymentId, retrieves the node-instance-id - * Calls the update resource API, passing object with deploymentId, and changed parameters - */ - $scope.ecdapp.rollbackWorkflow = function(revision) { - $scope.ecdapp.updatingDeployment = true; - $scope.ecdapp.isDataLoading = true; - InventoryDeploymentService.rollbackFlow($scope.ecdapp.rollbackRequest).then(function(jsonObj) { - if (debug) - $log.debug("inventoryDeploymentRollbackCtrl.rollbackWorkflow response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; - $scope.ecdapp.updatingDeployment = false; - $scope.ecdapp.isDataLoading = false; - } else { - console.log('%c ROLLBACK RESOURCES COMPLETED', 'color: magenta; font-weight: bold;'); - alert('Rollback request for ' + $scope.ecdapp.deploymentRef + ' successfully went through to Cloudiy. Rollback is now pending'); - $scope.ecdapp.updatingDeployment = false; - $scope.ecdapp.isDataLoading = false; - } - }, function(error) { - $scope.ecdapp.updatingDeployment = false; - $log.error('inventoryDeploymentRollbackCtrl failed: ' + error); - alert('Failed to rollback Deployment ' + $scope.ecdapp.deploymentRef + '. Please retry.'); - $scope.ecdapp.isDataLoading = false; - }); - } -}); - -/*************************************************************************/ -appDS2.controller('inventoryDeploymentUpgradeCtrl', function( - $scope, $rootScope, $log, $modalInstance, message, InventoryDeploymentService) { - - 'use strict'; - - // Controls logging in this controller - var debug = false; - - // this object holds all app data and functions - $scope.ecdapp = {}; - $scope.ecdapp.label = 'Deployment Upgrade'; - $scope.ecdapp.deployment = null; - $scope.ecdapp.deploymentRef = message.deployment.deploymentRef; //THIS IS THE BLUEPRINT ID - $scope.ecdapp.serviceId = message.deployment.serviceId; - $scope.ecdapp.errMsg = null; - $scope.ecdapp.isDataLoading = true; - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.updatingDeployment = false; - var selTenant = message.deployment.statusInfo.tenant_name; - if ( typeof selTenant === "undefined" ) { - selTenant = "default_tenant"; - } - $scope.ecdapp.tenant = selTenant; - $scope.ecdapp.ui_tenant = selTenant; - $scope.ecdapp.parmFileDict = {}; - - // This object holds data for editing the input parameters - $scope.ecdapp.editRequest = { - deployment_id: '', - type_id: '', - fileModel: null, - resourceConstants: {}, - resourceDefinitionChanges: {} - }; - //First get the blueprintId associated with the deployment, along with the inputs of the deployment - InventoryDeploymentService.getDeployment(message.deployment.deploymentRef, $scope.ecdapp.tenant).then(function(deployment) { - if (deployment.items.length == 0) { - $scope.ecdapp.errMsg = "404 - Deployment " + message.deployment.deploymentRef + " Not Found!"; - $log.error("InventoryDeploymentSerice.getDeployment failed: " - + $scope.ecdapp.errMsg); - $scope.ecdapp.isRequestFailed = true; - } - // Deployment IDs are unique, so this will always return exactly one item! - else { - $scope.ecdapp.errMsg = null; - $scope.ecdapp.deployment = deployment.items[0]; - $scope.ecdapp.isRequestFailed = false; - $scope.ecdapp.editRequest.type_id = deployment.items[0].blueprint_id; - $scope.ecdapp.parmFileDict = deployment.items[0].inputs; - Object.keys($scope.ecdapp.parmFileDict).map(function(key, index) { - if (key == 'config-format' || key == 'config-url' || key == 'chart-version' || key == 'chart-repo-url') { - $scope.ecdapp.editRequest.resourceDefinitionChanges[key] = $scope.ecdapp.parmFileDict[key]; - } else { - $scope.ecdapp.editRequest.resourceConstants[key] = $scope.ecdapp.parmFileDict[key]; - } - }); - } - $scope.ecdapp.isDataLoading = false; - }, - function(error) { - $log.error('InventoryDeploymentService.getDeployment failed: ' + JSON.stringify(error)); - $scope.ecdapp.isRequestFailed = true; - $scope.ecdapp.errMsg = error; - $scope.ecdapp.isDataLoading = false; - }); - - /** - * Validates content of user-editable fields. - * Returns null if all is well, - * a descriptive error message otherwise. - */ - $scope.ecdapp.validateRequest = function(editRequest) { - if (editRequest == null) - return 'No data found.\nPlease enter some values.'; - if (editRequest["chart-version"] == null || editRequest["chart-version"].trim() == '') - return 'Chart version is required.\nPlease enter a value.'; - if (!editRequest["config-format"] || editRequest["config-format"].trim() == '') { - return 'config format is required.\nPlease enter a value.'; - } - if (!editRequest["config-url"] || editRequest["config-url"].trim() == '') { - return 'Config URL is required.\nPlease enter a value.'; - } - return null; - }; - - /** - * Helm upgrade for deployment based on parameters user enters in modal popup - * First retrieves the node-id using the blueprintId - * Using the node-id and deploymentId, retrieves the node-instance-id - * Calls the start execution API, passing object with deploymentId, and changed parameters - */ - - $scope.ecdapp.upgradeWorkflow = function(resourceDefinitionChanges) { - $scope.ecdapp.updatingDeployment = true; - let nodeId = ''; - - // validate request - var validateMsg = $scope.ecdapp.validateRequest(resourceDefinitionChanges); - if (validateMsg != null) { - alert('Invalid Request:\n' + validateMsg); - $scope.ecdapp.updatingDeployment = false; - return; - } - //get node id from blueprint - InventoryDeploymentService.getBlueprint($scope.ecdapp.deploymentRef, $scope.ecdapp.tenant).then(function(blueprint) { - if (debug) - $log.debug("inventoryDeploymentUpgradeCtrl.getBlueprint response: " + JSON.stringify(blueprint)); - if (blueprint.error) { - $scope.ecdapp.errMsg = 'Request Failed: ' + blueprint.error; - $scope.ecdapp.updatingDeployment = false; - } - else { - //console.log('returned blueprint:' + blueprint); - let count = 0; - //console.log("number of node objects in array: " + blueprint.items[0].plan.nodes.length); - //console.log(JSON.stringify(blueprint)); - blueprint.items[0].plan.nodes.map(function(node) { - if (node.type == 'onap.nodes.component') { - //want to get FIRST node with type 'cloudify.kubernetes.resources.Deployment' so only set nodeID for first matching type - if (count < 1) { - nodeId = node.id; - } - count = count + 1; - } - }); - //if no node has type 'cloudify.kubernetes.resources.Deployment', return message saying no deployment exists and exit (ie nodeId still is '') - if (nodeId == '') { - alert('Failed to retrieve Node Id. No matching deployment found (no deployment exists)'); - $scope.ecdapp.updatingDeployment = false; - return; - } - //found node id. now need to retrieve node-instance-id - console.log('%c RETRIEVED NODE ID: ' + nodeId, 'color: orange; font-weight: bold;'); - let nodeInstanceId = ''; - InventoryDeploymentService.getNodeInstanceId($scope.ecdapp.deploymentRef, nodeId, $scope.ecdapp.tenant).then(function(jsonObj) { - if (debug) - $log.debug("inventoryDeploymentUpgradeCtrl.getNodeInstanceId response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; - $scope.ecdapp.updatingDeployment = false; - } - else { - //if nodeInstanceId is still '' then it wasn't found, stop flow) - if (jsonObj.items[0].id == '') { - alert('Failed to retrieve Node Instance Id for Node Id' + nodeId); - $scope.ecdapp.updatingDeployment = false; - return; - } - //found node-instance-id. now need to update resources - nodeInstanceId = jsonObj.items[0].id; - console.log('%c RETRIEVED NODE INSTANCE ID:' + nodeInstanceId, 'color: green; font-weight: bold;'); - //console.log(resourceDefinitionChanges); - InventoryDeploymentService.upgradeFlow($scope.ecdapp.deploymentRef, nodeInstanceId, resourceDefinitionChanges, $scope.ecdapp.tenant).then(function(jsonObj) { - if (debug) - $log.debug("inventoryDeploymentUpgradeCtrl.updateResources response: " + JSON.stringify(jsonObj)); - if (jsonObj.error) { - $scope.ecdapp.errMsg = 'Request Failed: ' + jsonObj.error; - $scope.ecdapp.updatingDeployment = false; - } - else { - console.log('%c UPDATE RESOURCES COMPLETED', 'color: magenta; font-weight: bold;'); - //console.log(jsonObj); - $scope.ecdapp.updatingDeployment = false; - alert('Helm Upgrade request for ' + $scope.ecdapp.deploymentRef + ' successfully went through to Cloudiy. Upgrade is now pending'); $modalInstance.dismiss('cancel'); - } - }, function(error) { - $scope.ecdapp.updatingDeployment = false; - alert('Failed to perform upgrade for Deployment Id ' + $scope.ecdapp.deploymentRef + ' and Node Instance Id ' + nodeInstanceId + '. Please retry.'); - $log.error('inventoryDeploymentUpgradeCtrl failed: ' + error); - }); - } - }, function(error) { - $scope.ecdapp.updatingDeployment = false; - alert('Failed to get Node Instance Id for deploymentId ' + $scope.ecdapp.deploymentRef + ' and Node Id ' + nodeId + '. Please retry.'); - $log.error('inventoryDeploymentUpgradeCtrl failed: ' + error); - }); - - } - }, function(error) { - $scope.ecdapp.updatingDeployment = false; - alert('Failed to get blueprint for blueprintId ' + $scope.ecdapp.deploymentRef + '. Please retry.'); - $log.error('inventoryDeploymentUpgradeCtrl failed: ' + error); - }); - }; - - /** - * Handler for file-read event reads file, parses JSON, validates content. - */ - - var fileReader = new FileReader(); - fileReader.onload = function(event) { - let jsonString = fileReader.result; - if (debug) - $log.debug('fileReader.onload: read: ' + jsonString); - let ydict = {}; - try { - ydict = JSON.parse(jsonString); - } - catch (ex) { - alert('Failed to parse file as JSON:\n' + ex); - } - // Process the file - for (var ykey in ydict) { - let yval = ydict[ykey]; - if (debug) - $log.debug('fileReader.onload: typeof ' + ykey + ' is ' + typeof ykey); - // Allow only expected keys with scalar values - if (! (ykey in $scope.ecdapp.parmFileDict)) - alert('Unexpected file content:\nKey not defined by blueprint:\n' + ykey); - if (yval.constructor === {}.constructor) - $scope.ecdapp.parmFileDict[ykey] = angular.toJson(yval); - else - $scope.ecdapp.parmFileDict[ykey] = yval; - } - if (debug) - $log.debug('fileReader.onload: parmFileDict: ' + JSON.stringify($scope.ecdapp.parmFileDict)); - - // Update table in all cases - //$scope.ecdapp.setResourceDefinitionChanges($scope.ecdapp.editRequest.resourceDefinitionChanges, $scope.ecdapp.editRequest.parmFileDict); - Object.keys($scope.ecdapp.parmFileDict).map(function(key, index) { - if (key == 'config-format' || key == 'config-url' || key == 'chart-version') { - $scope.ecdapp.editRequest.resourceDefinitionChanges[key] = $scope.ecdapp.parmFileDict[key]; - } else { - $scope.ecdapp.editRequest.resourceConstants[key] = $scope.ecdapp.parmFileDict[key]; - } - }); - //$scope.$apply(); - }; - - // Handler for file-select event - $scope.handleFileSelect = function() { - if (debug) - $log.debug('handleFileSelect: $scope.ecdapp.fileModel.name is ' + $scope.ecdapp.editRequest.fileModel.name); - fileReader.readAsText($scope.ecdapp.editRequest.fileModel); - }; - -}); \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-service.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-service.js index 3fa2b2c..7b7a177 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-service.js +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/deployment-service.js @@ -4,7 +4,7 @@ appDS2.factory('InventoryDeploymentService', function ($http, $q, $log) { * Gets one page of objects. * @param {Number} pageNum - page number; e.g., 1 * @param {Number} viewPerPage - number of items per page; e.g., 25 - * @return {JSON} Response object from remote side + * @return {JSON} Response object from remote side. */ getDeployments: function(pageNum,viewPerPage,sortBy,searchBy) { // cache control for IE @@ -17,7 +17,7 @@ appDS2.factory('InventoryDeploymentService', function ($http, $q, $log) { } else if (searchBy) { url = 'inventory/dcae-services?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&searchBy=' + searchBy + cc; } else { - url = url = 'inventory/dcae-services?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + cc; + url = 'inventory/dcae-services?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + cc; } return $http({ method: 'GET', @@ -35,6 +35,94 @@ appDS2.factory('InventoryDeploymentService', function ($http, $q, $log) { return $q.reject(error.statusText); }); }, + getDeploymentsAafFilter: function(pageNum,viewPerPage,aafUsername) { + // cache control for IE + let cc = "&cc=" + new Date().getTime().toString(); + let url = null; + + url = 'filtered-deployments?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&inputKey=aaf_username' + '&inputValue=' + aafUsername + cc; + + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryDeploymentService.getDeploymentsAafFilter: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeploymentsAafFilter failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getDeploymentsDcaeTargetTypeFilter: function(pageNum,viewPerPage,dcaeTargetType) { + // cache control for IE + let cc = "&cc=" + new Date().getTime().toString(); + let url = null; + + url = 'filtered-deployments?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&inputKey=dcae_target_type' + '&inputValue=' + dcaeTargetType + cc; + + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryDeploymentService.getDeploymentsDcaeTargetTypeFilter: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeploymentsDcaeTargetTypeFilter failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getDeploymentCount: function(searchBy) { + let url = 'service-list-count'; + if (searchBy) { + url = url + '?searchBy=' + searchBy; + } + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryDeploymentService.getDeploymentList: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeploymentList failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getDeploymentList: function(searchBy) { + let url = 'service-list'; + if (searchBy) { + url = url + '?searchBy=' + searchBy; + } + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryDeploymentService.getDeploymentList: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryDeploymentService.getDeploymentList failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, getDeploymentStatus: function(srvcIds) { let url = 'deployment-status'; return $http({ @@ -128,6 +216,26 @@ appDS2.factory('InventoryDeploymentService', function ($http, $q, $log) { return $q.reject(error.statusText); }); }, + deleteBlueprint: function(blueprintId, tenant) { + let url = 'blueprints/' + blueprintId + '?tenant=' + tenant; + return $http({ + method: 'DELETE', + url: url, + responseType: 'json' + }).then(function(response) { + if (response.data == null) + return $q.reject('InventoryDeploymentService.deleteBlueprint: response.data null or not object'); + else { + console.log('%c DELETE BLUEPRINT FOR ID ' + blueprintId, 'color: blue; font-weight: bold;'); + console.log(response.data); + return response.data; + } + }, + function(error) { + $log.error('InventoryDeploymentService.deleteBlueprint failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, getBlueprint: function(blueprintId, tenant) { let url = 'blueprints/' + blueprintId + '?tenant=' + tenant; //console.log("url: " + url); @@ -191,6 +299,46 @@ appDS2.factory('InventoryDeploymentService', function ($http, $q, $log) { return $q.reject(error.statusText); }); }, + getNodeInstances: function(deploymentId, tenant) { + console.log("entered getNodeInstances service function"); + let url = 'node-instances/' + deploymentId + '?tenant=' + tenant; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null) + return $q.reject('InventoryDeploymentService.getNodeInstances: response.data null or not object'); + else { + return response.data; + } + }, + function(error) { + $log.error('InventoryDeploymentService.getNodeInstances failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getNodeInstanceData: function(deploymentId, tenant) { + console.log("entered getNodeInstanceData service function"); + let url = 'node-instances-data?deployment=' + deploymentId + '&tenant=' + tenant; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null) + return $q.reject('InventoryDeploymentService.getNodeInstanceData: response.data null or not object'); + else { + return response.data; + } + }, + function(error) { + $log.error('InventoryDeploymentService.getNodeInstances failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, updateResources: function(deploymentId, nodeInstanceId, resource_definition_changes) { let body = { "deployment_id": deploymentId, @@ -291,6 +439,7 @@ appDS2.factory('InventoryDeploymentService', function ($http, $q, $log) { let configFormat = resource_definition_changes["config-format"]; let chartUrl = resource_definition_changes["chart-repo-url"]; let chartVersion = resource_definition_changes["chart-version"]; + let configSet = resource_definition_changes["config-set"]; let body = { "deployment_id": deploymentId, "workflow_id": "upgrade", @@ -298,11 +447,12 @@ appDS2.factory('InventoryDeploymentService', function ($http, $q, $log) { "force": true, "tenant": tenant, "parameters": { + "config_set": configSet, "node_instance_id": nodeInstanceId, + "chart_version": chartVersion, + "chart_repo_url": chartUrl, "config_url": configUrl, - "config_format": configFormat, - "chartRepo": chartUrl, - "chartVersion": chartVersion + "config_format": configFormat } }; let urlStr = 'executions'; diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/execution-service.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/execution-service.js index a4181f4..a756a2b 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/execution-service.js +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/execution-service.js @@ -6,6 +6,64 @@ appDS2.factory('InventoryExecutionService', function ($http, $q, $log) { * @param {Number} viewPerPage - number of items per page; e.g., 25 * @return {JSON} Response object from remote side */ + getActiveExecutions: function(pageNum, viewPerPage) { + let cc = "&cc=" + new Date().getTime().toString(); + let url = 'executions/active?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + cc; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryExecutionService.getActiveExecutions: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryExecutionService.getActiveExecutions failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getExecutionsById: function(id, tenant, pageNum, viewPerPage) { + let cc = "&cc=" + new Date().getTime().toString(); + let url = 'executions/'+ id + '?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&tenant=' + tenant + '&status=' + status + cc; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryExecutionService.getExecutionsById: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryExecutionService.getExecutionsById failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + getExecutionsByTenant: function(tenant, status, pageNum, viewPerPage) { + // cache control for IE + let cc = "&cc=" + new Date().getTime().toString(); + let url = 'executions/tenant?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&tenant=' + tenant + '&status=' + status + cc; + return $http({ + method: 'GET', + url: url, + cache: false, + responseType: 'json' + }).then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('InventoryExecutionService.getExecutionsByTenant: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('InventoryExecutionService.getExecutionsByTenant failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, getExecutionsByDeployment: function(deploymentId, tenant, pageNum, viewPerPage) { // cache control for IE let cc = "&cc=" + new Date().getTime().toString(); diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_blueprint_popups.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_blueprint_popups.html index eed1dfe..d17c065 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_blueprint_popups.html +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_blueprint_popups.html @@ -1,5 +1,5 @@ - - - - - - - - - - - - + \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_deployment_table.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_deployment_table.html deleted file mode 100644 index 66ab9b5..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_deployment_table.html +++ /dev/null @@ -1,148 +0,0 @@ -
    - -

    Deployments

    - - -
    -
    - - Please wait while the content loads. -
    -
    - -
    -
    -
    -
    - - - -
    -
    -
    - -
    - {{ecdapp.errMsg}} -
    - -
    -
    - - - - - - - - - - - - - - - - - - -
    Service ID/Deployment Ref.CreatedModifiedTenant - -
    -
    - - Tenant and Status Info loading -
    -
    -
    Install StatusActions
    - - - - - - - -
    - - -
    -
    -
    - -
    -
    - -
    -
    - -
    - -
    - -
    - -
diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_execution_popups.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_execution_popups.html index 4b870dc..6277207 100644 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_execution_popups.html +++ b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/inventory_execution_popups.html @@ -1,255 +1,271 @@ \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/dbcl_view.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/dbcl_view.html deleted file mode 100644 index da9fb74..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/dbcl_view.html +++ /dev/null @@ -1,6 +0,0 @@ -
-

DMaap Bus Controller

- -
\ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs-view-controller.js b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs-view-controller.js deleted file mode 100644 index f37a4f0..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs-view-controller.js +++ /dev/null @@ -1,271 +0,0 @@ -appDS2.controller('tabsController', function ($rootScope, $scope, $interval, b2bDOMHelper, $timeout, $route) { - 'use strict'; - $scope.ecdapp = {}; - $scope.ecdapp.opsItem = $route.current.$$route.item; - $scope.ecdapp.activeTabsId = $scope.ecdapp.opsItem ; - $scope.ecdapp.activeTabUrl = ''; - $scope.ecdapp.isInit = false; - $scope.ecdapp.cfy = {}; - $scope.ecdapp.cfy.url = ''; //$rootScope.opsMenu[0].url; - $scope.ecdapp.cfy.site = ''; - $scope.ecdapp.cnsl = {}; - $scope.ecdapp.cnsl.url = ''; //$rootScope.opsMenu[2].url; - $scope.ecdapp.k8 = {}; - $scope.ecdapp.k8.site = ''; - $scope.ecdapp.k8.url = ''; //$rootScope.opsMenu[3].url; - $scope.ecdapp.k8.tenant = ''; - $scope.ecdapp.prom = {}; - $scope.ecdapp.prom.tenant = ''; - $scope.ecdapp.prom.site = ''; - $scope.ecdapp.prom.url = ''; //$rootScope.opsMenu[4].url; - $scope.ecdapp.grf = {}; - $scope.ecdapp.grf.site = ''; - $scope.ecdapp.grf.tenant = ''; - $scope.ecdapp.grf.url = ''; //$rootScope.opsMenu[1].url; - $scope.ecdapp.isFrameLoaded = true; - $scope.ecdapp.cfySite = ''; - $scope.ecdapp.cnslSite = ''; - $scope.ecdapp.appCluster = ''; - $scope.ecdapp.k8.cluster = ''; - $scope.ecdapp.grf.cluster = ''; - $scope.ecdapp.prom.cluster = ''; - - var key = $scope.ecdapp.opsItem; - - // if it's not already part of our keys array - if($rootScope.menuKeys.indexOf(key) === -1) { - // add it to our keys array - $rootScope.menuKeys.push(key); - for (var itemTab = 0; itemTab < $rootScope.opsMenu.length; itemTab++) { - if ($rootScope.opsMenu[itemTab].id === key) { - $rootScope.gTabs.push($rootScope.opsMenu[itemTab]); - //$scope.ecdapp.activeTabUrl = $rootScope.opsMenu[itemTab].url; - break; - } - } - } - $scope.ecdapp.gTabs = $rootScope.gTabs; - /* - angular.forEach($rootScope.opsMenu, function(item) { - if - // we check to see whether our object exists - var key = $scope.ecdapp.opsItem; - // if it's not already part of our keys array - if($rootScope.menuKeys.indexOf(key) === -1) { - // add it to our keys array - $rootScope.menuKeys.push(key); - // push this item to our final output array - $rootScope.gTabs.push(item); - $scope.ecdapp.activeTabUrl = item.url; - } else { - if (item.id === key) { - $scope.ecdapp.activeTabUrl = item.url; - } - } - }); - - - for (var menuTab = 0; menuTab < $scope.ecdapp.gTabs.length; menuTab++) { - if ($scope.ecdapp.gTabs[menuTab].id === key) { - $scope.ecdapp.activeTabUrl = $scope.ecdapp.gTabs[menuTab].url; - break; - } - } - */ - $scope.ecdapp.isInit = true; - $rootScope.activeTabsId = $scope.ecdapp.opsItem; - - $rootScope.$watch('activeTabsId', function (newVal, oldVal) { - if(newVal !== oldVal) { - var selectedTab; - for (selectedTab = 0; selectedTab < $rootScope.opsMenu.length; selectedTab++) { - if ($rootScope.opsMenu[selectedTab].id === newVal) { - //$scope.ecdapp.activeTabUrl = $rootScope.opsMenu[selectedTab].url; - break; - } - } - var selectedTabPanelElement = document.getElementById($rootScope.opsMenu[selectedTab].tabPanelId); - - var elem = null; - if (selectedTabPanelElement) { - elem = b2bDOMHelper.firstTabableElement(selectedTabPanelElement); - } - - if (elem) { - $timeout(function () { - elem.focus(); - }, 100); - } - } - }); - - - $scope.ecdapp.selectAppTenant = function(site) { - if(site != "Select Site") { - for (var indx = 0; indx < $rootScope.site_tenant_map.length; indx++) { - if ($rootScope.site_tenant_map[indx].site === site) { - $scope.ecdapp.appTenants = $rootScope.site_tenant_map[indx].tenant; - break; - } - } - } - } - - $scope.ecdapp.selectCluster = function(tenant) { - if(tenant != "Select Tenant") { - for (var indx = 0; indx < $rootScope.tenant_cluster_map.length; indx++) { - if ($rootScope.tenant_cluster_map[indx].tenant === tenant) { - $scope.ecdapp.appCluster = $rootScope.tenant_cluster_map[indx].cluster; - } - } - } - } - - var stopPolling; - //var doIframePolling; - $scope.ecdapp.appFrameReload = function(cluster, app) { - if(cluster != "Select K8s cluster") { - $scope.ecdapp.isFrameLoaded = false; - for (var indx = 0; indx < $rootScope.tenant_cluster_apps_map.length; indx++) { - if ($rootScope.tenant_cluster_apps_map[indx].cluster === cluster) { - if (app === 'prom') { - $scope.ecdapp.prom.url = $rootScope.tenant_cluster_apps_map[indx].prom; - } else if (app === 'grf') { - $scope.ecdapp.grf.url = $rootScope.tenant_cluster_apps_map[indx].grf; - } else { - $scope.ecdapp.k8.url = $rootScope.tenant_cluster_apps_map[indx].k8; - } - break; - } - } - stopPolling = $timeout(function () { - $timeout.cancel(stopPolling); - stopPolling = undefined; - $scope.ecdapp.isFrameLoaded = true; - },30000); - } - } - - $scope.ecdapp.cfyCnslFrameReload = function(site, app) { - if(site != "Select Site") { - $scope.ecdapp.isFrameLoaded = false; - for (var indx = 0; indx < $rootScope.site_cfy_cnsl_map.length; indx++) { - if ($rootScope.site_cfy_cnsl_map[indx].site === site) { - if (app === 'cfy') { - $scope.ecdapp.cfy.url = $rootScope.site_cfy_cnsl_map[indx].cfy; - } else { - $scope.ecdapp.cnsl.url = $rootScope.site_cfy_cnsl_map[indx].cnsl; - } - break; - } - } - stopPolling = $timeout(function () { - $timeout.cancel(stopPolling); - stopPolling = undefined; - $scope.ecdapp.isFrameLoaded = true; - },30000); - } - } - document.querySelector("iframe").addEventListener("load", function() { - $scope.ecdapp.isFrameLoaded = true; - $scope.$apply(); - }); - $scope.$on("$destroy",function() { - $timeout.cancel(stopPolling); - //$interval.cancel(doIframePolling); - }); - - /* - * $scope.ecdapp.selectK8Tenant = function(site) { - if(site != "Select Site") { - for (var indx = 0; indx < $rootScope.site_tenant_map.length; indx++) { - if ($rootScope.site_tenant_map[indx].site === site) { - $scope.ecdapp.k8Tenants = $rootScope.site_tenant_map[indx].tenant; - break; - } - } - } - } - - $scope.ecdapp.selectK8App = function(t) { - if(t != "Select Tenant for K8s components") { - for (var indx = 0; indx < $rootScope.tenant_cluster_map.length; indx++) { - if ($rootScope.tenant_cluster_map[indx].tenant === t) { - $scope.ecdapp.k8.url = $rootScope.tenant_cluster_map[indx].k8s; - break; - } - } - } - } - - $scope.ecdapp.selectGrfTenant = function(site) { - if(site != "Select Site") { - for (var indx = 0; indx < $rootScope.site_tenant_map.length; indx++) { - if ($rootScope.site_tenant_map[indx].site === site) { - $scope.ecdapp.grfTenants = $rootScope.site_tenant_map[indx].tenant; - break; - } - } - } - } - - $scope.ecdapp.selectGrfApp = function(t) { - if(t != "Select Tenant for Grafana") { - for (var indx = 0; indx < $rootScope.tenant_cluster_map.length; indx++) { - if ($rootScope.tenant_cluster_map[indx].tenant === t) { - $scope.ecdapp.grf.url = $rootScope.tenant_cluster_map[indx].grf; - break; - } - } - } - } - - $scope.ecdapp.selectPromTenant = function(site) { - if(site != "Select Site") { - for (var indx = 0; indx < $rootScope.site_tenant_map.length; indx++) { - if ($rootScope.site_tenant_map[indx].site === site) { - $scope.ecdapp.promTenants = $rootScope.site_tenant_map[indx].tenant; - break; - } - } - } - } - - $scope.ecdapp.selectPromApp = function(t) { - if(t != "Select Tenant for Prometheus") { - for (var indx = 0; indx < $rootScope.tenant_cluster_map.length; indx++) { - if ($rootScope.tenant_cluster_map[indx].tenant === t) { - $scope.ecdapp.prom.url = $rootScope.tenant_cluster_map[indx].prom; - break; - } - } - } - } - - doIframePolling = $interval(function () { - if(document.querySelector("iframe") && - document.querySelector("iframe").contentDocument.head && - document.querySelector("iframe").contentDocument.head.innerHTML != '') - { - $interval.cancel(doIframePolling); - doIframePolling = undefined; - $timeout.cancel(stopPolling); - stopPolling = undefined; - $scope.ecdapp.isCfyLoadDone = true; - } - },400); - - stopPolling = $timeout(function () { - //$interval.cancel(doIframePolling); - //doIframePolling = undefined; - $timeout.cancel(stopPolling); - stopPolling = undefined; - $scope.ecdapp.isCfyLoadDone = true; - },30000); - } - } - - */ - - -}); \ No newline at end of file diff --git a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs_view.html b/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs_view.html deleted file mode 100644 index aa5b1f8..0000000 --- a/ccsdk-app-overlay/src/main/webapp/app/ccsdk/ops/tabs_view.html +++ /dev/null @@ -1,131 +0,0 @@ -
-
- - - {{tab.title}} - - -
- -
-
-
-
- - -
-
-
- - Please wait while the content loads. -
- -
-
-
-
- - -
-
- - -
-
- - -
-
-
- - Please wait while the content loads. -
- -
-
-
-
- - -
-
-
- - Please wait while the content loads. -
- -
-
-
-
- - -
-
- - -
-
- - -
-
-
- - Please wait while the content loads. -
- -
-
-
-
- - -
-
- - -
-
- - -
-
-
- - Please wait while the content loads. -
- -
-
- -
\ No newline at end of file -- cgit 1.2.3-korg