Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
| 3 | |
Matteo Scandolo | 0456495 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 4 | angular.module('xos.diagnostic') |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 5 | .service('ChartData', function($rootScope, $q, lodash, Tenant, Node, serviceTopologyConfig, Ceilometer, Instances) { |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 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 = { |
Matteo Scandolo | d4ea877 | 2016-03-01 15:20:29 -0800 | [diff] [blame] | 55 | cTag: tags.cTag, |
| 56 | sTag: tags.sTag |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 57 | }; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 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 | |
Matteo Scandolo | d4ea877 | 2016-03-01 15:20:29 -0800 | [diff] [blame] | 71 | this.getSubscriberTag = (subscriber) => { |
| 72 | const tags = { |
| 73 | cTag: subscriber.c_tag, |
| 74 | sTag: subscriber.s_tag |
| 75 | }; |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 76 | |
| 77 | this.addSubscriberTag(tags); |
| 78 | // add tags info to current subscriber |
Matteo Scandolo | d4ea877 | 2016-03-01 15:20:29 -0800 | [diff] [blame] | 79 | this.currentSubscriber.tags = tags; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 80 | |
| 81 | }; |
| 82 | |
Matteo Scandolo | 6c6e594 | 2016-03-02 10:59:46 -0800 | [diff] [blame] | 83 | this.getSubscriberIP = (subscriber) => { |
| 84 | // const ip = JSON.parse(this.currentServiceChain.children[0].children[0].tenant.service_specific_attribute).wan_container_ip; |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 85 | // const ip = this.currentServiceChain.children[0].children[0].tenant.wan_container_ip; |
Matteo Scandolo | 6c6e594 | 2016-03-02 10:59:46 -0800 | [diff] [blame] | 86 | this.logicTopologyData.children[0].subscriberIP = subscriber.wan_container_ip; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | this.selectSubscriber = (subscriber) => { |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 90 | // append the device with to config settings |
| 91 | serviceTopologyConfig.elWidths.push(160); |
| 92 | |
| 93 | this.addSubscriber(angular.copy(subscriber)); |
| 94 | |
Matteo Scandolo | 6aa165f | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 95 | //clean selected instances |
| 96 | this.highlightInstances([]); |
| 97 | |
Matteo Scandolo | d4ea877 | 2016-03-01 15:20:29 -0800 | [diff] [blame] | 98 | this.getSubscriberTag(subscriber); |
Matteo Scandolo | 6c6e594 | 2016-03-02 10:59:46 -0800 | [diff] [blame] | 99 | this.getSubscriberIP(subscriber); |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 100 | |
| 101 | }; |
| 102 | |
| 103 | this.highlightInstances = (instances) => { |
| 104 | |
| 105 | const computeNodes = this.logicTopologyData.children[0].children[0].computeNodes; |
| 106 | |
| 107 | // unselect all |
| 108 | computeNodes.map((node) => { |
| 109 | node.instances.map((instance) => { |
| 110 | instance.selected = false |
| 111 | return instance; |
| 112 | }); |
| 113 | }); |
| 114 | |
| 115 | lodash.forEach(instances, (instance) => { |
| 116 | computeNodes.map((node) => { |
| 117 | node.instances.map((d3instance) => { |
| 118 | if(d3instance.id === instance.id){ |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 119 | // console.log(d3instance, instance); |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 120 | d3instance.selected = true; |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 121 | d3instance.stats = instance.stats; //add stats to d3 node |
| 122 | d3instance.container = instance.container; // container info to d3 node |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 123 | } |
| 124 | return d3instance; |
| 125 | }); |
| 126 | }); |
| 127 | }); |
| 128 | |
| 129 | } |
| 130 | |
| 131 | this.getInstanceStatus = (service) => { |
| 132 | const deferred = $q.defer(); |
| 133 | |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 134 | let p; |
| 135 | |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 136 | // subscriber specific |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 137 | if(this.currentSubscriber){ |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 138 | |
| 139 | let attr; |
| 140 | try { |
| 141 | attr = JSON.parse(service.tenant.service_specific_attribute); |
| 142 | } |
| 143 | catch(e){ |
| 144 | attr = null; |
| 145 | } |
| 146 | |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 147 | // if no instances are associated to the subscriber |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 148 | if(!attr || !attr.instance_id){ |
| 149 | let d = $q.defer(); |
| 150 | d.resolve([]); |
| 151 | p = d.promise; |
| 152 | } |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 153 | // if ther is an instance |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 154 | else{ |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 155 | let instance = {}; |
| 156 | p = Instances.get({id: attr.instance_id}).$promise |
| 157 | .then(function(_instance){ |
| 158 | instance = _instance; |
| 159 | return Ceilometer.getInstanceStats(instance.instance_uuid); |
| 160 | }) |
| 161 | .then((stats) => { |
| 162 | instance.stats = stats; |
| 163 | const containerName = `vcpe-${this.currentSubscriber.tags.sTag}-${this.currentSubscriber.tags.cTag}`; |
| 164 | // append containers |
| 165 | instance.container = { |
| 166 | name: containerName |
| 167 | }; |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 168 | |
| 169 | // TODO fetch container stats |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 170 | return Ceilometer.getContainerStats(containerName); |
| 171 | }) |
| 172 | .then((containerStats) => { |
| 173 | instance.container.stats = containerStats.stats; |
| 174 | instance.container.port = containerStats.port; |
| 175 | return [instance]; |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 176 | }); |
| 177 | } |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 178 | } |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 179 | // global scope |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 180 | else { |
Matteo Scandolo | 26d17e1 | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 181 | const param = { |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 182 | 'service_vsg': {kind: 'vCPE'}, |
| 183 | 'service_vbng': {kind: 'vBNG'}, |
| 184 | 'service_volt': {kind: 'vOLT'} |
| 185 | }; |
| 186 | |
| 187 | p = Tenant.queryVsgInstances(param[service.name]).$promise |
| 188 | .then((instances) => { |
| 189 | |
| 190 | return Ceilometer.getInstancesStats(instances); |
| 191 | }); |
| 192 | } |
| 193 | |
| 194 | p.then((instances) => { |
| 195 | this.highlightInstances(instances); |
| 196 | deferred.resolve(instances); |
| 197 | }) |
| 198 | .catch((e) => { |
| 199 | deferred.reject(e); |
| 200 | }); |
| 201 | |
| 202 | return deferred.promise; |
| 203 | }; |
| 204 | }) |
| 205 | })(); |