blob: 5ca0b30f8f9ad2b3a4aa86f58eae7889140e44b2 [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',
Matteo Scandolodffc1382016-02-22 14:53:44 -080014 controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig){
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 Scandolo7fd4d042016-02-16 14:44:51 -080032 Node.queryWithInstances().$promise
33 .then((computeNodes) => {
34 LogicTopologyHelper.addComputeNodes(computeNodes);
35 LogicTopologyHelper.updateTree(svg);
36 });
37
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080038 }
39 });
40
41 $scope.$watch(() => this.selected, (selected) => {
42 if(selected){
43 $log.info(`Update logic layer for subscriber ${selected.humanReadableName}`);
Matteo Scandolodffc1382016-02-22 14:53:44 -080044
45 // append the device with to config settings
46 serviceTopologyConfig.elWidths.push(160);
47
48 LogicTopologyHelper.addSubscriber(angular.copy(selected));
49
50 Tenant.getSubscriberTag({subscriber_root: selected.id}).$promise
51 .then((tags) => {
52 LogicTopologyHelper.addSubscriberTag(tags);
53 LogicTopologyHelper.updateTree(svg);
54 })
Matteo Scandoloeeb9c082016-02-09 11:19:22 -080055 }
56 });
57
Matteo Scandoloc303fd02016-02-17 15:11:33 -080058 $rootScope.$on('instance.detail.hide', () => {
59 this.hideInstanceStats = true;
60 $timeout(() => {
61 this.selectedInstances = [];
62 LogicTopologyHelper.getInstanceStatus([]);
63 LogicTopologyHelper.updateTree(svg);
64 }, 500);
65 });
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080066
Matteo Scandoloc303fd02016-02-17 15:11:33 -080067 $rootScope.$on('instance.detail', (evt, service) => {
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -080068
Matteo Scandolodffc1382016-02-22 14:53:44 -080069 // NOTE consider if subscriber is selected or not,
70 // if not select instances
71 // else select containers (and follow subscriber chain to find the correct instance)
72
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080073 let param = {
74 'service_vsg': {kind: 'vCPE'},
75 'service_vbng': {kind: 'vBNG'},
76 'service_volt': {kind: 'vOLT'}
77 };
78
79 Tenant.queryVsgInstances(param[service.name]).$promise
80 .then((instances) => {
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080081
82 return Ceilometer.getInstancesStats(instances);
83 })
Matteo Scandoloc303fd02016-02-17 15:11:33 -080084 .then((instances) => {
Matteo Scandolodffc1382016-02-22 14:53:44 -080085 console.log(instances);
Matteo Scandoloc303fd02016-02-17 15:11:33 -080086 this.hideInstanceStats = false;
87 // HACK if array is empty wait for animation
88 if(instances.length === 0){
89 this.hideInstanceStats = true;
90 $timeout(() => {
91 this.selectedInstances = instances;
92 }, 500);
93 }
94 else{
95 this.selectedInstances = instances;
96 }
97
98 LogicTopologyHelper.getInstanceStatus(instances);
99 LogicTopologyHelper.updateTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -0800100 })
101 .catch((e) => {
102 throw new Error(e);
103 });
Matteo Scandoloedd3d6f2016-02-16 15:06:11 -0800104 })
105
Matteo Scandoloeeb9c082016-02-09 11:19:22 -0800106 handleSvg($element[0]);
Matteo Scandolo7fd4d042016-02-16 14:44:51 -0800107 LogicTopologyHelper.setupTree(svg);
Matteo Scandoloba2d63d2016-02-17 13:54:11 -0800108
Matteo Scandolocc8fa152016-02-22 09:57:55 -0800109 this.openSubscriberModal = () => {
110 this.subscriberModal = true;
111 $scope.$apply();
112 };
113
Matteo Scandolocc8fa152016-02-22 09:57:55 -0800114 // listen for subscriber modal event
115 $rootScope.$on('subscriber.modal.open', () => {
116 this.openSubscriberModal();
117 });
118
Matteo Scandolo735606c2016-02-09 09:13:30 -0800119 }
120 };
121 });
122})();