Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
| 3 | angular.module('xos.serviceTopology') |
| 4 | .directive('logicTopology', function(){ |
| 5 | return { |
| 6 | restrict: 'E', |
| 7 | scope: { |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 8 | subscribers: '=', |
| 9 | selected: '=' |
Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 10 | }, |
| 11 | bindToController: true, |
| 12 | controllerAs: 'vm', |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 13 | templateUrl: 'templates/logicTopology.tpl.html', |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame^] | 14 | controller: function($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig){ |
Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 15 | $log.info('Logic Plane'); |
| 16 | |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 17 | var svg; |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 18 | this.selectedInstances = []; |
| 19 | this.hideInstanceStats = true; |
Matteo Scandolo | 594dfbc | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 20 | |
| 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 Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 29 | $scope.$watch(() => this.subscribers, (subscribers) => { |
| 30 | if(subscribers){ |
Matteo Scandolo | 594dfbc | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 31 | |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 32 | Node.queryWithInstances().$promise |
| 33 | .then((computeNodes) => { |
| 34 | LogicTopologyHelper.addComputeNodes(computeNodes); |
| 35 | LogicTopologyHelper.updateTree(svg); |
| 36 | }); |
| 37 | |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 38 | } |
| 39 | }); |
| 40 | |
| 41 | $scope.$watch(() => this.selected, (selected) => { |
| 42 | if(selected){ |
| 43 | $log.info(`Update logic layer for subscriber ${selected.humanReadableName}`); |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame^] | 44 | |
| 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 Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 55 | } |
| 56 | }); |
| 57 | |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 58 | $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 Scandolo | edd3d6f | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 66 | |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 67 | $rootScope.$on('instance.detail', (evt, service) => { |
Matteo Scandolo | edd3d6f | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 68 | |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame^] | 69 | // 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 Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 73 | 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 Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 81 | |
| 82 | return Ceilometer.getInstancesStats(instances); |
| 83 | }) |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 84 | .then((instances) => { |
Matteo Scandolo | dffc138 | 2016-02-22 14:53:44 -0800 | [diff] [blame^] | 85 | console.log(instances); |
Matteo Scandolo | c303fd0 | 2016-02-17 15:11:33 -0800 | [diff] [blame] | 86 | 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 Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 100 | }) |
| 101 | .catch((e) => { |
| 102 | throw new Error(e); |
| 103 | }); |
Matteo Scandolo | edd3d6f | 2016-02-16 15:06:11 -0800 | [diff] [blame] | 104 | }) |
| 105 | |
Matteo Scandolo | eeb9c08 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 106 | handleSvg($element[0]); |
Matteo Scandolo | 7fd4d04 | 2016-02-16 14:44:51 -0800 | [diff] [blame] | 107 | LogicTopologyHelper.setupTree(svg); |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 108 | |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 109 | this.openSubscriberModal = () => { |
| 110 | this.subscriberModal = true; |
| 111 | $scope.$apply(); |
| 112 | }; |
| 113 | |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 114 | // listen for subscriber modal event |
| 115 | $rootScope.$on('subscriber.modal.open', () => { |
| 116 | this.openSubscriberModal(); |
| 117 | }); |
| 118 | |
Matteo Scandolo | 735606c | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 119 | } |
| 120 | }; |
| 121 | }); |
| 122 | })(); |