github.com/devdivbcp/moby@v17.12.0-ce-rc1.0.20200726071732-2d4bfdc789ad+incompatible/api/types/swarm/task.go (about)

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