github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/api/types/swarm/task.go (about) 1 package swarm 2 3 import ( 4 "time" 5 6 "github.com/docker/docker/api/types/swarm/runtime" 7 ) 8 9 // TaskState represents the state of a task. 10 type TaskState string 11 12 const ( 13 // TaskStateNew NEW 14 TaskStateNew TaskState = "new" 15 // TaskStateAllocated ALLOCATED 16 TaskStateAllocated TaskState = "allocated" 17 // TaskStatePending PENDING 18 TaskStatePending TaskState = "pending" 19 // TaskStateAssigned ASSIGNED 20 TaskStateAssigned TaskState = "assigned" 21 // TaskStateAccepted ACCEPTED 22 TaskStateAccepted TaskState = "accepted" 23 // TaskStatePreparing PREPARING 24 TaskStatePreparing TaskState = "preparing" 25 // TaskStateReady READY 26 TaskStateReady TaskState = "ready" 27 // TaskStateStarting STARTING 28 TaskStateStarting TaskState = "starting" 29 // TaskStateRunning RUNNING 30 TaskStateRunning TaskState = "running" 31 // TaskStateComplete COMPLETE 32 TaskStateComplete TaskState = "complete" 33 // TaskStateShutdown SHUTDOWN 34 TaskStateShutdown TaskState = "shutdown" 35 // TaskStateFailed FAILED 36 TaskStateFailed TaskState = "failed" 37 // TaskStateRejected REJECTED 38 TaskStateRejected TaskState = "rejected" 39 // TaskStateRemove REMOVE 40 TaskStateRemove TaskState = "remove" 41 // TaskStateOrphaned ORPHANED 42 TaskStateOrphaned TaskState = "orphaned" 43 ) 44 45 // Task represents a task. 46 type Task struct { 47 ID string 48 Meta 49 Annotations 50 51 Spec TaskSpec `json:",omitempty"` 52 ServiceID string `json:",omitempty"` 53 Slot int `json:",omitempty"` 54 NodeID string `json:",omitempty"` 55 Status TaskStatus `json:",omitempty"` 56 DesiredState TaskState `json:",omitempty"` 57 NetworksAttachments []NetworkAttachment `json:",omitempty"` 58 GenericResources []GenericResource `json:",omitempty"` 59 } 60 61 // TaskSpec represents the spec of a task. 62 type TaskSpec struct { 63 // ContainerSpec and PluginSpec are mutually exclusive. 64 // PluginSpec will only be used when the `Runtime` field is set to `plugin` 65 ContainerSpec *ContainerSpec `json:",omitempty"` 66 PluginSpec *runtime.PluginSpec `json:",omitempty"` 67 68 Resources *ResourceRequirements `json:",omitempty"` 69 RestartPolicy *RestartPolicy `json:",omitempty"` 70 Placement *Placement `json:",omitempty"` 71 Networks []NetworkAttachmentConfig `json:",omitempty"` 72 73 // LogDriver specifies the LogDriver to use for tasks created from this 74 // spec. If not present, the one on cluster default on swarm.Spec will be 75 // used, finally falling back to the engine default if not specified. 76 LogDriver *Driver `json:",omitempty"` 77 78 // ForceUpdate is a counter that triggers an update even if no relevant 79 // parameters have been changed. 80 ForceUpdate uint64 81 82 Runtime RuntimeType `json:",omitempty"` 83 } 84 85 // Resources represents resources (CPU/Memory). 86 type Resources struct { 87 NanoCPUs int64 `json:",omitempty"` 88 MemoryBytes int64 `json:",omitempty"` 89 GenericResources []GenericResource `json:",omitempty"` 90 } 91 92 // GenericResource represents a "user defined" resource which can 93 // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1) 94 type GenericResource struct { 95 NamedResourceSpec *NamedGenericResource `json:",omitempty"` 96 DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"` 97 } 98 99 // NamedGenericResource represents a "user defined" resource which is defined 100 // as a string. 101 // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...) 102 // Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...) 103 type NamedGenericResource struct { 104 Kind string `json:",omitempty"` 105 Value string `json:",omitempty"` 106 } 107 108 // DiscreteGenericResource represents a "user defined" resource which is defined 109 // as an integer 110 // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...) 111 // Value is used to count the resource (SSD=5, HDD=3, ...) 112 type DiscreteGenericResource struct { 113 Kind string `json:",omitempty"` 114 Value int64 `json:",omitempty"` 115 } 116 117 // ResourceRequirements represents resources requirements. 118 type ResourceRequirements struct { 119 Limits *Resources `json:",omitempty"` 120 Reservations *Resources `json:",omitempty"` 121 } 122 123 // Placement represents orchestration parameters. 124 type Placement struct { 125 Constraints []string `json:",omitempty"` 126 Preferences []PlacementPreference `json:",omitempty"` 127 128 // Platforms stores all the platforms that the image can run on. 129 // This field is used in the platform filter for scheduling. If empty, 130 // then the platform filter is off, meaning there are no scheduling restrictions. 131 Platforms []Platform `json:",omitempty"` 132 } 133 134 // PlacementPreference provides a way to make the scheduler aware of factors 135 // such as topology. 136 type PlacementPreference struct { 137 Spread *SpreadOver 138 } 139 140 // SpreadOver is a scheduling preference that instructs the scheduler to spread 141 // tasks evenly over groups of nodes identified by labels. 142 type SpreadOver struct { 143 // label descriptor, such as engine.labels.az 144 SpreadDescriptor string 145 } 146 147 // RestartPolicy represents the restart policy. 148 type RestartPolicy struct { 149 Condition RestartPolicyCondition `json:",omitempty"` 150 Delay *time.Duration `json:",omitempty"` 151 MaxAttempts *uint64 `json:",omitempty"` 152 Window *time.Duration `json:",omitempty"` 153 } 154 155 // RestartPolicyCondition represents when to restart. 156 type RestartPolicyCondition string 157 158 const ( 159 // RestartPolicyConditionNone NONE 160 RestartPolicyConditionNone RestartPolicyCondition = "none" 161 // RestartPolicyConditionOnFailure ON_FAILURE 162 RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure" 163 // RestartPolicyConditionAny ANY 164 RestartPolicyConditionAny RestartPolicyCondition = "any" 165 ) 166 167 // TaskStatus represents the status of a task. 168 type TaskStatus struct { 169 Timestamp time.Time `json:",omitempty"` 170 State TaskState `json:",omitempty"` 171 Message string `json:",omitempty"` 172 Err string `json:",omitempty"` 173 ContainerStatus ContainerStatus `json:",omitempty"` 174 PortStatus PortStatus `json:",omitempty"` 175 } 176 177 // ContainerStatus represents the status of a container. 178 type ContainerStatus struct { 179 ContainerID string `json:",omitempty"` 180 PID int `json:",omitempty"` 181 ExitCode int `json:",omitempty"` 182 } 183 184 // PortStatus represents the port status of a task's host ports whose 185 // service has published host ports 186 type PortStatus struct { 187 Ports []PortConfig `json:",omitempty"` 188 }