-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Introducing ControllerToAgentCallable
and ControllerToAgentFileCallable
#9921
Changes from 5 commits
faf2de3
582d3e8
42fd2cf
d7af175
9f3cd33
f073fcb
bba1ff0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
package jenkins; | ||
|
||
import hudson.FilePath.FileCallable; | ||
import hudson.remoting.VirtualChannel; | ||
import java.io.File; | ||
import jenkins.security.Roles; | ||
import jenkins.slaves.RemotingVersionInfo; | ||
import org.jenkinsci.remoting.RoleChecker; | ||
import jenkins.agents.ControllerToAgentFileCallable; | ||
|
||
/** | ||
* {@link FileCallable}s that are meant to be only used on the master. | ||
* | ||
* Note that the logic within {@link #invoke(File, VirtualChannel)} should use API of a minimum supported Remoting version. | ||
* See {@link RemotingVersionInfo#getMinimumSupportedVersion()}. | ||
* | ||
* {@link FileCallable}s that could run on an agent. | ||
* For new code, implement {@link ControllerToAgentFileCallable} | ||
* which has the advantage that it can be used on {@code record}s. | ||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that, should this class be deprecated to discourage any new usage, or hint existing ones to move to records? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose it could be, though it feels like overkill to deprecate it merely because an aesthetically preferable alternative is now available. |
||
* @since 1.587 / 1.580.1 | ||
* @param <T> the return type; note that this must either be defined in your plugin or included in the stock JEP-200 whitelist | ||
* @param <T> the return type | ||
*/ | ||
public abstract class MasterToSlaveFileCallable<T> implements FileCallable<T> { | ||
@Override | ||
public void checkRoles(RoleChecker checker) throws SecurityException { | ||
checker.check(this, Roles.SLAVE); | ||
} | ||
public abstract class MasterToSlaveFileCallable<T> implements ControllerToAgentFileCallable<T> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2024 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package jenkins.agents; | ||
|
||
import hudson.remoting.Callable; | ||
import jenkins.security.Roles; | ||
import jenkins.slaves.RemotingVersionInfo; | ||
import org.jenkinsci.remoting.RoleChecker; | ||
|
||
/** | ||
* {@link Callable} meant to be serialized then run on an agent. | ||
* A typical implementation will be a {@link Record} | ||
* since instance state merely transfers a set of parameters to an agent JVM. | ||
* <p>Note that the logic within {@link #call} may not use Remoting APIs | ||
* newer than {@link RemotingVersionInfo#getMinimumSupportedVersion}. | ||
* (Core and plugin APIs will be identical to those run inside the controller.) | ||
* @param <V> the return type; note that this must either be defined in your plugin or included in the stock JEP-200 whitelist | ||
* @since TODO | ||
*/ | ||
public interface ControllerToAgentCallable<V, T extends Throwable> extends Callable<V, T> { | ||
jglick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
default void checkRoles(RoleChecker checker) throws SecurityException { | ||
checker.check(this, Roles.SLAVE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2024 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package jenkins.agents; | ||
|
||
import hudson.FilePath; | ||
import jenkins.security.Roles; | ||
import org.jenkinsci.remoting.RoleChecker; | ||
|
||
/** | ||
* {@link FilePath.FileCallable} meant to be serialized then run on an agent. | ||
* Like {@link ControllerToAgentCallable} this will typically be a {@link Record}. | ||
* @param <T> the return type; note that this must either be defined in your plugin or included in the stock JEP-200 whitelist | ||
* @since TODO | ||
*/ | ||
public interface ControllerToAgentFileCallable<T> extends FilePath.FileCallable<T> { | ||
|
||
@Override | ||
default void checkRoles(RoleChecker checker) throws SecurityException { | ||
checker.check(this, Roles.SLAVE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
package jenkins.security; | ||
|
||
import hudson.remoting.Callable; | ||
import jenkins.slaves.RemotingVersionInfo; | ||
import org.jenkinsci.remoting.RoleChecker; | ||
import jenkins.agents.ControllerToAgentCallable; | ||
|
||
/** | ||
* Convenient {@link Callable} meant to be run on agent. | ||
* | ||
* Note that the logic within {@link #call()} should use API of a minimum supported Remoting version. | ||
* See {@link RemotingVersionInfo#getMinimumSupportedVersion()}. | ||
* | ||
* {@link Callable} meant to be run on agent. | ||
* For new code, implement {@link ControllerToAgentCallable} | ||
* which has the advantage that it can be used on {@code record}s. | ||
* @author Kohsuke Kawaguchi | ||
* @since 1.587 / 1.580.1 | ||
* @param <V> the return type; note that this must either be defined in your plugin or included in the stock JEP-200 whitelist | ||
* @param <V> the return type | ||
*/ | ||
public abstract class MasterToSlaveCallable<V, T extends Throwable> implements Callable<V, T> { | ||
public abstract class MasterToSlaveCallable<V, T extends Throwable> implements ControllerToAgentCallable<V, T> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public void checkRoles(RoleChecker checker) throws SecurityException { | ||
checker.check(this, Roles.SLAVE); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daniel-beck in #4683 you added this as a setter rather than constructor parameter, perhaps out of confusion with the similarly-named field in
Launcher
which actually needs to be mutable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, the original code is by Wadeck and it's been far too long at this point. If this works, the setter is restricted, so any cleanup is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it needed to be: the class was
private
to begin with.