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

[JENKINS-36479] First work on auto-clearing invalid locks. #35

Merged
merged 2 commits into from
Jul 8, 2016

Conversation

abayer
Copy link
Member

@abayer abayer commented Jul 6, 2016

JENKINS-36479

Update LockRunListener to work with Runs rather than just
AbstractProjects - this means that onCompleted and onDeleted will fire
correctly, obviating the need for anything more special-case/complex.

Probably supersedes #34 - this is a more general case solution that doesn't require new lock requests to clear the defunct locks.

cc @reviewbybees, esp @jglick and @amuniz

@ghost
Copy link

ghost commented Jul 6, 2016

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@@ -1,6 +1,5 @@
package org.jenkins.plugins.lockableresources;

import java.io.IOException;
Copy link
Member

Choose a reason for hiding this comment

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

Try

git checkout master -- src/main/java/org/jenkins/plugins/lockableresources/LockStepExecution.java

to revert irrelevant changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I went on the warpath of removing unused imports while I was here.

@jglick
Copy link
Member

jglick commented Jul 6, 2016

@amuniz had some reason for using two sets of APIs: one for AbstractBuild, that assumed one lock per build; one for Pipeline StepContext, which worked for any number of locks per build. This seems to erode the distinction, so I am not sure if that is kosher.

Update LockRunListener to work with Runs rather than just
AbstractProjects - this means that onCompleted and onDeleted will fire
correctly, obviating the need for anything more special-case/complex.
@abayer
Copy link
Member Author

abayer commented Jul 6, 2016

Rewrote the commit and force-pushed it.

@amuniz
Copy link
Member

amuniz commented Jul 7, 2016

I want to keep the listener for non-Pipelines jobs, where the lock flow is different as it applies to the whole build execution (you can not lock/unlock more than one resource at specific timing during a build), however that's possible in a Pipeline.

Looking at this specific change I'd say that LockRunListener#onStarted does not apply to Pipelines at all. So that's a 🐛 for me, however I like this approach more than #34 so I would suggest to continue working here and close the other PR.

About APIs in LockableResourcesManager I tried to keep methods that does not apply to Pipelines as they were - without modification, and adapt/create those that could be used on Pipelines or were required for Freestyle-Pipeline interoperability.


static final String LOG_PREFIX = "[lockable-resources]";
static final Logger LOGGER = Logger.getLogger(LockRunListener.class
.getName());

@Override
public void onStarted(AbstractBuild<?, ?> build, TaskListener listener) {
public void onStarted(Run<?, ?> build, TaskListener listener) {
Copy link
Member

Choose a reason for hiding this comment

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

🐛 Nothing to do for non-AbstractBuilds here, a check is needed to just return in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this around to just return if the build isn't an AbstractBuild.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that I kept the signature as Run for consistency with the onDeleted and onCompleted methods - I'd rather the consistent signature and handling of the AbstractBuild case than inconsistent signatures. But I'm flexible. =)

@amuniz amuniz changed the title JENKINS-36479. First work on auto-clearing invalid locks. [JENKINS-36479] First work on auto-clearing invalid locks. Jul 7, 2016
@abayer
Copy link
Member Author

abayer commented Jul 7, 2016

@amuniz So - what's your recommendation? Just switch out onStarted?

@abayer
Copy link
Member Author

abayer commented Jul 7, 2016

@amuniz So I think it does make sense to keep onDeleted and onCompleted handling Runs as well as AbstractBuilds - it's just a fallback for WorkflowRuns that don't clear their locks organically through LockStep, and won't matter in any other case, right?

@@ -61,7 +61,7 @@ public LockableResourcesManager() {
return matching;
}

public List<LockableResource> getResourcesFromBuild(AbstractBuild<?, ?> build) {
public List<LockableResource> getResourcesFromBuild(Run<?, ?> build) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@amuniz I know this is changing the API here and you did deliberately keep them separate, but given that this doesn't have side effects and works exactly the same whether you pass it an AbstractBuild or a Run, I'm not sure I see the reason to have it just be for AbstractBuilds, especially since the only places it's called are in LockRunListener#onCompleted and LockRunListener#onDeleted, which now do need to operate on Runs...

Copy link
Member

Choose a reason for hiding this comment

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

Ok.

@amuniz
Copy link
Member

amuniz commented Jul 7, 2016

So I think it does make sense to keep onDeleted and onCompleted handling Runs as well as AbstractBuilds

Right.

Current status LGTM 🐝 and 👍

@rsandell
Copy link
Member

rsandell commented Jul 8, 2016

🐝

@amuniz amuniz merged commit b0fe098 into jenkinsci:master Jul 8, 2016
// Skip locking for multiple configuration projects,
// only the child jobs will actually lock resources.
if (build instanceof MatrixBuild)
return;

AbstractProject<?, ?> proj = Utils.getProject(build);
Copy link
Member

Choose a reason for hiding this comment

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

Could have produced a much shorter diff using

if (!(build instanceof AbstractBuild)) {
    return;
}
// …as before

@jglick
Copy link
Member

jglick commented Jul 8, 2016

Belated 🐝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants