task.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. }
  61. // Resources represents resources (CPU/Memory).
  62. type Resources struct {
  63. NanoCPUs int64 `json:",omitempty"`
  64. MemoryBytes int64 `json:",omitempty"`
  65. }
  66. // ResourceRequirements represents resources requirements.
  67. type ResourceRequirements struct {
  68. Limits *Resources `json:",omitempty"`
  69. Reservations *Resources `json:",omitempty"`
  70. }
  71. // Placement represents orchestration parameters.
  72. type Placement struct {
  73. Constraints []string `json:",omitempty"`
  74. }
  75. // RestartPolicy represents the restart policy.
  76. type RestartPolicy struct {
  77. Condition RestartPolicyCondition `json:",omitempty"`
  78. Delay *time.Duration `json:",omitempty"`
  79. MaxAttempts *uint64 `json:",omitempty"`
  80. Window *time.Duration `json:",omitempty"`
  81. }
  82. // RestartPolicyCondition represents when to restart.
  83. type RestartPolicyCondition string
  84. const (
  85. // RestartPolicyConditionNone NONE
  86. RestartPolicyConditionNone RestartPolicyCondition = "none"
  87. // RestartPolicyConditionOnFailure ON_FAILURE
  88. RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
  89. // RestartPolicyConditionAny ANY
  90. RestartPolicyConditionAny RestartPolicyCondition = "any"
  91. )
  92. // TaskStatus represents the status of a task.
  93. type TaskStatus struct {
  94. Timestamp time.Time `json:",omitempty"`
  95. State TaskState `json:",omitempty"`
  96. Message string `json:",omitempty"`
  97. Err string `json:",omitempty"`
  98. ContainerStatus ContainerStatus `json:",omitempty"`
  99. PortStatus PortStatus `json:",omitempty"`
  100. }
  101. // ContainerStatus represents the status of a container.
  102. type ContainerStatus struct {
  103. ContainerID string `json:",omitempty"`
  104. PID int `json:",omitempty"`
  105. ExitCode int `json:",omitempty"`
  106. }
  107. // PortStatus represents the port status of a task's host ports whose
  108. // service has published host ports
  109. type PortStatus struct {
  110. Ports []PortConfig `json:",omitempty"`
  111. }