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-43496] - Add handling of the null Node#createComputer() result. #2922

Merged

Conversation

oleg-nenashev
Copy link
Member

@oleg-nenashev oleg-nenashev commented Jun 18, 2017

it is a follow-up to #2836 (comment)

De-facto many Cloud plugins return null in Node#createLauncher(), but it has never been documented.
In order to prevent possible API misusages in the future, I have added annotations and fixed handling of the extension point in AbstractCIBase#updateComputer() which may fail in the case of null or RuntimeException in the Node implementation.

See JENKINS-43496.

Changelog entries

Proposed changelog entries:

  • Entry 1: Prevent failure of the computer update logic if the Node implementation in a plugin does not support creation of ad-hoc computers or throws a runtime exception.
  • ...

Submitter checklist

  • JIRA issue is well described
  • Link to JIRA ticket in description, if appropriate
  • Appropriate autotests or explanation to why this change has no tests
  • For new API and extension points: Link to the reference implementation in open-source (or example in Javadoc)

Desired reviewers

@reviewbybees

it is a follow-up to jenkinsci#2836 (comment)

De-facto many Cloud plugins return `null` in `Node#createLauncher()`, but it has never been documented.
In order to prevent possible API misusages in the future, I have added annotations and fixed handling of the extension point in `AbstractCIBase#updateComputer()` which may fail in the case of `null` or `RuntimeException` in the Node implementation.
@oleg-nenashev
Copy link
Member Author

CC @abayer and @jtnord who were working on this codebase recently

@ghost
Copy link

ghost commented Jun 18, 2017

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.

@recampbell recampbell requested a review from stephenc June 19, 2017 15:44
Copy link
Member

@stephenc stephenc left a comment

Choose a reason for hiding this comment

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

One question to answer

*/
@CheckForNull
@Restricted(NoExternalUse.class)
Copy link
Member

Choose a reason for hiding this comment

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

Won't this cause compilation failures for sub-classes? (and if it doesn't then won't the subclass method be invocable anyway, in which case the annotation is useless

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed

Copy link
Member Author

Choose a reason for hiding this comment

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

@stephenc @jglick My intention was to reflect the Nobody but {@link Jenkins#updateComputerList()} should call this method. comment in Javadoc. If you know a better annotation for it, just let me know. Not sure if I can dedicate time to writing another restriction if it is missing, so I will just remove it in such case

Copy link
Member

Choose a reason for hiding this comment

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

@oleg-nenashev ah, were you looking for ProtectedExternally then?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jglick Yep, it should work better in this case

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Apparently gratuitous restriction on createComputer. I do not know offhand of Nodes which are neither Jenkins nor Slaves, but the API seems designed to make it possible.

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

The annotation on Slave does not appear to match reality. I do not know what it would mean to return null, but apparently some plugins do so for some reason.

* Nobody but {@link Jenkins#updateComputerList()} should call this method.
* @return Created instance of the computer.
* Can be {@code null} if the {@link Node} implementation does not support it (e.g. {@link Cloud} agent).
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually true? A Cloud agent would ultimately be a Slave, and that is now documented to return non-null—which seems to contradict your statement that some implementations do return non-null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. Slave#createLauncher() now can create nulls

@@ -306,6 +306,8 @@ public void setLabelString(String labelString) throws IOException {
return new GetClockDifference1();
}

@Override
@Nonnull
Copy link
Member

Choose a reason for hiding this comment

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

This is not true in the case of GoogleSlave, from a quick search.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. Better to just remove since the parent Javadoc describes the null case in a portable way

@oleg-nenashev
Copy link
Member Author

Needs another review

@oleg-nenashev oleg-nenashev added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Jun 21, 2017
@oleg-nenashev
Copy link
Member Author

@reviewbybees done, passing to @jenkinsci/code-reviewers

used.add(c);
} else {
// TODO: Maybe it should be allowed, but we would just get NPE in the original logic before JENKINS-43496
LOGGER.log(Level.WARNING, "Node {0} has not executors. Cannot udate the Computer instance for it", n.getNodeName());
Copy link
Member

Choose a reason for hiding this comment

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

… has no … update its …

@oleg-nenashev
Copy link
Member Author

@daniel-beck fine for you?

@oleg-nenashev
Copy link
Member Author

In IRC @daniel-beck said he sees no obvious issues, hence merging

@oleg-nenashev oleg-nenashev merged commit bcf55ec into jenkinsci:master Jul 1, 2017
olivergondza pushed a commit that referenced this pull request Jul 20, 2017
…lt. (#2922)

* [JENKINS-43496] - Add handling of the null Node#createComputer() result.

it is a follow-up to #2836 (comment)

De-facto many Cloud plugins return `null` in `Node#createLauncher()`, but it has never been documented.
In order to prevent possible API misusages in the future, I have added annotations and fixed handling of the extension point in `AbstractCIBase#updateComputer()` which may fail in the case of `null` or `RuntimeException` in the Node implementation.

* [JENKINS-43496] - Use ProtectedExternally to protect Node#createComputer()

* [JENKINS-43496] - Remove the erroneous Nonnull annotation after the feedback from @jglick

* [JENKINS-43496] - Fix typos noticed by @daniel-beck

(cherry picked from commit bcf55ec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
4 participants