Adding removeInstances method for a job -
-- This method takes the job key and the number of Instances to remove as parameters
This commit is contained in:
parent
811169a266
commit
40781fab82
2 changed files with 64 additions and 5 deletions
24
realis.go
24
realis.go
|
@ -25,11 +25,13 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
||||
"github.com/rdelval/gorealis/response"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Realis interface {
|
||||
AbortJobUpdate(updateKey aurora.JobUpdateKey, message string) (*aurora.Response, error)
|
||||
AddInstances(instKey aurora.InstanceKey, count int32) (*aurora.Response, error)
|
||||
RemoveInstances(key *aurora.JobKey, count int32) (*aurora.Response, error)
|
||||
CreateJob(auroraJob Job) (*aurora.Response, error)
|
||||
DescheduleCronJob(key *aurora.JobKey) (*aurora.Response, error)
|
||||
GetTaskStatus(query *aurora.TaskQuery) ([]*aurora.ScheduledTask, error)
|
||||
|
@ -320,6 +322,28 @@ func (r realisClient) AddInstances(instKey aurora.InstanceKey, count int32) (*au
|
|||
return response.ResponseCodeCheck(resp)
|
||||
}
|
||||
|
||||
//Scale down the number of instances under a job configuration using the configuratipn of a specific instance
|
||||
func (r realisClient) RemoveInstances(key *aurora.JobKey, count int32) (*aurora.Response, error) {
|
||||
instanceIds, err := r.GetInstanceIds(key, aurora.ACTIVE_STATES)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "RemoveInstances: Could not retrieve relevant instance IDs")
|
||||
}
|
||||
if len(instanceIds) < int(count) {
|
||||
return nil, errors.New(fmt.Sprintf("RemoveInstances: No sufficient instances to Kill - " +
|
||||
"Instances to kill %d Total Instances %d", count, len(instanceIds)))
|
||||
}
|
||||
instanceList := make([]int32, count)
|
||||
i := 0
|
||||
for k := range instanceIds {
|
||||
instanceList[i] = k
|
||||
i += 1
|
||||
if i == int(count) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return r.KillInstances(key, instanceList...)
|
||||
}
|
||||
|
||||
func (r realisClient) GetTaskStatus(query *aurora.TaskQuery) (tasks []*aurora.ScheduledTask, e error) {
|
||||
|
||||
resp, err := r.client.GetTasksStatus(query)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue