Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1499622 - Return 202 if provisioning job is in progress #498

Merged
merged 3 commits into from Oct 17, 2017

Conversation

dymurray
Copy link
Member

This PR fixes the scenario when the catalog sends two provisioning requests and we return a 200 without checking for jobs in progress.

Changes proposed in this pull request

  • Check for provisioning jobs and return 202 if jobs are running.

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 16, 2017
@dymurray dymurray changed the title Bug 1499622 - Return 202 if provisioning job is in progress [WIP] Bug 1499622 - Return 202 if provisioning job is in progress Oct 16, 2017
Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make the broker.Provision return a ProvisionResponse with the Operation. And then have the handler use that response. I would also update Deprovision the same way.

@@ -268,6 +268,8 @@ func (h handler) provision(w http.ResponseWriter, r *http.Request, params map[st
switch err {
case broker.ErrorDuplicate:
writeResponse(w, http.StatusConflict, broker.ProvisionResponse{})
case broker.ErrorProvisionInProgress:
writeResponse(w, http.StatusAccepted, broker.ProvisionResponse{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change broker.ProvisionResponse{} to resp.


if alreadyInProgress {
a.log.Infof("Provision requested for instance %s, but job is already in progress", serviceInstance.ID)
return nil, ErrorProvisionInProgress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change nil to &ProvisionResponse{Operation: token} somehow we'll need the token not sure yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 deleted my comment that was essentially the same as this.

@jmrodri
Copy link
Contributor

jmrodri commented Oct 16, 2017

@eriknelson thoughts on my comments about returning a ProvisionResponse with Operation when we are still in progress?

@@ -619,6 +621,16 @@ func (a AnsibleBroker) Provision(instanceUUID uuid.UUID, req *ProvisionRequest,
//
// if err is not nil, we will just bubble that up

alreadyInProgress, err := a.isProvisionInProgress(serviceInstance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this call needs to be within the if uuid.Equal.... block.

Reason being if it is a duplicate we want to return duplicate and not give the job token to the other service instance

@eriknelson
Copy link
Contributor

Will review this first thing tomorrow morning.

@eriknelson eriknelson self-requested a review October 17, 2017 04:09
@dymurray dymurray changed the title [WIP] Bug 1499622 - Return 202 if provisioning job is in progress Bug 1499622 - Return 202 if provisioning job is in progress Oct 17, 2017
@dymurray
Copy link
Member Author

Please look at the actual branch... for some reason the PR is showing out of date diffs.

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 17, 2017
@dymurray
Copy link
Member Author

@jmrodri @shawn-hurley Updated with your feedback.

@eriknelson
Copy link
Contributor

@jmrodri Does the spec call for the operation token on an InProgress response?

@dymurray
Copy link
Member Author

Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

if err != nil {
return nil, fmt.Errorf("An error occurred while trying to determine if a deprovision job is already in progress for instance: %s", instance.ID)
}

if alreadyInProgress {
a.log.Infof("Deprovision requested for instance %s, but job is already in progress", instance.ID)
return nil, ErrorDeprovisionInProgress
return &DeprovisionResponse{Operation: jobToken}, ErrorDeprovisionInProgress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@eriknelson
Copy link
Contributor

@jmrodri good catch re: the Op!

Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a nitpick but I suggest avoiding duplicate functions.

return len(proJobs) > 0, token, nil
}

func (a AnsibleBroker) isDeprovisionInProgress(instance *apb.ServiceInstance) (bool, string, error) {
Copy link
Member

@djzager djzager Oct 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be more of a nitpick but I am not a big fan of 2 functions that are so identical to each other. Suggest collapsing the two functions into 1 with a new function argument.

func (a AnsibleBroker) isJobInProgress(instance *apb.ServiceInstance, string method) (bool, string, error) {
...
    jobs := dao.MapJobStatesWithMethod(allJobs, method)
...
}

Then update provision/deprovision like:

// example for deprovision
alreadyInProgress, jobToken, err := a.isJobInProgress(&instance, apb.JobMethodDeprovision)

@openshift-ci-robot openshift-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 17, 2017
Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jmrodri jmrodri merged commit 6a749d1 into openshift:master Oct 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants