From ab057e793ba68fd7a5880b2fd79d31684d79fc77 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Tue, 2 Aug 2016 11:53:44 -0700 Subject: [PATCH] Shortening API by removing redundant words --- examples/Client.go | 50 +++++++++++++++++++++++----------------------- job.go | 24 +++++++++++----------- updatejob.go | 14 ++++++------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/examples/Client.go b/examples/Client.go index b355d7d..20d8106 100644 --- a/examples/Client.go +++ b/examples/Client.go @@ -52,29 +52,29 @@ func main() { fmt.Print("Error reading json config file: ", err) os.Exit(1) } - job = realis.NewJob().SetEnvironment("prod"). - SetRole("vagrant"). - SetName("hello_world_from_gorealis"). - SetExecutorName(aurora.AURORA_EXECUTOR_NAME). - SetExecutorData(string(payload)). - SetNumCpus(1). - SetRam(64). - SetDisk(100). - SetIsService(true). - SetInstanceCount(1). + job = realis.NewJob().Environment("prod"). + Role("vagrant"). + Name("hello_world_from_gorealis"). + ExecutorName(aurora.AURORA_EXECUTOR_NAME). + ExecutorData(string(payload)). + NumCpus(1). + Ram(64). + Disk(100). + IsService(true). + InstanceCount(1). AddPorts(1) break case "compose": - job = realis.NewJob().SetEnvironment("prod"). - SetRole("vagrant"). - SetName("docker-compose"). - SetExecutorName("docker-compose-executor"). - SetExecutorData("{}"). - SetNumCpus(1). - SetRam(64). - SetDisk(100). - SetIsService(false). - SetInstanceCount(1). + job = realis.NewJob().Environment("prod"). + Role("vagrant"). + Name("docker-compose"). + ExecutorName("docker-compose-executor"). + ExecutorData("{}"). + NumCpus(1). + Ram(64). + Disk(100). + IsService(false). + InstanceCount(1). AddPorts(1). AddLabel("fileName", "sample-app/sample-app.yml"). AddURI("https://dl.bintray.com/rdelvalle/mesos-compose-executor/sample-app.tar.gz", true, true) @@ -97,7 +97,7 @@ func main() { case "kill": fmt.Println("Killing job") - msg, err := r.KillJob(job.GetJobKey()) + msg, err := r.KillJob(job.JobKey()) if err != nil { fmt.Print(err) } @@ -106,7 +106,7 @@ func main() { break case "restart": fmt.Println("Restarting job") - msg, err := r.RestartJob(job.GetJobKey()) + msg, err := r.RestartJob(job.JobKey()) if err != nil { fmt.Print(err) } @@ -115,7 +115,7 @@ func main() { break case "flexUp": fmt.Println("Flexing up job") - msg, err := r.AddInstances(job.GetJobKey(), 5) + msg, err := r.AddInstances(job.JobKey(), 5) if err != nil { fmt.Print(err) } @@ -125,7 +125,7 @@ func main() { fmt.Println("Updating a job with a new name") updateJob := realis.NewUpdateJob(job) - updateJob.SetInstanceCount(3).SetRam(128) + updateJob.InstanceCount(3).Ram(128) msg, err := r.StartJobUpdate(updateJob, "") if err != nil { @@ -135,7 +135,7 @@ func main() { break case "abortUpdate": fmt.Println("Abort update") - msg, err := r.AbortJobUpdate(job.GetJobKey(), *updateId, "") + msg, err := r.AbortJobUpdate(job.JobKey(), *updateId, "") if err != nil { fmt.Print(err) } diff --git a/job.go b/job.go index 55ea741..8f7d417 100644 --- a/job.go +++ b/job.go @@ -66,12 +66,12 @@ func NewJob() *Job { return &Job{jobConfig, numCpus, ramMb, diskMb, 0} } -func (a *Job) SetEnvironment(env string) *Job { +func (a *Job) Environment(env string) *Job { a.jobConfig.Key.Environment = env return a } -func (a *Job) SetRole(role string) *Job { +func (a *Job) Role(role string) *Job { a.jobConfig.Key.Role = role //Will be deprecated @@ -81,58 +81,58 @@ func (a *Job) SetRole(role string) *Job { return a } -func (a *Job) SetName(name string) *Job { +func (a *Job) Name(name string) *Job { a.jobConfig.Key.Name = name return a } -func (a *Job) SetExecutorName(name string) *Job { +func (a *Job) ExecutorName(name string) *Job { a.jobConfig.TaskConfig.ExecutorConfig.Name = name return a } -func (a *Job) SetExecutorData(data string) *Job { +func (a *Job) ExecutorData(data string) *Job { a.jobConfig.TaskConfig.ExecutorConfig.Data = data return a } -func (a *Job) SetNumCpus(cpus float64) *Job { +func (a *Job) NumCpus(cpus float64) *Job { a.numCpus.NumCpus = &cpus a.jobConfig.TaskConfig.NumCpus = cpus //Will be deprecated soon return a } -func (a *Job) SetRam(ram int64) *Job { +func (a *Job) Ram(ram int64) *Job { a.ramMb.RamMb = &ram a.jobConfig.TaskConfig.RamMb = ram //Will be deprecated soon return a } -func (a *Job) SetDisk(disk int64) *Job { +func (a *Job) Disk(disk int64) *Job { a.diskMb.DiskMb = &disk a.jobConfig.TaskConfig.DiskMb = disk //Will be deprecated return a } -func (a *Job) SetMaxFailure(maxFail int32) *Job { +func (a *Job) MaxFailure(maxFail int32) *Job { a.jobConfig.TaskConfig.MaxTaskFailures = maxFail return a } -func (a *Job) SetInstanceCount(instCount int32) *Job { +func (a *Job) InstanceCount(instCount int32) *Job { a.jobConfig.InstanceCount = instCount return a } -func (a *Job) SetIsService(isService bool) *Job { +func (a *Job) IsService(isService bool) *Job { a.jobConfig.TaskConfig.IsService = isService return a } -func (a *Job) GetJobKey() *aurora.JobKey { +func (a *Job) JobKey() *aurora.JobKey { return a.jobConfig.Key } diff --git a/updatejob.go b/updatejob.go index 2ba0729..5f8554e 100644 --- a/updatejob.go +++ b/updatejob.go @@ -40,44 +40,44 @@ func NewUpdateJob(job *Job) *UpdateJob { return &UpdateJob{job, req} } -func (u *UpdateJob) SetInstanceCount(inst int32) *UpdateJob { +func (u *UpdateJob) InstanceCount(inst int32) *UpdateJob { u.req.InstanceCount = inst return u } // Max number of instances being updated at any given moment. -func (u *UpdateJob) SetBatchSize(size int32) *UpdateJob { +func (u *UpdateJob) BatchSize(size int32) *UpdateJob { u.req.Settings.UpdateGroupSize = size return u } // Minimum number of seconds a shard must remain in RUNNING state before considered a success -func (u *UpdateJob) SetWatchTime(milliseconds int32) *UpdateJob { +func (u *UpdateJob) WatchTime(milliseconds int32) *UpdateJob { u.req.Settings.MaxPerInstanceFailures = milliseconds return u } // Wait for all instances in a group to be done before moving on -func (u *UpdateJob) SetWaitForBatchCompletion(batchWait bool) *UpdateJob { +func (u *UpdateJob) WaitForBatchCompletion(batchWait bool) *UpdateJob { u.req.Settings.WaitForBatchCompletion = batchWait return u } // Max number of instance failures to tolerate before marking instance as FAILED. -func (u *UpdateJob) SetMaxPerInstanceFailures(inst int32) *UpdateJob { +func (u *UpdateJob) MaxPerInstanceFailures(inst int32) *UpdateJob { u.req.Settings.MaxPerInstanceFailures = inst return u } // Max number of FAILED instances to tolerate before terminating the update. -func (u *UpdateJob) SetMaxFailedInstances(inst int32) *UpdateJob { +func (u *UpdateJob) MaxFailedInstances(inst int32) *UpdateJob { u.req.Settings.MaxFailedInstances = inst return u } // When False, prevents auto rollback of a failed update -func (u *UpdateJob) SetRollbackOnFail(rollback bool) *UpdateJob { +func (u *UpdateJob) RollbackOnFail(rollback bool) *UpdateJob { u.req.Settings.RollbackOnFailure = rollback return u