task.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package swarm
  2. import "time"
  3. // TaskState represents the state of a task.
  4. type TaskState string
  5. const (
  6. // TaskStateNew NEW
  7. TaskStateNew TaskState = "new"
  8. // TaskStateAllocated ALLOCATED
  9. TaskStateAllocated TaskState = "allocated"
  10. // TaskStatePending PENDING
  11. TaskStatePending TaskState = "pending"
  12. // TaskStateAssigned ASSIGNED
  13. TaskStateAssigned TaskState = "assigned"
  14. // TaskStateAccepted ACCEPTED
  15. TaskStateAccepted TaskState = "accepted"
  16. // TaskStatePreparing PREPARING
  17. TaskStatePreparing TaskState = "preparing"
  18. // TaskStateReady READY
  19. TaskStateReady TaskState = "ready"
  20. // TaskStateStarting STARTING
  21. TaskStateStarting TaskState = "starting"
  22. // TaskStateRunning RUNNING
  23. TaskStateRunning TaskState = "running"
  24. // TaskStateComplete COMPLETE
  25. TaskStateComplete TaskState = "complete"
  26. // TaskStateShutdown SHUTDOWN
  27. TaskStateShutdown TaskState = "shutdown"
  28. // TaskStateFailed FAILED
  29. TaskStateFailed TaskState = "failed"
  30. // TaskStateRejected REJECTED
  31. TaskStateRejected TaskState = "rejected"
  32. )
  33. // Task represents a task.
  34. type Task struct {
  35. ID string
  36. Meta
  37. Annotations
  38. Spec TaskSpec `json:",omitempty"`
  39. ServiceID string `json:",omitempty"`
  40. Slot int `json:",omitempty"`
  41. NodeID string `json:",omitempty"`
  42. Status TaskStatus `json:",omitempty"`
  43. DesiredState TaskState `json:",omitempty"`
  44. NetworksAttachments []NetworkAttachment `json:",omitempty"`
  45. }
  46. // TaskSpec represents the spec of a task.
  47. type TaskSpec struct {
  48. ContainerSpec ContainerSpec `json:",omitempty"`
  49. Resources *ResourceRequirements `json:",omitempty"`
  50. RestartPolicy *RestartPolicy `json:",omitempty"`
  51. Placement *Placement `json:",omitempty"`
  52. Networks []NetworkAttachmentConfig `json:",omitempty"`
  53. // LogDriver specifies the LogDriver to use for tasks created from this
  54. // spec. If not present, the one on cluster default on swarm.Spec will be
  55. // used, finally falling back to the engine default if not specified.
  56. LogDriver *Driver `json:",omitempty"`
  57. // ForceUpdate is a counter that triggers an update even if no relevant
  58. // parameters have been changed.
  59. ForceUpdate uint64
  60. Runtime RuntimeType `json:",omitempty"`
  61. // TODO (ehazlett): this should be removed and instead
  62. // use struct tags (proto) for the runtimes
  63. RuntimeData []byte `json:",omitempty"`
  64. }
  65. // Resources represents resources (CPU/Memory).
  66. type Resources struct {
  67. NanoCPUs int64 `json:",omitempty"`
  68. MemoryBytes int64 `json:",omitempty"`
  69. }
  70. // ResourceRequirements represents resources requirements.
  71. type ResourceRequirements struct {
  72. Limits *Resources `json:",omitempty"`
  73. Reservations *Resources `json:",omitempty"`
  74. }
  75. // Placement represents orchestration parameters.
  76. type Placement struct {
  77. Constraints []string `json:",omitempty"`
  78. Preferences []PlacementPreference `json:",omitempty"`
  79. }
  80. // PlacementPreference provides a way to make the scheduler aware of factors
  81. // such as topology.
  82. type PlacementPreference struct {
  83. Spread *SpreadOver
  84. }
  85. // SpreadOver is a scheduling preference that instructs the scheduler to spread
  86. // tasks evenly over groups of nodes identified by labels.
  87. type SpreadOver struct {
  88. // label descriptor, such as engine.labels.az
  89. SpreadDescriptor string
  90. }
  91. // RestartPolicy represents the restart policy.
  92. type RestartPolicy struct {
  93. Condition RestartPolicyCondition `json:",omitempty"`
  94. Delay *time.Duration `json:",omitempty"`
  95. MaxAttempts *uint64 `json:",omitempty"`
  96. Window *time.Duration `json:",omitempty"`
  97. }
  98. // RestartPolicyCondition represents when to restart.
  99. type RestartPolicyCondition string
  100. const (
  101. // RestartPolicyConditionNone NONE
  102. RestartPolicyConditionNone RestartPolicyCondition = "none"
  103. // RestartPolicyConditionOnFailure ON_FAILURE
  104. RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
  105. // RestartPolicyConditionAny ANY
  106. RestartPolicyConditionAny RestartPolicyCondition = "any"
  107. )
  108. // TaskStatus represents the status of a task.
  109. type TaskStatus struct {
  110. Timestamp time.Time `json:",omitempty"`
  111. State TaskState `json:",omitempty"`
  112. Message string `json:",omitempty"`
  113. Err string `json:",omitempty"`
  114. ContainerStatus ContainerStatus `json:",omitempty"`
  115. PortStatus PortStatus `json:",omitempty"`
  116. }
  117. // ContainerStatus represents the status of a container.
  118. type ContainerStatus struct {
  119. ContainerID string `json:",omitempty"`
  120. PID int `json:",omitempty"`
  121. ExitCode int `json:",omitempty"`
  122. }
  123. // PortStatus represents the port status of a task's host ports whose
  124. // service has published host ports
  125. type PortStatus struct {
  126. Ports []PortConfig `json:",omitempty"`
  127. }