提交 bade7660 编写于 作者: K kohsuke

Added a new extension point that allows plugins to postpone the restart.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34846 71c3de6d-444a-0410-be80-ed276b4c234a
上级 1255b8f6
......@@ -2474,7 +2474,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
doQuietDown().generateResponse(null,rsp,this);
}
public synchronized HttpRedirect doQuietDown() {
public synchronized HttpRedirect doQuietDown() throws IOException {
try {
return doQuietDown(false,0);
} catch (InterruptedException e) {
......@@ -2485,7 +2485,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
@CLIMethod(name="quiet-down")
public HttpRedirect doQuietDown(
@Option(name="-block",usage="Block until the system really quiets down and no builds are running") @QueryParameter boolean block,
@Option(name="-timeout",usage="If non-zero, only block up to the specified number of milliseconds") @QueryParameter int timeout) throws InterruptedException {
@Option(name="-timeout",usage="If non-zero, only block up to the specified number of milliseconds") @QueryParameter int timeout) throws InterruptedException, IOException {
synchronized (this) {
checkPermission(ADMINISTER);
isQuietingDown = true;
......@@ -2493,8 +2493,8 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
if (block) {
if (timeout > 0) timeout += System.currentTimeMillis();
while (isQuietingDown
&& (overallLoad.computeTotalExecutors() > overallLoad.computeIdleExecutors())
&& (timeout <= 0 || System.currentTimeMillis() < timeout)) {
&& (timeout <= 0 || System.currentTimeMillis() < timeout)
&& RestartListener.isAllReady()) {
Thread.sleep(1000);
}
}
......@@ -2958,6 +2958,8 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
// give some time for the browser to load the "reloading" page
Thread.sleep(5000);
LOGGER.severe(String.format("Restarting VM as requested by %s",exitUser));
for (RestartListener listener : RestartListener.all())
listener.onRestart();
lifecycle.restart();
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to restart Hudson",e);
......@@ -2995,6 +2997,8 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
LOGGER.info("Restart in 10 seconds");
Thread.sleep(10000);
LOGGER.severe(String.format("Restarting VM as requested by %s",exitUser));
for (RestartListener listener : RestartListener.all())
listener.onRestart();
lifecycle.restart();
} else {
LOGGER.info("Safe-restart mode cancelled");
......
package hudson.model;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import java.io.IOException;
/**
* Extension point that allows plugins to veto the restart.
*
* @author Kohsuke Kawaguchi
* @since 1.376
*/
public abstract class RestartListener implements ExtensionPoint {
/**
* Called periodically during the safe restart.
*
* @return false to block the restart
*/
public abstract boolean isReadyToRestart() throws IOException, InterruptedException;
/**
* Called immediately before the restart is actually triggered.
*/
public void onRestart() {}
/**
* Returns all the registered {@link LabelFinder}s.
*/
public static ExtensionList<RestartListener> all() {
return Hudson.getInstance().getExtensionList(RestartListener.class);
}
/**
* Returns true iff all the listeners OKed the restart.
*/
public static boolean isAllReady() throws IOException, InterruptedException {
for (RestartListener listener : all()) {
if (!listener.isReadyToRestart())
return false;
}
return true;
}
/**
* Default logic. Wait for all the executors to become idle.
*/
@Extension
public static class Default extends RestartListener {
@Override
public boolean isReadyToRestart() throws IOException, InterruptedException {
Hudson h = Hudson.getInstance();
return h.overallLoad.computeTotalExecutors() <= h.overallLoad.computeIdleExecutors();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册