Formatting data to a flat list
diff --git a/xos-apps/auto-scale/gui/src/js/autoscaling.service.js b/xos-apps/auto-scale/gui/src/js/autoscaling.service.js
index 4146f19..15b9118 100644
--- a/xos-apps/auto-scale/gui/src/js/autoscaling.service.js
+++ b/xos-apps/auto-scale/gui/src/js/autoscaling.service.js
@@ -1,17 +1,43 @@
'use strict';
angular.module('autoscaling')
-.service('Autoscaling', function($http, $interval, $rootScope){
+.service('Autoscaling', function($http, $interval, $rootScope, lodash){
- const pollingFrequency = 1;
+ const pollingFrequency = 10;
var pollinginterval;
+ /**
+ * Convert data to a flat array of resources
+ */
+
+ this.formatData = (data) => {
+ const list = [];
+ // cicle trough all slices
+ lodash.map(data, (item) => {
+ // cicle trough every resource
+ item.resources = lodash.forEach(
+ Object.keys(item.resources),
+ (resource) => {
+ const tmp = item.resources[resource];
+ tmp.service = item.service;
+ tmp.slice = item.slice;
+ tmp.project_id = item.project_id;
+ tmp.instance_name = tmp.xos_instance_info.instance_name;
+ delete tmp.xos_instance_info;
+ list.push(tmp);
+ }
+ )
+ });
+ return list;
+ };
+
this.getAutoscalingData = () => {
- pollinginterval = $interval(() => {
- $http.get('/autoscaledata')
- .then((res) => {
- $rootScope.$emit('autoscaling.update', res.data);
+ // pollinginterval = $interval(() => {
+ // $http.get('/autoscaledata')
+ $http.get('../mocks/mock.json')
+ .success((res) => {
+ $rootScope.$emit('autoscaling.update', this.formatData(res));
});
- }, pollingFrequency * 1000)
+ // }, pollingFrequency * 1000)
};
});
\ No newline at end of file
diff --git a/xos-apps/auto-scale/gui/src/js/autoscaling_details.directive.js b/xos-apps/auto-scale/gui/src/js/autoscaling_details.directive.js
index e4bd9ef..f35508a 100644
--- a/xos-apps/auto-scale/gui/src/js/autoscaling_details.directive.js
+++ b/xos-apps/auto-scale/gui/src/js/autoscaling_details.directive.js
@@ -1,15 +1,40 @@
angular.module('autoscaling')
-.directive('serviceContainer', function(lodash){
+.directive('serviceContainer', function(lodash, Autoscaling){
return {
restrict: 'E',
scope: {},
bindToController: true,
controllerAs: 'vm',
templateUrl: 'templates/service-container.tpl.html',
- controller: ($rootScope) => {
+ controller: function($rootScope) {
+ Autoscaling.getAutoscalingData();
$rootScope.$on('autoscaling.update', (evt, data) => {
- console.log(data);
+ this.printData(data);
});
+
+ /**
+ * Group resources by service and slice
+ */
+
+ this.printData = (data) => {
+ this.services = lodash.groupBy(data, 'service');
+ lodash.forEach(Object.keys(this.services), (service) => {
+ this.services[service] = lodash.groupBy(this.services[service], 'slice');
+ lodash.forEach(Object.keys(this.services[service]), (slice) => {
+ // grouping instance by name
+ this.services[service][slice] = lodash.groupBy(this.services[service][slice], 'instance_name');
+ // instance can't have the same name,
+ // so take them out of an array
+ // and keep only the sample data
+ lodash.forEach(Object.keys(this.services[service][slice]), (instance) => {
+ // console.log(this.services[service][slice][instance]);
+ this.services[service][slice][instance] = this.services[service][slice][instance][0].queue;
+ });
+
+ })
+ });
+ console.log(this.services);
+ };
}
};
});
diff --git a/xos-apps/auto-scale/gui/src/js/main.js b/xos-apps/auto-scale/gui/src/js/main.js
index 665aafe..468f355 100644
--- a/xos-apps/auto-scale/gui/src/js/main.js
+++ b/xos-apps/auto-scale/gui/src/js/main.js
@@ -6,10 +6,6 @@
'ngAnimate',
'chart.js'
])
-.run((Autoscaling) => {
- // start polling data
- Autoscaling.getAutoscalingData();
-})
.config(($stateProvider, $urlRouterProvider) => {
$stateProvider
.state('ceilometerDashboard', {