Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 19 | (function () { |
| 20 | 'use strict'; |
| 21 | |
Matteo Scandolo | 0456495 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 22 | angular.module('xos.diagnostic') |
Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 23 | .service('Services', function($resource){ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 24 | return $resource('/api/core/services/:id', {id: '@id'}); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 25 | }) |
| 26 | .service('Tenant', function($resource){ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 27 | return $resource('/api/core/tenants', {id: '@id'}, { |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 28 | queryVsgInstances: { |
| 29 | method: 'GET', |
| 30 | isArray: true, |
| 31 | interceptor: { |
| 32 | response: (res) => { |
| 33 | |
| 34 | // NOTE |
| 35 | // Note that VCPETenant is now VSGTenant. |
| 36 | |
| 37 | let instances = []; |
| 38 | |
| 39 | angular.forEach(res.data, (tenant) => { |
| 40 | let info = JSON.parse(tenant.service_specific_attribute); |
| 41 | if(info && info.instance_id){ |
| 42 | instances.push(info.instance_id); |
| 43 | } |
| 44 | }); |
| 45 | |
| 46 | return instances; |
| 47 | } |
| 48 | } |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 49 | }, |
| 50 | getSubscriberTag: { |
| 51 | method: 'GET', |
| 52 | isArray: true, |
| 53 | interceptor: { |
| 54 | response: (res) => { |
| 55 | // NOTE we should receive only one vOLT tenant here |
| 56 | return JSON.parse(res.data[0].service_specific_attribute); |
| 57 | } |
| 58 | } |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 59 | } |
| 60 | }); |
| 61 | }) |
| 62 | .service('Ceilometer', function($http, $q, Instances) { |
| 63 | |
| 64 | /** |
| 65 | * Get stats for a single instance |
| 66 | */ |
| 67 | this.getInstanceStats = (instanceUuid) => { |
| 68 | let deferred = $q.defer(); |
| 69 | |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 70 | $http.get('/xoslib/xos-instance-statistics', {params: {'instance-uuid': instanceUuid}}) |
Matteo Scandolo | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 71 | .then((res) => { |
| 72 | deferred.resolve(res.data); |
| 73 | }) |
| 74 | .catch((e) => { |
| 75 | deferred.reject(e); |
| 76 | }) |
| 77 | |
| 78 | return deferred.promise; |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * Collect stats for an array of instances |
| 83 | */ |
| 84 | this.getInstancesStats = (instances) => { |
| 85 | let deferred = $q.defer(); |
| 86 | let instancePromises = []; |
| 87 | let instanceList = []; |
| 88 | |
| 89 | // retrieve instance details |
| 90 | instances.forEach((instanceId) => { |
| 91 | instancePromises.push(Instances.get({id: instanceId}).$promise); |
| 92 | }); |
| 93 | |
| 94 | // get all instance data |
| 95 | $q.all(instancePromises) |
| 96 | .then((_instanceList) => { |
| 97 | instanceList = _instanceList; |
| 98 | let promises = []; |
| 99 | // foreach instance query stats |
| 100 | instanceList.forEach((instance) => { |
| 101 | promises.push(this.getInstanceStats(instance.instance_uuid)); |
| 102 | }); |
| 103 | return $q.all(promises); |
| 104 | }) |
| 105 | .then(stats => { |
| 106 | // augment instance with stats information |
| 107 | instanceList.map((instance, i) => { |
| 108 | instance.stats = stats[i]; |
| 109 | }); |
| 110 | deferred.resolve(instanceList); |
| 111 | }) |
| 112 | .catch(deferred.reject); |
| 113 | |
| 114 | return deferred.promise; |
| 115 | }; |
Matteo Scandolo | f0d6e69 | 2016-02-24 11:14:01 -0800 | [diff] [blame] | 116 | |
| 117 | this.getContainerStats = (containerName) => { |
| 118 | const deferred = $q.defer(); |
| 119 | |
| 120 | let res = {}; |
| 121 | |
| 122 | $http.get('/xoslib/meterstatistics', {params: {'resource': containerName}}) |
| 123 | .then((containerStats) => { |
| 124 | res.stats = containerStats.data; |
| 125 | return $http.get('/xoslib/meterstatistics', {params: {'resource': `${containerName}-eth0`}}) |
| 126 | }) |
| 127 | .then((portStats) => { |
| 128 | res.port = { |
| 129 | eth0: portStats.data |
| 130 | }; |
| 131 | return $http.get('/xoslib/meterstatistics', {params: {'resource': `${containerName}-eth1`}}) |
| 132 | }) |
| 133 | .then((portStats) => { |
| 134 | res.port.eth1 = portStats.data; |
| 135 | deferred.resolve(res); |
| 136 | }) |
| 137 | .catch((e) => { |
| 138 | deferred.reject(e); |
| 139 | }) |
| 140 | |
| 141 | return deferred.promise; |
| 142 | } |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 143 | }) |
Matteo Scandolo | 06f45d6 | 2016-01-21 15:38:06 -0800 | [diff] [blame] | 144 | .service('Slice', function($resource){ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 145 | return $resource('/api/core/slices', {id: '@id'}); |
Matteo Scandolo | 06f45d6 | 2016-01-21 15:38:06 -0800 | [diff] [blame] | 146 | }) |
| 147 | .service('Instances', function($resource){ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 148 | return $resource('/api/core/instances/:id', {id: '@id'}); |
Matteo Scandolo | 170d3be | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 149 | }) |
| 150 | .service('Node', function($resource, $q, Instances){ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 151 | return $resource('/api/core/nodes', {id: '@id'}, { |
Matteo Scandolo | 170d3be | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 152 | queryWithInstances: { |
| 153 | method: 'GET', |
| 154 | isArray: true, |
| 155 | interceptor: { |
| 156 | response: function(res){ |
| 157 | |
| 158 | // TODO update the API to include instances in nodes |
| 159 | // http://stackoverflow.com/questions/14573102/how-do-i-include-related-model-fields-using-django-rest-framework |
| 160 | |
| 161 | const deferred = $q.defer(); |
| 162 | |
| 163 | let requests = []; |
| 164 | |
| 165 | angular.forEach(res.data, (node) => { |
| 166 | requests.push(Instances.query({node: node.id}).$promise); |
| 167 | }) |
| 168 | |
| 169 | $q.all(requests) |
| 170 | .then((list) => { |
| 171 | res.data.map((node, i) => { |
| 172 | node.instances = list[i]; |
| 173 | return node; |
| 174 | }); |
Matteo Scandolo | 170d3be | 2016-02-11 08:58:04 -0800 | [diff] [blame] | 175 | deferred.resolve(res.data); |
| 176 | }) |
| 177 | |
| 178 | return deferred.promise; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | }); |
Matteo Scandolo | 06f45d6 | 2016-01-21 15:38:06 -0800 | [diff] [blame] | 183 | }) |
Matteo Scandolo | e64dcc0 | 2016-08-02 11:53:22 -0700 | [diff] [blame] | 184 | // TODO extend the resource in xosLib |
| 185 | .service('SubscribersWithDevice', function($http, $q, Subscribers){ |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 186 | |
Matteo Scandolo | e64dcc0 | 2016-08-02 11:53:22 -0700 | [diff] [blame] | 187 | this.get = (s) => { |
| 188 | const d = $q.defer(); |
| 189 | let subscriber; |
Matteo Scandolo | 219b1a7 | 2016-02-09 11:19:22 -0800 | [diff] [blame] | 190 | |
Matteo Scandolo | e64dcc0 | 2016-08-02 11:53:22 -0700 | [diff] [blame] | 191 | Subscribers.get({id: s.id}).$promise |
| 192 | .then(res => { |
| 193 | subscriber = res; |
| 194 | return $http.get(`/api/tenant/cord/subscriber/${subscriber.id}/devices/`); |
| 195 | }) |
| 196 | .then(res => { |
| 197 | res.data.map(d => d.type = 'device'); |
| 198 | subscriber.devices = res.data; |
| 199 | subscriber.type = 'subscriber'; |
| 200 | d.resolve(subscriber); |
| 201 | }) |
| 202 | .catch(err => { |
| 203 | d.reject(err); |
| 204 | }); |
| 205 | return {$promise: d.promise}; |
| 206 | }; |
Matteo Scandolo | 7547f04 | 2016-02-09 09:13:30 -0800 | [diff] [blame] | 207 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 208 | }) |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 209 | .service('ServiceRelation', function($q, _, Services, Tenant, Slice, Instances){ |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 210 | |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 211 | // count the mas depth of an object |
| 212 | const depthOf = (obj) => { |
| 213 | var depth = 0; |
| 214 | if (obj.children) { |
| 215 | obj.children.forEach(function (d) { |
| 216 | var tmpDepth = depthOf(d); |
| 217 | if (tmpDepth > depth) { |
| 218 | depth = tmpDepth |
| 219 | } |
| 220 | }) |
| 221 | } |
| 222 | return 1 + depth |
| 223 | }; |
| 224 | |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 225 | // find all the relation defined for a given root |
| 226 | const findLevelRelation = (tenants, rootId) => { |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 227 | return _.filter(tenants, service => { |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 228 | return service.subscriber_service === rootId; |
| 229 | }); |
| 230 | }; |
| 231 | |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 232 | const findSpecificInformation = (tenants, rootId) => { |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 233 | var tenants = _.filter(tenants, service => { |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 234 | return service.provider_service === rootId && service.subscriber_tenant; |
| 235 | }); |
| 236 | |
| 237 | var info; |
| 238 | |
| 239 | tenants.forEach((tenant) => { |
| 240 | if(tenant.service_specific_attribute){ |
| 241 | info = JSON.parse(tenant.service_specific_attribute); |
| 242 | } |
| 243 | }); |
| 244 | |
| 245 | return info; |
| 246 | }; |
| 247 | |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 248 | // find all the service defined by a given array of relations |
| 249 | const findLevelServices = (relations, services) => { |
| 250 | const levelServices = []; |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 251 | _.forEach(relations, (tenant) => { |
| 252 | var service = _.find(services, {id: tenant.provider_service}); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 253 | levelServices.push(service); |
| 254 | }); |
| 255 | return levelServices; |
| 256 | }; |
| 257 | |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 258 | const buildLevel = (tenants, services, rootService, rootTenant, parentName = null) => { |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 259 | |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 260 | // build an array of unlinked services |
| 261 | // these are the services that should still placed in the tree |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 262 | var unlinkedServices = _.difference(services, [rootService]); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 263 | |
| 264 | // find all relations relative to this rootElement |
| 265 | const levelRelation = findLevelRelation(tenants, rootService.id); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 266 | // find all items related to rootElement |
| 267 | const levelServices = findLevelServices(levelRelation, services); |
| 268 | |
| 269 | // remove this item from the list (performance |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 270 | unlinkedServices = _.difference(unlinkedServices, levelServices); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 271 | |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 272 | rootService.service_specific_attribute = findSpecificInformation(tenants, rootService.id); |
| 273 | |
Matteo Scandolo | 384ff56 | 2016-03-07 17:58:34 -0800 | [diff] [blame] | 274 | if(rootService.humanReadableName === 'service_vbng'){ |
| 275 | rootService.humanReadableName = 'service_vrouter' |
| 276 | } |
| 277 | |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 278 | const tree = { |
| 279 | name: rootService.humanReadableName, |
| 280 | parent: parentName, |
| 281 | type: 'service', |
| 282 | service: rootService, |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 283 | tenant: rootTenant, |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 284 | children: [] |
| 285 | }; |
| 286 | |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 287 | _.forEach(levelServices, (service) => { |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 288 | if(service.humanReadableName === 'service_ONOS_vBNG' || service.humanReadableName === 'service_ONOS_vOLT'){ |
| 289 | // remove ONOSes from service chart |
| 290 | return; |
| 291 | } |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 292 | let tenant = _.find(tenants, {subscriber_tenant: rootTenant.id, provider_service: service.id}); |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 293 | tree.children.push(buildLevel(tenants, unlinkedServices, service, tenant, rootService.humanReadableName)); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 294 | }); |
| 295 | |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 296 | // if it is the last element append internet |
| 297 | if(tree.children.length === 0){ |
| 298 | tree.children.push({ |
Matteo Scandolo | 9fe01af | 2016-02-09 16:01:49 -0800 | [diff] [blame] | 299 | name: 'Router', |
| 300 | type: 'router', |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 301 | children: [] |
| 302 | }); |
| 303 | } |
| 304 | |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 305 | return tree; |
| 306 | }; |
| 307 | |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 308 | const buildSubscriberServiceTree = (services, tenants, subscriber = {id: 1, name: 'fakeSubs'}) => { |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 309 | |
| 310 | // find the root service |
| 311 | // it is the one attached to subsriber_root |
| 312 | // as now we have only one root so this can work |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 313 | const rootTenant = _.find(tenants, {subscriber_root: subscriber.id}); |
| 314 | const rootService = _.find(services, {id: rootTenant.provider_service}); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 315 | |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 316 | const serviceTree = buildLevel(tenants, services, rootService, rootTenant); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 317 | |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 318 | return { |
Matteo Scandolo | d4ea877 | 2016-03-01 15:20:29 -0800 | [diff] [blame] | 319 | name: subscriber.name || subscriber.humanReadableName, |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 320 | parent: null, |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 321 | type: 'subscriber', |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 322 | children: [serviceTree] |
| 323 | }; |
| 324 | |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 325 | }; |
| 326 | |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 327 | // applying domain knowledge to build the global service tree |
| 328 | const buildServiceTree = (services, tenants) => { |
| 329 | |
| 330 | // TODO refactor |
| 331 | const buildChild = (services, tenants, currentService) => { |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 332 | |
Matteo Scandolo | 384ff56 | 2016-03-07 17:58:34 -0800 | [diff] [blame] | 333 | if(currentService.humanReadableName === 'service_vbng'){ |
| 334 | currentService.humanReadableName = 'service_vrouter' |
| 335 | } |
| 336 | |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 337 | const response = { |
| 338 | type: 'service', |
| 339 | name: currentService.humanReadableName, |
| 340 | service: currentService |
| 341 | }; |
| 342 | |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 343 | let tenant = _.find(tenants, {subscriber_service: currentService.id}); |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 344 | if(tenant){ |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 345 | let next = _.find(services, {id: tenant.provider_service}); |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 346 | response.children = [buildChild(services, tenants, next)]; |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 347 | } |
| 348 | else { |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 349 | response.children = [ |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 350 | { |
| 351 | name: 'Router', |
| 352 | type: 'router', |
| 353 | children: [] |
| 354 | } |
| 355 | ] |
| 356 | } |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 357 | delete currentService.id; // conflict with d3 |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 358 | return response; |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 359 | } |
Matteo Scandolo | 70ac216 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 360 | |
Matteo Scandolo | fe307b1 | 2016-05-17 14:29:01 -0700 | [diff] [blame] | 361 | let baseService = _.find(services, {id: 3}); |
Matteo Scandolo | 70ac216 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 362 | |
| 363 | if(!angular.isDefined(baseService)){ |
| 364 | console.error('Missing Base service!'); |
| 365 | return; |
| 366 | } |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 367 | |
| 368 | const baseData = { |
| 369 | name: 'Subscriber', |
| 370 | type: 'subscriber', |
| 371 | parent: null, |
| 372 | children: [buildChild(services, tenants, baseService)] |
| 373 | }; |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 374 | return baseData; |
| 375 | }; |
| 376 | |
| 377 | const getBySubscriber = (subscriber) => { |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 378 | var deferred = $q.defer(); |
| 379 | var services, tenants; |
| 380 | Services.query().$promise |
| 381 | .then((res) => { |
| 382 | services = res; |
| 383 | return Tenant.query().$promise; |
| 384 | }) |
| 385 | .then((res) => { |
| 386 | tenants = res; |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 387 | deferred.resolve(buildSubscriberServiceTree(services, tenants, subscriber)); |
Matteo Scandolo | f16b379 | 2016-01-21 14:23:28 -0800 | [diff] [blame] | 388 | }) |
| 389 | .catch((e) => { |
| 390 | throw new Error(e); |
| 391 | }); |
| 392 | |
| 393 | return deferred.promise; |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 394 | }; |
Matteo Scandolo | ff7df76 | 2016-01-22 16:36:34 -0800 | [diff] [blame] | 395 | |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 396 | const get = () => { |
| 397 | var deferred = $q.defer(); |
| 398 | var services, tenants; |
| 399 | Services.query().$promise |
| 400 | .then((res) => { |
| 401 | services = res; |
| 402 | return Tenant.query({kind: 'coarse'}).$promise; |
| 403 | }) |
| 404 | .then((res) => { |
| 405 | tenants = res; |
| 406 | deferred.resolve(buildServiceTree(services, tenants)); |
| 407 | }) |
| 408 | .catch((e) => { |
| 409 | throw new Error(e); |
| 410 | }); |
| 411 | |
| 412 | return deferred.promise; |
| 413 | } |
| 414 | |
Matteo Scandolo | f2c9901 | 2016-01-25 10:10:38 -0800 | [diff] [blame] | 415 | // export APIs |
Matteo Scandolo | 5bf0457 | 2016-01-25 17:36:08 -0800 | [diff] [blame] | 416 | return { |
| 417 | get: get, |
Matteo Scandolo | 5bf0457 | 2016-01-25 17:36:08 -0800 | [diff] [blame] | 418 | buildServiceTree: buildServiceTree, |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 419 | getBySubscriber: getBySubscriber, |
| 420 | buildLevel: buildLevel, |
| 421 | buildSubscriberServiceTree: buildSubscriberServiceTree, |
Matteo Scandolo | 5bf0457 | 2016-01-25 17:36:08 -0800 | [diff] [blame] | 422 | findLevelRelation: findLevelRelation, |
| 423 | findLevelServices: findLevelServices, |
| 424 | depthOf: depthOf, |
Matteo Scandolo | c9ebd92 | 2016-01-28 12:02:57 -0800 | [diff] [blame] | 425 | findSpecificInformation: findSpecificInformation |
Matteo Scandolo | 5bf0457 | 2016-01-25 17:36:08 -0800 | [diff] [blame] | 426 | } |
Matteo Scandolo | 8a64fa4 | 2016-01-21 11:21:03 -0800 | [diff] [blame] | 427 | }); |
| 428 | |
| 429 | }()); |