diff options
author | 2017-08-18 10:09:01 -0400 | |
---|---|---|
committer | 2017-08-18 10:10:04 -0400 | |
commit | e8c966373f25bc769fae4512bccc44903bf7309b (patch) | |
tree | 577435a3d5668ca6608009a9af5e8b4dd9175abd /oom-app-overlay/src/main/webapp/app/oom/consul/service-controllers.js | |
parent | a6214cfb46570297c71fea29ee68014892a2484b (diff) |
Rename to OOM (no more ecd)
- Change to OOM Dashboard (no more ECOMP Controller)
- Rework some exception handling
Issue: CCSDK-61
Change-Id: Id5379e8b272b651373c79f46b20da1d32de013ed
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'oom-app-overlay/src/main/webapp/app/oom/consul/service-controllers.js')
-rw-r--r-- | oom-app-overlay/src/main/webapp/app/oom/consul/service-controllers.js | 366 |
1 files changed, 366 insertions, 0 deletions
diff --git a/oom-app-overlay/src/main/webapp/app/oom/consul/service-controllers.js b/oom-app-overlay/src/main/webapp/app/oom/consul/service-controllers.js new file mode 100644 index 0000000..339c436 --- /dev/null +++ b/oom-app-overlay/src/main/webapp/app/oom/consul/service-controllers.js @@ -0,0 +1,366 @@ +/******************************************************************************* + * =============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('serviceHealthTableController', function($scope, $log, $modal, modalService, ServiceHealthService) { + + 'use strict'; + + // 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 = 100; + // 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; + ServiceHealthService.getServicesHealth($scope.ecdapp.currentPageNum, + $scope.ecdapp.viewPerPage).then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("serviceHealthTableController.loadTable failed: " + + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + // $log.debug("serviceHealthController.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("serviceHealthTableController.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 to register a service. + */ + $scope.ecdapp.registerServiceModalPopup = function() { + var modalInstance = $modal.open({ + templateUrl : 'service_register_popup.html', + controller : 'serviceRegisterCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-medium', + resolve : { + message : function() { + return { /* no data */ } ; + } + } + }); + modalInstance.result.then(function(response) { + // $log.debug('addFeedModalPopup: 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 with service health history. + */ + $scope.ecdapp.viewHealthHistoryModalPopup = function(service) { + var modalInstance = $modal.open({ + templateUrl : 'service_history_popup.html', + controller : 'serviceHistoryCtlr', + windowClass: 'modal-docked', + sizeClass: 'modal-large', + resolve : { + message : function() { + return service; + } + } + }); + modalInstance.result.then(function(response) { + // $log.debug('addFeedModalPopup: 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 confirm deregistration. + * On successful completion, updates the table. + */ + $scope.ecdapp.deregisterServiceModalPopup = function(service) { + modalService.popupConfirmWin("Confirm", "Deregister service '" + + service.serviceName + "'?", function() { + ServiceHealthService.deregisterService(service.serviceName).then( + function(response) { + if (response && response.error) { + // $log.error('deleteBlueprint failed: ' + response.error); + alert('Failed to deregister service:\n' + response.error); + } + else { + // No response body on success. + $scope.ecdapp.loadTable(); + } + }, + function(error) { + $log.error('ServiceHealthService.deregisterService failed: ' + error); + alert('Failed to deregister service:\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('serviceRegisterCtrl', function($scope, $log, message, ServiceHealthService) { + + 'use strict'; + + // this object holds all app data and functions + $scope.ecdapp = {}; + + $scope.ecdapp.label = 'Register Service'; + // Model the data simply here. + // Build the complex request later. + $scope.ecdapp.registerRequest = + { + service_id : '', + service_name : '', + service_address : '', + service_port : '', + check_endpoint: '', + check_interval: '', + check_description: '', + check_name: '' + }; + + /** + * 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(request) { + if (request == null) + return "No data found.\nPlease enter some values."; + if (request.service_id == null || request.service_id.trim() == '') + return "Service ID is required.\nPlease enter a value."; + if (request.service_name == null || request.service_name.trim() == '') + return "Service name is required.\nPlease enter a value."; + if (request.service_address == null || request.service_address.trim() == '') + return "Service address is required.\nPlease enter a value."; + if (request.service_port == null || request.service_port.trim() == '') + return "Service port is required.\nPlease enter a value."; + if (request.check_endpoint == null || request.check_endpoint.trim() == '') + return "Check endpoint URL is required.\nPlease enter a value."; + if (request.check_interval == null || request.check_interval.trim() == '') + return "Check interval is required.\nPlease enter a value."; + // description and name are optional (I think) + return null; + } + + $scope.ecdapp.registerService = function(edit_req) { + var validateMsg = $scope.ecdapp.validateRequest(edit_req); + if (validateMsg != null) { + alert('Invalid registration request:\n' + validateMsg); + return; + } + // Build the complex request + let request = { + services : [ + { + id : edit_req.service_id, + name : edit_req.service_name, + address : edit_req.service_address, + port : edit_req.service_port, + tags: [ ], + checks : [ + { + endpoint : edit_req.check_endoint, + interval : edit_req.check_interval, + description : edit_req.description, + name : edit_req.check_name + } + ] + } + ] + }; + + ServiceHealthService.registerService(request) + .then(function(response) { + if (response.error) + alert('Failed to register service:\n' + response.error); + }, + function (error) { + $log.error('serviceRegisterCtrl: error while registering: ' + error); + alert('Server rejected registration request:\n' + error); + } + ); + + }; + +}); + + +appDS2.controller('serviceHistoryCtlr', function($scope, $log, $modal, message, ServiceHealthService) { + + 'use strict'; + + // Controls logging in this controller + var debug = false; + if (debug) + $log.debug('serviceHistoryCtlr: message: ' + JSON.stringify(message)); + + // this object holds all app data and functions + $scope.ecdapp = {}; + // For convenience + $scope.ecdapp.serviceName = message.serviceName; + $scope.ecdapp.label = 'History for Service ' + $scope.ecdapp.serviceName; + + // models for controls on screen + $scope.ecdapp.startDateTime = ''; + $scope.ecdapp.endDateTime = ''; + // data fetched from backend + $scope.ecdapp.tableData = []; + // progress and error handling + $scope.ecdapp.isDataLoading = false; + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + + /** + * 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.showHistory = function() { + // Validate the entries in the date fields. + // If user types, it's a STRING (not a Date). + if ($scope.ecdapp.startDateTime == null) { + alert("Please enter a start date."); + return; + } + let startDT = Date.parse($scope.ecdapp.startDateTime); + if (isNaN(startDT)) { + alert("Failed to parse start date."); + return; + } + else { + // Use the parsed version. + $scope.ecdapp.startDateTime = new Date(startDT); + } + if ($scope.ecdapp.endDateTime == null) { + alert("Please enter an end date."); + return; + } + let endDT = Date.parse($scope.ecdapp.endDateTime); + if (isNaN(endDT)) { + alert("Failed to parse end date."); + return; + } + else { + $scope.ecdapp.endDateTime = new Date(endDT); + } + if ($scope.ecdapp.startDateTime.getTime() >= $scope.ecdapp.endDateTime.getTime()) { + alert("The start date must be before the end date, please correct."); + return; + } + $scope.ecdapp.isDataLoading = true; + ServiceHealthService.getServiceHealthHistory( + $scope.ecdapp.serviceName, + $scope.ecdapp.startDateTime.toISOString(), + $scope.ecdapp.endDateTime.toISOString() ).then( + function(jsonObj) { + if (jsonObj.error) { + $log.error("serviceHistoryCtlr.getServiceHealthHistory reported error: " + + jsonObj.error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = jsonObj.error; + $scope.ecdapp.tableData = []; + } else { + if (debug) + $log.debug("serviceHistoryCtlr.getServiceHealthHistory succeeded, size " + jsonObj.length); + $scope.ecdapp.isRequestFailed = false; + $scope.ecdapp.errMsg = null; + $scope.ecdapp.tableData = jsonObj; + } + $scope.ecdapp.isDataLoading = false; + }, + function(error) { + $log.error("serviceHistoryCtlr.getServiceHealthHistory failed: " + + error); + $scope.ecdapp.isRequestFailed = true; + $scope.ecdapp.errMsg = error; + $scope.ecdapp.tableData = []; + $scope.ecdapp.isDataLoading = false; + }); + }; + +}); |