service.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // Networks field in ServiceSpec is deprecated. The
  21. // same field in TaskSpec should be used instead.
  22. // This field will be removed in a future release.
  23. Networks []NetworkAttachmentConfig `json:",omitempty"`
  24. EndpointSpec *EndpointSpec `json:",omitempty"`
  25. }
  26. // ServiceMode represents the mode of a service.
  27. type ServiceMode struct {
  28. Replicated *ReplicatedService `json:",omitempty"`
  29. Global *GlobalService `json:",omitempty"`
  30. }
  31. // UpdateState is the state of a service update.
  32. type UpdateState string
  33. const (
  34. // UpdateStateUpdating is the updating state.
  35. UpdateStateUpdating UpdateState = "updating"
  36. // UpdateStatePaused is the paused state.
  37. UpdateStatePaused UpdateState = "paused"
  38. // UpdateStateCompleted is the completed state.
  39. UpdateStateCompleted UpdateState = "completed"
  40. )
  41. // UpdateStatus reports the status of a service update.
  42. type UpdateStatus struct {
  43. State UpdateState `json:",omitempty"`
  44. StartedAt time.Time `json:",omitempty"`
  45. CompletedAt time.Time `json:",omitempty"`
  46. Message string `json:",omitempty"`
  47. }
  48. // ReplicatedService is a kind of ServiceMode.
  49. type ReplicatedService struct {
  50. Replicas *uint64 `json:",omitempty"`
  51. }
  52. // GlobalService is a kind of ServiceMode.
  53. type GlobalService struct{}
  54. const (
  55. // UpdateFailureActionPause PAUSE
  56. UpdateFailureActionPause = "pause"
  57. // UpdateFailureActionContinue CONTINUE
  58. UpdateFailureActionContinue = "continue"
  59. )
  60. // UpdateConfig represents the update configuration.
  61. type UpdateConfig struct {
  62. // Maximum number of tasks to be updated in one iteration.
  63. // 0 means unlimited parallelism.
  64. Parallelism uint64
  65. // Amount of time between updates.
  66. Delay time.Duration `json:",omitempty"`
  67. // FailureAction is the action to take when an update failures.
  68. FailureAction string `json:",omitempty"`
  69. // Monitor indicates how long to monitor a task for failure after it is
  70. // created. If the task fails by ending up in one of the states
  71. // REJECTED, COMPLETED, or FAILED, within Monitor from its creation,
  72. // this counts as a failure. If it fails after Monitor, it does not
  73. // count as a failure. If Monitor is unspecified, a default value will
  74. // be used.
  75. Monitor time.Duration `json:",omitempty"`
  76. // MaxFailureRatio is the fraction of tasks that may fail during
  77. // an update before the failure action is invoked. Any task created by
  78. // the current update which ends up in one of the states REJECTED,
  79. // COMPLETED or FAILED within Monitor from its creation counts as a
  80. // failure. The number of failures is divided by the number of tasks
  81. // being updated, and if this fraction is greater than
  82. // MaxFailureRatio, the failure action is invoked.
  83. //
  84. // If the failure action is CONTINUE, there is no effect.
  85. // If the failure action is PAUSE, no more tasks will be updated until
  86. // another update is started.
  87. MaxFailureRatio float32
  88. }