Skip to content

Commit

Permalink
[FIXED JENKINS-23481][FIXED JENKINS-23551] Send onOffline notificatio…
Browse files Browse the repository at this point in the history
…n to master computer prior Jenkins restart.

Introduces new overload `ComputerListener.onOffline(Computer, OfflineCause)`.
  • Loading branch information
olivergondza committed Jun 25, 2014
1 parent 7667abb commit 4afcf32
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
15 changes: 15 additions & 0 deletions core/src/main/java/hudson/slaves/ComputerListener.java
Expand Up @@ -36,6 +36,9 @@

import java.io.IOException;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
* Receives notifications about status changes of {@link Computer}s.
*
Expand Down Expand Up @@ -161,9 +164,21 @@ public void onOnline(Computer c, TaskListener listener) throws IOException, Inte

/**
* 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)}
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/hudson/slaves/OfflineCause.java
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/slaves/SlaveComputer.java
Expand Up @@ -625,7 +625,7 @@ private void closeChannel() {
logger.log(Level.SEVERE, "Failed to terminate channel to " + getDisplayName(), e);
}
for (ComputerListener cl : ComputerListener.all())
cl.onOffline(this);
cl.onOffline(this, offlineCause);
}
}

Expand Down
25 changes: 25 additions & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -3329,6 +3329,31 @@ public void run() {
}.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
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/model/Messages.properties
Expand Up @@ -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

0 comments on commit 4afcf32

Please sign in to comment.