提交 4eb314b3 编写于 作者: O Oleg Nenashev

[JENKINS-48761] - Restore binary compatibility with agents running old Remoting versions

上级 0ac93deb
......@@ -1289,7 +1289,7 @@ public abstract class Launcher {
}
public RemoteProcess call() throws IOException {
final Channel channel = getOpenChannelOrFail();
final Channel channel = _getOpenChannelOrFail();
Launcher.ProcStarter ps = new LocalLauncher(listener).launch();
ps.cmds(cmd).masks(masks).envs(env).stdin(in).stdout(out).stderr(err).quiet(quiet);
if(workDir!=null) ps.pwd(workDir);
......@@ -1308,7 +1308,11 @@ public abstract class Launcher {
Channel taskChannel = null;
try {
// Sync IO will fail automatically if the channel is being closed, no need to use getOpenChannelOrFail()
taskChannel = Channel.currentOrFail();
// TODOL Replace by Channel#currentOrFail() when Remoting version allows
taskChannel = Channel.current();
if (taskChannel == null) {
throw new IOException("No Remoting channel associated with this thread");
}
taskChannel.syncIO();
} catch (Throwable t) {
// this includes a failure to sync, agent.jar too old, etc
......
......@@ -1426,7 +1426,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
private static final class DumpExportTableTask extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
final Channel ch = getChannelOrFail();
final Channel ch = _getChannelOrFail();
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
ch.dumpExportTable(pw);
......
......@@ -134,7 +134,7 @@ public class ChannelPinger extends ComputerListener {
@Override
public Void call() throws IOException {
// No sense in setting up channel pinger if the channel is being closed
setUpPingForChannel(getOpenChannelOrFail(), null, pingTimeoutSeconds, pingIntervalSeconds, false);
setUpPingForChannel(_getOpenChannelOrFail(), null, pingTimeoutSeconds, pingIntervalSeconds, false);
return null;
}
......
......@@ -38,6 +38,7 @@ import hudson.model.TaskListener;
import hudson.model.User;
import hudson.remoting.Channel;
import hudson.remoting.ChannelBuilder;
import hudson.remoting.ChannelClosedException;
import hudson.remoting.Launcher;
import hudson.remoting.VirtualChannel;
import hudson.security.ACL;
......@@ -867,7 +868,11 @@ public class SlaveComputer extends Computer {
// ignore this error.
}
Channel.currentOrFail().setProperty("slave",Boolean.TRUE); // indicate that this side of the channel is the slave side.
try {
_getChannelOrFail().setProperty("slave",Boolean.TRUE); // indicate that this side of the channel is the slave side.
} catch (ChannelClosedException e) {
throw new IllegalStateException(e);
}
return null;
}
......
package jenkins.security;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.ChannelClosedException;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import javax.annotation.Nonnull;
/**
......@@ -11,10 +17,31 @@ import org.jenkinsci.remoting.RoleChecker;
* @since 1.587 / 1.580.1
*/
public abstract class MasterToSlaveCallable<V, T extends Throwable> implements Callable<V,T> {
private static final long serialVersionUID = 1L;
@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
checker.check(this,Roles.SLAVE);
}
private static final long serialVersionUID = 1L;
//TODO: replace by Callable#getChannelOrFail() once Minimal supported Remoting version is 3.15 or above
@Restricted(NoExternalUse.class)
protected static Channel _getChannelOrFail() throws ChannelClosedException {
final Channel ch = Channel.current();
if (ch == null) {
throw new ChannelClosedException("No channel associated with the thread", null);
}
return ch;
}
//TODO: replace by Callable#getOpenChannelOrFail() once Minimal supported Remoting version is 3.15 or above
@Restricted(NoExternalUse.class)
protected static Channel _getOpenChannelOrFail() throws ChannelClosedException {
final Channel ch = _getChannelOrFail();
if (ch.isClosingOrClosed()) { // TODO: Since Remoting 2.33, we still need to explicitly declare minimal Remoting version
throw new ChannelClosedException("The associated channel " + ch + " is closing down or has closed down", ch.getCloseRequestCause());
}
return ch;
}
}
......@@ -39,7 +39,7 @@ public class StandardOutputSwapper extends ComputerListener {
private static final class ChannelSwapper extends MasterToSlaveCallable<Boolean,Exception> {
public Boolean call() throws Exception {
if (File.pathSeparatorChar==';') return false; // Windows
Channel c = getOpenChannelOrFail();
Channel c = _getOpenChannelOrFail();
StandardOutputStream sos = (StandardOutputStream) c.getProperty(StandardOutputStream.class);
if (sos!=null) {
swap(sos);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册