Add container directive

Change-Id: I60c86f468248054149ee9b66828ccf72c3094b0b
This commit is contained in:
Vincent Fournier 2015-08-14 14:35:04 -04:00
parent e26236ac74
commit 547da5b17c
37 changed files with 225 additions and 171 deletions

View File

@ -11,8 +11,6 @@ angular.module('bansho', [
'bansho.surveil',
'bansho.datasource',
'bansho.directive',
'bansho.host',
'bansho.service',
'bansho.drupal',
'bansho.drupal.tile',
'bansho.drupal.info',

View File

@ -2,7 +2,7 @@
"env": "production",
"username":"",
"password":"",
"useStoredConfig": true,
"useStoredConfig": false,
"surveilApiUrl": "surveil/v2",
"surveilAuthUrl": "surveil/v2/auth",
"refreshInterval": -1

View File

@ -620,7 +620,7 @@
"type": "panel",
"components": [
{
"type": "host",
"type": "container",
"components": [
{
"type": "host-main",
@ -663,7 +663,7 @@
"type": "panel",
"components": [
{
"type": "service",
"type": "container",
"components": [
{
"type": "service-main",

View File

@ -0,0 +1,90 @@
'use strict';
angular.module('bansho.container', [])
.directive('banshoContainer', function () {
return {
restrict: 'E',
scope: {
options: '='
},
templateUrl: 'components/directive/container/container.html',
controller: ['$scope', 'templateManager', 'surveilStatus', 'surveilConfig', 'iframeUrl',
function ($scope, templateManager, surveilStatus, surveilConfig, iframeUrl) {
$scope.param = {
//host: {}
};
$scope.addDirectiveParamRequirements = function (param) {
if ($scope.param[param] === undefined) {
fillParams[param]();
}
};
var fillParams = {
"configHost": function () {
surveilConfig.getHost(templateManager.getPageParam('host_name'))
.then(function (data) {
$scope.param.configHost = data[0];
});
},
"command": function () {
surveilConfig.getCommand(templateManager.getPageParam('command_name'))
.then(function (data) {
$scope.param.command = data[0];
});
},
"host": function () {
var hostname = templateManager.getPageParam('host_name');
surveilStatus.getHost(templateManager.getPageParam('host_name')).then(function (data) {
surveilStatus.getService(templateManager.getPageParam('host_name')).then(function (services) {
$scope.param.host = data[0];
$scope.param.host.services = [];
angular.forEach(services, function (service) {
if (service.service_description === 'cpu') {
$scope.param.host.cpu = service;
} else if (service.service_description === 'load') {
$scope.param.host.load = service;
$scope.param.host.load.iframeUrl = iframeUrl.getIFrameUrl("metric_load1", hostname, "load");
} else {
$scope.param.host.services.push(service);
}
});
});
});
},
"hostMetrics": function () {
var hostname = templateManager.getPageParam('host_name');
surveilStatus.getHostMetricNames(hostname).then(function (metrics) {
$scope.param.host.metrics = metrics;
angular.forEach(metrics, function (metric) {
surveilStatus.getHostMetric(hostname, metric).then(function (data) {
// TODO: waiting for ORBER BY DESC support in InfluxDB
});
});
});
},
"service": function () {
var hostname = templateManager.getPageParam('host_name'),
serviceDescription = templateManager.getPageParam('service_description');
surveilStatus.getService(hostname, serviceDescription).then(function (data) {
$scope.param.service = data[0];
surveilStatus.getServiceMetricNames(hostname, serviceDescription).then(function(metric_names) {
$scope.param.service.iframeUrls = {};
angular.forEach(metric_names, function (metricName) {
$scope.param.service.iframeUrls[metricName] = iframeUrl.getIFrameUrl("metric_" + metricName, hostname, serviceDescription);
surveilStatus.getServiceMetric(hostname, serviceDescription).then(function(data) {
// TODO: waiting for ORBER BY DESC support in InfluxDB
});
});
});
});
}
};
$scope.components = $scope.options.components;
}]
};
});

View File

@ -1,12 +1,13 @@
'use strict';
angular.module('bansho.host')
angular.module('bansho.container')
.directive('banshoHostCpu', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/host/host_cpu/host_cpu.html',
templateUrl: 'components/directive/container/host_cpu/host_cpu.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('host');
}
};
});

View File

@ -0,0 +1,13 @@
'use strict';
angular.module('bansho.container')
.directive('banshoHostLive', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/container/host_live/host_live.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('host');
}
};
});

View File

@ -1,12 +1,13 @@
'use strict';
angular.module('bansho.host')
angular.module('bansho.container')
.directive('banshoHostLoad', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/host/host_load/host_load.html',
templateUrl: 'components/directive/container/host_load/host_load.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('host');
}
};
});

View File

@ -1,12 +1,13 @@
'use strict';
angular.module('bansho.host')
angular.module('bansho.container')
.directive('banshoHostMain', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/host/host_main/host_main.html',
templateUrl: 'components/directive/container/host_main/host_main.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('host');
}
};
});

