Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
| 3 | |
| 4 | const shapes = { |
| 5 | cloud: ' M 79.72 49.60 C 86.00 37.29 98.57 29.01 111.96 26.42 C 124.27 24.11 137.53 26.15 148.18 32.90 C 158.08 38.78 165.39 48.87 167.65 60.20 C 176.20 57.90 185.14 56.01 194.00 57.73 C 206.08 59.59 217.92 66.01 224.37 76.66 C 227.51 81.54 228.85 87.33 229.23 93.06 C 237.59 93.33 246.22 95.10 253.04 100.19 C 256.69 103.13 259.87 107.67 258.91 112.59 C 257.95 118.43 252.78 122.38 247.78 124.82 C 235.27 130.43 220.23 130.09 207.98 123.93 C 199.33 127.88 189.76 129.43 180.30 128.57 C 173.70 139.92 161.70 147.65 148.86 149.93 C 133.10 153.26 116.06 148.15 104.42 137.08 C 92.98 143.04 78.96 143.87 66.97 139.04 C 57.75 135.41 49.70 128.00 46.60 118.43 C 43.87 109.95 45.81 100.29 51.30 93.32 C 57.38 85.18 67.10 80.44 76.99 78.89 C 74.38 69.20 74.87 58.52 79.72 49.60 Z' |
| 6 | } |
| 7 | |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 8 | var computeNodeId = 0; |
| 9 | var instanceId = 0; |
| 10 | |
Matteo Scandolo | 4b3d872 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 11 | angular.module('xos.diagnostic') |
Matteo Scandolo | 78e9d0e | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 12 | .service('NodeDrawer', function(d3, serviceTopologyConfig, RackHelper, _){ |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 13 | |
| 14 | var _this = this; |
| 15 | |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 16 | this.addNetworks = (nodes) => { |
Matteo Scandolo | 105954e | 2016-03-11 11:16:58 -0800 | [diff] [blame] | 17 | |
| 18 | // clean childs |
| 19 | nodes.selectAll('*').remove(); |
| 20 | |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 21 | nodes.append('path') |
| 22 | .attr({ |
| 23 | d: shapes.cloud, |
Matteo Scandolo | 105954e | 2016-03-11 11:16:58 -0800 | [diff] [blame] | 24 | transform: 'translate(-100, -72), scale(0.7)', |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 25 | class: 'cloud' |
| 26 | }); |
| 27 | |
| 28 | nodes.append('text') |
| 29 | .attr({ |
Matteo Scandolo | bd66374 | 2016-03-07 16:07:13 -0800 | [diff] [blame] | 30 | 'text-anchor': 'middle', |
| 31 | y: -5, |
| 32 | x: 5, |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 33 | }) |
| 34 | .text(d => d.name) |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 35 | |
Matteo Scandolo | bd66374 | 2016-03-07 16:07:13 -0800 | [diff] [blame] | 36 | nodes.append('text') |
| 37 | .attr({ |
| 38 | 'text-anchor': 'middle', |
| 39 | y: 8, |
| 40 | x: 5, |
| 41 | class: 'small' |
| 42 | }) |
| 43 | .text(d => d.subtitle) |
| 44 | |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 45 | nodes.each(function(n){ |
| 46 | let currentNode = d3.select(this); |
| 47 | // cicle trouch node to add Tags and Public IP |
Matteo Scandolo | d54a7fd | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 48 | if(n.name === 'LAN-Side' && angular.isDefined(n.subscriberTag)){ |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 49 | currentNode.append('text') |
| 50 | .attr({ |
| 51 | 'text-anchor': 'middle', |
Matteo Scandolo | 105954e | 2016-03-11 11:16:58 -0800 | [diff] [blame] | 52 | y: 50 |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 53 | }) |
| 54 | .text(() => `C-Tag: ${n.subscriberTag.cTag}`); |
| 55 | |
| 56 | currentNode.append('text') |
| 57 | .attr({ |
| 58 | 'text-anchor': 'middle', |
Matteo Scandolo | 105954e | 2016-03-11 11:16:58 -0800 | [diff] [blame] | 59 | y: 70 |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 60 | }) |
| 61 | .text(() => `S-Tag: ${n.subscriberTag.sTag}`); |
| 62 | } |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 63 | |
Matteo Scandolo | d54a7fd | 2016-03-08 09:33:26 -0800 | [diff] [blame] | 64 | if(n.name === 'WAN-Side' && angular.isDefined(n.subscriberIP)){ |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 65 | currentNode.append('text') |
| 66 | .attr({ |
| 67 | 'text-anchor': 'middle', |
Matteo Scandolo | 105954e | 2016-03-11 11:16:58 -0800 | [diff] [blame] | 68 | y: 50 |
Matteo Scandolo | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 69 | }) |
| 70 | .text(() => `Public IP: ${n.subscriberIP}`); |
| 71 | } |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 72 | }); |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | this.addRack = (nodes) => { |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 76 | |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 77 | // loop because of D3 |
| 78 | // rack will be only one |
| 79 | nodes.each(d => { |
| 80 | let [w, h] = RackHelper.getRackSize(d.computeNodes); |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 81 | |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 82 | // TODO update instead of delete and redraw |
| 83 | nodes.select('g').remove(); |
| 84 | |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 85 | let rack = nodes |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 86 | .append('g'); |
| 87 | |
| 88 | rack |
| 89 | .attr({ |
| 90 | transform: `translate(0,0)` |
| 91 | }) |
| 92 | .transition() |
| 93 | .duration(serviceTopologyConfig.duration) |
| 94 | .attr({ |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 95 | transform: () => `translate(${- (w / 2)}, ${- (h / 2)})` |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 96 | }); |
| 97 | |
| 98 | rack |
| 99 | .append('rect') |
| 100 | .attr({ |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 101 | width: 0, |
| 102 | height: 0 |
| 103 | }) |
| 104 | .transition() |
| 105 | .duration(serviceTopologyConfig.duration) |
| 106 | .attr({ |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 107 | width: w, |
| 108 | height: h |
| 109 | }); |
| 110 | |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 111 | rack.append('text') |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 112 | .attr({ |
| 113 | 'text-anchor': 'middle', |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 114 | y: - 10, |
| 115 | x: w / 2, |
| 116 | opacity: 0 |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 117 | }) |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 118 | .text(d => d.name) |
| 119 | .transition() |
| 120 | .duration(serviceTopologyConfig.duration) |
| 121 | .attr({ |
| 122 | opacity: 1 |
| 123 | }) |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 124 | |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 125 | this.drawComputeNodes(rack, d.computeNodes); |
| 126 | |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 127 | }); |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 128 | |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | this.drawComputeNodes = (container, nodes) => { |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 132 | |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 133 | let elements = container.selectAll('.compute-nodes') |
| 134 | .data(nodes, d => { |
| 135 | if(!angular.isString(d.d3Id)){ |
| 136 | d.d3Id = `compute-node-${++computeNodeId}`; |
| 137 | } |
| 138 | return d.d3Id; |
| 139 | }); |
| 140 | |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 141 | let {width, height} = container.node().getBoundingClientRect(); |
| 142 | |
| 143 | var nodeContainer = elements.enter().append('g'); |
| 144 | |
| 145 | nodeContainer |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 146 | .attr({ |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 147 | transform: `translate(${width / 2}, ${ height / 2})`, |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 148 | class: 'compute-node', |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 149 | }) |
| 150 | .transition() |
| 151 | .duration(serviceTopologyConfig.duration) |
| 152 | .attr({ |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 153 | transform: (d) => `translate(${RackHelper.getComputeNodePosition(nodes, d.d3Id.replace('compute-node-', '') - 1)})` |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 154 | }); |
| 155 | |
| 156 | nodeContainer.append('rect') |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 157 | .attr({ |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 158 | width: 0, |
| 159 | height: 0 |
| 160 | }) |
| 161 | .transition() |
| 162 | .duration(serviceTopologyConfig.duration) |
| 163 | .attr({ |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 164 | width: d => RackHelper.getComputeNodeSize(d.instances)[0], |
| 165 | height: d => RackHelper.getComputeNodeSize(d.instances)[1], |
| 166 | }); |
| 167 | |
| 168 | nodeContainer.append('text') |
| 169 | .attr({ |
| 170 | 'text-anchor': 'start', |
Matteo Scandolo | 105954e | 2016-03-11 11:16:58 -0800 | [diff] [blame] | 171 | y: 17, //FIXME |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 172 | x: 10, //FIXME |
| 173 | opacity: 0 |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 174 | }) |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 175 | .text(d => d.humanReadableName.split('.')[0]) |
| 176 | .transition() |
| 177 | .duration(serviceTopologyConfig.duration) |
| 178 | .attr({ |
| 179 | opacity: 1 |
| 180 | }) |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 181 | |
| 182 | // if there are Compute Nodes |
| 183 | if(nodeContainer.length > 0){ |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 184 | // draw instances for each compute node |
| 185 | nodeContainer.each(function(a){ |
| 186 | _this.drawInstances(d3.select(this), a.instances); |
| 187 | }) |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | }; |
| 191 | |
Matteo Scandolo | 0cfd5a2 | 2016-02-16 13:29:26 -0800 | [diff] [blame] | 192 | // NOTE Stripping unuseful names to shorten labels. |
| 193 | // This is not elegant |
| 194 | const formatInstanceName = (name) => { |
| 195 | return name |
| 196 | .replace('app_', '') |
| 197 | .replace('service_', '') |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 198 | // .replace('ovs_', '') |
Matteo Scandolo | 0cfd5a2 | 2016-02-16 13:29:26 -0800 | [diff] [blame] | 199 | .replace('mysite_', '') |
| 200 | .replace('_instance', ''); |
| 201 | }; |
| 202 | |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 203 | const getInstanceStatusColor = (instance) => { |
| 204 | function startWith(val, string){ |
| 205 | return string.substring(0, val.length) === val; |
| 206 | } |
| 207 | |
| 208 | if(startWith('0 - ', instance.backend_status)){ |
| 209 | return 'provisioning'; |
| 210 | } |
| 211 | if(startWith('1 - ', instance.backend_status)){ |
| 212 | return 'good'; |
| 213 | } |
| 214 | if(startWith('2 - ', instance.backend_status)){ |
| 215 | return 'bad'; |
| 216 | } |
| 217 | else { |
| 218 | return ''; |
| 219 | } |
| 220 | }; |
| 221 | |
Matteo Scandolo | 653c509 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 222 | const drawContainer = (container, docker) => { |
| 223 | |
| 224 | const containerBox = container.append('g') |
| 225 | .attr({ |
| 226 | class: 'container', |
| 227 | transform: `translate(${serviceTopologyConfig.instance.margin}, 115)` |
| 228 | }); |
| 229 | |
| 230 | containerBox.append('rect') |
| 231 | .attr({ |
| 232 | width: 250 - (serviceTopologyConfig.container.margin * 2), |
| 233 | height: serviceTopologyConfig.container.height, |
| 234 | }); |
| 235 | |
| 236 | containerBox.append('text') |
| 237 | .attr({ |
| 238 | y: 20, |
| 239 | x: serviceTopologyConfig.instance.margin, |
| 240 | class: 'name' |
| 241 | }) |
| 242 | .text(docker.name) |
| 243 | |
| 244 | // add stats |
| 245 | const interestingMeters = ['memory', 'memory.usage', 'cpu_util']; |
| 246 | |
| 247 | interestingMeters.forEach((m, i) => { |
Matteo Scandolo | 78e9d0e | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 248 | const meter = _.find(docker.stats, {meter: m}); |
Matteo Scandolo | 653c509 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 249 | // if there is no meter stats skip rendering |
| 250 | if(!angular.isDefined(meter)){ |
| 251 | return; |
| 252 | } |
| 253 | containerBox.append('text') |
| 254 | .attr({ |
| 255 | y: 40 + (i * 15), |
| 256 | x: serviceTopologyConfig.instance.margin, |
| 257 | opacity: 0 |
| 258 | }) |
| 259 | .text(`${meter.description}: ${Math.round(meter.value)} ${meter.unit}`) |
| 260 | .transition() |
| 261 | .duration(serviceTopologyConfig.duration) |
| 262 | .attr({ |
| 263 | opacity: 1 |
| 264 | }); |
| 265 | }); |
| 266 | |
| 267 | // add port stats |
| 268 | const ports = ['eth0', 'eth1']; |
| 269 | const interestingPortMeters = [ |
| 270 | { |
| 271 | meter: 'network.incoming.bytes.rate', |
| 272 | label: 'Incoming' |
| 273 | }, |
| 274 | { |
| 275 | meter: 'network.outgoing.bytes.rate', |
| 276 | label: 'Outgoing' |
| 277 | } |
| 278 | ]; |
| 279 | |
| 280 | ports.forEach((p, j) => { |
| 281 | |
| 282 | // if there are no port stats skip rendering |
| 283 | if(docker.port[p].length === 0){ |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | containerBox.append('text') |
| 288 | .attr({ |
| 289 | y: 90, |
| 290 | x: serviceTopologyConfig.instance.margin + (120 * j), |
| 291 | class: 'name' |
| 292 | }) |
| 293 | .text(`${docker.name}-${p}`) |
| 294 | |
| 295 | interestingPortMeters.forEach((m, i) => { |
| 296 | |
Matteo Scandolo | 78e9d0e | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 297 | const meter = _.find(docker.port[p], {meter: m.meter}); |
Matteo Scandolo | 653c509 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 298 | // if there is no meter stats skip rendering |
| 299 | if(!angular.isDefined(meter)){ |
| 300 | return; |
| 301 | } |
| 302 | containerBox.append('text') |
| 303 | .attr({ |
| 304 | y: 105 + (i * 15), |
| 305 | x: serviceTopologyConfig.instance.margin + (120 * j), |
| 306 | opacity: 0 |
| 307 | }) |
| 308 | .text(`${m.label}: ${Math.round(meter.value)} ${meter.unit}`) |
| 309 | .transition() |
| 310 | .duration(serviceTopologyConfig.duration) |
| 311 | .attr({ |
| 312 | opacity: 1 |
| 313 | }); |
| 314 | }); |
| 315 | }); |
| 316 | } |
| 317 | |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 318 | const showInstanceStats = (container, instance) => { |
| 319 | |
| 320 | // NOTE this should be dinamically positioned |
| 321 | // base on the number of element present |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 322 | |
| 323 | // fake the position |
| 324 | let translation = { |
| 325 | 'mysite_vsg-1': '200, -120', |
| 326 | 'mysite_vsg-2': '-300, 30', |
| 327 | 'mysite_vsg-3': '-300, -250', |
| 328 | }; |
| 329 | |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 330 | const statsContainer = container.append('g') |
| 331 | .attr({ |
Matteo Scandolo | 44e5591 | 2016-03-10 11:21:19 -0800 | [diff] [blame] | 332 | transform: `translate(${translation[instance.humanReadableName] || translation['mysite_vsg-1']})`, |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 333 | class: 'stats-container' |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 334 | }) |
| 335 | .on('click', function(d) { |
| 336 | // toggling visisbility |
| 337 | d.fade = !d.fade; |
| 338 | let opacity; |
| 339 | if(d.fade){ |
| 340 | opacity = 0.1; |
| 341 | } |
| 342 | else{ |
| 343 | opacity = 1; |
| 344 | } |
| 345 | |
| 346 | d3.select(this) |
| 347 | .transition() |
| 348 | .duration(serviceTopologyConfig.duration) |
| 349 | .attr({ |
| 350 | opacity: opacity |
| 351 | }) |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 352 | }); |
| 353 | |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 354 | let lines = { |
| 355 | 'mysite_vsg-1': { |
Matteo Scandolo | 653c509 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 356 | x1: -160, |
| 357 | y1: 120, |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 358 | x2: 0, |
| 359 | y2: 50, |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 360 | }, |
| 361 | 'mysite_vsg-2': { |
| 362 | x1: 250, |
| 363 | y1: 50, |
| 364 | x2: 300, |
| 365 | y2: -10 |
| 366 | }, |
| 367 | 'mysite_vsg-3': { |
| 368 | x1: 250, |
| 369 | y1: 50, |
| 370 | x2: 300, |
| 371 | y2: 270 |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | statsContainer.append('line') |
| 376 | .attr({ |
Matteo Scandolo | d9806b3 | 2016-03-11 11:54:47 -0800 | [diff] [blame] | 377 | x1: d => lines[d.humanReadableName].x1 || lines['mysite_vsg-1'].x1, |
| 378 | y1: d => lines[d.humanReadableName].y1 || lines['mysite_vsg-1'].y1, |
| 379 | x2: d => lines[d.humanReadableName].x2 || lines['mysite_vsg-1'].x2, |
| 380 | y2: d => lines[d.humanReadableName].y2 || lines['mysite_vsg-1'].y2, |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 381 | stroke: 'black', |
| 382 | opacity: 0 |
| 383 | }) |
| 384 | .transition() |
| 385 | .duration(serviceTopologyConfig.duration) |
| 386 | .attr({ |
| 387 | opacity: 1 |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 388 | }) |
| 389 | |
| 390 | // NOTE rect should be dinamically sized base on the presence of a container |
| 391 | let statsHeight = 110; |
Matteo Scandolo | 653c509 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 392 | let statsWidth = 250; |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 393 | |
| 394 | if (instance.container){ |
| 395 | statsHeight += serviceTopologyConfig.container.height + (serviceTopologyConfig.container.margin * 2) |
| 396 | } |
| 397 | |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 398 | const statsVignette = statsContainer.append('rect') |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 399 | .attr({ |
| 400 | width: statsWidth, |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 401 | height: statsHeight, |
| 402 | opacity: 0 |
| 403 | }) |
| 404 | .transition() |
| 405 | .duration(serviceTopologyConfig.duration) |
| 406 | .attr({ |
| 407 | opacity: 1 |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 408 | }); |
| 409 | |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 410 | |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 411 | // add instance info |
| 412 | statsContainer.append('text') |
| 413 | .attr({ |
| 414 | y: 15, |
| 415 | x: serviceTopologyConfig.instance.margin, |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 416 | class: 'name', |
| 417 | opacity: 0 |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 418 | }) |
| 419 | .text(instance.humanReadableName) |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 420 | .transition() |
| 421 | .duration(serviceTopologyConfig.duration) |
| 422 | .attr({ |
| 423 | opacity: 1 |
| 424 | }) |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 425 | |
| 426 | statsContainer.append('text') |
| 427 | .attr({ |
| 428 | y: 30, |
| 429 | x: serviceTopologyConfig.instance.margin, |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 430 | class: 'ip', |
| 431 | opacity: 0 |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 432 | }) |
| 433 | .text(instance.ip) |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 434 | .transition() |
| 435 | .duration(serviceTopologyConfig.duration) |
| 436 | .attr({ |
| 437 | opacity: 1 |
| 438 | }) |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 439 | |
| 440 | // add stats |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 441 | const interestingMeters = ['memory', 'memory.usage', 'cpu', 'cpu_util']; |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 442 | |
| 443 | interestingMeters.forEach((m, i) => { |
Matteo Scandolo | 78e9d0e | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 444 | const meter = _.find(instance.stats, {meter: m}); |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 445 | |
| 446 | if(meter){ |
| 447 | |
| 448 | statsContainer.append('text') |
| 449 | .attr({ |
| 450 | y: 55 + (i * 15), |
| 451 | x: serviceTopologyConfig.instance.margin, |
| 452 | opacity: 0 |
| 453 | }) |
| 454 | .text(`${meter.description}: ${Math.round(meter.value)} ${meter.unit}`) |
| 455 | .transition() |
| 456 | .duration(serviceTopologyConfig.duration) |
| 457 | .attr({ |
| 458 | opacity: 1 |
| 459 | }); |
| 460 | } |
| 461 | |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 462 | }); |
| 463 | |
| 464 | if(instance.container){ |
| 465 | // draw container |
Matteo Scandolo | 653c509 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 466 | drawContainer(statsContainer, instance.container); |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | }; |
| 470 | |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 471 | this.drawInstances = (container, instances) => { |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 472 | |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 473 | // TODO check for stats field in instance and draw popup |
| 474 | |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 475 | let {width, height} = container.node().getBoundingClientRect(); |
| 476 | |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 477 | let elements = container.selectAll('.instances') |
| 478 | .data(instances, d => angular.isString(d.d3Id) ? d.d3Id : d.d3Id = `instance-${++instanceId}`) |
| 479 | |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 480 | var instanceContainer = elements.enter().append('g'); |
| 481 | |
| 482 | instanceContainer |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 483 | .attr({ |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 484 | transform: `translate(${width / 2}, ${ height / 2})`, |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 485 | class: d => `instance ${d.selected ? 'active' : ''} ${getInstanceStatusColor(d)}`, |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 486 | }) |
| 487 | .transition() |
| 488 | .duration(serviceTopologyConfig.duration) |
| 489 | .attr({ |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 490 | transform: (d, i) => `translate(${RackHelper.getInstancePosition(i)})` |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 491 | }); |
| 492 | |
| 493 | instanceContainer.append('rect') |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 494 | .attr({ |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 495 | width: 0, |
| 496 | height: 0 |
| 497 | }) |
| 498 | .transition() |
| 499 | .duration(serviceTopologyConfig.duration) |
| 500 | .attr({ |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 501 | width: serviceTopologyConfig.instance.width, |
| 502 | height: serviceTopologyConfig.instance.height |
| 503 | }); |
| 504 | |
| 505 | instanceContainer.append('text') |
| 506 | .attr({ |
Matteo Scandolo | 0cfd5a2 | 2016-02-16 13:29:26 -0800 | [diff] [blame] | 507 | 'text-anchor': 'middle', |
| 508 | y: 23, //FIXME |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 509 | x: 40, //FIXME |
| 510 | opacity: 0 |
Matteo Scandolo | b785b57 | 2016-02-16 11:50:51 -0800 | [diff] [blame] | 511 | }) |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 512 | .text(d => formatInstanceName(d.humanReadableName)) |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 513 | .transition() |
| 514 | .duration(serviceTopologyConfig.duration) |
| 515 | .attr({ |
| 516 | opacity: 1 |
| 517 | }); |
Matteo Scandolo | 0cfd5a2 | 2016-02-16 13:29:26 -0800 | [diff] [blame] | 518 | |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 519 | // if stats are attached and instance is active, |
| 520 | // draw stats |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 521 | instanceContainer.each(function(instance, i){ |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 522 | |
| 523 | const container = d3.select(this); |
| 524 | |
| 525 | if(angular.isDefined(instance.stats) && instance.selected){ |
Matteo Scandolo | 7818510 | 2016-02-23 14:03:03 -0800 | [diff] [blame] | 526 | showInstanceStats(container, instance, i); |
Matteo Scandolo | 06afdfe | 2016-02-23 13:47:14 -0800 | [diff] [blame] | 527 | } |
| 528 | }); |
| 529 | |
Matteo Scandolo | 7de629e | 2016-03-10 08:59:27 -0800 | [diff] [blame] | 530 | // instanceContainer |
| 531 | // .on('click', function(d){ |
| 532 | // console.log(`Draw vignette with stats for instance: ${d.name}`); |
| 533 | // }); |
Matteo Scandolo | 1418393 | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 534 | }; |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 535 | |
| 536 | this.addPhisical = (nodes) => { |
Matteo Scandolo | d1b3bf5 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 537 | |
| 538 | nodes.select('rect').remove(); |
| 539 | nodes.select('text').remove(); |
| 540 | |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 541 | nodes.append('rect') |
| 542 | .attr(serviceTopologyConfig.square); |
| 543 | |
| 544 | nodes.append('text') |
| 545 | .attr({ |
| 546 | 'text-anchor': 'middle', |
| 547 | y: serviceTopologyConfig.square.y - 10 |
| 548 | }) |
Matteo Scandolo | a03110c | 2016-03-01 15:20:29 -0800 | [diff] [blame] | 549 | .text(d => { |
| 550 | return d.name || d.humanReadableName |
| 551 | }); |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | this.addDevice = (nodes) => { |
| 555 | nodes.append('circle') |
| 556 | .attr(serviceTopologyConfig.circle); |
| 557 | |
| 558 | nodes.append('text') |
| 559 | .attr({ |
| 560 | 'text-anchor': 'end', |
| 561 | x: - serviceTopologyConfig.circle.r - 10, |
| 562 | y: serviceTopologyConfig.circle.r / 2 |
| 563 | }) |
Matteo Scandolo | db8a185 | 2016-02-23 10:04:36 -0800 | [diff] [blame] | 564 | .text(d => d.name || d.mac); |
Matteo Scandolo | 38ba331 | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 565 | } |
| 566 | }); |
| 567 | })(); |