mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
feat(services): rollback service capability (#3057)
* feat(services): rollback service capability * refactor(services): notification reword Co-Authored-By: William <william.conquest@portainer.io> * refactor(services): remove TODO comment + add note on rollback capability * fix(services): service update rpc error version out of sync * feat(services): confirmation modal on rollback * feat(services): rpc error no previous spec message
This commit is contained in:
parent
ec19faaa24
commit
52704e681b
4 changed files with 70 additions and 12 deletions
|
@ -22,7 +22,8 @@ function ($q, $scope, $transition$, $state, $location, $timeout, $anchorScroll,
|
|||
|
||||
$scope.state = {
|
||||
updateInProgress: false,
|
||||
deletionInProgress: false
|
||||
deletionInProgress: false,
|
||||
rollbackInProgress: false,
|
||||
};
|
||||
|
||||
$scope.tasks = [];
|
||||
|
@ -281,7 +282,7 @@ function ($q, $scope, $transition$, $state, $location, $timeout, $anchorScroll,
|
|||
return hasChanges;
|
||||
};
|
||||
|
||||
$scope.updateService = function updateService(service) {
|
||||
function buildChanges(service) {
|
||||
var config = ServiceHelper.serviceToConfig(service.Model);
|
||||
config.Name = service.Name;
|
||||
config.Labels = LabelHelper.fromKeyValueToLabelHash(service.ServiceLabels);
|
||||
|
@ -361,8 +362,55 @@ function ($q, $scope, $transition$, $state, $location, $timeout, $anchorScroll,
|
|||
Mode: (config.EndpointSpec && config.EndpointSpec.Mode) || 'vip',
|
||||
Ports: service.Ports
|
||||
};
|
||||
return service, config;
|
||||
}
|
||||
|
||||
Service.update({ id: service.Id, version: service.Version }, config, function (data) {
|
||||
function rollbackService(service) {
|
||||
$scope.state.rollbackInProgress = true;
|
||||
let config = {};
|
||||
service, config = buildChanges(service);
|
||||
ServiceService.update(service, config, 'previous')
|
||||
.then(function (data) {
|
||||
if (data.message && data.message.match(/^rpc error:/)) {
|
||||
Notifications.error(data.message, 'Error');
|
||||
} else {
|
||||
Notifications.success('Success', 'Service successfully rolled back');
|
||||
$scope.cancelChanges({});
|
||||
initView();
|
||||
}
|
||||
}).catch(function (e) {
|
||||
if (e.data.message && e.data.message.includes('does not have a previous spec')) {
|
||||
Notifications.error('Failure', { message: 'No previous config to rollback to.' });
|
||||
} else {
|
||||
Notifications.error('Failure', e, 'Unable to rollback service');
|
||||
}
|
||||
}).finally(function () {
|
||||
$scope.state.rollbackInProgress = false;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.rollbackService = function(service) {
|
||||
ModalService.confirm({
|
||||
title: 'Rollback service',
|
||||
message: 'Are you sure you want to rollback?',
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: 'Yes',
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function onConfirm(confirmed) {
|
||||
if(!confirmed) { return; }
|
||||
rollbackService(service);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.updateService = function updateService(service) {
|
||||
let config = {};
|
||||
service, config = buildChanges(service);
|
||||
ServiceService.update(service, config)
|
||||
.then(function (data) {
|
||||
if (data.message && data.message.match(/^rpc error:/)) {
|
||||
Notifications.error(data.message, 'Error');
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue