Browse Source

Add support for the "rollback" failure action

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Aaron Lehmann 8 years ago
parent
commit
cc9d04647a

+ 1 - 0
api/swagger.yaml

@@ -2256,6 +2256,7 @@ definitions:
             enum:
             enum:
               - "continue"
               - "continue"
               - "pause"
               - "pause"
+              - "rollback"
           Monitor:
           Monitor:
             description: "Amount of time to monitor each updated task for failures, in nanoseconds."
             description: "Amount of time to monitor each updated task for failures, in nanoseconds."
             type: "integer"
             type: "integer"

+ 8 - 0
api/types/swarm/service.go

@@ -45,6 +45,12 @@ const (
 	UpdateStatePaused UpdateState = "paused"
 	UpdateStatePaused UpdateState = "paused"
 	// UpdateStateCompleted is the completed state.
 	// UpdateStateCompleted is the completed state.
 	UpdateStateCompleted UpdateState = "completed"
 	UpdateStateCompleted UpdateState = "completed"
+	// UpdateStateRollbackStarted is the state with a rollback in progress.
+	UpdateStateRollbackStarted UpdateState = "rollback_started"
+	// UpdateStateRollbackPaused is the state with a rollback in progress.
+	UpdateStateRollbackPaused UpdateState = "rollback_paused"
+	// UpdateStateRollbackCompleted is the state with a rollback in progress.
+	UpdateStateRollbackCompleted UpdateState = "rollback_completed"
 )
 )
 
 
 // UpdateStatus reports the status of a service update.
 // UpdateStatus reports the status of a service update.
@@ -68,6 +74,8 @@ const (
 	UpdateFailureActionPause = "pause"
 	UpdateFailureActionPause = "pause"
 	// UpdateFailureActionContinue CONTINUE
 	// UpdateFailureActionContinue CONTINUE
 	UpdateFailureActionContinue = "continue"
 	UpdateFailureActionContinue = "continue"
+	// UpdateFailureActionRollback ROLLBACK
+	UpdateFailureActionRollback = "rollback"
 )
 )
 
 
 // UpdateConfig represents the update configuration.
 // UpdateConfig represents the update configuration.

+ 1 - 1
cli/command/service/opts.go

@@ -487,7 +487,7 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
 	flags.DurationVar(&opts.update.delay, flagUpdateDelay, time.Duration(0), "Delay between updates (ns|us|ms|s|m|h) (default 0s)")
 	flags.DurationVar(&opts.update.delay, flagUpdateDelay, time.Duration(0), "Delay between updates (ns|us|ms|s|m|h) (default 0s)")
 	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)")
 	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)")
 	flags.SetAnnotation(flagUpdateMonitor, "version", []string{"1.25"})
 	flags.SetAnnotation(flagUpdateMonitor, "version", []string{"1.25"})
-	flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", `Action on update failure ("pause"|"continue")`)
+	flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", `Action on update failure ("pause"|"continue"|"rollback")`)
 	flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
 	flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
 	flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"})
 	flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"})
 
 

+ 10 - 0
daemon/cluster/convert/service.go

@@ -35,6 +35,12 @@ func ServiceFromGRPC(s swarmapi.Service) types.Service {
 			service.UpdateStatus.State = types.UpdateStatePaused
 			service.UpdateStatus.State = types.UpdateStatePaused
 		case swarmapi.UpdateStatus_COMPLETED:
 		case swarmapi.UpdateStatus_COMPLETED:
 			service.UpdateStatus.State = types.UpdateStateCompleted
 			service.UpdateStatus.State = types.UpdateStateCompleted
+		case swarmapi.UpdateStatus_ROLLBACK_STARTED:
+			service.UpdateStatus.State = types.UpdateStateRollbackStarted
+		case swarmapi.UpdateStatus_ROLLBACK_PAUSED:
+			service.UpdateStatus.State = types.UpdateStateRollbackPaused
+		case swarmapi.UpdateStatus_ROLLBACK_COMPLETED:
+			service.UpdateStatus.State = types.UpdateStateRollbackCompleted
 		}
 		}
 
 
 		startedAt, _ := gogotypes.TimestampFromProto(s.UpdateStatus.StartedAt)
 		startedAt, _ := gogotypes.TimestampFromProto(s.UpdateStatus.StartedAt)
@@ -102,6 +108,8 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec {
 			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionPause
 			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionPause
 		case swarmapi.UpdateConfig_CONTINUE:
 		case swarmapi.UpdateConfig_CONTINUE:
 			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionContinue
 			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionContinue
+		case swarmapi.UpdateConfig_ROLLBACK:
+			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionRollback
 		}
 		}
 	}
 	}
 
 
@@ -187,6 +195,8 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) {
 			failureAction = swarmapi.UpdateConfig_PAUSE
 			failureAction = swarmapi.UpdateConfig_PAUSE
 		case types.UpdateFailureActionContinue:
 		case types.UpdateFailureActionContinue:
 			failureAction = swarmapi.UpdateConfig_CONTINUE
 			failureAction = swarmapi.UpdateConfig_CONTINUE
+		case types.UpdateFailureActionRollback:
+			failureAction = swarmapi.UpdateConfig_ROLLBACK
 		default:
 		default:
 			return swarmapi.ServiceSpec{}, fmt.Errorf("unrecognized update failure action %s", s.UpdateConfig.FailureAction)
 			return swarmapi.ServiceSpec{}, fmt.Errorf("unrecognized update failure action %s", s.UpdateConfig.FailureAction)
 		}
 		}

+ 1 - 0
docs/api/version-history.md

@@ -22,6 +22,7 @@ keywords: "API, Docker, rcli, REST, documentation"
 * `GET /containers/json` now supports `publish` and `expose` filters to filter containers that expose or publish certain ports.
 * `GET /containers/json` now supports `publish` and `expose` filters to filter containers that expose or publish certain ports.
 * `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.
 * `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.
 * `POST /build` now accepts `extrahosts` parameter to specify a host to ip mapping to use during the build.
 * `POST /build` now accepts `extrahosts` parameter to specify a host to ip mapping to use during the build.
+* `POST /services/create` and `POST /services/(id or name)/update` now accept a `rollback` value for `FailureAction`.
 
 
 ## v1.26 API changes
 ## v1.26 API changes
 
 

+ 1 - 1
docs/reference/commandline/service_create.md

@@ -62,7 +62,7 @@ Options:
       --stop-signal string               Signal to stop the container
       --stop-signal string               Signal to stop the container
   -t, --tty                              Allocate a pseudo-TTY
   -t, --tty                              Allocate a pseudo-TTY
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
-      --update-failure-action string     Action on update failure ("pause"|"continue") (default "pause")
+      --update-failure-action string     Action on update failure ("pause"|"continue"|"rollback") (default "pause")
       --update-max-failure-ratio float   Failure rate to tolerate during an update
       --update-max-failure-ratio float   Failure rate to tolerate during an update
       --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
       --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
       --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)
       --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)

+ 1 - 1
docs/reference/commandline/service_update.md

@@ -75,7 +75,7 @@ Options:
       --stop-signal string               Signal to stop the container
       --stop-signal string               Signal to stop the container
   -t, --tty                              Allocate a pseudo-TTY
   -t, --tty                              Allocate a pseudo-TTY
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
       --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
-      --update-failure-action string     Action on update failure ("pause"|"continue") (default "pause")
+      --update-failure-action string     Action on update failure ("pause"|"continue"|"rollback") (default "pause")
       --update-max-failure-ratio float   Failure rate to tolerate during an update
       --update-max-failure-ratio float   Failure rate to tolerate during an update
       --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
       --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
       --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)
       --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)