service.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package swarm // import "github.com/docker/docker/api/types/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. // ServiceStatus is an optional, extra field indicating the number of
  12. // desired and running tasks. It is provided primarily as a shortcut to
  13. // calculating these values client-side, which otherwise would require
  14. // listing all tasks for a service, an operation that could be
  15. // computation and network expensive.
  16. ServiceStatus *ServiceStatus `json:",omitempty"`
  17. // JobStatus is the status of a Service which is in one of ReplicatedJob or
  18. // GlobalJob modes. It is absent on Replicated and Global services.
  19. JobStatus *JobStatus `json:",omitempty"`
  20. }
  21. // ServiceSpec represents the spec of a service.
  22. type ServiceSpec struct {
  23. Annotations
  24. // TaskTemplate defines how the service should construct new tasks when
  25. // orchestrating this service.
  26. TaskTemplate TaskSpec `json:",omitempty"`
  27. Mode ServiceMode `json:",omitempty"`
  28. UpdateConfig *UpdateConfig `json:",omitempty"`
  29. RollbackConfig *UpdateConfig `json:",omitempty"`
  30. // Networks specifies which networks the service should attach to.
  31. //
  32. // Deprecated: This field is deprecated since v1.44. The Networks field in TaskSpec should be used instead.
  33. Networks []NetworkAttachmentConfig `json:",omitempty"`
  34. EndpointSpec *EndpointSpec `json:",omitempty"`
  35. }
  36. // ServiceMode represents the mode of a service.
  37. type ServiceMode struct {
  38. Replicated *ReplicatedService `json:",omitempty"`
  39. Global *GlobalService `json:",omitempty"`
  40. ReplicatedJob *ReplicatedJob `json:",omitempty"`
  41. GlobalJob *GlobalJob `json:",omitempty"`
  42. }
  43. // UpdateState is the state of a service update.
  44. type UpdateState string
  45. const (
  46. // UpdateStateUpdating is the updating state.
  47. UpdateStateUpdating UpdateState = "updating"
  48. // UpdateStatePaused is the paused state.
  49. UpdateStatePaused UpdateState = "paused"
  50. // UpdateStateCompleted is the completed state.
  51. UpdateStateCompleted UpdateState = "completed"
  52. // UpdateStateRollbackStarted is the state with a rollback in progress.
  53. UpdateStateRollbackStarted UpdateState = "rollback_started"
  54. // UpdateStateRollbackPaused is the state with a rollback in progress.
  55. UpdateStateRollbackPaused UpdateState = "rollback_paused"
  56. // UpdateStateRollbackCompleted is the state with a rollback in progress.
  57. UpdateStateRollbackCompleted UpdateState = "rollback_completed"
  58. )
  59. // UpdateStatus reports the status of a service update.
  60. type UpdateStatus struct {
  61. State UpdateState `json:",omitempty"`
  62. StartedAt *time.Time `json:",omitempty"`
  63. CompletedAt *time.Time `json:",omitempty"`
  64. Message string `json:",omitempty"`
  65. }
  66. // ReplicatedService is a kind of ServiceMode.
  67. type ReplicatedService struct {
  68. Replicas *uint64 `json:",omitempty"`
  69. }
  70. // GlobalService is a kind of ServiceMode.
  71. type GlobalService struct{}
  72. // ReplicatedJob is the a type of Service which executes a defined Tasks
  73. // in parallel until the specified number of Tasks have succeeded.
  74. type ReplicatedJob struct {
  75. // MaxConcurrent indicates the maximum number of Tasks that should be
  76. // executing simultaneously for this job at any given time. There may be
  77. // fewer Tasks that MaxConcurrent executing simultaneously; for example, if
  78. // there are fewer than MaxConcurrent tasks needed to reach
  79. // TotalCompletions.
  80. //
  81. // If this field is empty, it will default to a max concurrency of 1.
  82. MaxConcurrent *uint64 `json:",omitempty"`
  83. // TotalCompletions is the total number of Tasks desired to run to
  84. // completion.
  85. //
  86. // If this field is empty, the value of MaxConcurrent will be used.
  87. TotalCompletions *uint64 `json:",omitempty"`
  88. }
  89. // GlobalJob is the type of a Service which executes a Task on every Node
  90. // matching the Service's placement constraints. These tasks run to completion
  91. // and then exit.
  92. //
  93. // This type is deliberately empty.
  94. type GlobalJob struct{}
  95. const (
  96. // UpdateFailureActionPause PAUSE
  97. UpdateFailureActionPause = "pause"
  98. // UpdateFailureActionContinue CONTINUE
  99. UpdateFailureActionContinue = "continue"
  100. // UpdateFailureActionRollback ROLLBACK
  101. UpdateFailureActionRollback = "rollback"
  102. // UpdateOrderStopFirst STOP_FIRST
  103. UpdateOrderStopFirst = "stop-first"
  104. // UpdateOrderStartFirst START_FIRST
  105. UpdateOrderStartFirst = "start-first"
  106. )
  107. // UpdateConfig represents the update configuration.
  108. type UpdateConfig struct {
  109. // Maximum number of tasks to be updated in one iteration.
  110. // 0 means unlimited parallelism.
  111. Parallelism uint64
  112. // Amount of time between updates.
  113. Delay time.Duration `json:",omitempty"`
  114. // FailureAction is the action to take when an update failures.
  115. FailureAction string `json:",omitempty"`
  116. // Monitor indicates how long to monitor a task for failure after it is
  117. // created. If the task fails by ending up in one of the states
  118. // REJECTED, COMPLETED, or FAILED, within Monitor from its creation,
  119. // this counts as a failure. If it fails after Monitor, it does not
  120. // count as a failure. If Monitor is unspecified, a default value will
  121. // be used.
  122. Monitor time.Duration `json:",omitempty"`
  123. // MaxFailureRatio is the fraction of tasks that may fail during
  124. // an update before the failure action is invoked. Any task created by
  125. // the current update which ends up in one of the states REJECTED,
  126. // COMPLETED or FAILED within Monitor from its creation counts as a
  127. // failure. The number of failures is divided by the number of tasks
  128. // being updated, and if this fraction is greater than
  129. // MaxFailureRatio, the failure action is invoked.
  130. //
  131. // If the failure action is CONTINUE, there is no effect.
  132. // If the failure action is PAUSE, no more tasks will be updated until
  133. // another update is started.
  134. MaxFailureRatio float32
  135. // Order indicates the order of operations when rolling out an updated
  136. // task. Either the old task is shut down before the new task is
  137. // started, or the new task is started before the old task is shut down.
  138. Order string
  139. }
  140. // ServiceStatus represents the number of running tasks in a service and the
  141. // number of tasks desired to be running.
  142. type ServiceStatus struct {
  143. // RunningTasks is the number of tasks for the service actually in the
  144. // Running state
  145. RunningTasks uint64
  146. // DesiredTasks is the number of tasks desired to be running by the
  147. // service. For replicated services, this is the replica count. For global
  148. // services, this is computed by taking the number of tasks with desired
  149. // state of not-Shutdown.
  150. DesiredTasks uint64
  151. // CompletedTasks is the number of tasks in the state Completed, if this
  152. // service is in ReplicatedJob or GlobalJob mode. This field must be
  153. // cross-referenced with the service type, because the default value of 0
  154. // may mean that a service is not in a job mode, or it may mean that the
  155. // job has yet to complete any tasks.
  156. CompletedTasks uint64
  157. }
  158. // JobStatus is the status of a job-type service.
  159. type JobStatus struct {
  160. // JobIteration is a value increased each time a Job is executed,
  161. // successfully or otherwise. "Executed", in this case, means the job as a
  162. // whole has been started, not that an individual Task has been launched. A
  163. // job is "Executed" when its ServiceSpec is updated. JobIteration can be
  164. // used to disambiguate Tasks belonging to different executions of a job.
  165. //
  166. // Though JobIteration will increase with each subsequent execution, it may
  167. // not necessarily increase by 1, and so JobIteration should not be used to
  168. // keep track of the number of times a job has been executed.
  169. JobIteration Version
  170. // LastExecution is the time that the job was last executed, as observed by
  171. // Swarm manager.
  172. LastExecution time.Time `json:",omitempty"`
  173. }