Adding ability to start an update.
This commit is contained in:
parent
d7db155d88
commit
f6ddd016aa
5 changed files with 59 additions and 78 deletions
|
@ -52,6 +52,7 @@ type Job struct {
|
|||
Disk int64 `yaml:"disk"`
|
||||
Executor Executor `yaml:"executor"`
|
||||
Instances int32 `yaml:"instances"`
|
||||
MaxFailures int32 `yaml:"maxFailures"`
|
||||
URIs []URI `yaml:"uris"`
|
||||
Metadata map[string]string `yaml:"labels"`
|
||||
Service bool `yaml:"service"`
|
||||
|
@ -59,22 +60,22 @@ type Job struct {
|
|||
Container *Container `yaml:"container,omitempty"`
|
||||
}
|
||||
type InstanceRange struct {
|
||||
Start int `yaml:"start"`
|
||||
End int `yaml:"end"`
|
||||
First int32 `yaml:"first"`
|
||||
Last int32 `yaml:"last"`
|
||||
}
|
||||
|
||||
type VariableBatchStrategy struct {
|
||||
GroupSizes []int `yaml:"groupSizes"`
|
||||
AutoPause bool `yaml:"autoPause"`
|
||||
GroupSizes []int32 `yaml:"groupSizes"`
|
||||
AutoPause bool `yaml:"autoPause"`
|
||||
}
|
||||
|
||||
type BatchStrategy struct {
|
||||
GroupSize int `yaml:"groupSize"`
|
||||
AutoPause bool `yaml:"autoPause"`
|
||||
GroupSize int32 `yaml:"groupSize"`
|
||||
AutoPause bool `yaml:"autoPause"`
|
||||
}
|
||||
|
||||
type QueueStrategy struct {
|
||||
GroupSize int `yaml:"groupSize"`
|
||||
GroupSize int32 `yaml:"groupSize"`
|
||||
}
|
||||
|
||||
type UpdateStrategy struct {
|
||||
|
@ -83,12 +84,13 @@ type UpdateStrategy struct {
|
|||
Queue *QueueStrategy `yaml:"queue"`
|
||||
}
|
||||
type UpdateSettings struct {
|
||||
MaxPerInstanceFailures int `yaml:"maxPerInstanceFailures"`
|
||||
MaxFailedInstances int `yaml:"maxFailedInstances"`
|
||||
MaxPerInstanceFailures int32 `yaml:"maxPerInstanceFailures"`
|
||||
MaxFailedInstances int32 `yaml:"maxFailedInstances"`
|
||||
MinTimeInRunning time.Duration `yaml:"minTimeRunning"`
|
||||
RollbackOnFailure bool `yaml:"rollbackOnFailure"`
|
||||
InstanceRanges []InstanceRange `yaml:"instanceRanges"`
|
||||
BlockIfNoPulseAfter time.Duration `yaml:"blockIfNoPulseAfter"`
|
||||
InstanceCount int32 `yaml:"instanceCount"`
|
||||
PulseTimeout time.Duration `yaml:"pulseTimeout"`
|
||||
SLAAware bool `yaml:"slaAware"`
|
||||
Strategy UpdateStrategy `yaml:"strategy"`
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type MonitorCmdConfig struct {
|
||||
Cmd *cobra.Command
|
||||
MonitorInterval, MonitorTimeout time.Duration
|
||||
|
@ -109,44 +110,47 @@ func UnmarshalJob(filename string) (Job, error) {
|
|||
return job, errors.Wrap(err, "unable to parse job config file")
|
||||
}
|
||||
|
||||
if !job.Validate() {
|
||||
return job, errors.New("invalid job config")
|
||||
if err := job.Validate(); err != nil {
|
||||
return job, fmt.Errorf("invalid job config %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return job, nil
|
||||
}
|
||||
|
||||
func (j *Job) Validate() bool {
|
||||
func (j *Job) Validate() error {
|
||||
if j.Name == "" {
|
||||
return false
|
||||
return errors.New("job name not specified")
|
||||
}
|
||||
|
||||
if j.Role == "" {
|
||||
return false
|
||||
return errors.New("job role not specified")
|
||||
}
|
||||
|
||||
if j.Environment == "" {
|
||||
return false
|
||||
return errors.New("job environment not specified")
|
||||
}
|
||||
|
||||
if j.Instances <= 0 {
|
||||
return false
|
||||
return errors.New("number of instances in job cannot be less than or equal to 0")
|
||||
}
|
||||
|
||||
if j.CPU <= 0.0 {
|
||||
return false
|
||||
return errors.New("CPU must be greater than 0")
|
||||
}
|
||||
|
||||
if j.RAM <= 0 {
|
||||
return false
|
||||
return errors.New("RAM must be greater than 0")
|
||||
}
|
||||
|
||||
if j.Disk <= 0 {
|
||||
return false
|
||||
return errors.New("Disk must be greater than 0")
|
||||
}
|
||||
|
||||
return true
|
||||
if len(j.Thermos) == 0 && j.Executor.Name == "" && j.Container == nil {
|
||||
return errors.New("task does not contain a thermos definition, a custom executor name, or a container to launch")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UnmarshalUpdate(filename string) (UpdateJob, error) {
|
||||
|
@ -160,11 +164,11 @@ func UnmarshalUpdate(filename string) (UpdateJob, error) {
|
|||
return updateJob, errors.Wrap(err, "unable to parse job config file")
|
||||
}
|
||||
|
||||
if !updateJob.JobConfig.Validate() {
|
||||
return updateJob, errors.New("invalid job config")
|
||||
if err := updateJob.JobConfig.Validate(); err != nil {
|
||||
return updateJob, fmt.Errorf("invalid job config %w", err)
|
||||
}
|
||||
if err := updateJob.UpdateSettings.Validate(); err != nil {
|
||||
return updateJob, errors.Wrap(err, "invalid update configuration")
|
||||
return updateJob, fmt.Errorf("invalid update configuration %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,6 +176,10 @@ func UnmarshalUpdate(filename string) (UpdateJob, error) {
|
|||
}
|
||||
|
||||
func (u *UpdateSettings) Validate() error {
|
||||
if u.InstanceCount <= 0 {
|
||||
return errors.New("instance count must be larger than 0")
|
||||
}
|
||||
|
||||
if u.Strategy.VariableBatch != nil {
|
||||
if len(u.Strategy.VariableBatch.GroupSizes) == 0 {
|
||||
return errors.New("variable batch strategy must specify at least one batch size")
|
||||
|
@ -191,7 +199,6 @@ func (u *UpdateSettings) Validate() error {
|
|||
}
|
||||
} else {
|
||||
log.Info("No strategy set, falling back on queue strategy with a group size 1")
|
||||
u.Strategy.Queue = &QueueStrategy{GroupSize: 1}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue