Added a hook to perform additional diagnostic activities before killing the channel.

ssh-slaves plugin can leverage this to try to obtain the state of the slave JVM via SSH.

Reference: ZD-23093
This commit is contained in:
Kohsuke Kawaguchi committed 2014-11-20 20:12:22 +01:00
1 parent 960b4053a1
commit d237acc447
3 files changed
+39

No files matched your search

@@ -31,6 +31,7 @@ import hudson.model.TaskListener;
import hudson.remoting.Channel;
import hudson.remoting.PingThread;
import jenkins.security.MasterToSlaveCallable;
import jenkins.slaves.PingFailureAnalyzer;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -107,6 +108,9 @@ public class ChannelPinger extends ComputerListener {
final PingThread t = new PingThread(channel, interval * 60 * 1000) {
protected void onDead(Throwable cause) {
try {
for (PingFailureAnalyzer pfa : PingFailureAnalyzer.all()) {
pfa.onPingFailure(channel,cause);
}
if (isInClosed.get()) {
LOGGER.log(FINE,"Ping failed after the channel "+channel.getName()+" is already partially closed.",cause);
} else {
@@ -450,6 +450,8 @@ public class SlaveComputer extends Computer {
final TaskListener taskListener = new StreamTaskListener(launchLog);
PrintStream log = taskListener.getLogger();
channel.setProperty(SlaveComputer.class, this);
channel.addListener(new Channel.Listener() {
@Override
public void onClosed(Channel c, IOException cause) {
@@ -0,0 +1,33 @@
package jenkins.slaves;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.remoting.Channel;
import jenkins.model.Jenkins;
import java.io.IOException;
/**
* Get notified when a channel triggered a ping failure, but before the channel is killed.
*
* <p>
* This provides the opportunity to perform diagnostic activities.
*
* @author Kohsuke Kawaguchi
* @since 1.592
*/
public abstract class PingFailureAnalyzer implements ExtensionPoint {
/**
*
* @param c
* The channel that caused the ping failure. Because this channel is in a troubled state,
* do not attempt a remote call on this channel. Doing so would risk creating a hang.
* @param cause
* Cause of the ping failure. Informational, and probably uninteresting to most callees.
*/
public abstract void onPingFailure(Channel c, Throwable cause) throws IOException;
public static ExtensionList<PingFailureAnalyzer> all() {
return Jenkins.getInstance().getExtensionList(PingFailureAnalyzer.class);
}
}