View File

@ -1,12 +1,13 @@
'use strict';
angular.module('bansho.host')
angular.module('bansho.container')
.directive('banshoHostServicesList', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/host/host_services_list/host_services_list.html',
templateUrl: 'components/directive/container/host_services_list/host_services_list.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('host');
}
};
});

View File

@ -0,0 +1,13 @@
<span data-ng-repeat="(key, datamodel) in datamodels">
<div data-ng-show="param[datamodel]" class="subcomponent__live">
<h2>{{key}}</h2>
<table class="data-table">
<tbody data-ng-repeat="(key, value) in param[datamodel]">
<tr>
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
</tbody>
</table>
</div>
</span>

View File

@ -1,10 +1,10 @@
'use strict';
angular.module('bansho.info', [])
angular.module('bansho.container')
.directive('banshoInfo', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/info/info.html',
templateUrl: 'components/directive/container/info/info.html',
link: function (scope) {
scope.param = scope.$parent.param;
angular.forEach(scope.components, function(component) {
@ -12,6 +12,10 @@ angular.module('bansho.info', [])
scope.datamodels = component.attributes.datamodel;
}
});
angular.forEach(scope.datamodels, function (datamodel) {
scope.$parent.addDirectiveParamRequirements(datamodel);
});
}
};
});

View File

@ -0,0 +1,13 @@
'use strict';
angular.module('bansho.container')
.directive('banshoServiceGraphs', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/container/service_graphs/service_graphs.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('service');
}
};
});

View File

@ -0,0 +1,13 @@
'use strict';
angular.module('bansho.container')
.directive('banshoServiceInfo', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/container/service_info/service_info.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('service');
}
};
});

View File

@ -0,0 +1,13 @@
'use strict';
angular.module('bansho.container')
.directive('banshoServiceLive', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/container/service_live/service_live.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('service');
}
};
});

View File

@ -1,12 +1,13 @@
'use strict';
angular.module('bansho.service')
angular.module('bansho.container')
.directive('banshoServiceMain', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/service/service_main/service_main.html',
templateUrl: 'components/directive/container/service_main/service_main.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('service');
}
};
});

View File

@ -1,12 +1,13 @@
'use strict';
angular.module('bansho.service.metrics', [])
angular.module('bansho.container')
.directive('banshoServiceMetrics', function () {
return {
restrict: 'E',
templateUrl: 'components/service/service_metrics/service_metrics.html',
templateUrl: 'components/directive/container/service_metrics/service_metrics.html',
link: function (scope) {
scope.param = scope.$parent.param;
scope.$parent.addDirectiveParamRequirements('service');
}
};
});

View File

