blob: a051350f0e8db9795cac98880f863dae258436a9 [file] [log] [blame]
Matteo Scandolo78b80452016-03-21 17:27:42 -07001/**
2 * © OpenCORD
3 *
4 * Visit http://guide.xosproject.org/devguide/addview/ for more information
5 *
6 * Created by teone on 3/21/16.
7 */
8
9(function () {
10 'use strict';
11
12 angular.module('xos.ceilometerDashboard')
13 .directive('ceilometerDashboard', function(lodash){
14 return {
15 restrict: 'E',
16 scope: {},
17 bindToController: true,
18 controllerAs: 'vm',
19 templateUrl: 'templates/ceilometer-dashboard.tpl.html',
20 controller: function(Ceilometer){
21
22 this.showStats = false;
23
24 // this open the accordion
25 this.accordion = {
26 open: {}
27 };
28
29 /**
30 * Open the active panel base on the service stored values
31 */
32 this.openPanels = () => {
33 if(Ceilometer.selectedService){
34 this.accordion.open[Ceilometer.selectedService] = true;
35 if(Ceilometer.selectedSlice){
36 this.loadSliceMeter(Ceilometer.selectedSlice, Ceilometer.selectedService);
37 this.selectedSlice = Ceilometer.selectedSlice;
38 if(Ceilometer.selectedResource){
39 this.selectedResource = Ceilometer.selectedResource;
40 }
41 }
42 }
43 };
44
45 /**
46 * Load the list of service and slices
47 */
Matteo Scandolo78b80452016-03-21 17:27:42 -070048 this.loadMappings = () => {
49 this.loader = true;
50 Ceilometer.getMappings()
51 .then((services) => {
52
53 // rename thing in UI
54 services.map((service) => {
55 if(service.service === 'service_ONOS_vBNG'){
56 service.service = 'ONOS_FABRIC';
57 }
58 if(service.service === 'service_ONOS_vOLT'){
59 service.service = 'ONOS_CORD';
60 }
61
62 service.slices.map(s => {
63 if(s.slice === 'mysite_onos_volt'){
64 s.slice = 'ONOS_CORD';
65 }
66 if(s.slice === 'mysite_onos_vbng'){
67 s.slice = 'ONOS_FABRIC';
68 }
69 if(s.slice === 'mysite_vbng'){
70 s.slice = 'mysite_vRouter';
71 }
72 });
73
74 return service;
75 });
76 // end rename thing in UI
77
78 this.services = services;
79 this.openPanels();
80 })
81 .catch(err => {
82 this.error = (err.data && err.data.detail) ? err.data.detail : 'An Error occurred. Please try again later.';
83 })
84 .finally(() => {
85 this.loader = false;
86 });
87 };
88
89 this.loadMappings();
90
91 /**
92 * Load the list of a single slice
93 */
Matteo Scandolo78b80452016-03-21 17:27:42 -070094 this.loadSliceMeter = (slice, service_name) => {
95
96 Ceilometer.selectedSlice = null;
97 Ceilometer.selectedService = null;
98 Ceilometer.selectedResources = null;
99
100 // visualization info
101 this.loader = true;
102 this.error = null;
103 this.ceilometerError = null;
104
105 Ceilometer.getMeters({tenant: slice.project_id})
106 .then((sliceMeters) => {
107 this.selectedSlice = slice.slice;
108 this.selectedTenant = slice.project_id;
109
110 // store the status
111 Ceilometer.selectedSlice = slice;
112 Ceilometer.selectedService = service_name;
113
114 // rename things in UI
115 sliceMeters.map(m => {
116 m.resource_name = m.resource_name.replace('mysite_onos_vbng', 'ONOS_FABRIC');
117 m.resource_name = m.resource_name.replace('mysite_onos_volt', 'ONOS_CORD');
118 m.resource_name = m.resource_name.replace('mysite_vbng', 'mysite_vRouter');
119 return m;
120 });
121 // end rename things in UI
122
123 this.selectedResources = lodash.groupBy(sliceMeters, 'resource_name');
124
125 // hacky
126 if(Ceilometer.selectedResource){
127 this.selectedMeters = this.selectedResources[Ceilometer.selectedResource];
128 }
129 })
130 .catch(err => {
131
132 // this means that ceilometer is not yet ready
133 if(err.status === 503){
134 return this.ceilometerError = err.data.detail.specific_error;
135 }
136
Matteo Scandolo48d07ee2016-03-24 11:56:06 -0700137 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 Scandolo78b80452016-03-21 17:27:42 -0700138 })
139 .finally(() => {
140 this.loader = false;
141 });
142 };
143
144 /**
145 * Select Meters for a resource
146 *
147 * @param Array meters The list of selected resources
148 * @returns void
149 */
150 this.selectedMeters = null;
151 this.selectMeters = (meters, resource) => {
152 this.selectedMeters = meters;
153
154 Ceilometer.selectedResource = resource;
155 this.selectedResource = resource;
156 }
157
158 }
159 };
160 })
161})();
162