Merge pull request #10 from kkrishna/master
Externalize JobUpdateSettings for update api and remove os.exit
This commit is contained in:
commit
da0f181b96
3 changed files with 39 additions and 9 deletions
|
@ -272,7 +272,7 @@ func main() {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
updateJob := realis.NewUpdateJob(taskConfig)
|
updateJob := realis.NewDefaultUpdateJob(taskConfig)
|
||||||
updateJob.InstanceCount(5).RAM(128)
|
updateJob.InstanceCount(5).RAM(128)
|
||||||
|
|
||||||
resp, err := r.StartJobUpdate(updateJob, "")
|
resp, err := r.StartJobUpdate(updateJob, "")
|
||||||
|
|
13
monitors.go
13
monitors.go
|
@ -20,7 +20,6 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
||||||
"github.com/rdelval/gorealis/response"
|
"github.com/rdelval/gorealis/response"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ type Monitor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Polls the scheduler every certain amount of time to see if the update has succeeded
|
// 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{
|
updateQ := aurora.JobUpdateQuery{
|
||||||
Key: &updateKey,
|
Key: &updateKey,
|
||||||
|
@ -40,14 +39,14 @@ func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout
|
||||||
respDetail, err := m.Client.JobUpdateDetails(updateQ)
|
respDetail, err := m.Client.JobUpdateDetails(updateQ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDetail := response.JobUpdateDetails(respDetail)
|
updateDetail := response.JobUpdateDetails(respDetail)
|
||||||
|
|
||||||
if len(updateDetail) == 0 {
|
if len(updateDetail) == 0 {
|
||||||
fmt.Println("No update found")
|
fmt.Println("No update found")
|
||||||
return false
|
return false, errors.New("No update found for "+updateKey.String())
|
||||||
}
|
}
|
||||||
status := updateDetail[0].Update.Summary.State.Status
|
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 we encounter an inactive state and it is not at rolled forward, update failed
|
||||||
if status == aurora.JobUpdateStatus_ROLLED_FORWARD {
|
if status == aurora.JobUpdateStatus_ROLLED_FORWARD {
|
||||||
fmt.Println("Update succeded")
|
fmt.Println("Update succeded")
|
||||||
return true
|
return true, nil
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Update failed")
|
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")
|
fmt.Println("Timed out")
|
||||||
return false
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval int, timeout int) (bool, error) {
|
func (m *Monitor) Instances(key *aurora.JobKey, instances int32, interval int, timeout int) (bool, error) {
|
||||||
|
|
33
updatejob.go
33
updatejob.go
|
@ -25,7 +25,7 @@ type UpdateJob struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a default UpdateJob object.
|
// Create a default UpdateJob object.
|
||||||
func NewUpdateJob(config *aurora.TaskConfig) *UpdateJob {
|
func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob {
|
||||||
|
|
||||||
req := aurora.NewJobUpdateRequest()
|
req := aurora.NewJobUpdateRequest()
|
||||||
req.TaskConfig = config
|
req.TaskConfig = config
|
||||||
|
@ -66,6 +66,37 @@ func NewUpdateJob(config *aurora.TaskConfig) *UpdateJob {
|
||||||
return &UpdateJob{job, req}
|
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.
|
// Set instance count the job will have after the update.
|
||||||
func (u *UpdateJob) InstanceCount(inst int32) *UpdateJob {
|
func (u *UpdateJob) InstanceCount(inst int32) *UpdateJob {
|
||||||
u.req.InstanceCount = inst
|
u.req.InstanceCount = inst
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue