提交 c7a6c824 编写于 作者: K Kohsuke Kawaguchi

Added additional event hooks.

- Pass TaskListener to enable listeners to report what they are doing
- Added another callback to report a failure
上级 be08aa09
......@@ -66,6 +66,9 @@ Upcoming changes</a>
<li class=rfe>
Proactively watch out for incomplete extensions to avoid cryptic NPE.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-8866">issue 8866</a>)
<li class=rfe>
Added more event callbacks on <tt>ComputerListener</tt>
(<a href="http://jenkins.361315.n4.nabble.com/Hooking-into-failed-slave-launches-td3339646.html">thread</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -44,20 +44,43 @@ import java.io.IOException;
*/
public abstract class ComputerListener implements ExtensionPoint {
/**
* Called before a {@link Computer} is brought online.
* Called before a {@link ComputerLauncher} is asked to launch a connection with {@link Computer}.
*
* <p>
* This enables you to do some configurable checks to see if we
* want to bring this slave online or if there are considerations
* that would keep us from doing so.
*
* <p>
* Throwing {@link AbortException} would let you veto the launch operation. Other thrown exceptions
* will also have the same effect, but their stack trace will be dumped, so they are meant for error situation.
*
* @param c
* Computer that's being launched. Never null.
* @param taskListener
* Connected to the slave console log. Useful for reporting progress/errors on a lengthy operation.
* Never null.
* @throws AbortException
* Exceptions will be recorded to the listener, and
* the computer will not become online.
*
* @since 1.400
* @since 1.402
*/
public void preLaunch(Computer c, TaskListener taskListener) throws IOException, InterruptedException {
}
/**
* Called when a slave attempted to connect via {@link ComputerLauncher} but it failed.
*
* @param c
* Computer that was trying to launch. Never null.
* @param taskListener
* Connected to the slave console log. Useful for reporting progress/errors on a lengthy operation.
* Never null.
*
* @since 1.402
*/
public void allowOnline(Computer c) throws AbortException {
public void onLaunchFailure(Computer c, TaskListener taskListener) throws IOException, InterruptedException {
}
/**
......
......@@ -192,7 +192,7 @@ public class SlaveComputer extends Computer {
log.rewind();
try {
for (ComputerListener cl : ComputerListener.all())
cl.allowOnline(SlaveComputer.this);
cl.preLaunch(SlaveComputer.this, taskListener);
launcher.launch(SlaveComputer.this, taskListener);
return null;
} catch (AbortException e) {
......@@ -207,8 +207,11 @@ public class SlaveComputer extends Computer {
throw e;
}
} finally {
if (channel==null)
if (channel==null) {
offlineCause = new OfflineCause.LaunchFailed();
for (ComputerListener cl : ComputerListener.all())
cl.onLaunchFailure(SlaveComputer.this, taskListener);
}
}
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册