Shortening API by removing redundant words

This commit is contained in:
Renan DelValle 2016-08-02 11:53:44 -07:00
parent 982bbe4e08
commit ab057e793b
3 changed files with 44 additions and 44 deletions

View file

@ -52,29 +52,29 @@ func main() {
fmt.Print("Error reading json config file: ", err) fmt.Print("Error reading json config file: ", err)
os.Exit(1) os.Exit(1)
} }
job = realis.NewJob().SetEnvironment("prod"). job = realis.NewJob().Environment("prod").
SetRole("vagrant"). Role("vagrant").
SetName("hello_world_from_gorealis"). Name("hello_world_from_gorealis").
SetExecutorName(aurora.AURORA_EXECUTOR_NAME). ExecutorName(aurora.AURORA_EXECUTOR_NAME).
SetExecutorData(string(payload)). ExecutorData(string(payload)).
SetNumCpus(1). NumCpus(1).
SetRam(64). Ram(64).
SetDisk(100). Disk(100).
SetIsService(true). IsService(true).
SetInstanceCount(1). InstanceCount(1).
AddPorts(1) AddPorts(1)
break break
case "compose": case "compose":
job = realis.NewJob().SetEnvironment("prod"). job = realis.NewJob().Environment("prod").
SetRole("vagrant"). Role("vagrant").
SetName("docker-compose"). Name("docker-compose").
SetExecutorName("docker-compose-executor"). ExecutorName("docker-compose-executor").
SetExecutorData("{}"). ExecutorData("{}").
SetNumCpus(1). NumCpus(1).
SetRam(64). Ram(64).
SetDisk(100). Disk(100).
SetIsService(false). IsService(false).
SetInstanceCount(1). InstanceCount(1).
AddPorts(1). AddPorts(1).
AddLabel("fileName", "sample-app/sample-app.yml"). AddLabel("fileName", "sample-app/sample-app.yml").
AddURI("https://dl.bintray.com/rdelvalle/mesos-compose-executor/sample-app.tar.gz", true, true) AddURI("https://dl.bintray.com/rdelvalle/mesos-compose-executor/sample-app.tar.gz", true, true)
@ -97,7 +97,7 @@ func main() {
case "kill": case "kill":
fmt.Println("Killing job") fmt.Println("Killing job")
msg, err := r.KillJob(job.GetJobKey()) msg, err := r.KillJob(job.JobKey())
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
} }
@ -106,7 +106,7 @@ func main() {
break break
case "restart": case "restart":
fmt.Println("Restarting job") fmt.Println("Restarting job")
msg, err := r.RestartJob(job.GetJobKey()) msg, err := r.RestartJob(job.JobKey())
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
} }
@ -115,7 +115,7 @@ func main() {
break break
case "flexUp": case "flexUp":
fmt.Println("Flexing up job") fmt.Println("Flexing up job")
msg, err := r.AddInstances(job.GetJobKey(), 5) msg, err := r.AddInstances(job.JobKey(), 5)
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
} }
@ -125,7 +125,7 @@ func main() {
fmt.Println("Updating a job with a new name") fmt.Println("Updating a job with a new name")
updateJob := realis.NewUpdateJob(job) updateJob := realis.NewUpdateJob(job)
updateJob.SetInstanceCount(3).SetRam(128) updateJob.InstanceCount(3).Ram(128)
msg, err := r.StartJobUpdate(updateJob, "") msg, err := r.StartJobUpdate(updateJob, "")
if err != nil { if err != nil {
@ -135,7 +135,7 @@ func main() {
break break
case "abortUpdate": case "abortUpdate":
fmt.Println("Abort update") fmt.Println("Abort update")
msg, err := r.AbortJobUpdate(job.GetJobKey(), *updateId, "") msg, err := r.AbortJobUpdate(job.JobKey(), *updateId, "")
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
} }

24
job.go
View file

@ -66,12 +66,12 @@ func NewJob() *Job {
return &Job{jobConfig, numCpus, ramMb, diskMb, 0} 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 a.jobConfig.Key.Environment = env
return a return a
} }
func (a *Job) SetRole(role string) *Job { func (a *Job) Role(role string) *Job {
a.jobConfig.Key.Role = role a.jobConfig.Key.Role = role
//Will be deprecated //Will be deprecated
@ -81,58 +81,58 @@ func (a *Job) SetRole(role string) *Job {
return a return a
} }
func (a *Job) SetName(name string) *Job { func (a *Job) Name(name string) *Job {
a.jobConfig.Key.Name = name a.jobConfig.Key.Name = name
return a return a
} }
func (a *Job) SetExecutorName(name string) *Job { func (a *Job) ExecutorName(name string) *Job {
a.jobConfig.TaskConfig.ExecutorConfig.Name = name a.jobConfig.TaskConfig.ExecutorConfig.Name = name
return a return a
} }
func (a *Job) SetExecutorData(data string) *Job { func (a *Job) ExecutorData(data string) *Job {
a.jobConfig.TaskConfig.ExecutorConfig.Data = data a.jobConfig.TaskConfig.ExecutorConfig.Data = data
return a return a
} }
func (a *Job) SetNumCpus(cpus float64) *Job { func (a *Job) NumCpus(cpus float64) *Job {
a.numCpus.NumCpus = &cpus a.numCpus.NumCpus = &cpus
a.jobConfig.TaskConfig.NumCpus = cpus //Will be deprecated soon a.jobConfig.TaskConfig.NumCpus = cpus //Will be deprecated soon
return a return a
} }
func (a *Job) SetRam(ram int64) *Job { func (a *Job) Ram(ram int64) *Job {
a.ramMb.RamMb = &ram a.ramMb.RamMb = &ram
a.jobConfig.TaskConfig.RamMb = ram //Will be deprecated soon a.jobConfig.TaskConfig.RamMb = ram //Will be deprecated soon
return a return a
} }
func (a *Job) SetDisk(disk int64) *Job { func (a *Job) Disk(disk int64) *Job {
a.diskMb.DiskMb = &disk a.diskMb.DiskMb = &disk
a.jobConfig.TaskConfig.DiskMb = disk //Will be deprecated a.jobConfig.TaskConfig.DiskMb = disk //Will be deprecated
return a return a
} }
func (a *Job) SetMaxFailure(maxFail int32) *Job { func (a *Job) MaxFailure(maxFail int32) *Job {
a.jobConfig.TaskConfig.MaxTaskFailures = maxFail a.jobConfig.TaskConfig.MaxTaskFailures = maxFail
return a return a
} }
func (a *Job) SetInstanceCount(instCount int32) *Job { func (a *Job) InstanceCount(instCount int32) *Job {
a.jobConfig.InstanceCount = instCount a.jobConfig.InstanceCount = instCount
return a return a
} }
func (a *Job) SetIsService(isService bool) *Job { func (a *Job) IsService(isService bool) *Job {
a.jobConfig.TaskConfig.IsService = isService a.jobConfig.TaskConfig.IsService = isService
return a return a
} }
func (a *Job) GetJobKey() *aurora.JobKey { func (a *Job) JobKey() *aurora.JobKey {
return a.jobConfig.Key return a.jobConfig.Key
} }

View file

@ -40,44 +40,44 @@ func NewUpdateJob(job *Job) *UpdateJob {
return &UpdateJob{job, req} return &UpdateJob{job, req}
} }
func (u *UpdateJob) SetInstanceCount(inst int32) *UpdateJob { func (u *UpdateJob) InstanceCount(inst int32) *UpdateJob {
u.req.InstanceCount = inst u.req.InstanceCount = inst
return u return u
} }
// Max number of instances being updated at any given moment. // 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 u.req.Settings.UpdateGroupSize = size
return u return u
} }
// Minimum number of seconds a shard must remain in RUNNING state before considered a success // 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 u.req.Settings.MaxPerInstanceFailures = milliseconds
return u return u
} }
// Wait for all instances in a group to be done before moving on // 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 u.req.Settings.WaitForBatchCompletion = batchWait
return u return u
} }
// Max number of instance failures to tolerate before marking instance as FAILED. // 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 u.req.Settings.MaxPerInstanceFailures = inst
return u return u
} }
// Max number of FAILED instances to tolerate before terminating the update. // 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 u.req.Settings.MaxFailedInstances = inst
return u return u
} }
// When False, prevents auto rollback of a failed update // 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 u.req.Settings.RollbackOnFailure = rollback
return u return u