github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/api/types/swarm/task.go (about)

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