Specify field names when initializing structs (#47)

* Added field names to struct initializations.
This commit is contained in:
PRADYUMNA KAUSHIK 2017-12-23 10:33:42 -08:00 committed by Renan DelValle
parent ff545e8aa6
commit 9631aa3aab
6 changed files with 84 additions and 29 deletions

View file

@ -44,7 +44,10 @@ func (c DockerContainer) Image(image string) DockerContainer {
} }
func (c DockerContainer) AddParameter(name, value string) DockerContainer { func (c DockerContainer) AddParameter(name, value string) DockerContainer {
c.container.Parameters = append(c.container.Parameters, &aurora.DockerParameter{name, value}) c.container.Parameters = append(c.container.Parameters, &aurora.DockerParameter{
Name: name,
Value: value,
})
return c return c
} }
@ -61,7 +64,7 @@ func (c MesosContainer) DockerImage(name, tag string) MesosContainer {
c.container.Image = aurora.NewImage() c.container.Image = aurora.NewImage()
} }
c.container.Image.Docker = &aurora.DockerImage{name, tag} c.container.Image.Docker = &aurora.DockerImage{Name: name, Tag: tag}
return c return c
} }
@ -70,6 +73,6 @@ func (c MesosContainer) AppcImage(name, imageId string) MesosContainer {
c.container.Image = aurora.NewImage() c.container.Image = aurora.NewImage()
} }
c.container.Image.Appc = &aurora.AppcImage{name, imageId} c.container.Image.Appc = &aurora.AppcImage{Name: name, ImageId: imageId}
return c return c
} }

View file

@ -348,7 +348,12 @@ func main() {
instId = k instId = k
break break
} }
resp, err := r.AddInstances(aurora.InstanceKey{job.JobKey(), instId}, numOfInstances) resp, err := r.AddInstances(aurora.InstanceKey{
JobKey: job.JobKey(),
InstanceId: instId,
},
numOfInstances)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
@ -399,7 +404,10 @@ func main() {
instId = k instId = k
break break
} }
taskConfig, err := r.FetchTaskConfig(aurora.InstanceKey{job.JobKey(), instId}) taskConfig, err := r.FetchTaskConfig(aurora.InstanceKey{
JobKey: job.JobKey(),
InstanceId: instId,
})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
@ -418,7 +426,12 @@ func main() {
break break
case "updateDetails": case "updateDetails":
resp, err := r.JobUpdateDetails(aurora.JobUpdateQuery{ resp, err := r.JobUpdateDetails(aurora.JobUpdateQuery{
Key: &aurora.JobUpdateKey{job.JobKey(), updateId}, Limit: 1}) Key: &aurora.JobUpdateKey{
Job: job.JobKey(),
ID: updateId,
},
Limit: 1,
})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -428,7 +441,12 @@ func main() {
break break
case "abortUpdate": case "abortUpdate":
fmt.Println("Abort update") fmt.Println("Abort update")
resp, err := r.AbortJobUpdate(aurora.JobUpdateKey{job.JobKey(), updateId}, "") resp, err := r.AbortJobUpdate(aurora.JobUpdateKey{
Job: job.JobKey(),
ID: updateId,
},
"")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
@ -437,7 +455,12 @@ func main() {
break break
case "rollbackUpdate": case "rollbackUpdate":
fmt.Println("Abort update") fmt.Println("Abort update")
resp, err := r.RollbackJobUpdate(aurora.JobUpdateKey{job.JobKey(), updateId}, "") resp, err := r.RollbackJobUpdate(aurora.JobUpdateKey{
Job: job.JobKey(),
ID: updateId,
},
"")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
@ -456,7 +479,10 @@ func main() {
instId = k instId = k
break break
} }
config, err := r.FetchTaskConfig(aurora.InstanceKey{job.JobKey(), instId}) config, err := r.FetchTaskConfig(aurora.InstanceKey{
JobKey: job.JobKey(),
InstanceId: instId,
})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -478,7 +504,8 @@ func main() {
fmt.Println(updatesummary) fmt.Println(updatesummary)
case "taskStatus": case "taskStatus":
fmt.Println("Getting task status") fmt.Println("Getting task status")
taskQ := &aurora.TaskQuery{Role: job.JobKey().Role, taskQ := &aurora.TaskQuery{
Role: job.JobKey().Role,
Environment: job.JobKey().Environment, Environment: job.JobKey().Environment,
JobName: job.JobKey().Name, JobName: job.JobKey().Name,
} }
@ -491,7 +518,8 @@ func main() {
fmt.Printf("tasks: %+v\n", tasks) fmt.Printf("tasks: %+v\n", tasks)
case "tasksWithoutConfig": case "tasksWithoutConfig":
fmt.Println("Getting task status") fmt.Println("Getting task status")
taskQ := &aurora.TaskQuery{Role: job.JobKey().Role, taskQ := &aurora.TaskQuery{
Role: job.JobKey().Role,
Environment: job.JobKey().Environment, Environment: job.JobKey().Environment,
JobName: job.JobKey().Name, JobName: job.JobKey().Name,
} }

39
job.go
View file

@ -91,7 +91,11 @@ func NewJob() Job {
ramMb.RamMb = new(int64) ramMb.RamMb = new(int64)
diskMb.DiskMb = new(int64) diskMb.DiskMb = new(int64)
return &AuroraJob{jobConfig, resources, 0} return &AuroraJob{
jobConfig: jobConfig,
resources: resources,
portCount: 0,
}
} }
// Set Job Key environment. // Set Job Key environment.
@ -105,7 +109,7 @@ func (j *AuroraJob) Role(role string) Job {
j.jobConfig.Key.Role = role j.jobConfig.Key.Role = role
//Will be deprecated //Will be deprecated
identity := &aurora.Identity{role} identity := &aurora.Identity{User: role}
j.jobConfig.Owner = identity j.jobConfig.Owner = identity
j.jobConfig.TaskConfig.Owner = identity j.jobConfig.TaskConfig.Owner = identity
return j return j
@ -211,9 +215,11 @@ func (j *AuroraJob) TaskConfig() *aurora.TaskConfig {
// --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.MesosFetcherUris[&aurora.MesosFetcherURI{
TaskConfig. Value: value,
MesosFetcherUris[&aurora.MesosFetcherURI{value, &extract, &cache}] = true Extract: &extract,
Cache: &cache,
}] = true
} }
return j return j
} }
@ -221,7 +227,7 @@ 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: key, Value: value}] = true
return j return j
} }
@ -261,8 +267,16 @@ func (j *AuroraJob) AddValueConstraint(name string, negated bool, values ...stri
for _, value := range values { for _, value := range values {
constraintValues[value] = true constraintValues[value] = true
} }
j.jobConfig.TaskConfig.Constraints[&aurora.Constraint{name, j.jobConfig.TaskConfig.Constraints[&aurora.Constraint{
&aurora.TaskConstraint{&aurora.ValueConstraint{negated, constraintValues}, nil}}] = true Name: name,
Constraint: &aurora.TaskConstraint{
Value: &aurora.ValueConstraint{
Negated: negated,
Values: constraintValues,
},
Limit: nil,
},
}] = true
return j return j
} }
@ -271,8 +285,13 @@ func (j *AuroraJob) AddValueConstraint(name string, negated bool, values ...stri
// 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{
&aurora.TaskConstraint{nil, &aurora.LimitConstraint{limit}}}] = true Name: name,
Constraint: &aurora.TaskConstraint{
Value: nil,
Limit: &aurora.LimitConstraint{Limit: limit},
},
}] = true
return j return j
} }

