Changing AuroraJob to *AuroraJob in order to not create new objects so that UpdateJob is able to change parameters.

This commit is contained in:
Renan DelValle 2017-09-14 16:38:26 -07:00
parent ef49df747f
commit 13cc103faa
2 changed files with 27 additions and 27 deletions

50
job.go
View file

@ -87,17 +87,17 @@ func NewJob() Job {
taskConfig.Resources[ramMb] = true taskConfig.Resources[ramMb] = true
taskConfig.Resources[diskMb] = true taskConfig.Resources[diskMb] = true
return AuroraJob{jobConfig, resources, 0} return &AuroraJob{jobConfig, resources, 0}
} }
// Set Job Key environment. // Set Job Key environment.
func (j AuroraJob) Environment(env string) Job { func (j *AuroraJob) Environment(env string) Job {
j.jobConfig.Key.Environment = env j.jobConfig.Key.Environment = env
return j return j
} }
// Set Job Key Role. // Set Job Key Role.
func (j AuroraJob) Role(role string) Job { func (j *AuroraJob) Role(role string) Job {
j.jobConfig.Key.Role = role j.jobConfig.Key.Role = role
//Will be deprecated //Will be deprecated
@ -108,13 +108,13 @@ func (j AuroraJob) Role(role string) Job {
} }
// Set Job Key Name. // Set Job Key Name.
func (j AuroraJob) Name(name string) Job { func (j *AuroraJob) Name(name string) Job {
j.jobConfig.Key.Name = name j.jobConfig.Key.Name = name
return j return j
} }
// Set name of the executor that will the task will be configured to. // Set name of the executor that will the task will be configured to.
func (j AuroraJob) ExecutorName(name string) Job { func (j *AuroraJob) ExecutorName(name string) Job {
if j.jobConfig.TaskConfig.ExecutorConfig == nil { if j.jobConfig.TaskConfig.ExecutorConfig == nil {
j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig() j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig()
@ -125,7 +125,7 @@ func (j AuroraJob) ExecutorName(name string) Job {
} }
// Will be included as part of entire task inside the scheduler that will be serialized. // Will be included as part of entire task inside the scheduler that will be serialized.
func (j AuroraJob) ExecutorData(data string) Job { func (j *AuroraJob) ExecutorData(data string) Job {
if j.jobConfig.TaskConfig.ExecutorConfig == nil { if j.jobConfig.TaskConfig.ExecutorConfig == nil {
j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig() j.jobConfig.TaskConfig.ExecutorConfig = aurora.NewExecutorConfig()
@ -135,21 +135,21 @@ func (j AuroraJob) ExecutorData(data string) Job {
return j return j
} }
func (j AuroraJob) CPU(cpus float64) Job { func (j *AuroraJob) CPU(cpus float64) Job {
j.resources["cpu"].NumCpus = &cpus j.resources["cpu"].NumCpus = &cpus
j.jobConfig.TaskConfig.NumCpus = cpus //Will be deprecated soon j.jobConfig.TaskConfig.NumCpus = cpus //Will be deprecated soon
return j return j
} }
func (j AuroraJob) RAM(ram int64) Job { func (j *AuroraJob) RAM(ram int64) Job {
j.resources["ram"].RamMb = &ram j.resources["ram"].RamMb = &ram
j.jobConfig.TaskConfig.RamMb = ram //Will be deprecated soon j.jobConfig.TaskConfig.RamMb = ram //Will be deprecated soon
return j return j
} }
func (j AuroraJob) Disk(disk int64) Job { func (j *AuroraJob) Disk(disk int64) Job {
j.resources["disk"].DiskMb = &disk j.resources["disk"].DiskMb = &disk
j.jobConfig.TaskConfig.DiskMb = disk //Will be deprecated j.jobConfig.TaskConfig.DiskMb = disk //Will be deprecated
@ -157,55 +157,55 @@ func (j AuroraJob) Disk(disk int64) Job {
} }
// How many failures to tolerate before giving up. // How many failures to tolerate before giving up.
func (j AuroraJob) MaxFailure(maxFail int32) Job { func (j *AuroraJob) MaxFailure(maxFail int32) Job {
j.jobConfig.TaskConfig.MaxTaskFailures = maxFail j.jobConfig.TaskConfig.MaxTaskFailures = maxFail
return j return j
} }
// How many instances of the job to run // How many instances of the job to run
func (j AuroraJob) InstanceCount(instCount int32) Job { func (j *AuroraJob) InstanceCount(instCount int32) Job {
j.jobConfig.InstanceCount = instCount j.jobConfig.InstanceCount = instCount
return j return j
} }
func (j AuroraJob) CronSchedule(cron string) Job { func (j *AuroraJob) CronSchedule(cron string) Job {
j.jobConfig.CronSchedule = &cron j.jobConfig.CronSchedule = &cron
return j return j
} }
func (j AuroraJob) CronCollisionPolicy(policy aurora.CronCollisionPolicy) Job { func (j *AuroraJob) CronCollisionPolicy(policy aurora.CronCollisionPolicy) Job {
j.jobConfig.CronCollisionPolicy = policy j.jobConfig.CronCollisionPolicy = policy
return j return j
} }
// How many instances of the job to run // How many instances of the job to run
func (j AuroraJob) GetInstanceCount() int32 { func (j *AuroraJob) GetInstanceCount() int32 {
return j.jobConfig.InstanceCount return j.jobConfig.InstanceCount
} }
// Restart the job's tasks if they fail // Restart the job's tasks if they fail
func (j AuroraJob) IsService(isService bool) Job { func (j *AuroraJob) IsService(isService bool) Job {
j.jobConfig.TaskConfig.IsService = isService j.jobConfig.TaskConfig.IsService = isService
return j return j
} }
// Get the current job configurations key to use for some realis calls. // Get the current job configurations key to use for some realis calls.
func (j AuroraJob) JobKey() *aurora.JobKey { func (j *AuroraJob) JobKey() *aurora.JobKey {
return j.jobConfig.Key return j.jobConfig.Key
} }
// Get the current job configurations key to use for some realis calls. // Get the current job configurations key to use for some realis calls.
func (j AuroraJob) JobConfig() *aurora.JobConfiguration { func (j *AuroraJob) JobConfig() *aurora.JobConfiguration {
return j.jobConfig return j.jobConfig
} }
func (j AuroraJob) TaskConfig() *aurora.TaskConfig { func (j *AuroraJob) TaskConfig() *aurora.TaskConfig {
return j.jobConfig.TaskConfig return j.jobConfig.TaskConfig
} }
// Add a list of URIs with the same extract and cache configuration. Scheduler must have // Add a list of URIs with the same extract and cache configuration. Scheduler must have
// --enable_mesos_fetcher flag enabled. Currently there is no duplicate detection. // --enable_mesos_fetcher flag enabled. Currently there is no duplicate detection.
func (j AuroraJob) AddURIs(extract bool, cache bool, values ...string) Job { func (j *AuroraJob) AddURIs(extract bool, cache bool, values ...string) Job {
for _, value := range values { for _, value := range values {
j.jobConfig. j.jobConfig.
TaskConfig. TaskConfig.
@ -216,14 +216,14 @@ func (j AuroraJob) AddURIs(extract bool, cache bool, values ...string) Job {
// Adds a Mesos label to the job. Note that Aurora will add the // Adds a Mesos label to the job. Note that Aurora will add the
// prefix "org.apache.aurora.metadata." to the beginning of each key. // prefix "org.apache.aurora.metadata." to the beginning of each key.
func (j AuroraJob) AddLabel(key string, value string) Job { func (j *AuroraJob) AddLabel(key string, value string) Job {
j.jobConfig.TaskConfig.Metadata[&aurora.Metadata{key, value}] = true j.jobConfig.TaskConfig.Metadata[&aurora.Metadata{key, value}] = true
return j return j
} }
// Add a named port to the job configuration These are random ports as it's // Add a named port to the job configuration These are random ports as it's
// not currently possible to request specific ports using Aurora. // not currently possible to request specific ports using Aurora.
func (j AuroraJob) AddNamedPorts(names ...string) Job { func (j *AuroraJob) AddNamedPorts(names ...string) Job {
j.portCount += len(names) j.portCount += len(names)
for _, name := range names { for _, name := range names {
j.jobConfig.TaskConfig.Resources[&aurora.Resource{NamedPort: &name}] = true j.jobConfig.TaskConfig.Resources[&aurora.Resource{NamedPort: &name}] = true
@ -236,7 +236,7 @@ func (j AuroraJob) AddNamedPorts(names ...string) Job {
// will be org.apache.aurora.port.X, where X is the current port count for the job configuration // will be org.apache.aurora.port.X, where X is the current port count for the job configuration
// starting at 0. These are random ports as it's not currently possible to request // starting at 0. These are random ports as it's not currently possible to request
// specific ports using Aurora. // specific ports using Aurora.
func (j AuroraJob) AddPorts(num int) Job { func (j *AuroraJob) AddPorts(num int) Job {
start := j.portCount start := j.portCount
j.portCount += num j.portCount += num
for i := start; i < j.portCount; i++ { for i := start; i < j.portCount; i++ {
@ -252,7 +252,7 @@ func (j AuroraJob) AddPorts(num int) Job {
// name - Mesos slave attribute that the constraint is matched against. // name - Mesos slave attribute that the constraint is matched against.
// If negated = true , treat this as a 'not' - to avoid specific values. // If negated = true , treat this as a 'not' - to avoid specific values.
// Values - list of values we look for in attribute name // Values - list of values we look for in attribute name
func (j AuroraJob) AddValueConstraint(name string, negated bool, values ...string) Job { func (j *AuroraJob) AddValueConstraint(name string, negated bool, values ...string) Job {
constraintValues := make(map[string]bool) constraintValues := make(map[string]bool)
for _, value := range values { for _, value := range values {
constraintValues[value] = true constraintValues[value] = true
@ -266,7 +266,7 @@ func (j AuroraJob) AddValueConstraint(name string, negated bool, values ...strin
// From Aurora Docs: // From Aurora Docs:
// A constraint that specifies the maximum number of active tasks on a host with // A constraint that specifies the maximum number of active tasks on a host with
// a matching attribute that may be scheduled simultaneously. // a matching attribute that may be scheduled simultaneously.
func (j AuroraJob) AddLimitConstraint(name string, limit int32) Job { func (j *AuroraJob) AddLimitConstraint(name string, limit int32) Job {
j.jobConfig.TaskConfig.Constraints[&aurora.Constraint{name, j.jobConfig.TaskConfig.Constraints[&aurora.Constraint{name,
&aurora.TaskConstraint{nil, &aurora.LimitConstraint{limit}}}] = true &aurora.TaskConstraint{nil, &aurora.LimitConstraint{limit}}}] = true
@ -274,7 +274,7 @@ func (j AuroraJob) AddLimitConstraint(name string, limit int32) Job {
} }
// Set a container to run for the job configuration to run. // Set a container to run for the job configuration to run.
func (j AuroraJob) Container(container Container) Job { func (j *AuroraJob) Container(container Container) Job {
j.jobConfig.TaskConfig.Container = container.Build() j.jobConfig.TaskConfig.Container = container.Build()
return j return j

View file

@ -31,7 +31,7 @@ func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob {
req.TaskConfig = config req.TaskConfig = config
req.Settings = aurora.NewJobUpdateSettings() req.Settings = aurora.NewJobUpdateSettings()
job := NewJob().(AuroraJob) job := NewJob().(*AuroraJob)
job.jobConfig.TaskConfig = config job.jobConfig.TaskConfig = config
// Rebuild resource map from TaskConfig // Rebuild resource map from TaskConfig
@ -72,7 +72,7 @@ func NewUpdateJob(config *aurora.TaskConfig, settings *aurora.JobUpdateSettings)
req.TaskConfig = config req.TaskConfig = config
req.Settings = settings req.Settings = settings
job := NewJob().(AuroraJob) job := NewJob().(*AuroraJob)
job.jobConfig.TaskConfig = config job.jobConfig.TaskConfig = config
// Rebuild resource map from TaskConfig // Rebuild resource map from TaskConfig