Breaking change for CreateJob

Create job has changed from a tuple return to a single error return
which simplifies how we interact with the api.
This commit is contained in:
Renán Del Valle 2021-04-30 11:17:52 -07:00
parent ae295b9cea
commit 085bc39c50
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
3 changed files with 12 additions and 14 deletions

View file

@ -166,11 +166,10 @@ func main() {
switch cmd { switch cmd {
case "create": case "create":
fmt.Println("Creating job") fmt.Println("Creating job")
resp, err := r.CreateJob(job) err := r.CreateJob(job)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
fmt.Println(resp.String())
if ok, mErr := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 5, 50); !ok || mErr != nil { if ok, mErr := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 5, 50); !ok || mErr != nil {
_, err := r.KillJob(job.JobKey()) _, err := r.KillJob(job.JobKey())
@ -205,11 +204,10 @@ func main() {
fmt.Println("Creating a docker based job") fmt.Println("Creating a docker based job")
container := realis.NewDockerContainer().Image("python:2.7").AddParameter("network", "host") container := realis.NewDockerContainer().Image("python:2.7").AddParameter("network", "host")
job.Container(container) job.Container(container)
resp, err := r.CreateJob(job) err := r.CreateJob(job)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println(resp.String())
if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 10, 300); !ok || err != nil { if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 10, 300); !ok || err != nil {
_, err := r.KillJob(job.JobKey()) _, err := r.KillJob(job.JobKey())
@ -222,11 +220,10 @@ func main() {
fmt.Println("Creating a docker based job") fmt.Println("Creating a docker based job")
container := realis.NewMesosContainer().DockerImage("python", "2.7") container := realis.NewMesosContainer().DockerImage("python", "2.7")
job.Container(container) job.Container(container)
resp, err := r.CreateJob(job) err := r.CreateJob(job)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println(resp.String())
if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 10, 300); !ok || err != nil { if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 10, 300); !ok || err != nil {
_, err := r.KillJob(job.JobKey()) _, err := r.KillJob(job.JobKey())

View file

@ -44,7 +44,7 @@ const version = "1.23.1"
type Realis interface { type Realis interface {
AbortJobUpdate(updateKey aurora.JobUpdateKey, message string) (*aurora.Response, error) AbortJobUpdate(updateKey aurora.JobUpdateKey, message string) (*aurora.Response, error)
AddInstances(instKey aurora.InstanceKey, count int32) (*aurora.Response, error) AddInstances(instKey aurora.InstanceKey, count int32) (*aurora.Response, error)
CreateJob(auroraJob Job) (*aurora.Response, error) CreateJob(auroraJob Job) error
CreateService( CreateService(
auroraJob Job, auroraJob Job,
settings *aurora.JobUpdateSettings) (*aurora.Response, *aurora.StartJobUpdateResult_, error) settings *aurora.JobUpdateSettings) (*aurora.Response, *aurora.StartJobUpdateResult_, error)
@ -663,11 +663,12 @@ func (r *realisClient) KillJob(key *aurora.JobKey) (*aurora.Response, error) {
// Although this API is able to create service jobs, it is better to use CreateService instead // Although this API is able to create service jobs, it is better to use CreateService instead
// as that API uses the update thrift call which has a few extra features available. // as that API uses the update thrift call which has a few extra features available.
// Use this API to create ad-hoc jobs. // Use this API to create ad-hoc jobs.
func (r *realisClient) CreateJob(auroraJob Job) (*aurora.Response, error) { func (r *realisClient) CreateJob(auroraJob Job) error {
r.logger.debugPrintf("CreateJob Thrift Payload: %+v\n", auroraJob.JobConfig()) r.logger.debugPrintf("CreateJob Thrift Payload: %+v\n", auroraJob.JobConfig())
resp, retryErr := r.thriftCallWithRetries( // Response is checked by the thrift retry code
_, retryErr := r.thriftCallWithRetries(
false, false,
func() (*aurora.Response, error) { func() (*aurora.Response, error) {
return r.client.CreateJob(context.TODO(), auroraJob.JobConfig()) return r.client.CreateJob(context.TODO(), auroraJob.JobConfig())
@ -692,9 +693,9 @@ func (r *realisClient) CreateJob(auroraJob Job) (*aurora.Response, error) {
) )
if retryErr != nil { if retryErr != nil {
return resp, errors.Wrap(retryErr, "error sending Create command to Aurora Scheduler") return errors.Wrap(retryErr, "error sending Create command to Aurora Scheduler")
} }
return resp, nil return nil
} }
// CreateService uses the scheduler's updating mechanism to create a job. // CreateService uses the scheduler's updating mechanism to create a job.

View file

@ -167,7 +167,7 @@ func (r *realisClient) thriftCallWithRetries(
// Print out the error to the user // Print out the error to the user
r.logger.Printf("Client Error: %v", clientErr) r.logger.Printf("Client Error: %v", clientErr)
temporary, timedout := processClientError(clientErr) temporary, timedout := isConnectionError(clientErr)
if !temporary && r.RealisConfig().failOnPermanentErrors { if !temporary && r.RealisConfig().failOnPermanentErrors {
return nil, errors.Wrap(clientErr, "permanent connection error") return nil, errors.Wrap(clientErr, "permanent connection error")
} }
@ -257,10 +257,10 @@ func (r *realisClient) thriftCallWithRetries(
return nil, newRetryError(errors.New("ran out of retries"), curStep) return nil, newRetryError(errors.New("ran out of retries"), curStep)
} }
// processClientError processes the error received by the client. // isConnectionError processes the error received by the client.
// The return values indicate weather this was determined to be a temporary error // The return values indicate weather this was determined to be a temporary error
// and weather it was determined to be a timeout error // and weather it was determined to be a timeout error
func processClientError(err error) (bool, bool) { func isConnectionError(err error) (bool, bool) {
// Determine if error is a temporary URL error by going up the stack // Determine if error is a temporary URL error by going up the stack
transportException, ok := err.(thrift.TTransportException) transportException, ok := err.(thrift.TTransportException)