Adds support for creating jobs with limit constraints and value constraints. (#16)
* Adds support for creating jobs with limit constraints and value constraints.
This commit is contained in:
parent
464ef72e6b
commit
9fa6edaa3e
3 changed files with 58 additions and 0 deletions
|
@ -47,6 +47,17 @@ type Container struct {
|
||||||
Docker *DockerContainer `yaml:"docker"`
|
Docker *DockerContainer `yaml:"docker"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ValueConstraint struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Values []string `yaml:"values"`
|
||||||
|
Negated bool `yaml:"negated"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LimitConstraint struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Limit int32 `yaml:"limit"`
|
||||||
|
}
|
||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
Environment string `yaml:"environment"`
|
Environment string `yaml:"environment"`
|
||||||
Role string `yaml:"role"`
|
Role string `yaml:"role"`
|
||||||
|
@ -64,6 +75,8 @@ type Job struct {
|
||||||
Container *Container `yaml:"container,omitempty"`
|
Container *Container `yaml:"container,omitempty"`
|
||||||
CronSchedule *string `yaml:"cronSchedule,omitempty"`
|
CronSchedule *string `yaml:"cronSchedule,omitempty"`
|
||||||
CronCollisionPolicy *string `yaml:"cronCollisionPolicy,omitempty"`
|
CronCollisionPolicy *string `yaml:"cronCollisionPolicy,omitempty"`
|
||||||
|
ValueConstraints []ValueConstraint `yaml:"valueConstraints,flow,omitempty"`
|
||||||
|
LimitConstraints []LimitConstraint `yaml:"limitConstraints,flow,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Job) ToRealis() (*realis.AuroraJob, error) {
|
func (j *Job) ToRealis() (*realis.AuroraJob, error) {
|
||||||
|
@ -125,6 +138,15 @@ func (j *Job) ToRealis() (*realis.AuroraJob, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setting Constraints
|
||||||
|
for _, valConstraint := range j.ValueConstraints {
|
||||||
|
auroraJob.AddValueConstraint(valConstraint.Name, valConstraint.Negated, valConstraint.Values...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, limit := range j.LimitConstraints {
|
||||||
|
auroraJob.AddLimitConstraint(limit.Name, limit.Limit)
|
||||||
|
}
|
||||||
|
|
||||||
return auroraJob, nil
|
return auroraJob, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +184,7 @@ func (j *Job) Validate() error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Job) ValidateCron() error {
|
func (j *Job) ValidateCron() error {
|
||||||
if j.CronSchedule == nil {
|
if j.CronSchedule == nil {
|
||||||
return errors.New("cron schedule must be set")
|
return errors.New("cron schedule must be set")
|
||||||
|
|
|
@ -25,6 +25,11 @@ func TestUnmarshalJob(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalDedicatedJob(t *testing.T) {
|
||||||
|
_, err := UnmarshalJob("../test/hello_world_dedicated.yaml")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestUnmarshalCron(t *testing.T) {
|
func TestUnmarshalCron(t *testing.T) {
|
||||||
cron, err := UnmarshalJob("../test/hello_world_cron.yaml")
|
cron, err := UnmarshalJob("../test/hello_world_cron.yaml")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
30
test/hello_world_dedicated.yaml
Normal file
30
test/hello_world_dedicated.yaml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
---
|
||||||
|
environment: "prod"
|
||||||
|
role: "vagrant"
|
||||||
|
name: "hello_world"
|
||||||
|
cpu: 0.09
|
||||||
|
ram: 64
|
||||||
|
disk: 128
|
||||||
|
instances: 1
|
||||||
|
valueConstraints:
|
||||||
|
- name: "dedicated"
|
||||||
|
values:
|
||||||
|
- "vagrant/bar"
|
||||||
|
thermos:
|
||||||
|
- name: "bootstrap"
|
||||||
|
cmd: "echo bootstrapping"
|
||||||
|
- name: "hello_gorealis"
|
||||||
|
cmd: "while true; do echo hello world from gorealis; sleep 10; done"
|
||||||
|
updateSettings:
|
||||||
|
maxPerInstanceFailures: 1
|
||||||
|
maxFailedInstances: 1
|
||||||
|
minTimeInRunning: 1m
|
||||||
|
rollbackOnFailure: true
|
||||||
|
instanceRanges:
|
||||||
|
- start: 1
|
||||||
|
end: 4
|
||||||
|
blockIfNoPulseAfter: 1m
|
||||||
|
slaAware: false
|
||||||
|
strategy:
|
||||||
|
name: Batch
|
||||||
|
groupSize: 2
|
Loading…
Add table
Add a link
Reference in a new issue