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

Ensure initial state set when job started. Reduce repition in job definitions. Allow jobs to be mocked out at broker level #909

Merged

Conversation

maleck13
Copy link
Contributor

I did not create an issue for this change. If one is needed that is no problem. Also as did this out of scope work, if it is felt that it is not needed then I happy to remove the PR. The things here that is likely important is the initialization of the state. Also I know there is a freeze right now so not expecting this to land immediately

Describe what this PR does and why we need it:

While working on the state changes. I was looking into the jobs and work engine. This pr creates a mockable interface laying some of the ground work to allow us to potentially create e2e tests that run against the API ensuring the correct responses without the need to actually spin up APBS but still execute the key paths in the code. It also reduces duplication on in the jobs code.

Changes proposed in this pull request

  • consolidate the job types and reduce the need for separate method definitions on each job type
  • Add an interface for getting work in the broker WorkFactory
  • Ensure to set the initial job state before handing control back to the caller to avoid the state not being set and possible race condition (more than one job being created and service catalog asking for last operation update before state has been set).
  • generate a mock dao

@openshift-ci-robot openshift-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 26, 2018
@jmrodri jmrodri self-requested a review April 26, 2018 15:29
@shawn-hurley
Copy link
Contributor

I really like the changes to the engine here. This to me is the next logical step of @eriknelson works to simplify the creation of jobs.

I think we need to hold this until we branch for the release.

@shawn-hurley shawn-hurley added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 1, 2018
@rthallisey rthallisey added 3.10 | release-1.2 Kubernetes 1.10 | Openshift 3.10 | Broker release-1.2 3.11 | release-1.3 Kubernetes 1.11 | Openshift 3.11 | Broker release-1.3 and removed 3.10 | release-1.2 Kubernetes 1.10 | Openshift 3.10 | Broker release-1.2 labels May 3, 2018
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 29, 2018
@maleck13 maleck13 force-pushed the work-engine-job-improvements branch from 72f76e5 to c23ef74 Compare May 31, 2018 12:16
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 31, 2018
@maleck13 maleck13 force-pushed the work-engine-job-improvements branch from c23ef74 to 7fc1751 Compare May 31, 2018 12:19
@jmrodri jmrodri requested a review from eriknelson May 31, 2018 18:34
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'm not 100% sure of the need for the WorkFactory. Feels like we went from concrete structs to methods that "look like structs'.

If we do plan on keeping the WorkFactory I would prefer that it have New*Job style methods instead.

NewProvisionJob(...)
NewBindJob(...)
etc.

If would be nice if it could've been NewWork(method string, ...) but because the parameters are so diverse so just renaming them to New*Job would be nicer IMO. I don't like ProvisionJob(...) because it looks like a struct initialization but with incorrect parens. To avoid confusion, I prefer the New prefix.

pkg/app/app.go Outdated
@@ -282,8 +282,11 @@ func CreateApp(args Args, regs []registries.Registry) App {
KeepNamespaceOnError: app.config.GetBool("openshift.keep_namespace_on_error"),
}
apb.InitializeClusterConfig(clusterConfig)
brokerNS := app.config.GetString("openshift.namespace")
// initialize the work factory
workFactory := broker.NewWorkFactory()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure of the need for the WorkFactory.

Copy link
Contributor Author

@maleck13 maleck13 Jun 6, 2018

Choose a reason for hiding this comment

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

The intention here was creating an interface that would encapsulate the creation of work and allow a mock to be used later down the line to do tests against a running broker without it needing to actually start pods etc. Initializing the stuct directly in the code makes it difficult to control the behavior. Really just saw it as a step in the direction of a more unit testable broker.
Is the concern it is premature abstraction? Can change to use the struct if preferred and can always add the interface back at a later stage. The key is probably the dependency injection of in line initialization.

func (j *apbJob) Method() apb.JobMethod {
return j.method
}

Copy link
Contributor

Choose a reason for hiding this comment

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

ID and Method are good additions.

run: func(exec apb.Executor) <-chan apb.StatusMessage {
return exec.Provision(j.serviceInstance)
// ProvisionJob will setup a Work implementation that will perform the provision work
func (wf *workFactory) ProvisionJob(si *apb.ServiceInstance) Work {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of using the old struct name as a function now. It feels confusing to see something that looks like a "struct" vs something that is a method. For example when I see ProvisionJob I'd expect to see {} after it like: ProvisionJob{id: "foo", blah blah blah}.

If we're going to keep these I prefer making them look like constructor methods: NewProvisionJob, NewBindJob, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure happy to change these

return nil
}

func (engine *WorkEngine) runJob(token string, work Work, topic WorkTopic) {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to setupJob and runJob vs startJob.

@maleck13 maleck13 force-pushed the work-engine-job-improvements branch from 7fc1751 to 502efe8 Compare June 6, 2018 15:18
@coveralls
Copy link

coveralls commented Jun 6, 2018

Coverage Status

Coverage increased (+0.2%) to 33.435% when pulling ee996f4 on maleck13:work-engine-job-improvements into 9916cb0 on openshift:master.

@shawn-hurley shawn-hurley removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 12, 2018
…initions. Allow jobs to be mocked out at broker level
@maleck13 maleck13 force-pushed the work-engine-job-improvements branch from 502efe8 to ee996f4 Compare June 12, 2018 14:18
@maleck13
Copy link
Contributor Author

@jmrodri changes made as requested

Copy link
Contributor

@eriknelson eriknelson left a comment

Choose a reason for hiding this comment

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

visiack

@shawn-hurley shawn-hurley merged commit 5efd847 into openshift:master Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 | release-1.3 Kubernetes 1.11 | Openshift 3.11 | Broker release-1.3 size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants