Changing return type of all realis job related tasks to be *aurora.Response in order to account for future changes and provide the programmer flexibility
This commit is contained in:
parent
f52e5105b8
commit
37be87d609
2 changed files with 43 additions and 43 deletions
|
@ -47,11 +47,11 @@ func main() {
|
|||
switch *executor {
|
||||
case "thermos":
|
||||
payload, err := ioutil.ReadFile("examples/thermos_payload.json")
|
||||
|
||||
if err != nil {
|
||||
fmt.Print("Error reading json config file: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
job = realis.NewJob().
|
||||
Environment("prod").
|
||||
Role("vagrant").
|
||||
|
@ -59,7 +59,7 @@ func main() {
|
|||
ExecutorName(aurora.AURORA_EXECUTOR_NAME).
|
||||
ExecutorData(string(payload)).
|
||||
CPU(1).
|
||||
Ram(64).
|
||||
RAM(64).
|
||||
Disk(100).
|
||||
IsService(true).
|
||||
InstanceCount(1).
|
||||
|
@ -73,7 +73,7 @@ func main() {
|
|||
ExecutorName("docker-compose-executor").
|
||||
ExecutorData("{}").
|
||||
CPU(1).
|
||||
Ram(64).
|
||||
RAM(64).
|
||||
Disk(100).
|
||||
IsService(false).
|
||||
InstanceCount(1).
|
||||
|
@ -89,62 +89,62 @@ func main() {
|
|||
switch *cmd {
|
||||
case "create":
|
||||
fmt.Println("Creating job")
|
||||
msg, err := r.CreateJob(job)
|
||||
response, err := r.CreateJob(job)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
fmt.Print(msg)
|
||||
fmt.Print(response.String())
|
||||
break
|
||||
case "kill":
|
||||
fmt.Println("Killing job")
|
||||
|
||||
msg, err := r.KillJob(job.JobKey())
|
||||
response, err := r.KillJob(job.JobKey())
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
fmt.Print(msg)
|
||||
fmt.Print(response.String())
|
||||
break
|
||||
case "restart":
|
||||
fmt.Println("Restarting job")
|
||||
msg, err := r.RestartJob(job.JobKey())
|
||||
response, err := r.RestartJob(job.JobKey())
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
fmt.Print(msg)
|
||||
fmt.Print(response.String())
|
||||
break
|
||||
case "flexUp":
|
||||
fmt.Println("Flexing up job")
|
||||
msg, err := r.AddInstances(job.JobKey(), 5)
|
||||
response, err := r.AddInstances(job.JobKey(), 5)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
fmt.Print(msg)
|
||||
fmt.Print(response.String())
|
||||
break
|
||||
case "update":
|
||||
fmt.Println("Updating a job with a new name")
|
||||
updateJob := realis.NewUpdateJob(job)
|
||||
|
||||
updateJob.InstanceCount(3).Ram(128)
|
||||
updateJob.InstanceCount(3).RAM(128)
|
||||
|
||||
msg, err := r.StartJobUpdate(updateJob, "")
|
||||
resposne, err := r.StartJobUpdate(updateJob, "")
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
fmt.Print(msg)
|
||||
fmt.Print(resposne.String())
|
||||
break
|
||||
case "abortUpdate":
|
||||
fmt.Println("Abort update")
|
||||
msg, err := r.AbortJobUpdate(job.JobKey(), *updateId, "")
|
||||
response, err := r.AbortJobUpdate(job.JobKey(), *updateId, "")
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
fmt.Print(msg)
|
||||
fmt.Print(response.String())
|
||||
break
|
||||
default:
|
||||
fmt.Println("Only Create, Kill, and Restart are supported now")
|
||||
fmt.Println("Only create, kill, restart, flexUp, update, and abortUpdate are supported now")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
52
realis.go
52
realis.go
|
@ -52,7 +52,7 @@ func NewDefaultConfig(url string) (RealisConfig, error) {
|
|||
jar, err := cookiejar.New(nil)
|
||||
|
||||
if err != nil {
|
||||
return RealisConfig{}, errors.Wrap(err, "Error creating Cookie Jar")
|
||||
return RealisConfig{}, errors.Wrap(err, "Error creating Cookie Jar.")
|
||||
}
|
||||
|
||||
//Custom client to timeout after 10 seconds to avoid hanging
|
||||
|
@ -60,12 +60,12 @@ func NewDefaultConfig(url string) (RealisConfig, error) {
|
|||
thrift.THttpClientOptions{Client: &http.Client{Timeout: time.Second * 10, Jar: jar}})
|
||||
|
||||
if err != nil {
|
||||
return RealisConfig{}, errors.Wrap(err, "Error creating transport")
|
||||
return RealisConfig{}, errors.Wrap(err, "Error creating transport.")
|
||||
}
|
||||
|
||||
if err := trans.Open(); err != nil {
|
||||
fmt.Fprintln(os.Stderr)
|
||||
return RealisConfig{}, errors.Wrapf(err, "Error opening connection to %s", url)
|
||||
return RealisConfig{}, errors.Wrapf(err, "Error opening connection to %s.", url)
|
||||
}
|
||||
|
||||
return RealisConfig{transport: trans}, nil
|
||||
|
@ -111,85 +111,86 @@ func (r *Realis) getActiveTaskIds(key *aurora.JobKey) (map[int32]bool, error) {
|
|||
}
|
||||
|
||||
// Sends a kill message to the scheduler for all active tasks under a job
|
||||
func (r *Realis) KillJob(key *aurora.JobKey) (string, error) {
|
||||
func (r *Realis) KillJob(key *aurora.JobKey) (*aurora.Response, error) {
|
||||
|
||||
taskIds, err := r.getActiveTaskIds(key)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Could not retrieve relevant task IDs")
|
||||
return nil, errors.Wrap(err, "Could not retrieve relevant task IDs.")
|
||||
}
|
||||
|
||||
if len(taskIds) > 0 {
|
||||
response, err := r.client.KillTasks(key, taskIds)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Error sending Kill command to Aurora Scheduler")
|
||||
return nil, errors.Wrap(err, "Error sending Kill command to Aurora Scheduler.")
|
||||
}
|
||||
return response.String(), nil
|
||||
|
||||
return response, nil
|
||||
} else {
|
||||
return "No tasks in the Active state.", nil
|
||||
return nil, errors.New("No tasks in the Active state.")
|
||||
}
|
||||
}
|
||||
|
||||
// Sends a create job message to the scheduler with a specific job configuration
|
||||
func (r *Realis) CreateJob(auroraJob *Job) (string, error) {
|
||||
func (r *Realis) CreateJob(auroraJob *Job) (*aurora.Response, error) {
|
||||
response, err := r.client.CreateJob(auroraJob.jobConfig)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Error sending Create command to Aurora Scheduler")
|
||||
return nil, errors.Wrap(err, "Error sending Create command to Aurora Scheduler.")
|
||||
}
|
||||
|
||||
return response.String(), nil
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// Restarts all active tasks under a job configuration
|
||||
func (r *Realis) RestartJob(key *aurora.JobKey) (string, error) {
|
||||
func (r *Realis) RestartJob(key *aurora.JobKey) (*aurora.Response, error) {
|
||||
|
||||
taskIds, err := r.getActiveTaskIds(key)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Could not retrieve relevant task IDs")
|
||||
return nil, errors.Wrap(err, "Could not retrieve relevant task IDs.")
|
||||
}
|
||||
|
||||
if len(taskIds) > 0 {
|
||||
response, err := r.client.RestartShards(key, taskIds)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Error sending Restart command to Aurora Scheduler")
|
||||
return nil, errors.Wrap(err, "Error sending Restart command to Aurora Scheduler.")
|
||||
}
|
||||
|
||||
return response.String(), nil
|
||||
return response, nil
|
||||
} else {
|
||||
return "No tasks in the Active state.", nil
|
||||
return nil, errors.New("No tasks in the Active state.")
|
||||
}
|
||||
}
|
||||
|
||||
// Update all tasks under a job configuration
|
||||
func (r *Realis) StartJobUpdate(updateJob *UpdateJob, message string) (string, error) {
|
||||
func (r *Realis) StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error) {
|
||||
|
||||
response, err := r.client.StartJobUpdate(updateJob.req, message)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Error sending StartJobUpdate command to Aurora Scheduler")
|
||||
return nil, errors.Wrap(err, "Error sending StartJobUpdate command to Aurora Scheduler.")
|
||||
}
|
||||
|
||||
return response.String(), nil
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (r *Realis) AbortJobUpdate(
|
||||
key *aurora.JobKey,
|
||||
updateId string,
|
||||
message string) (string, error) {
|
||||
message string) (*aurora.Response, error) {
|
||||
|
||||
response, err := r.client.AbortJobUpdate(&aurora.JobUpdateKey{key, updateId}, message)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Error sending AbortJobUpdate command to Aurora Scheduler")
|
||||
return nil, errors.Wrap(err, "Error sending AbortJobUpdate command to Aurora Scheduler.")
|
||||
}
|
||||
|
||||
return response.String(), nil
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// Scale up the number of instances under a job configuration
|
||||
func (r *Realis) AddInstances(key *aurora.JobKey, count int32) (string, error) {
|
||||
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}
|
||||
|
@ -197,9 +198,8 @@ func (r *Realis) AddInstances(key *aurora.JobKey, count int32) (string, error) {
|
|||
response, err := r.client.AddInstances(instKey, count)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Error sending AddInstances command to Aurora Scheduler")
|
||||
return nil, errors.Wrap(err, "Error sending AddInstances command to Aurora Scheduler.")
|
||||
}
|
||||
|
||||
return response.String(), nil
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue