Browse code

Add support for the "rollback" failure action

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2017/02/16 07:53:58
Showing 7 changed files
... ...
@@ -2256,6 +2256,7 @@ definitions:
2256 2256
             enum:
2257 2257
               - "continue"
2258 2258
               - "pause"
2259
+              - "rollback"
2259 2260
           Monitor:
2260 2261
             description: "Amount of time to monitor each updated task for failures, in nanoseconds."
2261 2262
             type: "integer"
... ...
@@ -45,6 +45,12 @@ const (
45 45
 	UpdateStatePaused UpdateState = "paused"
46 46
 	// UpdateStateCompleted is the completed state.
47 47
 	UpdateStateCompleted UpdateState = "completed"
48
+	// UpdateStateRollbackStarted is the state with a rollback in progress.
49
+	UpdateStateRollbackStarted UpdateState = "rollback_started"
50
+	// UpdateStateRollbackPaused is the state with a rollback in progress.
51
+	UpdateStateRollbackPaused UpdateState = "rollback_paused"
52
+	// UpdateStateRollbackCompleted is the state with a rollback in progress.
53
+	UpdateStateRollbackCompleted UpdateState = "rollback_completed"
48 54
 )
49 55
 
50 56
 // UpdateStatus reports the status of a service update.
... ...
@@ -68,6 +74,8 @@ const (
68 68
 	UpdateFailureActionPause = "pause"
69 69
 	// UpdateFailureActionContinue CONTINUE
70 70
 	UpdateFailureActionContinue = "continue"
71
+	// UpdateFailureActionRollback ROLLBACK
72
+	UpdateFailureActionRollback = "rollback"
71 73
 )
72 74
 
73 75
 // UpdateConfig represents the update configuration.
... ...
@@ -487,7 +487,7 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
487 487
 	flags.DurationVar(&opts.update.delay, flagUpdateDelay, time.Duration(0), "Delay between updates (ns|us|ms|s|m|h) (default 0s)")
488 488
 	flags.DurationVar(&opts.update.monitor, flagUpdateMonitor, time.Duration(0), "Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)")
489 489
 	flags.SetAnnotation(flagUpdateMonitor, "version", []string{"1.25"})
490
-	flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", `Action on update failure ("pause"|"continue")`)
490
+	flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", `Action on update failure ("pause"|"continue"|"rollback")`)
491 491
 	flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
492 492
 	flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"})
493 493
 
... ...
@@ -35,6 +35,12 @@ func ServiceFromGRPC(s swarmapi.Service) types.Service {
35 35
 			service.UpdateStatus.State = types.UpdateStatePaused
36 36
 		case swarmapi.UpdateStatus_COMPLETED:
37 37
 			service.UpdateStatus.State = types.UpdateStateCompleted
38
+		case swarmapi.UpdateStatus_ROLLBACK_STARTED:
39
+			service.UpdateStatus.State = types.UpdateStateRollbackStarted
40
+		case swarmapi.UpdateStatus_ROLLBACK_PAUSED:
41
+			service.UpdateStatus.State = types.UpdateStateRollbackPaused
42
+		case swarmapi.UpdateStatus_ROLLBACK_COMPLETED:
43
+			service.UpdateStatus.State = types.UpdateStateRollbackCompleted
38 44
 		}
39 45
 
40 46
 		startedAt, _ := gogotypes.TimestampFromProto(s.UpdateStatus.StartedAt)
... ...
@@ -102,6 +108,8 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec {
102 102
 			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionPause
103 103
 		case swarmapi.UpdateConfig_CONTINUE:
104 104
 			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionContinue
105
+		case swarmapi.UpdateConfig_ROLLBACK:
106
+			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionRollback
105 107
 		}
106 108
 	}
107 109
 
... ...
@@ -187,6 +195,8 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) {
187 187
 			failureAction = swarmapi.UpdateConfig_PAUSE
188 188
 		case types.UpdateFailureActionContinue:
189 189
 			failureAction = swarmapi.UpdateConfig_CONTINUE
190
+		case types.UpdateFailureActionRollback:
191
+			failureAction = swarmapi.UpdateConfig_ROLLBACK
190 192
 		default:
191 193
 			return swarmapi.ServiceSpec{}, fmt.Errorf("unrecognized update failure action %s", s.UpdateConfig.FailureAction)
192 194
 		}
... ...
@@ -22,6 +22,7 @@ keywords: "API, Docker, rcli, REST, documentation"
22 22
 * `GET /containers/json` now supports `publish` and `expose` filters to filter containers that expose or publish certain ports.
23 23
 * `POST /services/create` and `POST /services/(id or name)/update` now accept the `ReadOnly` parameter, which mounts the container's root filesystem as read only.
24 24
 * `POST /build` now accepts `extrahosts` parameter to specify a host to ip mapping to use during the build.
25
+* `POST /services/create` and `POST /services/(id or name)/update` now accept a `rollback` value for `FailureAction`.
25 26
 
26 27
 ## v1.26 API changes
27 28
 
... ...
@@ -62,7 +62,7 @@ Options:
62 62
       --stop-signal string               Signal to stop the container
63 63
   -t, --tty                              Allocate a pseudo-TTY
64 64
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
65
-      --update-failure-action string     Action on update failure ("pause"|"continue") (default "pause")
65
+      --update-failure-action string     Action on update failure ("pause"|"continue"|"rollback") (default "pause")
66 66
       --update-max-failure-ratio float   Failure rate to tolerate during an update
67 67
       --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
68 68
       --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)
... ...
@@ -75,7 +75,7 @@ Options:
75 75
       --stop-signal string               Signal to stop the container
76 76
   -t, --tty                              Allocate a pseudo-TTY
77 77
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
78
-      --update-failure-action string     Action on update failure ("pause"|"continue") (default "pause")
78
+      --update-failure-action string     Action on update failure ("pause"|"continue"|"rollback") (default "pause")
79 79
       --update-max-failure-ratio float   Failure rate to tolerate during an update
80 80
       --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
81 81
       --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)