Clean up usages of `Callable#getChannelOrFail` and `Callable#getOpenChannelOrFail` (#7328)

This commit is contained in:
Basil Crow 2022-11-02 07:46:52 -07:00 committed by GitHub
parent 4cd96661b2
commit e0690dd111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 28 deletions

View File

@ -48,7 +48,6 @@ import hudson.model.TaskListener;
import hudson.model.User;
import hudson.remoting.Channel;
import hudson.remoting.ChannelBuilder;
import hudson.remoting.ChannelClosedException;
import hudson.remoting.CommandTransport;
import hudson.remoting.Engine;
import hudson.remoting.Launcher;
@ -90,6 +89,7 @@ import jenkins.slaves.RemotingVersionInfo;
import jenkins.slaves.systemInfo.SlaveSystemInfo;
import jenkins.util.Listeners;
import jenkins.util.SystemProperties;
import org.jenkinsci.remoting.ChannelStateException;
import org.jenkinsci.remoting.util.LoggingChannelListener;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
@ -1113,7 +1113,7 @@ public class SlaveComputer extends Computer {
try {
getChannelOrFail().setProperty("agent", Boolean.TRUE); // indicate that this side of the channel is the agent side.
} catch (ChannelClosedException e) {
} catch (ChannelStateException e) {
throw new IllegalStateException(e);
}

View File

@ -1,8 +1,6 @@
package jenkins.security;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.ChannelClosedException;
import jenkins.slaves.RemotingVersionInfo;
import org.jenkinsci.remoting.RoleChecker;
@ -24,24 +22,4 @@ public abstract class MasterToSlaveCallable<V, T extends Throwable> implements C
public void checkRoles(RoleChecker checker) throws SecurityException {
checker.check(this, Roles.SLAVE);
}
//TODO: remove once Minimum supported Remoting version is 3.15 or above
@Override
public Channel getChannelOrFail() throws ChannelClosedException {
final Channel ch = Channel.current();
if (ch == null) {
throw new ChannelClosedException((Channel) null, new IllegalStateException("No channel associated with the thread"));
}
return ch;
}
//TODO: remove Callable#getOpenChannelOrFail() once minimum supported Remoting version is 3.15 or above
@Override
public Channel getOpenChannelOrFail() throws ChannelClosedException {
final Channel ch = getChannelOrFail();
if (ch.isClosingOrClosed()) { // TODO: Since Remoting 2.33, we still need to explicitly declare minimum Remoting version
throw new ChannelClosedException(ch, new IllegalStateException("The associated channel " + ch + " is closing down or has closed down", ch.getCloseRequestCause()));
}
return ch;
}
}

View File

@ -252,7 +252,7 @@ THE SOFTWARE.
<version>${remoting.minimum.supported.version}</version>
<type>jar</type>
<outputDirectory>${project.build.outputDirectory}/old-remoting</outputDirectory>
<destFileName>remoting-minimal-supported.jar</destFileName>
<destFileName>remoting-minimum-supported.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.jenkins-ci.main</groupId>

View File

@ -83,16 +83,16 @@ public class OldRemotingAgentTest {
@Before
public void extractAgent() throws Exception {
agentJar = new File(tmpDir.getRoot(), "old-agent.jar");
FileUtils.copyURLToFile(OldRemotingAgentTest.class.getResource("/old-remoting/remoting-minimal-supported.jar"), agentJar);
FileUtils.copyURLToFile(OldRemotingAgentTest.class.getResource("/old-remoting/remoting-minimum-supported.jar"), agentJar);
}
@Test
@Issue("JENKINS-48761")
public void shouldBeAbleToConnectAgentWithMinimalSupportedVersion() throws Exception {
public void shouldBeAbleToConnectAgentWithMinimumSupportedVersion() throws Exception {
Label agentLabel = new LabelAtom("old-agent");
Slave agent = j.createOnlineSlave(agentLabel);
boolean isUnix = agent.getComputer().isUnix();
assertThat("Received wrong agent version. A minimal supported version is expected",
assertThat("Received wrong agent version. A minimum supported version is expected",
agent.getComputer().getSlaveVersion(),
equalTo(RemotingVersionInfo.getMinimumSupportedVersion().toString()));