update api change and remove os.exit

This commit is contained in:
Kumar Krishna 2016-11-14 23:16:36 -08:00
parent 8905233375
commit 3b10c10dd1
3 changed files with 39 additions and 9 deletions

View file

@ -272,7 +272,7 @@ func main() {
fmt.Println(err)
os.Exit(1)
}
updateJob := realis.NewUpdateJob(taskConfig)
updateJob := realis.NewDefaultUpdateJob(taskConfig)
updateJob.InstanceCount(5).RAM(128)
resp, err := r.StartJobUpdate(updateJob, "")

View file

@ -20,7 +20,6 @@ import (
"github.com/pkg/errors"
"github.com/rdelval/gorealis/gen-go/apache/aurora"
"github.com/rdelval/gorealis/response"
"os"
"time"
)
@ -29,7 +28,7 @@ type Monitor struct {
}
// Polls the scheduler every certain amount of time to see if the update has succeeded
func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout int) bool {
func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout int) (bool, error) {
updateQ := aurora.JobUpdateQuery{
Key: &updateKey,
@ -40,14 +39,14 @@ func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout
respDetail, err := m.Client.JobUpdateDetails(updateQ)
if err != nil {
fmt.Println(err)
os.Exit(1)
return false, err
}
updateDetail := response.JobUpdateDetails(respDetail)
if len(updateDetail) == 0 {
fmt.Println("No update found")
return false
return false, errors.New("No update found for "+updateKey.String())
}
status := updateDetail[0].Update.Summary.State.Status
@ -57,10 +56,10 @@ func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout
// if we encounter an inactive state and it is not at rolled forward, update failed
if status == aurora.JobUpdateStatus_ROLLED_FORWARD {
fmt.Println("Update succeded")
return true
return true, nil
} else {
fmt.Println("Update failed")
return false
return false, nil
}
}
@ -69,7 +68,7 @@ func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout
}
fmt.Println("Timed out")
return false
return false, nil
}
func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval int, timeout int) (bool, error) {

View file

@ -25,7 +25,7 @@ type UpdateJob struct {
}
// Create a default UpdateJob object.
func NewUpdateJob(config *aurora.TaskConfig) *UpdateJob {
func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob {
req := aurora.NewJobUpdateRequest()
req.TaskConfig = config
@ -66,6 +66,37 @@ func NewUpdateJob(config *aurora.TaskConfig) *UpdateJob {
return &UpdateJob{job, req}
}
func NewUpdateJob(config *aurora.TaskConfig, settings *aurora.JobUpdateSettings) *UpdateJob {
req := aurora.NewJobUpdateRequest()
req.TaskConfig = config
req.Settings = settings
job := NewJob().(AuroraJob)
job.jobConfig.TaskConfig = config
// Rebuild resource map from TaskConfig
for ptr := range config.Resources {
if ptr.NumCpus != nil {
job.resources["cpu"].NumCpus = ptr.NumCpus
continue // Guard against Union violations that Go won't enforce
}
if ptr.RamMb != nil {
job.resources["ram"].RamMb = ptr.RamMb
continue
}
if ptr.DiskMb != nil {
job.resources["disk"].DiskMb = ptr.DiskMb
continue
}
}
//TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior
return &UpdateJob{job, req}
}
// Set instance count the job will have after the update.
func (u *UpdateJob) InstanceCount(inst int32) *UpdateJob {
u.req.InstanceCount = inst