task.go 6.6 KB

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