fix(services): Fix invalid replica count for global services (#1353)

pull/1360/head
Thomas Krzero 2017-11-06 15:50:59 +01:00 committed by Anthony Lapenna
parent 407f0f5807
commit b9e535d7a5
2 changed files with 9 additions and 6 deletions

View File

@ -97,19 +97,22 @@ function ($q, $scope, $transition$, $state, Service, ServiceService, ServiceHelp
$('#loadServicesSpinner').show();
$q.all({
services: Service.query({}).$promise,
tasks: Task.query({filters: {'desired-state': ['running']}}).$promise,
tasks: Task.query({filters: {'desired-state': ['running','accepted']}}).$promise,
nodes: Node.query({}).$promise
})
.then(function success(data) {
$scope.swarmManagerIP = NodeHelper.getManagerIP(data.nodes);
$scope.services = data.services.map(function (service) {
var serviceTasks = data.tasks.filter(function (task) {
var runningTasks = data.tasks.filter(function (task) {
return task.ServiceID === service.ID && task.Status.State === 'running';
});
var allTasks = data.tasks.filter(function (task) {
return task.ServiceID === service.ID;
});
var taskNodes = data.nodes.filter(function (node) {
return node.Spec.Availability === 'active' && node.Status.State === 'ready';
});
return new ServiceViewModel(service, serviceTasks, taskNodes);
return new ServiceViewModel(service, runningTasks, allTasks, taskNodes);
});
})
.catch(function error(err) {

View File

@ -1,4 +1,4 @@
function ServiceViewModel(data, runningTasks, nodes) {
function ServiceViewModel(data, runningTasks, allTasks, nodes) {
this.Model = data;
this.Id = data.ID;
this.Tasks = [];
@ -12,8 +12,8 @@ function ServiceViewModel(data, runningTasks, nodes) {
this.Replicas = data.Spec.Mode.Replicated.Replicas;
} else {
this.Mode = 'global';
if (nodes) {
this.Replicas = nodes.length;
if (allTasks) {
this.Replicas = allTasks.length;
}
}
if (runningTasks) {