github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/operator.go (about)

     1  package structs
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/hashicorp/raft"
     8  )
     9  
    10  // RaftServer has information about a server in the Raft configuration.
    11  type RaftServer struct {
    12  	// ID is the unique ID for the server. These are currently the same
    13  	// as the address, but they will be changed to a real GUID in a future
    14  	// release of Nomad.
    15  	ID raft.ServerID
    16  
    17  	// Node is the node name of the server, as known by Nomad, or this
    18  	// will be set to "(unknown)" otherwise.
    19  	Node string
    20  
    21  	// Address is the IP:port of the server, used for Raft communications.
    22  	Address raft.ServerAddress
    23  
    24  	// Leader is true if this server is the current cluster leader.
    25  	Leader bool
    26  
    27  	// Voter is true if this server has a vote in the cluster. This might
    28  	// be false if the server is staging and still coming online, or if
    29  	// it's a non-voting server, which will be added in a future release of
    30  	// Nomad.
    31  	Voter bool
    32  
    33  	// RaftProtocol is the version of the Raft protocol spoken by this server.
    34  	RaftProtocol string
    35  }
    36  
    37  // RaftConfigurationResponse is returned when querying for the current Raft
    38  // configuration.
    39  type RaftConfigurationResponse struct {
    40  	// Servers has the list of servers in the Raft configuration.
    41  	Servers []*RaftServer
    42  
    43  	// Index has the Raft index of this configuration.
    44  	Index uint64
    45  }
    46  
    47  // RaftPeerByAddressRequest is used by the Operator endpoint to apply a Raft
    48  // operation on a specific Raft peer by address in the form of "IP:port".
    49  type RaftPeerByAddressRequest struct {
    50  	// Address is the peer to remove, in the form "IP:port".
    51  	Address raft.ServerAddress
    52  
    53  	// WriteRequest holds the Region for this request.
    54  	WriteRequest
    55  }
    56  
    57  // RaftPeerByIDRequest is used by the Operator endpoint to apply a Raft
    58  // operation on a specific Raft peer by ID.
    59  type RaftPeerByIDRequest struct {
    60  	// ID is the peer ID to remove.
    61  	ID raft.ServerID
    62  
    63  	// WriteRequest holds the Region for this request.
    64  	WriteRequest
    65  }
    66  
    67  // AutopilotSetConfigRequest is used by the Operator endpoint to update the
    68  // current Autopilot configuration of the cluster.
    69  type AutopilotSetConfigRequest struct {
    70  	// Datacenter is the target this request is intended for.
    71  	Datacenter string
    72  
    73  	// Config is the new Autopilot configuration to use.
    74  	Config AutopilotConfig
    75  
    76  	// CAS controls whether to use check-and-set semantics for this request.
    77  	CAS bool
    78  
    79  	// WriteRequest holds the ACL token to go along with this request.
    80  	WriteRequest
    81  }
    82  
    83  // RequestDatacenter returns the datacenter for a given request.
    84  func (op *AutopilotSetConfigRequest) RequestDatacenter() string {
    85  	return op.Datacenter
    86  }
    87  
    88  // AutopilotConfig is the internal config for the Autopilot mechanism.
    89  type AutopilotConfig struct {
    90  	// CleanupDeadServers controls whether to remove dead servers when a new
    91  	// server is added to the Raft peers.
    92  	CleanupDeadServers bool
    93  
    94  	// ServerStabilizationTime is the minimum amount of time a server must be
    95  	// in a stable, healthy state before it can be added to the cluster. Only
    96  	// applicable with Raft protocol version 3 or higher.
    97  	ServerStabilizationTime time.Duration
    98  
    99  	// LastContactThreshold is the limit on the amount of time a server can go
   100  	// without leader contact before being considered unhealthy.
   101  	LastContactThreshold time.Duration
   102  
   103  	// MaxTrailingLogs is the amount of entries in the Raft Log that a server can
   104  	// be behind before being considered unhealthy.
   105  	MaxTrailingLogs uint64
   106  
   107  	// MinQuorum sets the minimum number of servers required in a cluster
   108  	// before autopilot can prune dead servers.
   109  	MinQuorum uint
   110  
   111  	// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
   112  	EnableRedundancyZones bool
   113  
   114  	// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
   115  	// strategy of waiting until enough newer-versioned servers have been added to the
   116  	// cluster before promoting them to voters.
   117  	DisableUpgradeMigration bool
   118  
   119  	// (Enterprise-only) EnableCustomUpgrades specifies whether to enable using custom
   120  	// upgrade versions when performing migrations.
   121  	EnableCustomUpgrades bool
   122  
   123  	// CreateIndex/ModifyIndex store the create/modify indexes of this configuration.
   124  	CreateIndex uint64
   125  	ModifyIndex uint64
   126  }
   127  
   128  func (a *AutopilotConfig) Copy() *AutopilotConfig {
   129  	if a == nil {
   130  		return nil
   131  	}
   132  
   133  	na := *a
   134  	return &na
   135  }
   136  
   137  // SchedulerAlgorithm is an enum string that encapsulates the valid options for a
   138  // SchedulerConfiguration stanza's SchedulerAlgorithm. These modes will allow the
   139  // scheduler to be user-selectable.
   140  type SchedulerAlgorithm string
   141  
   142  const (
   143  	// SchedulerAlgorithmBinpack indicates that the scheduler should spread
   144  	// allocations as evenly as possible over the available hardware.
   145  	SchedulerAlgorithmBinpack SchedulerAlgorithm = "binpack"
   146  
   147  	// SchedulerAlgorithmSpread indicates that the scheduler should spread
   148  	// allocations as evenly as possible over the available hardware.
   149  	SchedulerAlgorithmSpread SchedulerAlgorithm = "spread"
   150  )
   151  
   152  // SchedulerConfiguration is the config for controlling scheduler behavior
   153  type SchedulerConfiguration struct {
   154  	// SchedulerAlgorithm lets you select between available scheduling algorithms.
   155  	SchedulerAlgorithm SchedulerAlgorithm `hcl:"scheduler_algorithm"`
   156  
   157  	// PreemptionConfig specifies whether to enable eviction of lower
   158  	// priority jobs to place higher priority jobs.
   159  	PreemptionConfig PreemptionConfig `hcl:"preemption_config"`
   160  
   161  	// MemoryOversubscriptionEnabled specifies whether memory oversubscription is enabled
   162  	MemoryOversubscriptionEnabled bool `hcl:"memory_oversubscription_enabled"`
   163  
   164  	// RejectJobRegistration disables new job registrations except with a
   165  	// management ACL token
   166  	RejectJobRegistration bool `hcl:"reject_job_registration"`
   167  
   168  	// PauseEvalBroker is a boolean to control whether the evaluation broker
   169  	// should be paused on the cluster leader. Only a single broker runs per
   170  	// region, and it must be persisted to state so the parameter is consistent
   171  	// during leadership transitions.
   172  	PauseEvalBroker bool `hcl:"pause_eval_broker"`
   173  
   174  	// CreateIndex/ModifyIndex store the create/modify indexes of this configuration.
   175  	CreateIndex uint64
   176  	ModifyIndex uint64
   177  }
   178  
   179  func (s *SchedulerConfiguration) Copy() *SchedulerConfiguration {
   180  	if s == nil {
   181  		return s
   182  	}
   183  
   184  	ns := *s
   185  	return &ns
   186  }
   187  
   188  func (s *SchedulerConfiguration) EffectiveSchedulerAlgorithm() SchedulerAlgorithm {
   189  	if s == nil || s.SchedulerAlgorithm == "" {
   190  		return SchedulerAlgorithmBinpack
   191  	}
   192  
   193  	return s.SchedulerAlgorithm
   194  }
   195  
   196  func (s *SchedulerConfiguration) Canonicalize() {
   197  	if s != nil && s.SchedulerAlgorithm == "" {
   198  		s.SchedulerAlgorithm = SchedulerAlgorithmBinpack
   199  	}
   200  }
   201  
   202  func (s *SchedulerConfiguration) Validate() error {
   203  	if s == nil {
   204  		return nil
   205  	}
   206  
   207  	switch s.SchedulerAlgorithm {
   208  	case "", SchedulerAlgorithmBinpack, SchedulerAlgorithmSpread:
   209  	default:
   210  		return fmt.Errorf("invalid scheduler algorithm: %v", s.SchedulerAlgorithm)
   211  	}
   212  
   213  	return nil
   214  }
   215  
   216  // SchedulerConfigurationResponse is the response object that wraps SchedulerConfiguration
   217  type SchedulerConfigurationResponse struct {
   218  	// SchedulerConfig contains scheduler config options
   219  	SchedulerConfig *SchedulerConfiguration
   220  
   221  	QueryMeta
   222  }
   223  
   224  // SchedulerSetConfigurationResponse is the response object used
   225  // when updating scheduler configuration
   226  type SchedulerSetConfigurationResponse struct {
   227  	// Updated returns whether the config was actually updated
   228  	// Only set when the request uses CAS
   229  	Updated bool
   230  
   231  	WriteMeta
   232  }
   233  
   234  // PreemptionConfig specifies whether preemption is enabled based on scheduler type
   235  type PreemptionConfig struct {
   236  	// SystemSchedulerEnabled specifies if preemption is enabled for system jobs
   237  	SystemSchedulerEnabled bool `hcl:"system_scheduler_enabled"`
   238  
   239  	// SysBatchSchedulerEnabled specifies if preemption is enabled for sysbatch jobs
   240  	SysBatchSchedulerEnabled bool `hcl:"sysbatch_scheduler_enabled"`
   241  
   242  	// BatchSchedulerEnabled specifies if preemption is enabled for batch jobs
   243  	BatchSchedulerEnabled bool `hcl:"batch_scheduler_enabled"`
   244  
   245  	// ServiceSchedulerEnabled specifies if preemption is enabled for service jobs
   246  	ServiceSchedulerEnabled bool `hcl:"service_scheduler_enabled"`
   247  }
   248  
   249  // SchedulerSetConfigRequest is used by the Operator endpoint to update the
   250  // current Scheduler configuration of the cluster.
   251  type SchedulerSetConfigRequest struct {
   252  	// Config is the new Scheduler configuration to use.
   253  	Config SchedulerConfiguration
   254  
   255  	// CAS controls whether to use check-and-set semantics for this request.
   256  	CAS bool
   257  
   258  	// WriteRequest holds the ACL token to go along with this request.
   259  	WriteRequest
   260  }
   261  
   262  // SnapshotSaveRequest is used by the Operator endpoint to get a Raft snapshot
   263  type SnapshotSaveRequest struct {
   264  	QueryOptions
   265  }
   266  
   267  // SnapshotSaveResponse is the header for the streaming snapshot endpoint,
   268  // and followed by the snapshot file content.
   269  type SnapshotSaveResponse struct {
   270  
   271  	// SnapshotChecksum returns the checksum of snapshot file in the format
   272  	// `<algo>=<base64>` (e.g. `sha-256=...`)
   273  	SnapshotChecksum string
   274  
   275  	// ErrorCode is an http error code if an error is found, e.g. 403 for permission errors
   276  	ErrorCode int `codec:",omitempty"`
   277  
   278  	// ErrorMsg is the error message if an error is found, e.g. "Permission Denied"
   279  	ErrorMsg string `codec:",omitempty"`
   280  
   281  	QueryMeta
   282  }
   283  
   284  type SnapshotRestoreRequest struct {
   285  	WriteRequest
   286  }
   287  
   288  type SnapshotRestoreResponse struct {
   289  	ErrorCode int    `codec:",omitempty"`
   290  	ErrorMsg  string `codec:",omitempty"`
   291  
   292  	QueryMeta
   293  }