task.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. // Volumes is the list of VolumeAttachments for this task. It specifies
  59. // which particular volumes are to be used by this particular task, and
  60. // fulfilling what mounts in the spec.
  61. Volumes []VolumeAttachment
  62. }
  63. // TaskSpec represents the spec of a task.
  64. type TaskSpec struct {
  65. // ContainerSpec, NetworkAttachmentSpec, and PluginSpec are mutually exclusive.
  66. // PluginSpec is only used when the `Runtime` field is set to `plugin`
  67. // NetworkAttachmentSpec is used if the `Runtime` field is set to
  68. // `attachment`.
  69. ContainerSpec *ContainerSpec `json:",omitempty"`
  70. PluginSpec *runtime.PluginSpec `json:",omitempty"`
  71. NetworkAttachmentSpec *NetworkAttachmentSpec `json:",omitempty"`
  72. Resources *ResourceRequirements `json:",omitempty"`
  73. RestartPolicy *RestartPolicy `json:",omitempty"`
  74. Placement *Placement `json:",omitempty"`
  75. Networks []NetworkAttachmentConfig `json:",omitempty"`
  76. // LogDriver specifies the LogDriver to use for tasks created from this
  77. // spec. If not present, the one on cluster default on swarm.Spec will be
  78. // used, finally falling back to the engine default if not specified.
  79. LogDriver *Driver `json:",omitempty"`
  80. // ForceUpdate is a counter that triggers an update even if no relevant
  81. // parameters have been changed.
  82. ForceUpdate uint64
  83. Runtime RuntimeType `json:",omitempty"`
  84. }
  85. // Resources represents resources (CPU/Memory) which can be advertised by a
  86. // node and requested to be reserved for a task.
  87. type Resources struct {
  88. NanoCPUs int64 `json:",omitempty"`
  89. MemoryBytes int64 `json:",omitempty"`
  90. GenericResources []GenericResource `json:",omitempty"`
  91. }
  92. // Limit describes limits on resources which can be requested by a task.
  93. type Limit struct {
  94. NanoCPUs int64 `json:",omitempty"`
  95. MemoryBytes int64 `json:",omitempty"`
  96. Pids int64 `json:",omitempty"`
  97. }
  98. // GenericResource represents a "user defined" resource which can
  99. // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1)
  100. type GenericResource struct {
  101. NamedResourceSpec *NamedGenericResource `json:",omitempty"`
  102. DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"`
  103. }
  104. // NamedGenericResource represents a "user defined" resource which is defined
  105. // as a string.
  106. // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
  107. // Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...)
  108. type NamedGenericResource struct {
  109. Kind string `json:",omitempty"`
  110. Value string `json:",omitempty"`
  111. }
  112. // DiscreteGenericResource represents a "user defined" resource which is defined
  113. // as an integer
  114. // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
  115. // Value is used to count the resource (SSD=5, HDD=3, ...)
  116. type DiscreteGenericResource struct {
  117. Kind string `json:",omitempty"`
  118. Value int64 `json:",omitempty"`
  119. }
  120. // ResourceRequirements represents resources requirements.
  121. type ResourceRequirements struct {
  122. Limits *Limit `json:",omitempty"`
  123. Reservations *Resources `json:",omitempty"`
  124. }
  125. // Placement represents orchestration parameters.
  126. type Placement struct {
  127. Constraints []string `json:",omitempty"`
  128. Preferences []PlacementPreference `json:",omitempty"`
  129. MaxReplicas uint64 `json:",omitempty"`
  130. // Platforms stores all the platforms that the image can run on.
  131. // This field is used in the platform filter for scheduling. If empty,
  132. // then the platform filter is off, meaning there are no scheduling restrictions.
  133. Platforms []Platform `json:",omitempty"`
  134. }
  135. // PlacementPreference provides a way to make the scheduler aware of factors
  136. // such as topology.
  137. type PlacementPreference struct {
  138. Spread *SpreadOver
  139. }
  140. // SpreadOver is a scheduling preference that instructs the scheduler to spread
  141. // tasks evenly over groups of nodes identified by labels.
  142. type SpreadOver struct {
  143. // label descriptor, such as engine.labels.az
  144. SpreadDescriptor string
  145. }
  146. // RestartPolicy represents the restart policy.
  147. type RestartPolicy struct {
  148. Condition RestartPolicyCondition `json:",omitempty"`
  149. Delay *time.Duration `json:",omitempty"`
  150. MaxAttempts *uint64 `json:",omitempty"`
  151. Window *time.Duration `json:",omitempty"`
  152. }
  153. // RestartPolicyCondition represents when to restart.
  154. type RestartPolicyCondition string
  155. const (
  156. // RestartPolicyConditionNone NONE
  157. RestartPolicyConditionNone RestartPolicyCondition = "none"
  158. // RestartPolicyConditionOnFailure ON_FAILURE
  159. RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
  160. // RestartPolicyConditionAny ANY
  161. RestartPolicyConditionAny RestartPolicyCondition = "any"
  162. )
  163. // TaskStatus represents the status of a task.
  164. type TaskStatus struct {
  165. Timestamp time.Time `json:",omitempty"`
  166. State TaskState `json:",omitempty"`
  167. Message string `json:",omitempty"`
  168. Err string `json:",omitempty"`
  169. ContainerStatus *ContainerStatus `json:",omitempty"`
  170. PortStatus PortStatus `json:",omitempty"`
  171. }
  172. // ContainerStatus represents the status of a container.
  173. type ContainerStatus struct {
  174. ContainerID string
  175. PID int
  176. ExitCode int
  177. }
  178. // PortStatus represents the port status of a task's host ports whose
  179. // service has published host ports
  180. type PortStatus struct {
  181. Ports []PortConfig `json:",omitempty"`
  182. }
  183. // VolumeAttachment contains the associating a Volume to a Task.
  184. type VolumeAttachment struct {
  185. // ID is the Swarmkit ID of the Volume. This is not the CSI VolumeId.
  186. ID string `json:",omitempty"`
  187. // Source, together with Target, indicates the Mount, as specified in the
  188. // ContainerSpec, that this volume fulfills.
  189. Source string `json:",omitempty"`
  190. // Target, together with Source, indicates the Mount, as specified
  191. // in the ContainerSpec, that this volume fulfills.
  192. Target string `json:",omitempty"`
  193. }