task.go 6.9 KB

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