View file

@ -297,7 +297,8 @@ func Jitter(duration time.Duration, maxFactor float64) time.Duration {
} }
func GetDefaultClusterFromZKUrl(zkurl string) *Cluster { func GetDefaultClusterFromZKUrl(zkurl string) *Cluster {
return &Cluster{Name: "defaultCluster", return &Cluster{
Name: "defaultCluster",
AuthMechanism: "UNAUTHENTICATED", AuthMechanism: "UNAUTHENTICATED",
ZK: zkurl, ZK: zkurl,
SchedZKPath: "/aurora/scheduler", SchedZKPath: "/aurora/scheduler",
@ -506,10 +507,12 @@ func (r *realisClient) Close() {
// Uses predefined set of states to retrieve a set of active jobs in Apache Aurora. // Uses predefined set of states to retrieve a set of active jobs in Apache Aurora.
func (r *realisClient) GetInstanceIds(key *aurora.JobKey, states map[aurora.ScheduleStatus]bool) (map[int32]bool, error) { func (r *realisClient) GetInstanceIds(key *aurora.JobKey, states map[aurora.ScheduleStatus]bool) (map[int32]bool, error) {
taskQ := &aurora.TaskQuery{Role: key.Role, taskQ := &aurora.TaskQuery{
Role: key.Role,
Environment: key.Environment, Environment: key.Environment,
JobName: key.Name, JobName: key.Name,
Statuses: states} Statuses: states,
}
var resp *aurora.Response var resp *aurora.Response
var clientErr error var clientErr error
@ -977,11 +980,13 @@ func (r *realisClient) FetchTaskConfig(instKey aurora.InstanceKey) (*aurora.Task
ids := make(map[int32]bool) ids := make(map[int32]bool)
ids[instKey.InstanceId] = true ids[instKey.InstanceId] = true
taskQ := &aurora.TaskQuery{Role: instKey.JobKey.Role, taskQ := &aurora.TaskQuery{
Role: instKey.JobKey.Role,
Environment: instKey.JobKey.Environment, Environment: instKey.JobKey.Environment,
JobName: instKey.JobKey.Name, JobName: instKey.JobKey.Name,
InstanceIds: ids, InstanceIds: ids,
Statuses: aurora.ACTIVE_STATES} Statuses: aurora.ACTIVE_STATES,
}
var resp *aurora.Response var resp *aurora.Response
var clientErr error var clientErr error

View file

@ -45,7 +45,7 @@ func TestMain(m *testing.M) {
} }
// Create monitor // Create monitor
monitor = &realis.Monitor{r} monitor = &realis.Monitor{Client: r}
thermosPayload, err = ioutil.ReadFile("examples/thermos_payload.json") thermosPayload, err = ioutil.ReadFile("examples/thermos_payload.json")
if err != nil { if err != nil {

View file

@ -63,7 +63,7 @@ func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob {
req.Settings.RollbackOnFailure = true req.Settings.RollbackOnFailure = true
//TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior //TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior
return &UpdateJob{job, req} return &UpdateJob{Job: job, req: req}
} }
func NewUpdateJob(config *aurora.TaskConfig, settings *aurora.JobUpdateSettings) *UpdateJob { func NewUpdateJob(config *aurora.TaskConfig, settings *aurora.JobUpdateSettings) *UpdateJob {
@ -94,7 +94,7 @@ func NewUpdateJob(config *aurora.TaskConfig, settings *aurora.JobUpdateSettings)
} }
//TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior //TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior
return &UpdateJob{job, req} return &UpdateJob{Job: job, req: req}
} }
// Set instance count the job will have after the update. // Set instance count the job will have after the update.