github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/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 66 // Resources represents resources (CPU/Memory). 67 type Resources struct { 68 NanoCPUs int64 `json:",omitempty"` 69 MemoryBytes int64 `json:",omitempty"` 70 } 71 72 // ResourceRequirements represents resources requirements. 73 type ResourceRequirements struct { 74 Limits *Resources `json:",omitempty"` 75 Reservations *Resources `json:",omitempty"` 76 } 77 78 // Placement represents orchestration parameters. 79 type Placement struct { 80 Constraints []string `json:",omitempty"` 81 } 82 83 // RestartPolicy represents the restart policy. 84 type RestartPolicy struct { 85 Condition RestartPolicyCondition `json:",omitempty"` 86 Delay *time.Duration `json:",omitempty"` 87 MaxAttempts *uint64 `json:",omitempty"` 88 Window *time.Duration `json:",omitempty"` 89 } 90 91 // RestartPolicyCondition represents when to restart. 92 type RestartPolicyCondition string 93 94 const ( 95 // RestartPolicyConditionNone NONE 96 RestartPolicyConditionNone RestartPolicyCondition = "none" 97 // RestartPolicyConditionOnFailure ON_FAILURE 98 RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure" 99 // RestartPolicyConditionAny ANY 100 RestartPolicyConditionAny RestartPolicyCondition = "any" 101 ) 102 103 // TaskStatus represents the status of a task. 104 type TaskStatus struct { 105 Timestamp time.Time `json:",omitempty"` 106 State TaskState `json:",omitempty"` 107 Message string `json:",omitempty"` 108 Err string `json:",omitempty"` 109 ContainerStatus ContainerStatus `json:",omitempty"` 110 } 111 112 // ContainerStatus represents the status of a container. 113 type ContainerStatus struct { 114 ContainerID string `json:",omitempty"` 115 PID int `json:",omitempty"` 116 ExitCode int `json:",omitempty"` 117 }