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