blob: 4c53a03bddc03e43d4a5bc1e04f5d37abe09447c [file] [log] [blame]
Matteo Scandolo0344ef32016-02-22 16:53:22 -08001(function () {
2 'use strict';
3
4 angular.module('xos.serviceTopology')
5 .service('ChartData', function($rootScope, $q, lodash, Tenant, Node, serviceTopologyConfig, Ceilometer) {
6 this.currentSubscriber = null;
7 this.currentServiceChain = null;
8
9 this.logicTopologyData = {
10 name: 'Router',
11 type: 'router',
12 children: [
13 {
14 name: 'WAN',
15 type: 'network',
16 children: [
17 {
18 name: 'Rack',
19 type: 'rack',
20 computeNodes: [],
21 children: [
22 {
23 name: 'LAN',
24 type: 'network',
25 children: [{
26 name: 'Subscriber',
27 type: 'subscriber'
28 }] //subscribers goes here
29 }
30 ]
31 }
32 ]
33 }
34 ]
35 };
36
37 this.getLogicTree = () => {
38 const deferred = $q.defer();
39
40 Node.queryWithInstances().$promise
41 .then((computeNodes) => {
42 this.logicTopologyData.children[0].children[0].computeNodes = computeNodes;
43 // LogicTopologyHelper.updateTree(svg);
44 deferred.resolve(this.logicTopologyData);
45 });
46
47 return deferred.promise;
48 };
49
50 /**
51 * Add Subscriber tag to LAN Network
52 */
53 this.addSubscriberTag = (tags) => {
54 this.logicTopologyData.children[0].children[0].children[0].subscriberTag = {
55 cTag: tags.c_tag,
56 sTag: tags.s_tag
57 }
58 };
59
60 /**
61 * Add Subscribers to the tree
62 */
63 this.addSubscriber = (subscriber) => {
64 subscriber.children = subscriber.devices;
65
66 // add subscriber to data tree
67 this.logicTopologyData.children[0].children[0].children[0].children = [subscriber];
68 return this.logicTopologyData;
69 };
70
71 this.getSubscriberTag = () => {
72
73 this.addSubscriberTag(JSON.parse(this.currentServiceChain.children[0].tenant.service_specific_attribute));
74
75 };
76
77 this.getSubscriberIP = () => {
78 const ip = this.currentServiceChain.children[0].children[0].tenant.wan_container_ip;
79 this.logicTopologyData.children[0].subscriberIP = ip;
80 };
81
82 this.selectSubscriber = (subscriber) => {
83
84 // append the device with to config settings
85 serviceTopologyConfig.elWidths.push(160);
86
87 this.addSubscriber(angular.copy(subscriber));
88
89 this.getSubscriberTag();
90 this.getSubscriberIP();
91
92 };
93
94 this.highlightInstances = (instances) => {
95
96 const computeNodes = this.logicTopologyData.children[0].children[0].computeNodes;
97
98 // unselect all
99 computeNodes.map((node) => {
100 node.instances.map((instance) => {
101 instance.selected = false
102 return instance;
103 });
104 });
105
106 lodash.forEach(instances, (instance) => {
107 computeNodes.map((node) => {
108 node.instances.map((d3instance) => {
109 if(d3instance.id === instance.id){
110 d3instance.selected = true;
111 }
112 return d3instance;
113 });
114 });
115 });
116
117 }
118
119 this.getInstanceStatus = (service) => {
120 const deferred = $q.defer();
121
122 // NOTE consider if subscriber is selected or not,
123 // if not select instances
124 // else select containers (and follow subscriber chain to find the correct instance)
125
126 let p;
127
128 if(this.currentSubscriber){
129 let instances = [JSON.parse(service.tenant.service_specific_attribute).instance_id];
130 p = Ceilometer.getInstancesStats(instances);
131 }
132 else {
133 let param = {
134 'service_vsg': {kind: 'vCPE'},
135 'service_vbng': {kind: 'vBNG'},
136 'service_volt': {kind: 'vOLT'}
137 };
138
139 p = Tenant.queryVsgInstances(param[service.name]).$promise
140 .then((instances) => {
141
142 return Ceilometer.getInstancesStats(instances);
143 });
144 }
145
146 p.then((instances) => {
147 this.highlightInstances(instances);
148 deferred.resolve(instances);
149 })
150 .catch((e) => {
151 deferred.reject(e);
152 });
153
154 return deferred.promise;
155 };
156 })
157})();