github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/api/types/swarm/service.go (about)

     1  package 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  
    15  // ServiceSpec represents the spec of a service.
    16  type ServiceSpec struct {
    17  	Annotations
    18  
    19  	// TaskTemplate defines how the service should construct new tasks when
    20  	// orchestrating this service.
    21  	TaskTemplate   TaskSpec      `json:",omitempty"`
    22  	Mode           ServiceMode   `json:",omitempty"`
    23  	UpdateConfig   *UpdateConfig `json:",omitempty"`
    24  	RollbackConfig *UpdateConfig `json:",omitempty"`
    25  
    26  	// Networks field in ServiceSpec is deprecated. The
    27  	// same field in TaskSpec should be used instead.
    28  	// This field will be removed in a future release.
    29  	Networks     []NetworkAttachmentConfig `json:",omitempty"`
    30  	EndpointSpec *EndpointSpec             `json:",omitempty"`
    31  }
    32  
    33  // ServiceMode represents the mode of a service.
    34  type ServiceMode struct {
    35  	Replicated *ReplicatedService `json:",omitempty"`
    36  	Global     *GlobalService     `json:",omitempty"`
    37  }
    38  
    39  // UpdateState is the state of a service update.
    40  type UpdateState string
    41  
    42  const (
    43  	// UpdateStateUpdating is the updating state.
    44  	UpdateStateUpdating UpdateState = "updating"
    45  	// UpdateStatePaused is the paused state.
    46  	UpdateStatePaused UpdateState = "paused"
    47  	// UpdateStateCompleted is the completed state.
    48  	UpdateStateCompleted UpdateState = "completed"
    49  	// UpdateStateRollbackStarted is the state with a rollback in progress.
    50  	UpdateStateRollbackStarted UpdateState = "rollback_started"
    51  	// UpdateStateRollbackPaused is the state with a rollback in progress.
    52  	UpdateStateRollbackPaused UpdateState = "rollback_paused"
    53  	// UpdateStateRollbackCompleted is the state with a rollback in progress.
    54  	UpdateStateRollbackCompleted UpdateState = "rollback_completed"
    55  )
    56  
    57  // UpdateStatus reports the status of a service update.
    58  type UpdateStatus struct {
    59  	State       UpdateState `json:",omitempty"`
    60  	StartedAt   *time.Time  `json:",omitempty"`
    61  	CompletedAt *time.Time  `json:",omitempty"`
    62  	Message     string      `json:",omitempty"`
    63  }
    64  
    65  // ReplicatedService is a kind of ServiceMode.
    66  type ReplicatedService struct {
    67  	Replicas *uint64 `json:",omitempty"`
    68  }
    69  
    70  // GlobalService is a kind of ServiceMode.
    71  type GlobalService struct{}
    72  
    73  const (
    74  	// UpdateFailureActionPause PAUSE
    75  	UpdateFailureActionPause = "pause"
    76  	// UpdateFailureActionContinue CONTINUE
    77  	UpdateFailureActionContinue = "continue"
    78  	// UpdateFailureActionRollback ROLLBACK
    79  	UpdateFailureActionRollback = "rollback"
    80  
    81  	// UpdateOrderStopFirst STOP_FIRST
    82  	UpdateOrderStopFirst = "stop-first"
    83  	// UpdateOrderStartFirst START_FIRST
    84  	UpdateOrderStartFirst = "start-first"
    85  )
    86  
    87  // UpdateConfig represents the update configuration.
    88  type UpdateConfig struct {
    89  	// Maximum number of tasks to be updated in one iteration.
    90  	// 0 means unlimited parallelism.
    91  	Parallelism uint64
    92  
    93  	// Amount of time between updates.
    94  	Delay time.Duration `json:",omitempty"`
    95  
    96  	// FailureAction is the action to take when an update failures.
    97  	FailureAction string `json:",omitempty"`
    98  
    99  	// Monitor indicates how long to monitor a task for failure after it is
   100  	// created. If the task fails by ending up in one of the states
   101  	// REJECTED, COMPLETED, or FAILED, within Monitor from its creation,
   102  	// this counts as a failure. If it fails after Monitor, it does not
   103  	// count as a failure. If Monitor is unspecified, a default value will
   104  	// be used.
   105  	Monitor time.Duration `json:",omitempty"`
   106  
   107  	// MaxFailureRatio is the fraction of tasks that may fail during
   108  	// an update before the failure action is invoked. Any task created by
   109  	// the current update which ends up in one of the states REJECTED,
   110  	// COMPLETED or FAILED within Monitor from its creation counts as a
   111  	// failure. The number of failures is divided by the number of tasks
   112  	// being updated, and if this fraction is greater than
   113  	// MaxFailureRatio, the failure action is invoked.
   114  	//
   115  	// If the failure action is CONTINUE, there is no effect.
   116  	// If the failure action is PAUSE, no more tasks will be updated until
   117  	// another update is started.
   118  	MaxFailureRatio float32
   119  
   120  	// Order indicates the order of operations when rolling out an updated
   121  	// task. Either the old task is shut down before the new task is
   122  	// started, or the new task is started before the old task is shut down.
   123  	Order string
   124  }