From d0e147137d592d469a3c0fe48ebfd48380c4b302 Mon Sep 17 00:00:00 2001 From: "Miguel A. C" <30386061+doncicuto@users.noreply.github.com> Date: Thu, 7 Dec 2017 21:05:45 +0100 Subject: [PATCH] feat(service): add restart policy options in service create/details (#1479) --- .../createService/createServiceController.js | 18 ++- .../createService/createservice.html | 71 +--------- .../includes/update-restart.html | 132 ++++++++++++++++++ app/components/service/includes/restart.html | 10 +- app/components/service/serviceController.js | 10 +- app/helpers/serviceHelper.js | 2 +- 6 files changed, 161 insertions(+), 82 deletions(-) create mode 100644 app/components/createService/includes/update-restart.html diff --git a/app/components/createService/createServiceController.js b/app/components/createService/createServiceController.js index 32b7e5c78..ab85f14ed 100644 --- a/app/components/createService/createServiceController.js +++ b/app/components/createService/createServiceController.js @@ -35,7 +35,11 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C MemoryLimit: 0, MemoryReservation: 0, MemoryLimitUnit: 'MB', - MemoryReservationUnit: 'MB' + MemoryReservationUnit: 'MB', + RestartCondition: 'any', + RestartDelay: '5s', + RestartMaxAttempts: 0, + RestartWindow: '0s' }; $scope.state = { @@ -243,12 +247,21 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C function prepareUpdateConfig(config, input) { config.UpdateConfig = { Parallelism: input.Parallelism || 0, - Delay: ServiceHelper.translateHumanDurationToNanos(input.UpdateDelay), + Delay: ServiceHelper.translateHumanDurationToNanos(input.UpdateDelay) || 0, FailureAction: input.FailureAction, Order: input.UpdateOrder }; } + function prepareRestartPolicy(config, input) { + config.TaskTemplate.RestartPolicy = { + Condition: input.RestartCondition || 'any', + Delay: ServiceHelper.translateHumanDurationToNanos(input.RestartDelay) || 5000000000, + MaxAttempts: input.RestartMaxAttempts || 0, + Window: ServiceHelper.translateHumanDurationToNanos(input.RestartWindow) || 0 + }; + } + function preparePlacementConfig(config, input) { config.TaskTemplate.Placement.Constraints = ServiceHelper.translateKeyValueToPlacementConstraints(input.PlacementConstraints); config.TaskTemplate.Placement.Preferences = ServiceHelper.translateKeyValueToPlacementPreferences(input.PlacementPreferences); @@ -348,6 +361,7 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C preparePlacementConfig(config, input); prepareResourcesCpuConfig(config, input); prepareResourcesMemoryConfig(config, input); + prepareRestartPolicy(config, input); return config; } diff --git a/app/components/createService/createservice.html b/app/components/createService/createservice.html index 426696e04..9a86ee73c 100644 --- a/app/components/createService/createservice.html +++ b/app/components/createService/createservice.html @@ -130,7 +130,7 @@
- Delay between restart attempts. Time in seconds. + Delay between restart attempts expressed by a number followed by unit (ns|us|ms|s|m|h). Default value is 5s, 5 seconds.
- Maximum attempts to restart a given container before giving up (default value is 0, which is ignored). + Maximum attempts to restart a given task before giving up (default value is 0, which means unlimited).
- The time window used to evaluate the restart policy (default value is 0, which is unbounded). Time in seconds. + Time window to evaluate restart attempts expressed by a number followed by unit (ns|us|ms|s|m|h). Default value is 0 seconds, which is unbounded.