2018-06-11 13:13:19 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-06-20 13:53:58 +00:00
|
|
|
.controller('ServicesDatatableActionsController', ['$state', 'ServiceService', 'ServiceHelper', 'Notifications', 'ModalService', 'ImageHelper',
|
|
|
|
function ($state, ServiceService, ServiceHelper, Notifications, ModalService, ImageHelper) {
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
this.scaleAction = function scaleService(service) {
|
|
|
|
var config = ServiceHelper.serviceToConfig(service.Model);
|
|
|
|
config.Mode.Replicated.Replicas = service.Replicas;
|
|
|
|
ServiceService.update(service, config)
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
2018-06-11 13:13:19 +00:00
|
|
|
Notifications.success('Service successfully scaled', 'New replica count: ' + service.Replicas);
|
|
|
|
$state.reload();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to scale service');
|
|
|
|
service.Scale = false;
|
|
|
|
service.Replicas = service.ReplicaCount;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.removeAction = function(selectedItems) {
|
|
|
|
ModalService.confirmDeletion(
|
|
|
|
'Do you want to remove the selected service(s)? All the containers associated to the selected service(s) will be removed too.',
|
|
|
|
function onConfirm(confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
removeServices(selectedItems);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-06-20 13:53:58 +00:00
|
|
|
this.updateAction = function(selectedItems) {
|
|
|
|
ModalService.confirmServiceForceUpdate(
|
|
|
|
'Do you want to force an update of the selected service(s)? All the tasks associated to the selected service(s) will be recreated.',
|
|
|
|
function (result) {
|
|
|
|
if(!result) { return; }
|
|
|
|
var pullImage = false;
|
|
|
|
if (result[0]) {
|
|
|
|
pullImage = true;
|
|
|
|
}
|
|
|
|
forceUpdateServices(selectedItems, pullImage);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function forceUpdateServices(services, pullImage) {
|
2018-06-11 13:13:19 +00:00
|
|
|
var actionCount = services.length;
|
|
|
|
angular.forEach(services, function (service) {
|
|
|
|
var config = ServiceHelper.serviceToConfig(service.Model);
|
2018-06-20 13:53:58 +00:00
|
|
|
if (pullImage) {
|
|
|
|
config.TaskTemplate.ContainerSpec.Image = ImageHelper.removeDigestFromRepository(config.TaskTemplate.ContainerSpec.Image);
|
|
|
|
}
|
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
// 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)
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
2018-06-11 13:13:19 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove service');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}]);
|