@ -2,10 +2,8 @@
angular.module('bansho.directive', [
'bansho.actionbar',
'bansho.host',
'bansho.container',
'bansho.hostTree',
'bansho.info',
'bansho.service',
'bansho.table',
'bansho.tabpanel',
'bansho.tactical',

View File

@ -1,55 +0,0 @@
'use strict';
angular.module('bansho.host', ['bansho.datasource'])
.directive('banshoHost', function () {
return {
restrict: 'E',
scope: {
options: '='
},
templateUrl: 'components/directive/host/host.html',
controller: ['$scope', 'templateManager', 'surveilStatus', 'surveilConfig', 'iframeUrl',
function ($scope, templateManager, surveilStatus, surveilConfig, iframeUrl) {
var hostname = templateManager.getPageParam('host_name');
$scope.param = {
host: {},
configHost: {}
};
surveilConfig.getHost(hostname).then(function (data) {
$scope.param.configHost = data[0];
});
surveilStatus.getHost(hostname).then(function (data) {
surveilStatus.getService(hostname).then(function(services) {
$scope.param.host = data[0];
$scope.param.host.services = [];
angular.forEach(services, function (service) {
if (service.service_description === 'cpu') {
$scope.param.host.cpu = service;
} else if (service.service_description === 'load') {
$scope.param.host.load = service;
$scope.param.host.load.iframeUrl = iframeUrl.getIFrameUrl("metric_load1", hostname, "load");
} else {
$scope.param.host.services.push(service);
}
});
});
});
surveilStatus.getHostMetricNames(hostname).then(function(metrics) {
$scope.param.host.metrics = metrics;
angular.forEach(metrics, function (metric) {
surveilStatus.getHostMetric(hostname, metric).then(function(data) {
// TODO: waiting for ORBER BY DESC support in InfluxDB
});
});
});
$scope.components = $scope.options.components;
}]
};
});

View File

@ -1,12 +0,0 @@
'use strict';
angular.module('bansho.host')
.directive('banshoHostLive', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/host/host_live/host_live.html',
link: function ($scope) {
$scope.param = $scope.$parent.param;
}
};
});

View File

@ -1,11 +0,0 @@
<div class="subcomponent__live" data-ng-repeat="(key, datamodel) in datamodels">
<h2>{{key}}</h2>
<table class="data-table" >
<tbody data-ng-repeat="(key, value) in param[datamodel]">
<tr>
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
</tbody>
</table>
</div>

View File

@ -15,18 +15,6 @@ angular.module('bansho.service', ['bansho.datasource'])
serviceDescription = templateManager.getPageParam('service_description');
$scope.param = {};
surveilStatus.getService(hostname, serviceDescription).then(function (data) {
$scope.param.service = data[0];
surveilStatus.getServiceMetricNames(hostname, serviceDescription).then(function(metric_names) {
$scope.param.service.iframeUrls = {};
angular.forEach(metric_names, function (metricName) {
$scope.param.service.iframeUrls[metricName] = iframeUrl.getIFrameUrl("metric_" + metricName, hostname, serviceDescription);
surveilStatus.getServiceMetric(hostname, serviceDescription, metricName).then(function(data) {
// TODO: waiting for ORBER BY DESC support in InfluxDB
});
});
});
});
$scope.components = $scope.options.components;
}]
};

View File

@ -1,9 +0,0 @@
'use strict';
angular.module('bansho.service')
.directive('banshoServiceGraphs', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/service/service_graphs/service_graphs.html'
};
});

View File

@ -1,9 +0,0 @@
'use strict';
angular.module('bansho.service')
.directive('banshoServiceInfo', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/service/service_info/service_info.html'
};
});

View File

@ -1,9 +0,0 @@
'use strict';
angular.module('bansho.service')
.directive('banshoServiceLive', function () {
return {
restrict: 'E',
templateUrl: 'components/directive/service/service_live/service_live.html'
};
});

View File

