github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/api/types/swarm/service.go (about)

     1  package swarm // import "github.com/docker/docker/api/types/swarm"
     2  
     3  import "time"
     4  
     5  // Service represents a service.
     6  type Service struct {
     7  	ID string
     8  	Meta
     9  	Spec         ServiceSpec   `json:",omitempty"`
    10  	PreviousSpec *ServiceSpec  `json:",omitempty"`
    11  	Endpoint     Endpoint      `json:",omitempty"`
    12  	UpdateStatus *UpdateStatus `json:",omitempty"`
    13  
    14  	// ServiceStatus is an optional, extra field indicating the number of
    15  	// desired and running tasks. It is provided primarily as a shortcut to
    16  	// calculating these values client-side, which otherwise would require
    17  	// listing all tasks for a service, an operation that could be
    18  	// computation and network expensive.
    19  	ServiceStatus *ServiceStatus `json:",omitempty"`
    20  
    21  	// JobStatus is the status of a Service which is in one of ReplicatedJob or
    22  	// GlobalJob modes. It is absent on Replicated and Global services.
    23  	JobStatus *JobStatus `json:",omitempty"`
    24  }
    25  
    26  // ServiceSpec represents the spec of a service.
    27  type ServiceSpec struct {
    28  	Annotations
    29  
    30  	// TaskTemplate defines how the service should construct new tasks when
    31  	// orchestrating this service.
    32  	TaskTemplate   TaskSpec      `json:",omitempty"`
    33  	Mode           ServiceMode   `json:",omitempty"`
    34  	UpdateConfig   *UpdateConfig `json:",omitempty"`
    35  	RollbackConfig *UpdateConfig `json:",omitempty"`
    36  
    37  	// Networks field in ServiceSpec is deprecated. The
    38  	// same field in TaskSpec should be used instead.
    39  	// This field will be removed in a future release.
    40  	Networks     []NetworkAttachmentConfig `json:",omitempty"`
    41  	EndpointSpec *EndpointSpec             `json:",omitempty"`
    42  }
    43  
    44  // ServiceMode represents the mode of a service.
    45  type ServiceMode struct {
    46  	Replicated    *ReplicatedService `json:",omitempty"`
    47  	Global        *GlobalService     `json:",omitempty"`
    48  	ReplicatedJob *ReplicatedJob     `json:",omitempty"`
    49  	GlobalJob     *GlobalJob         `json:",omitempty"`
    50  }
    51  
    52  // UpdateState is the state of a service update.
    53  type UpdateState string
    54  
    55  const (
    56  	// UpdateStateUpdating is the updating state.
    57  	UpdateStateUpdating UpdateState = "updating"
    58  	// UpdateStatePaused is the paused state.
    59  	UpdateStatePaused UpdateState = "paused"
    60  	// UpdateStateCompleted is the completed state.
    61  	UpdateStateCompleted UpdateState = "completed"
    62  	// UpdateStateRollbackStarted is the state with a rollback in progress.
    63  	UpdateStateRollbackStarted UpdateState = "rollback_started"
    64  	// UpdateStateRollbackPaused is the state with a rollback in progress.
    65  	UpdateStateRollbackPaused UpdateState = "rollback_paused"
    66  	// UpdateStateRollbackCompleted is the state with a rollback in progress.
    67  	UpdateStateRollbackCompleted UpdateState = "rollback_completed"
    68  )
    69  
    70  // UpdateStatus reports the status of a service update.
    71  type UpdateStatus struct {
    72  	State       UpdateState `json:",omitempty"`
    73  	StartedAt   *time.Time  `json:",omitempty"`
    74  	CompletedAt *time.Time  `json:",omitempty"`
    75  	Message     string      `json:",omitempty"`
    76  }
    77  
    78  // ReplicatedService is a kind of ServiceMode.
    79  type ReplicatedService struct {
    80  	Replicas *uint64 `json:",omitempty"`
    81  }
    82  
    83  // GlobalService is a kind of ServiceMode.
    84  type GlobalService struct{}
    85  
    86  // ReplicatedJob is the a type of Service which executes a defined Tasks
    87  // in parallel until the specified number of Tasks have succeeded.
    88  type ReplicatedJob struct {
    89  	// MaxConcurrent indicates the maximum number of Tasks that should be
    90  	// executing simultaneously for this job at any given time. There may be
    91  	// fewer Tasks that MaxConcurrent executing simultaneously; for example, if
    92  	// there are fewer than MaxConcurrent tasks needed to reach
    93  	// TotalCompletions.
    94  	//
    95  	// If this field is empty, it will default to a max concurrency of 1.
    96  	MaxConcurrent *uint64 `json:",omitempty"`
    97  
    98  	// TotalCompletions is the total number of Tasks desired to run to
    99  	// completion.
   100  	//
   101  	// If this field is empty, the value of MaxConcurrent will be used.
   102  	TotalCompletions *uint64 `json:",omitempty"`
   103  }
   104  
   105  // GlobalJob is the type of a Service which executes a Task on every Node
   106  // matching the Service's placement constraints. These tasks run to completion
   107  // and then exit.
   108  //
   109  // This type is deliberately empty.
   110  type GlobalJob struct{}
   111  
   112  const (
   113  	// UpdateFailureActionPause PAUSE
   114  	UpdateFailureActionPause = "pause"
   115  	// UpdateFailureActionContinue CONTINUE
   116  	UpdateFailureActionContinue = "continue"
   117  	// UpdateFailureActionRollback ROLLBACK
   118  	UpdateFailureActionRollback = "rollback"
   119  
   120  	// UpdateOrderStopFirst STOP_FIRST
   121  	UpdateOrderStopFirst = "stop-first"
   122  	// UpdateOrderStartFirst START_FIRST
   123  	UpdateOrderStartFirst = "start-first"
   124  )
   125  
   126  // UpdateConfig represents the update configuration.
   127  type UpdateConfig struct {
   128  	// Maximum number of tasks to be updated in one iteration.
   129  	// 0 means unlimited parallelism.
   130  	Parallelism uint64
   131  
   132  	// Amount of time between updates.
   133  	Delay time.Duration `json:",omitempty"`
   134  
   135  	// FailureAction is the action to take when an update failures.
   136  	FailureAction string `json:",omitempty"`
   137  
   138  	// Monitor indicates how long to monitor a task for failure after it is
   139  	// created. If the task fails by ending up in one of the states
   140  	// REJECTED, COMPLETED, or FAILED, within Monitor from its creation,
   141  	// this counts as a failure. If it fails after Monitor, it does not
   142  	// count as a failure. If Monitor is unspecified, a default value will
   143  	// be used.
   144  	Monitor time.Duration `json:",omitempty"`
   145  
   146  	// MaxFailureRatio is the fraction of tasks that may fail during
   147  	// an update before the failure action is invoked. Any task created by
   148  	// the current update which ends up in one of the states REJECTED,
   149  	// COMPLETED or FAILED within Monitor from its creation counts as a
   150  	// failure. The number of failures is divided by the number of tasks
   151  	// being updated, and if this fraction is greater than
   152  	// MaxFailureRatio, the failure action is invoked.
   153  	//
   154  	// If the failure action is CONTINUE, there is no effect.
   155  	// If the failure action is PAUSE, no more tasks will be updated until
   156  	// another update is started.
   157  	MaxFailureRatio float32
   158  
   159  	// Order indicates the order of operations when rolling out an updated
   160  	// task. Either the old task is shut down before the new task is
   161  	// started, or the new task is started before the old task is shut down.
   162  	Order string
   163  }
   164  
   165  // ServiceStatus represents the number of running tasks in a service and the
   166  // number of tasks desired to be running.
   167  type ServiceStatus struct {
   168  	// RunningTasks is the number of tasks for the service actually in the
   169  	// Running state
   170  	RunningTasks uint64
   171  
   172  	// DesiredTasks is the number of tasks desired to be running by the
   173  	// service. For replicated services, this is the replica count. For global
   174  	// services, this is computed by taking the number of tasks with desired
   175  	// state of not-Shutdown.
   176  	DesiredTasks uint64
   177  
   178  	// CompletedTasks is the number of tasks in the state Completed, if this
   179  	// service is in ReplicatedJob or GlobalJob mode. This field must be
   180  	// cross-referenced with the service type, because the default value of 0
   181  	// may mean that a service is not in a job mode, or it may mean that the
   182  	// job has yet to complete any tasks.
   183  	CompletedTasks uint64
   184  }
   185  
   186  // JobStatus is the status of a job-type service.
   187  type JobStatus struct {
   188  	// JobIteration is a value increased each time a Job is executed,
   189  	// successfully or otherwise. "Executed", in this case, means the job as a
   190  	// whole has been started, not that an individual Task has been launched. A
   191  	// job is "Executed" when its ServiceSpec is updated. JobIteration can be
   192  	// used to disambiguate Tasks belonging to different executions of a job.
   193  	//
   194  	// Though JobIteration will increase with each subsequent execution, it may
   195  	// not necessarily increase by 1, and so JobIteration should not be used to
   196  	// keep track of the number of times a job has been executed.
   197  	JobIteration Version
   198  
   199  	// LastExecution is the time that the job was last executed, as observed by
   200  	// Swarm manager.
   201  	LastExecution time.Time `json:",omitempty"`
   202  }