提交 4afcf32c 编写于 作者: O Oliver Gondža

[FIXED JENKINS-23481][FIXED JENKINS-23551] Send onOffline notification to...

[FIXED JENKINS-23481][FIXED JENKINS-23551] Send onOffline notification to master computer prior Jenkins restart.

Introduces new overload `ComputerListener.onOffline(Computer, OfflineCause)`.
上级 7667abba
......@@ -36,6 +36,9 @@ import hudson.AbortException;
import java.io.IOException;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
* Receives notifications about status changes of {@link Computer}s.
*
......@@ -161,9 +164,21 @@ public abstract class ComputerListener implements ExtensionPoint {
/**
* Called right after a {@link Computer} went offline.
*
* @deprecated since TODO. Use {@link #onOffline(Computer, OfflineCause)} instead.
*/
@Deprecated
public void onOffline(Computer c) {}
/**
* Called right after a {@link Computer} went offline.
*
* @since TODO
*/
public void onOffline(@Nonnull Computer c, @CheckForNull OfflineCause cause) {
onOffline(c);
}
/**
* Indicates that the computer was marked as temporarily online by the administrator.
* This is the reverse operation of {@link #onTemporarilyOffline(Computer, OfflineCause)}
......
......@@ -55,7 +55,10 @@ public abstract class OfflineCause {
public static class SimpleOfflineCause extends OfflineCause {
public final Localizable description;
private SimpleOfflineCause(Localizable description) {
/**
* @since TODO
*/
protected SimpleOfflineCause(Localizable description) {
this.description = description;
}
......
......@@ -625,7 +625,7 @@ public class SlaveComputer extends Computer {
logger.log(Level.SEVERE, "Failed to terminate channel to " + getDisplayName(), e);
}
for (ComputerListener cl : ComputerListener.all())
cl.onOffline(this);
cl.onOffline(this, offlineCause);
}
}
......
......@@ -3329,6 +3329,31 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
}.start();
}
@Extension @Restricted(NoExternalUse.class)
public static class MasterRestartNotifyier extends RestartListener {
@Override
public void onRestart() {
Computer computer = Jenkins.getInstance().toComputer();
if (computer == null) return;
RestartCause cause = new RestartCause();
for (ComputerListener listener: ComputerListener.all()) {
listener.onOffline(computer, cause);
}
}
@Override
public boolean isReadyToRestart() throws IOException, InterruptedException {
return true;
}
private static class RestartCause extends OfflineCause.SimpleOfflineCause {
protected RestartCause() {
super(Messages._Jenkins_IsRestarting());
}
}
}
/**
* Shutdown the system.
* @since 1.161
......
......@@ -359,3 +359,4 @@ Jenkins.CheckDisplayName.NameNotUniqueWarning=The display name, "{0}", is used a
Jenkins.CheckDisplayName.DisplayNameNotUniqueWarning=The display name, "{0}", is already in use by another job and could cause confusion and delay.
Jenkins.NotAllowedName="{0}" is not allowed name
Jenkins.IsRestarting=Jenkins is restarting
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册