task.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. // Platforms stores all the platforms that the image can run on.
  114. // This field is used in the platform filter for scheduling. If empty,
  115. // then the platform filter is off, meaning there are no scheduling restrictions.
  116. Platforms []Platform `json:",omitempty"`
  117. }
  118. // PlacementPreference provides a way to make the scheduler aware of factors
  119. // such as topology.
  120. type PlacementPreference struct {
  121. Spread *SpreadOver
  122. }
  123. // SpreadOver is a scheduling preference that instructs the scheduler to spread
  124. // tasks evenly over groups of nodes identified by labels.
  125. type SpreadOver struct {
  126. // label descriptor, such as engine.labels.az
  127. SpreadDescriptor string
  128. }
  129. // RestartPolicy represents the restart policy.
  130. type RestartPolicy struct {
  131. Condition RestartPolicyCondition `json:",omitempty"`
  132. Delay *time.Duration `json:",omitempty"`
  133. MaxAttempts *uint64 `json:",omitempty"`
  134. Window *time.Duration `json:",omitempty"`
  135. }
  136. // RestartPolicyCondition represents when to restart.
  137. type RestartPolicyCondition string
  138. const (
  139. // RestartPolicyConditionNone NONE
  140. RestartPolicyConditionNone RestartPolicyCondition = "none"
  141. // RestartPolicyConditionOnFailure ON_FAILURE
  142. RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
  143. // RestartPolicyConditionAny ANY
  144. RestartPolicyConditionAny RestartPolicyCondition = "any"
  145. )
  146. // TaskStatus represents the status of a task.
  147. type TaskStatus struct {
  148. Timestamp time.Time `json:",omitempty"`
  149. State TaskState `json:",omitempty"`
  150. Message string `json:",omitempty"`
  151. Err string `json:",omitempty"`
  152. ContainerStatus *ContainerStatus `json:",omitempty"`
  153. PortStatus PortStatus `json:",omitempty"`
  154. }
  155. // ContainerStatus represents the status of a container.
  156. type ContainerStatus struct {
  157. ContainerID string
  158. PID int
  159. ExitCode int
  160. }
  161. // PortStatus represents the port status of a task's host ports whose
  162. // service has published host ports
  163. type PortStatus struct {
  164. Ports []PortConfig `json:",omitempty"`
  165. }