From 07173df33ca09ebe2ea7bfe405a2a821138373b9 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Tue, 9 Aug 2016 13:44:54 -0700 Subject: [PATCH] Changing some of the API to allow killing of a single task Updated AddInstances command to now use InstanceKey allow flexibility Removing line that's not needed --- README.md | 7 +++---- examples/client.go | 2 +- realis.go | 21 +++++++++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 98722e8..2c2bc4a 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,7 @@ Finally, terminate the job: $ go run $GOPATH/src/github.com/rdelval/gorealis.git/examples/client.go -executor=compose -url=http://192.168.33.7:8081 -cmd=kill ``` -### Leveraging the library -Commands available: create, kill, restart +### How to leverage the library (based on the [sample client](examples/client.go)) Create a default configuration file (alternatively, manually create your own Config): ``` @@ -107,7 +106,7 @@ r.RestartJob(job.GetKey()) Adding instances (based on config of instance 0) to Aurora: ``` -r.AddInstances(job.GetKey(), 5) +r.AddInstances(&aurora.InstanceKey{job.GetKey(),0}, 5) ``` Updating the job configuration of a service job: @@ -126,7 +125,7 @@ msg, err := r.UpdateJob(updateJob, "") |CreateJob | `*Job` | Sends a job create request to Apache Aurora | |KillJob | `*aurora.JobKey` | Attempts to kill all active instances running in Aurora. Only needs environment, role, name | |RestartJob| `*aurora.JobKey` | Attempts to restart all active instances running in Aurora | -|AddInstances|`*aurora.JobKey`, `int32`| Launches the specified number of new instances based on existing job config | +|AddInstances|`*aurora.InstanceKey`, `int32`| Launches the specified number of new instances based on existing job config | |StartUpdateJob|`*UpdateJob`, `string`| Updates a service job with a new configuration | |AbortUpdateJob|`*aurora.Jobkey`, `string`, `string`| Abort the job update that matches the ID | diff --git a/examples/client.go b/examples/client.go index 75f29ae..a8db962 100644 --- a/examples/client.go +++ b/examples/client.go @@ -117,7 +117,7 @@ func main() { break case "flexUp": fmt.Println("Flexing up job") - response, err := r.AddInstances(job.JobKey(), 5) + response, err := r.AddInstances(&aurora.InstanceKey{job.JobKey(), 0}, 5) if err != nil { fmt.Print(err) } diff --git a/realis.go b/realis.go index 265674c..6e1f2b2 100644 --- a/realis.go +++ b/realis.go @@ -110,6 +110,22 @@ func (r *Realis) getActiveTaskIds(key *aurora.JobKey) (map[int32]bool, error) { return jobTaskIds, nil } + +func (r *Realis) KillTask(key *aurora.JobKey, taskId int32) { + + taskIds := make(map[int32]bool) + taskIds[taskId] = true + + response, err := r.client.KillTasks(key, taskIds) + + if err != nil { + return nil, errors.Wrap(err, "Error sending Kill command to Aurora Scheduler.") + } + + return response, nil + +} + // Sends a kill message to the scheduler for all active tasks under a job func (r *Realis) KillJob(key *aurora.JobKey) (*aurora.Response, error) { @@ -190,10 +206,7 @@ func (r *Realis) AbortJobUpdate( } // Scale up the number of instances under a job configuration -func (r *Realis) AddInstances(key *aurora.JobKey, count int32) (*aurora.Response, error) { - - //Scale up using the config from task 0. All tasks should be homogeneous. - instKey := &aurora.InstanceKey{key, 0} +func (r *Realis) AddInstances(instKey *aurora.InstanceKey, count int32) (*aurora.Response, error) { response, err := r.client.AddInstances(instKey, count)