Skip to content

Commit

Permalink
[JENKINS-51541,JENKINS-51551,...] - Remoting 3.21 + Allow passing cus…
Browse files Browse the repository at this point in the history
…tom CommandTransport implementations to SlaveComputer from ComputerLauncher (#3455)

* [JENKINS-51541] - Introduce new SlaveComputer#setChannel() method which takes custom ChannelBuilder and CommandTransport

* [JENKINS-51551] - Pick Remoting version with the API patch

* [JENKINS-51541] - Listener is nullable according to the documentation

* [JENKINS-51551,JENKINS-51223,JENKINS-50965] - Update Remoting to 3.21

* [JENKINS-51541] - Restrict SlaveComputer#setChannel(ChannelBuilder cb, …) to Beta-use only
  • Loading branch information
oleg-nenashev committed Jun 8, 2018
1 parent ec10b8c commit c405ae7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions core/src/main/java/hudson/slaves/SlaveComputer.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.slaves;

import com.google.common.io.NullOutputStream;
import hudson.AbortException;
import hudson.FilePath;
import hudson.Functions;
Expand All @@ -39,6 +40,7 @@
import hudson.remoting.Channel;
import hudson.remoting.ChannelBuilder;
import hudson.remoting.ChannelClosedException;
import hudson.remoting.CommandTransport;
import hudson.remoting.Launcher;
import hudson.remoting.VirtualChannel;
import hudson.security.ACL;
Expand All @@ -61,6 +63,7 @@
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;
Expand All @@ -72,6 +75,7 @@
import org.kohsuke.stapler.interceptor.RequirePOST;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.OverridingMethodsMustInvokeSuper;
import javax.servlet.ServletException;
import java.io.File;
Expand Down Expand Up @@ -419,6 +423,40 @@ public void setChannel(InputStream in, OutputStream out, OutputStream launchLog,
setChannel(channel,launchLog,listener);
}

/**
* Creates a {@link Channel} from the given Channel Builder and Command Transport.
* This method can be used to allow {@link ComputerLauncher}s to create channels not based on I/O streams.
*
* @param cb
* Channel Builder.
* To print launch logs this channel builder should have a Header Stream defined
* (see {@link ChannelBuilder#getHeaderStream()}) in this argument or by one of {@link ChannelConfigurator}s.
* @param commandTransport
* Command Transport
* @param listener
* Gets a notification when the channel closes, to perform clean up. Can be {@code null}.
* By the time this method is called, the cause of the termination is reported to the user,
* so the implementation of the listener doesn't need to do that again.
* @since TODO
*/
@Restricted(Beta.class)
public void setChannel(@Nonnull ChannelBuilder cb,
@Nonnull CommandTransport commandTransport,
@CheckForNull Channel.Listener listener) throws IOException, InterruptedException {
for (ChannelConfigurator cc : ChannelConfigurator.all()) {
cc.onChannelBuilding(cb,this);
}

OutputStream headerStream = cb.getHeaderStream();
if (headerStream == null) {
LOGGER.log(Level.WARNING, "No header stream defined when setting channel for computer {0}. " +
"Launch log won't be printed", this);
headerStream = new NullOutputStream();
}
Channel channel = cb.build(commandTransport);
setChannel(channel, headerStream, listener);
}

/**
* Shows {@link Channel#classLoadingCount}.
* @since 1.495
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -106,7 +106,7 @@ THE SOFTWARE.
<maven-war-plugin.version>3.0.0</maven-war-plugin.version> <!-- JENKINS-47127 bump when 3.2.0 is out. Cf. MWAR-407 -->

<!-- Bundled Remoting version -->
<remoting.version>3.20</remoting.version>
<remoting.version>3.21</remoting.version>
<!-- Minimum Remoting version, which is tested for API compatibility -->
<remoting.minimum.supported.version>2.60</remoting.minimum.supported.version>

Expand Down

0 comments on commit c405ae7

Please sign in to comment.