@ -18,37 +18,40 @@ angular.module('bansho.surveil')
var getData = function (fields, filters, endpoint, paging) {
var promise = $q.defer();
if (!queryEndpoint[endpoint]) {
if (!validEndpoint[endpoint]) {
throw new Error('getData in surveilConfig : Invalid endpoint ' + endpoint);
}
queryEndpoint[endpoint](fields, filters, paging, function (data) {
queryEndpoint(endpoint, fields, filters, paging, function (data) {
promise.resolve(data);
});
return promise.promise;
};
var queryEndpoint = {
"hosts": function (fields, filters, paging, callback) {
var hostQuery = surveilQuery(fields, filters.hosts, paging),
method = 'POST',
hostUrl = surveilApiConfig.endpoint('config') + '/hosts/';
executeQuery(hostUrl, method, hostQuery)
.success(function (hosts) {
var response = [];
angular.forEach(hosts, function (host) {
response.push(host);
});
callback(response);
});
}
var validEndpoint = {
"hosts": true,
"commands": true
};
var queryEndpoint = function (endpoint, fields, filters, paging, callback) {
var query = surveilQuery(fields, filters[endpoint], paging),
method = 'POST',
url = surveilApiConfig.endpoint('config') + '/' + endpoint + '/';
executeQuery(url, method, query)
.success(function (data) {
var response = [];
angular.forEach(data, function (obj) {
response.push(obj);
});
callback(response);
});
};
return {
getData: getData,
getHost: function (hostname) {
@ -59,5 +62,13 @@ angular.module('bansho.surveil')
});
return promise.promise;
},
getCommand: function (commandName) {
var promise = $q.defer(), query = {"commands": {"is": {"command_name": [ commandName ] } } };
getData([], query, "commands")
.then(function (data) {
promise.resolve(data);
});
return promise.promise;
}
};
}]);

View File

@ -72,6 +72,7 @@
<!-- Table components -->
<script src="components/directive/container/container.js"></script>
<script src="components/directive/actionbar/actionbar.js"></script>
<script src="components/directive/actionbar/component_acknowledge/acknowledge.js"></script>
<script src="components/directive/actionbar/component_downtime/downtime.js"></script>
@ -79,7 +80,7 @@
<script src="components/directive/actionbar/component_more/more.js"></script>
<script src="components/directive/actionbar/component_recheck/recheck.js"></script>
<script src="components/directive/actionbar/component_search_filter/search_filter.js"></script>
<script src="components/directive/info/info.js"></script>
<script src="components/directive/container/info/info.js"></script>
<script src="components/directive/table/table.js"></script>
<script src="components/directive/table/pagingbar/pagingbar.js"></script>
<script src="components/directive/table/cell_status_duration/cell_status_duration.js"></script>
@ -105,19 +106,17 @@
<script src="components/directive/state_icon/state_icon.js"></script>
<script src="components/grafana/grafana.js"></script>
<script src="components/directive/host/host.js"></script>
<script src="components/directive/host/host_cpu/host_cpu.js"></script>
<script src="components/directive/host/host_load/host_load.js"></script>
<script src="components/directive/host/host_main/host_main.js"></script>
<script src="components/directive/host/host_live/host_live.js"></script>
<script src="components/directive/host/host_services_list/host_services_list.js"></script>
<script src="components/directive/container/host_cpu/host_cpu.js"></script>
<script src="components/directive/container/host_load/host_load.js"></script>
<script src="components/directive/container/host_main/host_main.js"></script>
<script src="components/directive/container/host_live/host_live.js"></script>
<script src="components/directive/container/host_services_list/host_services_list.js"></script>
<script src="components/directive/hostTree/hostTree.js"></script>
<script src="components/directive/service/service.js"></script>
<script src="components/directive/service/service_main/service_main.js"></script>
<script src="components/directive/service/service_live/service_live.js"></script>
<script src="components/directive/service/service_info/service_info.js"></script>
<script src="components/directive/service/service_graphs/service_graphs.js"></script>
<script src="components/directive/service/service_metrics/service_metrics.js"></script>
<script src="components/directive/container/service_main/service_main.js"></script>
<script src="components/directive/container/service_live/service_live.js"></script>
<script src="components/directive/container/service_info/service_info.js"></script>
<script src="components/directive/container/service_graphs/service_graphs.js"></script>
<script src="components/directive/container/service_metrics/service_metrics.js"></script>
<script src="components/drupal/drupal.js"></script>
<script src="components/drupal/drupal_tile/drupal_tile.js"></script>
<script src="components/drupal/drupal_info/drupal_info.js"></script>