2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-02-21 09:55:51 +00:00
|
|
|
.controller('ServicesController', ['$q', '$scope', '$state', 'Service', 'ServiceService', 'ServiceHelper', 'Notifications', 'Task', 'Node', 'ModalService', 'EndpointProvider',
|
|
|
|
function ($q, $scope, $state, Service, ServiceService, ServiceHelper, Notifications, Task, Node, ModalService, EndpointProvider) {
|
|
|
|
|
|
|
|
$scope.state = {
|
|
|
|
publicURL: EndpointProvider.endpointPublicURL()
|
|
|
|
};
|
2017-01-24 01:28:40 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.scaleAction = function scaleService(service) {
|
2016-09-23 04:54:58 +00:00
|
|
|
var config = ServiceHelper.serviceToConfig(service.Model);
|
|
|
|
config.Mode.Replicated.Replicas = service.Replicas;
|
2017-12-06 11:04:02 +00:00
|
|
|
ServiceService.update(service, config)
|
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Service successfully scaled', 'New replica count: ' + service.Replicas);
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.reload();
|
2017-12-06 11:04:02 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to scale service');
|
2016-09-23 04:54:58 +00:00
|
|
|
service.Scale = false;
|
|
|
|
service.Replicas = service.ReplicaCount;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-01-08 21:06:56 +00:00
|
|
|
$scope.forceUpdateAction = function(selectedItems) {
|
|
|
|
ModalService.confirmServiceForceUpdate(
|
|
|
|
'Do you want to force update of selected service(s)? All the tasks associated to the selected service(s) will be recreated.',
|
|
|
|
function onConfirm(confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
forceUpdateServices(selectedItems);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function forceUpdateServices(services) {
|
|
|
|
var actionCount = services.length;
|
|
|
|
angular.forEach(services, function (service) {
|
|
|
|
var config = ServiceHelper.serviceToConfig(service.Model);
|
|
|
|
// As explained in https://github.com/docker/swarmkit/issues/2364 ForceUpdate can accept a random
|
|
|
|
// value or an increment of the counter value to force an update.
|
|
|
|
config.TaskTemplate.ForceUpdate++;
|
|
|
|
ServiceService.update(service, config)
|
|
|
|
.then(function success(data) {
|
|
|
|
Notifications.success('Service successfully updated', service.Name);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to force update service', service.Name);
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.removeAction = function(selectedItems) {
|
2017-03-30 09:22:59 +00:00
|
|
|
ModalService.confirmDeletion(
|
2017-04-25 08:20:57 +00:00
|
|
|
'Do you want to remove the selected service(s)? All the containers associated to the selected service(s) will be removed too.',
|
2017-03-30 09:22:59 +00:00
|
|
|
function onConfirm(confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
2017-12-06 11:04:02 +00:00
|
|
|
removeServices(selectedItems);
|
2017-03-30 09:22:59 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
function removeServices(services) {
|
|
|
|
var actionCount = services.length;
|
|
|
|
angular.forEach(services, function (service) {
|
|
|
|
ServiceService.remove(service)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Service successfully removed', service.Name);
|
|
|
|
var index = $scope.services.indexOf(service);
|
|
|
|
$scope.services.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove service');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
2017-03-12 16:24:15 +00:00
|
|
|
}
|
2017-12-06 11:04:02 +00:00
|
|
|
});
|
2017-03-12 16:24:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
function initView() {
|
2017-03-12 17:24:41 +00:00
|
|
|
$q.all({
|
|
|
|
services: Service.query({}).$promise,
|
2017-11-06 14:50:59 +00:00
|
|
|
tasks: Task.query({filters: {'desired-state': ['running','accepted']}}).$promise,
|
2017-05-23 18:56:10 +00:00
|
|
|
nodes: Node.query({}).$promise
|
2017-03-12 17:24:41 +00:00
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.services = data.services.map(function (service) {
|
2017-11-06 14:50:59 +00:00
|
|
|
var runningTasks = data.tasks.filter(function (task) {
|
2017-05-23 18:56:10 +00:00
|
|
|
return task.ServiceID === service.ID && task.Status.State === 'running';
|
2017-03-12 17:24:41 +00:00
|
|
|
});
|
2017-11-06 14:50:59 +00:00
|
|
|
var allTasks = data.tasks.filter(function (task) {
|
|
|
|
return task.ServiceID === service.ID;
|
|
|
|
});
|
2017-03-12 17:24:41 +00:00
|
|
|
var taskNodes = data.nodes.filter(function (node) {
|
|
|
|
return node.Spec.Availability === 'active' && node.Status.State === 'ready';
|
|
|
|
});
|
2017-11-06 14:50:59 +00:00
|
|
|
return new ServiceViewModel(service, runningTasks, allTasks, taskNodes);
|
2016-09-23 04:54:58 +00:00
|
|
|
});
|
2017-03-12 17:24:41 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2016-10-08 01:59:58 +00:00
|
|
|
$scope.services = [];
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve services');
|
2016-09-23 04:54:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
initView();
|
2016-09-23 04:54:58 +00:00
|
|
|
}]);
|