service.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package swarm
  2. import "time"
  3. // Service represents a service.
  4. type Service struct {
  5. ID string
  6. Meta
  7. Spec ServiceSpec `json:",omitempty"`
  8. PreviousSpec *ServiceSpec `json:",omitempty"`
  9. Endpoint Endpoint `json:",omitempty"`
  10. UpdateStatus *UpdateStatus `json:",omitempty"`
  11. }
  12. // ServiceSpec represents the spec of a service.
  13. type ServiceSpec struct {
  14. Annotations
  15. // TaskTemplate defines how the service should construct new tasks when
  16. // orchestrating this service.
  17. TaskTemplate TaskSpec `json:",omitempty"`
  18. Mode ServiceMode `json:",omitempty"`
  19. UpdateConfig *UpdateConfig `json:",omitempty"`
  20. RollbackConfig *UpdateConfig `json:",omitempty"`
  21. // Networks field in ServiceSpec is deprecated. The
  22. // same field in TaskSpec should be used instead.
  23. // This field will be removed in a future release.
  24. Networks []NetworkAttachmentConfig `json:",omitempty"`
  25. EndpointSpec *EndpointSpec `json:",omitempty"`
  26. }
  27. // ServiceMode represents the mode of a service.
  28. type ServiceMode struct {
  29. Replicated *ReplicatedService `json:",omitempty"`
  30. Global *GlobalService `json:",omitempty"`
  31. }
  32. // UpdateState is the state of a service update.
  33. type UpdateState string
  34. const (
  35. // UpdateStateUpdating is the updating state.
  36. UpdateStateUpdating UpdateState = "updating"
  37. // UpdateStatePaused is the paused state.
  38. UpdateStatePaused UpdateState = "paused"
  39. // UpdateStateCompleted is the completed state.
  40. UpdateStateCompleted UpdateState = "completed"
  41. // UpdateStateRollbackStarted is the state with a rollback in progress.
  42. UpdateStateRollbackStarted UpdateState = "rollback_started"
  43. // UpdateStateRollbackPaused is the state with a rollback in progress.
  44. UpdateStateRollbackPaused UpdateState = "rollback_paused"
  45. // UpdateStateRollbackCompleted is the state with a rollback in progress.
  46. UpdateStateRollbackCompleted UpdateState = "rollback_completed"
  47. )
  48. // UpdateStatus reports the status of a service update.
  49. type UpdateStatus struct {
  50. State UpdateState `json:",omitempty"`
  51. StartedAt *time.Time `json:",omitempty"`
  52. CompletedAt *time.Time `json:",omitempty"`
  53. Message string `json:",omitempty"`
  54. }
  55. // ReplicatedService is a kind of ServiceMode.
  56. type ReplicatedService struct {
  57. Replicas *uint64 `json:",omitempty"`
  58. }
  59. // GlobalService is a kind of ServiceMode.
  60. type GlobalService struct{}
  61. const (
  62. // UpdateFailureActionPause PAUSE
  63. UpdateFailureActionPause = "pause"
  64. // UpdateFailureActionContinue CONTINUE
  65. UpdateFailureActionContinue = "continue"
  66. // UpdateFailureActionRollback ROLLBACK
  67. UpdateFailureActionRollback = "rollback"
  68. )
  69. // UpdateConfig represents the update configuration.
  70. type UpdateConfig struct {
  71. // Maximum number of tasks to be updated in one iteration.
  72. // 0 means unlimited parallelism.
  73. Parallelism uint64
  74. // Amount of time between updates.
  75. Delay time.Duration `json:",omitempty"`
  76. // FailureAction is the action to take when an update failures.
  77. FailureAction string `json:",omitempty"`
  78. // Monitor indicates how long to monitor a task for failure after it is
  79. // created. If the task fails by ending up in one of the states
  80. // REJECTED, COMPLETED, or FAILED, within Monitor from its creation,
  81. // this counts as a failure. If it fails after Monitor, it does not
  82. // count as a failure. If Monitor is unspecified, a default value will
  83. // be used.
  84. Monitor time.Duration `json:",omitempty"`
  85. // MaxFailureRatio is the fraction of tasks that may fail during
  86. // an update before the failure action is invoked. Any task created by
  87. // the current update which ends up in one of the states REJECTED,
  88. // COMPLETED or FAILED within Monitor from its creation counts as a
  89. // failure. The number of failures is divided by the number of tasks
  90. // being updated, and if this fraction is greater than
  91. // MaxFailureRatio, the failure action is invoked.
  92. //
  93. // If the failure action is CONTINUE, there is no effect.
  94. // If the failure action is PAUSE, no more tasks will be updated until
  95. // another update is started.
  96. MaxFailureRatio float32
  97. }