task.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package 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. )
  36. // Task represents a task.
  37. type Task struct {
  38. ID string
  39. Meta
  40. Annotations
  41. Spec TaskSpec `json:",omitempty"`
  42. ServiceID string `json:",omitempty"`
  43. Slot int `json:",omitempty"`
  44. NodeID string `json:",omitempty"`
  45. Status TaskStatus `json:",omitempty"`
  46. DesiredState TaskState `json:",omitempty"`
  47. NetworksAttachments []NetworkAttachment `json:",omitempty"`
  48. }
  49. // TaskSpec represents the spec of a task.
  50. type TaskSpec struct {
  51. // ContainerSpec and PluginSpec are mutually exclusive.
  52. // PluginSpec will only be used when the `Runtime` field is set to `plugin`
  53. ContainerSpec *ContainerSpec `json:",omitempty"`
  54. PluginSpec *runtime.PluginSpec `json:",omitempty"`
  55. Resources *ResourceRequirements `json:",omitempty"`
  56. RestartPolicy *RestartPolicy `json:",omitempty"`
  57. Placement *Placement `json:",omitempty"`
  58. Networks []NetworkAttachmentConfig `json:",omitempty"`
  59. // LogDriver specifies the LogDriver to use for tasks created from this
  60. // spec. If not present, the one on cluster default on swarm.Spec will be
  61. // used, finally falling back to the engine default if not specified.
  62. LogDriver *Driver `json:",omitempty"`
  63. // ForceUpdate is a counter that triggers an update even if no relevant
  64. // parameters have been changed.
  65. ForceUpdate uint64
  66. Runtime RuntimeType `json:",omitempty"`
  67. }
  68. // Resources represents resources (CPU/Memory).
  69. type Resources struct {
  70. NanoCPUs int64 `json:",omitempty"`
  71. MemoryBytes int64 `json:",omitempty"`
  72. }
  73. // ResourceRequirements represents resources requirements.
  74. type ResourceRequirements struct {
  75. Limits *Resources `json:",omitempty"`
  76. Reservations *Resources `json:",omitempty"`
  77. }
  78. // Placement represents orchestration parameters.
  79. type Placement struct {
  80. Constraints []string `json:",omitempty"`
  81. Preferences []PlacementPreference `json:",omitempty"`
  82. // Platforms stores all the platforms that the image can run on.
  83. // This field is used in the platform filter for scheduling. If empty,
  84. // then the platform filter is off, meaning there are no scheduling restrictions.
  85. Platforms []Platform `json:",omitempty"`
  86. }
  87. // PlacementPreference provides a way to make the scheduler aware of factors
  88. // such as topology.
  89. type PlacementPreference struct {
  90. Spread *SpreadOver
  91. }
  92. // SpreadOver is a scheduling preference that instructs the scheduler to spread
  93. // tasks evenly over groups of nodes identified by labels.
  94. type SpreadOver struct {
  95. // label descriptor, such as engine.labels.az
  96. SpreadDescriptor string
  97. }
  98. // RestartPolicy represents the restart policy.
  99. type RestartPolicy struct {
  100. Condition RestartPolicyCondition `json:",omitempty"`
  101. Delay *time.Duration `json:",omitempty"`
  102. MaxAttempts *uint64 `json:",omitempty"`
  103. Window *time.Duration `json:",omitempty"`
  104. }
  105. // RestartPolicyCondition represents when to restart.
  106. type RestartPolicyCondition string
  107. const (
  108. // RestartPolicyConditionNone NONE
  109. RestartPolicyConditionNone RestartPolicyCondition = "none"
  110. // RestartPolicyConditionOnFailure ON_FAILURE
  111. RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
  112. // RestartPolicyConditionAny ANY
  113. RestartPolicyConditionAny RestartPolicyCondition = "any"
  114. )
  115. // TaskStatus represents the status of a task.
  116. type TaskStatus struct {
  117. Timestamp time.Time `json:",omitempty"`
  118. State TaskState `json:",omitempty"`
  119. Message string `json:",omitempty"`
  120. Err string `json:",omitempty"`
  121. ContainerStatus ContainerStatus `json:",omitempty"`
  122. PortStatus PortStatus `json:",omitempty"`
  123. }
  124. // ContainerStatus represents the status of a container.
  125. type ContainerStatus struct {
  126. ContainerID string `json:",omitempty"`
  127. PID int `json:",omitempty"`
  128. ExitCode int `json:",omitempty"`
  129. }
  130. // PortStatus represents the port status of a task's host ports whose
  131. // service has published host ports
  132. type PortStatus struct {
  133. Ports []PortConfig `json:",omitempty"`
  134. }