blob: da2fef6e50614707222eda84769d1cb4523376fc [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',
Matteo Scandoloc303fd02016-02-17 15:11:33 -080013 templateUrl: 'templates/logicTopology.tpl.html',
14 controller: function($element, $log, $scope, $rootScope, $timeout, 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;
Matteo Scandoloc303fd02016-02-17 15:11:33 -080018 this.selectedInstances = [];
19 this.hideInstanceStats = true;
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080020
21 const handleSvg = (el) => {
22
23 svg = d3.select(el)
24 .append('svg')
25 .style('width', `${el.clientWidth}px`)
26 .style('height', `${el.clientHeight}px`);
27 }
28
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080029 $scope.$watch(() => this.subscribers, (subscribers) => {
30 if(subscribers){
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080031
Matteo Scandolo4aae3aa2016-02-16 16:33:26 -080032 // LogicTopologyHelper.addSubscribers(angular.copy(subscribers));
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080033
Matteo Scandolo7fd4d042016-02-16 14:44:51 -080034 Node.queryWithInstances().$promise
35 .then((computeNodes) => {
36 LogicTopologyHelper.addComputeNodes(computeNodes);
37 LogicTopologyHelper.updateTree(svg);
38 });
39
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080040 }
41 });
42
43 $scope.$watch(() => this.selected, (selected) => {
44 if(selected){
45 $log.info(`Update logic layer for subscriber ${selected.humanReadableName}`);
46 }
47 });
48
Matteo Scandoloc303fd02016-02-17 15:11:33 -080049 $rootScope.$on('instance.detail.hide', () => {
50 this.hideInstanceStats = true;
51 $timeout(() => {
52 this.selectedInstances = [];
53 LogicTopologyHelper.getInstanceStatus([]);
54 LogicTopologyHelper.updateTree(svg);
55 }, 500);
56 });
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080057
Matteo Scandoloc303fd02016-02-17 15:11:33 -080058 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080059
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080060 let param = {
61 'service_vsg': {kind: 'vCPE'},
62 'service_vbng': {kind: 'vBNG'},
63 'service_volt': {kind: 'vOLT'}
64 };
65
66 Tenant.queryVsgInstances(param[service.name]).$promise
67 .then((instances) => {
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080068
69 return Ceilometer.getInstancesStats(instances);
70 })
Matteo Scandoloc303fd02016-02-17 15:11:33 -080071 .then((instances) => {
72 this.hideInstanceStats = false;
73 // HACK if array is empty wait for animation
74 if(instances.length === 0){
75 this.hideInstanceStats = true;
76 $timeout(() => {
77 this.selectedInstances = instances;
78 }, 500);
79 }
80 else{
81 this.selectedInstances = instances;
82 }
83
84 LogicTopologyHelper.getInstanceStatus(instances);
85 LogicTopologyHelper.updateTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080086 })
87 .catch((e) => {
88 throw new Error(e);
89 });
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080090 })
91
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080092 handleSvg($element[0]);
Matteo Scandolo7fd4d042016-02-16 14:44:51 -080093 LogicTopologyHelper.setupTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080094
Matteo Scandolo735606c2016-02-09 09:13:30 -080095 }
96 };
97 });
98})();