service.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. // UpdateOrderStopFirst STOP_FIRST
  69. UpdateOrderStopFirst = "stop-first"
  70. // UpdateOrderStartFirst START_FIRST
  71. UpdateOrderStartFirst = "start-first"
  72. )
  73. // UpdateConfig represents the update configuration.
  74. type UpdateConfig struct {
  75. // Maximum number of tasks to be updated in one iteration.
  76. // 0 means unlimited parallelism.
  77. Parallelism uint64
  78. // Amount of time between updates.
  79. Delay time.Duration `json:",omitempty"`
  80. // FailureAction is the action to take when an update failures.
  81. FailureAction string `json:",omitempty"`
  82. // Monitor indicates how long to monitor a task for failure after it is
  83. // created. If the task fails by ending up in one of the states
  84. // REJECTED, COMPLETED, or FAILED, within Monitor from its creation,
  85. // this counts as a failure. If it fails after Monitor, it does not
  86. // count as a failure. If Monitor is unspecified, a default value will
  87. // be used.
  88. Monitor time.Duration `json:",omitempty"`
  89. // MaxFailureRatio is the fraction of tasks that may fail during
  90. // an update before the failure action is invoked. Any task created by
  91. // the current update which ends up in one of the states REJECTED,
  92. // COMPLETED or FAILED within Monitor from its creation counts as a
  93. // failure. The number of failures is divided by the number of tasks
  94. // being updated, and if this fraction is greater than
  95. // MaxFailureRatio, the failure action is invoked.
  96. //
  97. // If the failure action is CONTINUE, there is no effect.
  98. // If the failure action is PAUSE, no more tasks will be updated until
  99. // another update is started.
  100. MaxFailureRatio float32
  101. // Order indicates the order of operations when rolling out an updated
  102. // task. Either the old task is shut down before the new task is
  103. // started, or the new task is started before the old task is shut down.
  104. Order string
  105. }