task.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package swarm // import "github.com/docker/docker/api/types/swarm"
  2. import (
  3. "time"
  4. "github.com/docker/docker/api/types/swarm/runtime"
  5. )
  6. // TaskState represents the state of a task.
  7. type TaskState string
  8. const (
  9. // TaskStateNew NEW
  10. TaskStateNew TaskState = "new"
  11. // TaskStateAllocated ALLOCATED
  12. TaskStateAllocated TaskState = "allocated"
  13. // TaskStatePending PENDING
  14. TaskStatePending TaskState = "pending"
  15. // TaskStateAssigned ASSIGNED
  16. TaskStateAssigned TaskState = "assigned"
  17. // TaskStateAccepted ACCEPTED
  18. TaskStateAccepted TaskState = "accepted"
  19. // TaskStatePreparing PREPARING
  20. TaskStatePreparing TaskState = "preparing"
  21. // TaskStateReady READY
  22. TaskStateReady TaskState = "ready"
  23. // TaskStateStarting STARTING
  24. TaskStateStarting TaskState = "starting"
  25. // TaskStateRunning RUNNING
  26. TaskStateRunning TaskState = "running"
  27. // TaskStateComplete COMPLETE
  28. TaskStateComplete TaskState = "complete"
  29. // TaskStateShutdown SHUTDOWN
  30. TaskStateShutdown TaskState = "shutdown"
  31. // TaskStateFailed FAILED
  32. TaskStateFailed TaskState = "failed"
  33. // TaskStateRejected REJECTED
  34. TaskStateRejected TaskState = "rejected"
  35. // TaskStateRemove REMOVE
  36. TaskStateRemove TaskState = "remove"
  37. // TaskStateOrphaned ORPHANED
  38. TaskStateOrphaned TaskState = "orphaned"
  39. )
  40. // Task represents a task.
  41. type Task struct {
  42. ID string
  43. Meta
  44. Annotations
  45. Spec TaskSpec `json:",omitempty"`
  46. ServiceID string `json:",omitempty"`
  47. Slot int `json:",omitempty"`
  48. NodeID string `json:",omitempty"`
  49. Status TaskStatus `json:",omitempty"`
  50. DesiredState TaskState `json:",omitempty"`
  51. NetworksAttachments []NetworkAttachment `json:",omitempty"`
  52. GenericResources []GenericResource `json:",omitempty"`
  53. // JobIteration is the JobIteration of the Service that this Task was
  54. // spawned from, if the Service is a ReplicatedJob or GlobalJob. This is
  55. // used to determine which Tasks belong to which run of the job. This field
  56. // is absent if the Service mode is Replicated or Global.
  57. JobIteration *Version `json:",omitempty"`
  58. }
  59. // TaskSpec represents the spec of a task.
  60. type TaskSpec struct {
  61. // ContainerSpec, NetworkAttachmentSpec, and PluginSpec are mutually exclusive.
  62. // PluginSpec is only used when the `Runtime` field is set to `plugin`
  63. // NetworkAttachmentSpec is used if the `Runtime` field is set to
  64. // `attachment`.
  65. ContainerSpec *ContainerSpec `json:",omitempty"`
  66. PluginSpec *runtime.PluginSpec `json:",omitempty"`
  67. NetworkAttachmentSpec *NetworkAttachmentSpec `json:",omitempty"`
  68. Resources *ResourceRequirements `json:",omitempty"`
  69. RestartPolicy *RestartPolicy `json:",omitempty"`
  70. Placement *Placement `json:",omitempty"`
  71. Networks []NetworkAttachmentConfig `json:",omitempty"`
  72. // LogDriver specifies the LogDriver to use for tasks created from this
  73. // spec. If not present, the one on cluster default on swarm.Spec will be
  74. // used, finally falling back to the engine default if not specified.
  75. LogDriver *Driver `json:",omitempty"`
  76. // ForceUpdate is a counter that triggers an update even if no relevant
  77. // parameters have been changed.
  78. ForceUpdate uint64
  79. Runtime RuntimeType `json:",omitempty"`
  80. }
  81. // Resources represents resources (CPU/Memory) which can be advertised by a
  82. // node and requested to be reserved for a task.
  83. type Resources struct {
  84. NanoCPUs int64 `json:",omitempty"`
  85. MemoryBytes int64 `json:",omitempty"`
  86. GenericResources []GenericResource `json:",omitempty"`
  87. }
  88. // Limit describes limits on resources which can be requested by a task.
  89. type Limit struct {
  90. NanoCPUs int64 `json:",omitempty"`
  91. MemoryBytes int64 `json:",omitempty"`
  92. }
  93. // GenericResource represents a "user defined" resource which can
  94. // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1)
  95. type GenericResource struct {
  96. NamedResourceSpec *NamedGenericResource `json:",omitempty"`
  97. DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"`
  98. }
  99. // NamedGenericResource represents a "user defined" resource which is defined
  100. // as a string.
  101. // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
  102. // Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...)
  103. type NamedGenericResource struct {
  104. Kind string `json:",omitempty"`
  105. Value string `json:",omitempty"`
  106. }
  107. // DiscreteGenericResource represents a "user defined" resource which is defined
  108. // as an integer
  109. // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
  110. // Value is used to count the resource (SSD=5, HDD=3, ...)
  111. type DiscreteGenericResource struct {
  112. Kind string `json:",omitempty"`
  113. Value int64 `json:",omitempty"`
  114. }
  115. // ResourceRequirements represents resources requirements.
  116. type ResourceRequirements struct {
  117. Limits *Limit `json:",omitempty"`
  118. Reservations *Resources `json:",omitempty"`
  119. }
  120. // Placement represents orchestration parameters.
  121. type Placement struct {
  122. Constraints []string `json:",omitempty"`
  123. Preferences []PlacementPreference `json:",omitempty"`
  124. MaxReplicas uint64 `json:",omitempty"`
  125. // Platforms stores all the platforms that the image can run on.
  126. // This field is used in the platform filter for scheduling. If empty,
  127. // then the platform filter is off, meaning there are no scheduling restrictions.
  128. Platforms []Platform `json:",omitempty"`
  129. }
  130. // PlacementPreference provides a way to make the scheduler aware of factors
  131. // such as topology.
  132. type PlacementPreference struct {
  133. Spread *SpreadOver
  134. }
  135. // SpreadOver is a scheduling preference that instructs the scheduler to spread
  136. // tasks evenly over groups of nodes identified by labels.
  137. type SpreadOver struct {
  138. // label descriptor, such as engine.labels.az
  139. SpreadDescriptor string
  140. }
  141. // RestartPolicy represents the restart policy.
  142. type RestartPolicy struct {
  143. Condition RestartPolicyCondition `json:",omitempty"`
  144. Delay *time.Duration `json:",omitempty"`
  145. MaxAttempts *uint64 `json:",omitempty"`
  146. Window *time.Duration `json:",omitempty"`
  147. }
  148. // RestartPolicyCondition represents when to restart.
  149. type RestartPolicyCondition string
  150. const (
  151. // RestartPolicyConditionNone NONE
  152. RestartPolicyConditionNone RestartPolicyCondition = "none"
  153. // RestartPolicyConditionOnFailure ON_FAILURE
  154. RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
  155. // RestartPolicyConditionAny ANY
  156. RestartPolicyConditionAny RestartPolicyCondition = "any"
  157. )
  158. // TaskStatus represents the status of a task.
  159. type TaskStatus struct {
  160. Timestamp time.Time `json:",omitempty"`
  161. State TaskState `json:",omitempty"`
  162. Message string `json:",omitempty"`
  163. Err string `json:",omitempty"`
  164. ContainerStatus *ContainerStatus `json:",omitempty"`
  165. PortStatus PortStatus `json:",omitempty"`
  166. }
  167. // ContainerStatus represents the status of a container.
  168. type ContainerStatus struct {
  169. ContainerID string
  170. PID int
  171. ExitCode int
  172. }
  173. // PortStatus represents the port status of a task's host ports whose
  174. // service has published host ports
  175. type PortStatus struct {
  176. Ports []PortConfig `json:",omitempty"`
  177. }