task.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. Pids int64 `json:",omitempty"`
  93. }
  94. // GenericResource represents a "user defined" resource which can
  95. // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1)
  96. type GenericResource struct {
  97. NamedResourceSpec *NamedGenericResource `json:",omitempty"`
  98. DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"`
  99. }
  100. // NamedGenericResource represents a "user defined" resource which is defined
  101. // as a string.
  102. // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
  103. // Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...)
  104. type NamedGenericResource struct {
  105. Kind string `json:",omitempty"`
  106. Value string `json:",omitempty"`
  107. }
  108. // DiscreteGenericResource represents a "user defined" resource which is defined
  109. // as an integer
  110. // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
  111. // Value is used to count the resource (SSD=5, HDD=3, ...)
  112. type DiscreteGenericResource struct {
  113. Kind string `json:",omitempty"`
  114. Value int64 `json:",omitempty"`
  115. }
  116. // ResourceRequirements represents resources requirements.
  117. type ResourceRequirements struct {
  118. Limits *Limit `json:",omitempty"`
  119. Reservations *Resources `json:",omitempty"`
  120. }
  121. // Placement represents orchestration parameters.
  122. type Placement struct {
  123. Constraints []string `json:",omitempty"`
  124. Preferences []PlacementPreference `json:",omitempty"`
  125. MaxReplicas uint64 `json:",omitempty"`
  126. // Platforms stores all the platforms that the image can run on.
  127. // This field is used in the platform filter for scheduling. If empty,
  128. // then the platform filter is off, meaning there are no scheduling restrictions.
  129. Platforms []Platform `json:",omitempty"`
  130. }
  131. // PlacementPreference provides a way to make the scheduler aware of factors
  132. // such as topology.
  133. type PlacementPreference struct {
  134. Spread *SpreadOver
  135. }
  136. // SpreadOver is a scheduling preference that instructs the scheduler to spread
  137. // tasks evenly over groups of nodes identified by labels.
  138. type SpreadOver struct {
  139. // label descriptor, such as engine.labels.az
  140. SpreadDescriptor string
  141. }
  142. // RestartPolicy represents the restart policy.
  143. type RestartPolicy struct {
  144. Condition RestartPolicyCondition `json:",omitempty"`
  145. Delay *time.Duration `json:",omitempty"`
  146. MaxAttempts *uint64 `json:",omitempty"`
  147. Window *time.Duration `json:",omitempty"`
  148. }
  149. // RestartPolicyCondition represents when to restart.
  150. type RestartPolicyCondition string
  151. const (
  152. // RestartPolicyConditionNone NONE
  153. RestartPolicyConditionNone RestartPolicyCondition = "none"
  154. // RestartPolicyConditionOnFailure ON_FAILURE
  155. RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
  156. // RestartPolicyConditionAny ANY
  157. RestartPolicyConditionAny RestartPolicyCondition = "any"
  158. )
  159. // TaskStatus represents the status of a task.
  160. type TaskStatus struct {
  161. Timestamp time.Time `json:",omitempty"`
  162. State TaskState `json:",omitempty"`
  163. Message string `json:",omitempty"`
  164. Err string `json:",omitempty"`
  165. ContainerStatus *ContainerStatus `json:",omitempty"`
  166. PortStatus PortStatus `json:",omitempty"`
  167. }
  168. // ContainerStatus represents the status of a container.
  169. type ContainerStatus struct {
  170. ContainerID string
  171. PID int
  172. ExitCode int
  173. }
  174. // PortStatus represents the port status of a task's host ports whose
  175. // service has published host ports
  176. type PortStatus struct {
  177. Ports []PortConfig `json:",omitempty"`
  178. }