blob: 9181e569260e2415b78a3271935d3057e00eea2f [file] [log] [blame]
Matteo Scandolo735606c2016-02-09 09:13:30 -08001(function () {
2 'use strict';
3 angular.module('xos.serviceTopology')
4 .directive('logicTopology', function(){
5 return {
6 restrict: 'E',
7 scope: {
Matteo Scandoloeeb9c082016-02-09 11:19:22 -08008 subscribers: '=',
9 selected: '='
Matteo Scandolo735606c2016-02-09 09:13:30 -080010 },
11 bindToController: true,
12 controllerAs: 'vm',
13 template: '',
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080014 controller: function($element, $log, $scope, $rootScope, d3, LogicTopologyHelper, Node, Tenant, Ceilometer){
Matteo Scandolo735606c2016-02-09 09:13:30 -080015 $log.info('Logic Plane');
16
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080017 var svg;
18
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080019
20 const handleSvg = (el) => {
21
22 svg = d3.select(el)
23 .append('svg')
24 .style('width', `${el.clientWidth}px`)
25 .style('height', `${el.clientHeight}px`);
26 }
27
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080028 $scope.$watch(() => this.subscribers, (subscribers) => {
29 if(subscribers){
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080030
Matteo Scandolo4aae3aa2016-02-16 16:33:26 -080031 // LogicTopologyHelper.addSubscribers(angular.copy(subscribers));
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080032
Matteo Scandolo7fd4d042016-02-16 14:44:51 -080033 Node.queryWithInstances().$promise
34 .then((computeNodes) => {
35 LogicTopologyHelper.addComputeNodes(computeNodes);
36 LogicTopologyHelper.updateTree(svg);
37 });
38
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080039 }
40 });
41
42 $scope.$watch(() => this.selected, (selected) => {
43 if(selected){
44 $log.info(`Update logic layer for subscriber ${selected.humanReadableName}`);
45 }
46 });
47
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080048 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080049
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080050 $log.info(`Highlight instance`, service)
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080051
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080052 let param = {
53 'service_vsg': {kind: 'vCPE'},
54 'service_vbng': {kind: 'vBNG'},
55 'service_volt': {kind: 'vOLT'}
56 };
57
58 Tenant.queryVsgInstances(param[service.name]).$promise
59 .then((instances) => {
60 console.log(instances);
61 LogicTopologyHelper.getInstanceStatus(instances);
62 LogicTopologyHelper.updateTree(svg);
63
64 return Ceilometer.getInstancesStats(instances);
65 })
66 .then((stats) => {
67 console.log('stats', stats);
68 })
69 .catch((e) => {
70 throw new Error(e);
71 });
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080072 })
73
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080074 handleSvg($element[0]);
Matteo Scandolo7fd4d042016-02-16 14:44:51 -080075 LogicTopologyHelper.setupTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080076
Matteo Scandolo735606c2016-02-09 09:13:30 -080077 }
78 };
79 });
80})();