service.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. }
  18. // ServiceSpec represents the spec of a service.
  19. type ServiceSpec struct {
  20. Annotations
  21. // TaskTemplate defines how the service should construct new tasks when
  22. // orchestrating this service.
  23. TaskTemplate TaskSpec `json:",omitempty"`
  24. Mode ServiceMode `json:",omitempty"`
  25. UpdateConfig *UpdateConfig `json:",omitempty"`
  26. RollbackConfig *UpdateConfig `json:",omitempty"`
  27. // Networks field in ServiceSpec is deprecated. The
  28. // same field in TaskSpec should be used instead.
  29. // This field will be removed in a future release.
  30. Networks []NetworkAttachmentConfig `json:",omitempty"`
  31. EndpointSpec *EndpointSpec `json:",omitempty"`
  32. }
  33. // ServiceMode represents the mode of a service.
  34. type ServiceMode struct {
  35. Replicated *ReplicatedService `json:",omitempty"`
  36. Global *GlobalService `json:",omitempty"`
  37. }
  38. // UpdateState is the state of a service update.
  39. type UpdateState string
  40. const (
  41. // UpdateStateUpdating is the updating state.
  42. UpdateStateUpdating UpdateState = "updating"
  43. // UpdateStatePaused is the paused state.
  44. UpdateStatePaused UpdateState = "paused"
  45. // UpdateStateCompleted is the completed state.
  46. UpdateStateCompleted UpdateState = "completed"
  47. // UpdateStateRollbackStarted is the state with a rollback in progress.
  48. UpdateStateRollbackStarted UpdateState = "rollback_started"
  49. // UpdateStateRollbackPaused is the state with a rollback in progress.
  50. UpdateStateRollbackPaused UpdateState = "rollback_paused"
  51. // UpdateStateRollbackCompleted is the state with a rollback in progress.
  52. UpdateStateRollbackCompleted UpdateState = "rollback_completed"
  53. )
  54. // UpdateStatus reports the status of a service update.
  55. type UpdateStatus struct {
  56. State UpdateState `json:",omitempty"`
  57. StartedAt *time.Time `json:",omitempty"`
  58. CompletedAt *time.Time `json:",omitempty"`
  59. Message string `json:",omitempty"`
  60. }
  61. // ReplicatedService is a kind of ServiceMode.
  62. type ReplicatedService struct {
  63. Replicas *uint64 `json:",omitempty"`
  64. }
  65. // GlobalService is a kind of ServiceMode.
  66. type GlobalService struct{}
  67. const (
  68. // UpdateFailureActionPause PAUSE
  69. UpdateFailureActionPause = "pause"
  70. // UpdateFailureActionContinue CONTINUE
  71. UpdateFailureActionContinue = "continue"
  72. // UpdateFailureActionRollback ROLLBACK
  73. UpdateFailureActionRollback = "rollback"
  74. // UpdateOrderStopFirst STOP_FIRST
  75. UpdateOrderStopFirst = "stop-first"
  76. // UpdateOrderStartFirst START_FIRST
  77. UpdateOrderStartFirst = "start-first"
  78. )
  79. // UpdateConfig represents the update configuration.
  80. type UpdateConfig struct {
  81. // Maximum number of tasks to be updated in one iteration.
  82. // 0 means unlimited parallelism.
  83. Parallelism uint64
  84. // Amount of time between updates.
  85. Delay time.Duration `json:",omitempty"`
  86. // FailureAction is the action to take when an update failures.
  87. FailureAction string `json:",omitempty"`
  88. // Monitor indicates how long to monitor a task for failure after it is
  89. // created. If the task fails by ending up in one of the states
  90. // REJECTED, COMPLETED, or FAILED, within Monitor from its creation,
  91. // this counts as a failure. If it fails after Monitor, it does not
  92. // count as a failure. If Monitor is unspecified, a default value will
  93. // be used.
  94. Monitor time.Duration `json:",omitempty"`
  95. // MaxFailureRatio is the fraction of tasks that may fail during
  96. // an update before the failure action is invoked. Any task created by
  97. // the current update which ends up in one of the states REJECTED,
  98. // COMPLETED or FAILED within Monitor from its creation counts as a
  99. // failure. The number of failures is divided by the number of tasks
  100. // being updated, and if this fraction is greater than
  101. // MaxFailureRatio, the failure action is invoked.
  102. //
  103. // If the failure action is CONTINUE, there is no effect.
  104. // If the failure action is PAUSE, no more tasks will be updated until
  105. // another update is started.
  106. MaxFailureRatio float32
  107. // Order indicates the order of operations when rolling out an updated
  108. // task. Either the old task is shut down before the new task is
  109. // started, or the new task is started before the old task is shut down.
  110. Order string
  111. }
  112. // ServiceStatus represents the number of running tasks in a service and the
  113. // number of tasks desired to be running.
  114. type ServiceStatus struct {
  115. // RunningTasks is the number of tasks for the service actually in the
  116. // Running state
  117. RunningTasks uint64
  118. // DesiredTasks is the number of tasks desired to be running by the
  119. // service. For replicated services, this is the replica count. For global
  120. // services, this is computed by taking the number of tasks with desired
  121. // state of not-Shutdown.
  122. DesiredTasks uint64
  123. }