Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | f0577ac | 2016-03-21 17:27:42 -0700 | [diff] [blame] | 19 | /** |
| 20 | * © OpenCORD |
| 21 | * |
| 22 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 23 | * |
| 24 | * Created by teone on 3/21/16. |
| 25 | */ |
| 26 | |
| 27 | (function () { |
| 28 | 'use strict'; |
| 29 | |
| 30 | angular.module('xos.ceilometerDashboard') |
Matteo Scandolo | 54bc5f7 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 31 | .directive('ceilometerDashboard', function(_){ |
Matteo Scandolo | f0577ac | 2016-03-21 17:27:42 -0700 | [diff] [blame] | 32 | return { |
| 33 | restrict: 'E', |
| 34 | scope: {}, |
| 35 | bindToController: true, |
| 36 | controllerAs: 'vm', |
| 37 | templateUrl: 'templates/ceilometer-dashboard.tpl.html', |
| 38 | controller: function(Ceilometer){ |
| 39 | |
| 40 | this.showStats = false; |
| 41 | |
| 42 | // this open the accordion |
| 43 | this.accordion = { |
| 44 | open: {} |
| 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * Open the active panel base on the service stored values |
| 49 | */ |
| 50 | this.openPanels = () => { |
| 51 | if(Ceilometer.selectedService){ |
| 52 | this.accordion.open[Ceilometer.selectedService] = true; |
| 53 | if(Ceilometer.selectedSlice){ |
| 54 | this.loadSliceMeter(Ceilometer.selectedSlice, Ceilometer.selectedService); |
| 55 | this.selectedSlice = Ceilometer.selectedSlice; |
| 56 | if(Ceilometer.selectedResource){ |
| 57 | this.selectedResource = Ceilometer.selectedResource; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * Load the list of service and slices |
| 65 | */ |
Matteo Scandolo | f0577ac | 2016-03-21 17:27:42 -0700 | [diff] [blame] | 66 | this.loadMappings = () => { |
| 67 | this.loader = true; |
| 68 | Ceilometer.getMappings() |
| 69 | .then((services) => { |
| 70 | |
| 71 | // rename thing in UI |
| 72 | services.map((service) => { |
| 73 | if(service.service === 'service_ONOS_vBNG'){ |
| 74 | service.service = 'ONOS_FABRIC'; |
| 75 | } |
| 76 | if(service.service === 'service_ONOS_vOLT'){ |
| 77 | service.service = 'ONOS_CORD'; |
| 78 | } |
| 79 | |
| 80 | service.slices.map(s => { |
| 81 | if(s.slice === 'mysite_onos_volt'){ |
| 82 | s.slice = 'ONOS_CORD'; |
| 83 | } |
| 84 | if(s.slice === 'mysite_onos_vbng'){ |
| 85 | s.slice = 'ONOS_FABRIC'; |
| 86 | } |
| 87 | if(s.slice === 'mysite_vbng'){ |
| 88 | s.slice = 'mysite_vRouter'; |
| 89 | } |
| 90 | }); |
| 91 | |
| 92 | return service; |
| 93 | }); |
| 94 | // end rename thing in UI |
| 95 | |
| 96 | this.services = services; |
| 97 | this.openPanels(); |
| 98 | }) |
| 99 | .catch(err => { |
| 100 | this.error = (err.data && err.data.detail) ? err.data.detail : 'An Error occurred. Please try again later.'; |
| 101 | }) |
| 102 | .finally(() => { |
| 103 | this.loader = false; |
| 104 | }); |
| 105 | }; |
| 106 | |
| 107 | this.loadMappings(); |
| 108 | |
| 109 | /** |
| 110 | * Load the list of a single slice |
| 111 | */ |
Matteo Scandolo | f0577ac | 2016-03-21 17:27:42 -0700 | [diff] [blame] | 112 | this.loadSliceMeter = (slice, service_name) => { |
| 113 | |
| 114 | Ceilometer.selectedSlice = null; |
| 115 | Ceilometer.selectedService = null; |
| 116 | Ceilometer.selectedResources = null; |
| 117 | |
| 118 | // visualization info |
| 119 | this.loader = true; |
| 120 | this.error = null; |
| 121 | this.ceilometerError = null; |
| 122 | |
| 123 | Ceilometer.getMeters({tenant: slice.project_id}) |
| 124 | .then((sliceMeters) => { |
| 125 | this.selectedSlice = slice.slice; |
| 126 | this.selectedTenant = slice.project_id; |
| 127 | |
| 128 | // store the status |
| 129 | Ceilometer.selectedSlice = slice; |
| 130 | Ceilometer.selectedService = service_name; |
| 131 | |
| 132 | // rename things in UI |
| 133 | sliceMeters.map(m => { |
| 134 | m.resource_name = m.resource_name.replace('mysite_onos_vbng', 'ONOS_FABRIC'); |
| 135 | m.resource_name = m.resource_name.replace('mysite_onos_volt', 'ONOS_CORD'); |
| 136 | m.resource_name = m.resource_name.replace('mysite_vbng', 'mysite_vRouter'); |
| 137 | return m; |
| 138 | }); |
| 139 | // end rename things in UI |
| 140 | |
Matteo Scandolo | 54bc5f7 | 2016-05-18 14:06:45 -0700 | [diff] [blame] | 141 | this.selectedResources = _.groupBy(sliceMeters, 'resource_name'); |
Matteo Scandolo | f0577ac | 2016-03-21 17:27:42 -0700 | [diff] [blame] | 142 | |
| 143 | // hacky |
| 144 | if(Ceilometer.selectedResource){ |
| 145 | this.selectedMeters = this.selectedResources[Ceilometer.selectedResource]; |
| 146 | } |
| 147 | }) |
| 148 | .catch(err => { |
| 149 | |
| 150 | // this means that ceilometer is not yet ready |
| 151 | if(err.status === 503){ |
| 152 | return this.ceilometerError = err.data.detail.specific_error; |
| 153 | } |
| 154 | |
Matteo Scandolo | 11020a0 | 2016-03-24 11:56:06 -0700 | [diff] [blame] | 155 | this.ceilometerError = (err.data && err.data.detail && err.data.detail.specific_error) ? err.data.detail.specific_error : 'An Error occurred. Please try again later.'; |
Matteo Scandolo | f0577ac | 2016-03-21 17:27:42 -0700 | [diff] [blame] | 156 | }) |
| 157 | .finally(() => { |
| 158 | this.loader = false; |
| 159 | }); |
| 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * Select Meters for a resource |
| 164 | * |
| 165 | * @param Array meters The list of selected resources |
| 166 | * @returns void |
| 167 | */ |
| 168 | this.selectedMeters = null; |
| 169 | this.selectMeters = (meters, resource) => { |
| 170 | this.selectedMeters = meters; |
| 171 | |
| 172 | Ceilometer.selectedResource = resource; |
| 173 | this.selectedResource = resource; |
| 174 | } |
| 175 | |
| 176 | } |
| 177 | }; |
| 178 | }) |
| 179 | })(); |
| 180 | |