Matteo Scandolo | 8942e04 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('autoscaling') |
Matteo Scandolo | 4d7ee39 | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 4 | .service('Autoscaling', function($http, $interval, $rootScope, lodash){ |
Matteo Scandolo | 8942e04 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 5 | |
Matteo Scandolo | 4d7ee39 | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 6 | const pollingFrequency = 10; |
Matteo Scandolo | 8942e04 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 7 | var pollinginterval; |
| 8 | |
Matteo Scandolo | 4d7ee39 | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 9 | /** |
| 10 | * Convert data to a flat array of resources |
| 11 | */ |
| 12 | |
| 13 | this.formatData = (data) => { |
| 14 | const list = []; |
| 15 | // cicle trough all slices |
| 16 | lodash.map(data, (item) => { |
| 17 | // cicle trough every resource |
| 18 | item.resources = lodash.forEach( |
| 19 | Object.keys(item.resources), |
| 20 | (resource) => { |
| 21 | const tmp = item.resources[resource]; |
| 22 | tmp.service = item.service; |
| 23 | tmp.slice = item.slice; |
| 24 | tmp.project_id = item.project_id; |
| 25 | tmp.instance_name = tmp.xos_instance_info.instance_name; |
| 26 | delete tmp.xos_instance_info; |
| 27 | list.push(tmp); |
| 28 | } |
| 29 | ) |
| 30 | }); |
| 31 | return list; |
| 32 | }; |
| 33 | |
Matteo Scandolo | 8942e04 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 34 | this.getAutoscalingData = () => { |
Matteo Scandolo | 4d7ee39 | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 35 | // pollinginterval = $interval(() => { |
| 36 | // $http.get('/autoscaledata') |
| 37 | $http.get('../mocks/mock.json') |
| 38 | .success((res) => { |
| 39 | $rootScope.$emit('autoscaling.update', this.formatData(res)); |
Matteo Scandolo | 8942e04 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 40 | }); |
Matteo Scandolo | 4d7ee39 | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 41 | // }, pollingFrequency * 1000) |
Matteo Scandolo | 8942e04 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 42 | }; |
| 43 | }); |