github.com/shishir-a412ed/docker@v1.3.2-0.20180103180333-fda904911d87/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  )
    40  
    41  // Task represents a task.
    42  type Task struct {
    43  	ID string
    44  	Meta
    45  	Annotations
    46  
    47  	Spec                TaskSpec            `json:",omitempty"`
    48  	ServiceID           string              `json:",omitempty"`
    49  	Slot                int                 `json:",omitempty"`
    50  	NodeID              string              `json:",omitempty"`
    51  	Status              TaskStatus          `json:",omitempty"`
    52  	DesiredState        TaskState           `json:",omitempty"`
    53  	NetworksAttachments []NetworkAttachment `json:",omitempty"`
    54  	GenericResources    []GenericResource   `json:",omitempty"`
    55  }
    56  
    57  // TaskSpec represents the spec of a task.
    58  type TaskSpec struct {
    59  	// ContainerSpec and PluginSpec are mutually exclusive.
    60  	// PluginSpec will only be used when the `Runtime` field is set to `plugin`
    61  	ContainerSpec *ContainerSpec      `json:",omitempty"`
    62  	PluginSpec    *runtime.PluginSpec `json:",omitempty"`
    63  
    64  	Resources     *ResourceRequirements     `json:",omitempty"`
    65  	RestartPolicy *RestartPolicy            `json:",omitempty"`
    66  	Placement     *Placement                `json:",omitempty"`
    67  	Networks      []NetworkAttachmentConfig `json:",omitempty"`
    68  
    69  	// LogDriver specifies the LogDriver to use for tasks created from this
    70  	// spec. If not present, the one on cluster default on swarm.Spec will be
    71  	// used, finally falling back to the engine default if not specified.
    72  	LogDriver *Driver `json:",omitempty"`
    73  
    74  	// ForceUpdate is a counter that triggers an update even if no relevant
    75  	// parameters have been changed.
    76  	ForceUpdate uint64
    77  
    78  	Runtime RuntimeType `json:",omitempty"`
    79  }
    80  
    81  // Resources represents resources (CPU/Memory).
    82  type Resources struct {
    83  	NanoCPUs         int64             `json:",omitempty"`
    84  	MemoryBytes      int64             `json:",omitempty"`
    85  	GenericResources []GenericResource `json:",omitempty"`
    86  }
    87  
    88  // GenericResource represents a "user defined" resource which can
    89  // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1)
    90  type GenericResource struct {
    91  	NamedResourceSpec    *NamedGenericResource    `json:",omitempty"`
    92  	DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"`
    93  }
    94  
    95  // NamedGenericResource represents a "user defined" resource which is defined
    96  // as a string.
    97  // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
    98  // Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...)
    99  type NamedGenericResource struct {
   100  	Kind  string `json:",omitempty"`
   101  	Value string `json:",omitempty"`
   102  }
   103  
   104  // DiscreteGenericResource represents a "user defined" resource which is defined
   105  // as an integer
   106  // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
   107  // Value is used to count the resource (SSD=5, HDD=3, ...)
   108  type DiscreteGenericResource struct {
   109  	Kind  string `json:",omitempty"`
   110  	Value int64  `json:",omitempty"`
   111  }
   112  
   113  // ResourceRequirements represents resources requirements.
   114  type ResourceRequirements struct {
   115  	Limits       *Resources `json:",omitempty"`
   116  	Reservations *Resources `json:",omitempty"`
   117  }
   118  
   119  // Placement represents orchestration parameters.
   120  type Placement struct {
   121  	Constraints []string              `json:",omitempty"`
   122  	Preferences []PlacementPreference `json:",omitempty"`
   123  
   124  	// Platforms stores all the platforms that the image can run on.
   125  	// This field is used in the platform filter for scheduling. If empty,
   126  	// then the platform filter is off, meaning there are no scheduling restrictions.
   127  	Platforms []Platform `json:",omitempty"`
   128  }
   129  
   130  // PlacementPreference provides a way to make the scheduler aware of factors
   131  // such as topology.
   132  type PlacementPreference struct {
   133  	Spread *SpreadOver
   134  }
   135  
   136  // SpreadOver is a scheduling preference that instructs the scheduler to spread
   137  // tasks evenly over groups of nodes identified by labels.
   138  type SpreadOver struct {
   139  	// label descriptor, such as engine.labels.az
   140  	SpreadDescriptor string
   141  }
   142  
   143  // RestartPolicy represents the restart policy.
   144  type RestartPolicy struct {
   145  	Condition   RestartPolicyCondition `json:",omitempty"`
   146  	Delay       *time.Duration         `json:",omitempty"`
   147  	MaxAttempts *uint64                `json:",omitempty"`
   148  	Window      *time.Duration         `json:",omitempty"`
   149  }
   150  
   151  // RestartPolicyCondition represents when to restart.
   152  type RestartPolicyCondition string
   153  
   154  const (
   155  	// RestartPolicyConditionNone NONE
   156  	RestartPolicyConditionNone RestartPolicyCondition = "none"
   157  	// RestartPolicyConditionOnFailure ON_FAILURE
   158  	RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
   159  	// RestartPolicyConditionAny ANY
   160  	RestartPolicyConditionAny RestartPolicyCondition = "any"
   161  )
   162  
   163  // TaskStatus represents the status of a task.
   164  type TaskStatus struct {
   165  	Timestamp       time.Time       `json:",omitempty"`
   166  	State           TaskState       `json:",omitempty"`
   167  	Message         string          `json:",omitempty"`
   168  	Err             string          `json:",omitempty"`
   169  	ContainerStatus ContainerStatus `json:",omitempty"`
   170  	PortStatus      PortStatus      `json:",omitempty"`
   171  }
   172  
   173  // ContainerStatus represents the status of a container.
   174  type ContainerStatus struct {
   175  	ContainerID string `json:",omitempty"`
   176  	PID         int    `json:",omitempty"`
   177  	ExitCode    int    `json:",omitempty"`
   178  }
   179  
   180  // PortStatus represents the port status of a task's host ports whose
   181  // service has published host ports
   182  type PortStatus struct {
   183  	Ports []PortConfig `json:",omitempty"`
   184  }