Code cleanup, added ability to attach logger, added CreateService api
* Code cleanup: Deleted multiple functions which have become stale. Removed cluster example as we replaced the need to create the Cluster object. * Cleaned up ZK connection code by using the backoff function. Added a test to the end to end to test that we're getting the host correctly from ZK. Changed clusters test to be an outside package. * Added LeaderFromZKURL test to end to end tests. * Added logger to realisConfig so that users can attach their own Loggers to the client. Logger is an interface that shadows most popular logging libraries. Only Print, Println, and Printf are needed to be a realis.Logger type. Example in the client uses the std library log. * Moved most fmt.Print* calls to be redirected to user provided logger. Logger by default is a no-op logger. * Adding CreateService to realis interface. Uses the StartJobUpdate API to create services instead of the createJobs API. * Bumping up version number inside client in anticipation of new release.
This commit is contained in:
parent
72b746e431
commit
e614e04f27
8 changed files with 292 additions and 298 deletions
69
updatejob.go
69
updatejob.go
|
@ -24,12 +24,15 @@ type UpdateJob struct {
|
|||
req *aurora.JobUpdateRequest
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create a default UpdateJob object.
|
||||
func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob {
|
||||
|
||||
req := aurora.NewJobUpdateRequest()
|
||||
req.TaskConfig = config
|
||||
req.Settings = aurora.NewJobUpdateSettings()
|
||||
s := NewUpdateSettings().Settings()
|
||||
req.Settings = &s
|
||||
|
||||
job := NewJob().(*AuroraJob)
|
||||
job.jobConfig.TaskConfig = config
|
||||
|
@ -60,7 +63,6 @@ func NewDefaultUpdateJob(config *aurora.TaskConfig) *UpdateJob {
|
|||
req.Settings.MaxPerInstanceFailures = 0
|
||||
req.Settings.MaxFailedInstances = 0
|
||||
req.Settings.RollbackOnFailure = true
|
||||
req.Settings.WaitForBatchCompletion = false
|
||||
|
||||
//TODO(rdelvalle): Deep copy job struct to avoid unexpected behavior
|
||||
return &UpdateJob{job, req}
|
||||
|
@ -138,3 +140,66 @@ func (u *UpdateJob) RollbackOnFail(rollback bool) *UpdateJob {
|
|||
u.req.Settings.RollbackOnFailure = rollback
|
||||
return u
|
||||
}
|
||||
|
||||
|
||||
// TODO(rdelvalle): Integrate this struct with the JobUpdate struct so that we don't repeat code
|
||||
type UpdateSettings struct {
|
||||
settings aurora.JobUpdateSettings
|
||||
}
|
||||
|
||||
func NewUpdateSettings() *UpdateSettings {
|
||||
|
||||
us := new(UpdateSettings)
|
||||
|
||||
// Mirrors defaults set by Pystachio
|
||||
us.settings.UpdateOnlyTheseInstances = make(map[*aurora.Range]bool)
|
||||
us.settings.UpdateGroupSize = 1
|
||||
us.settings.WaitForBatchCompletion = false
|
||||
us.settings.MinWaitInInstanceRunningMs = 45000
|
||||
us.settings.MaxPerInstanceFailures = 0
|
||||
us.settings.MaxFailedInstances = 0
|
||||
us.settings.RollbackOnFailure = true
|
||||
|
||||
return us
|
||||
}
|
||||
|
||||
// Max number of instances being updated at any given moment.
|
||||
func (u *UpdateSettings) BatchSize(size int32) *UpdateSettings {
|
||||
u.settings.UpdateGroupSize = size
|
||||
return u
|
||||
}
|
||||
|
||||
// Minimum number of seconds a shard must remain in RUNNING state before considered a success.
|
||||
func (u *UpdateSettings) WatchTime(ms int32) *UpdateSettings {
|
||||
u.settings.MinWaitInInstanceRunningMs = ms
|
||||
return u
|
||||
}
|
||||
|
||||
// Wait for all instances in a group to be done before moving on.
|
||||
func (u *UpdateSettings) WaitForBatchCompletion(batchWait bool) *UpdateSettings {
|
||||
u.settings.WaitForBatchCompletion = batchWait
|
||||
return u
|
||||
}
|
||||
|
||||
// Max number of instance failures to tolerate before marking instance as FAILED.
|
||||
func (u *UpdateSettings) MaxPerInstanceFailures(inst int32) *UpdateSettings {
|
||||
u.settings.MaxPerInstanceFailures = inst
|
||||
return u
|
||||
}
|
||||
|
||||
// Max number of FAILED instances to tolerate before terminating the update.
|
||||
func (u *UpdateSettings) MaxFailedInstances(inst int32) *UpdateSettings {
|
||||
u.settings.MaxFailedInstances = inst
|
||||
return u
|
||||
}
|
||||
|
||||
// When False, prevents auto rollback of a failed update.
|
||||
func (u *UpdateSettings) RollbackOnFail(rollback bool) *UpdateSettings {
|
||||
u.settings.RollbackOnFailure = rollback
|
||||
return u
|
||||
}
|
||||
|
||||
// Return internal Thrift API structure
|
||||
func (u UpdateSettings) Settings() aurora.JobUpdateSettings {
|
||||
return u.settings
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue