From c459f724d48dfde7e57d6090c717a98da189a7bc Mon Sep 17 00:00:00 2001 From: kohsuke Date: Mon, 30 Jul 2007 01:01:14 +0000 Subject: [PATCH] added a method to connect to all offline slaves. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3937 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Computer.java | 8 ++++++++ core/src/main/java/hudson/model/ComputerSet.java | 10 ++++++++++ core/src/main/java/hudson/model/Hudson.java | 4 ++++ core/src/main/java/hudson/model/Slave.java | 7 ++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 1d7ea52b05..3d616908bb 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -85,6 +85,14 @@ public abstract class Computer implements ModelObject { */ public abstract void doLaunchSlaveAgent( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException; + /** + * Do the same as {@link #doLaunchSlaveAgent(StaplerRequest, StaplerResponse)} + * but outside the context of serving a request. + * + * If already connected, no-op. + */ + public abstract void launch(); + /** * Number of {@link Executor}s that are configured for this computer. * diff --git a/core/src/main/java/hudson/model/ComputerSet.java b/core/src/main/java/hudson/model/ComputerSet.java index 6c2430fd71..3e41a5e9c5 100644 --- a/core/src/main/java/hudson/model/ComputerSet.java +++ b/core/src/main/java/hudson/model/ComputerSet.java @@ -8,6 +8,7 @@ import org.kohsuke.stapler.StaplerResponse; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.io.IOException; /** * Serves as the top of {@link Computer}s in the URL hierarchy. @@ -48,4 +49,13 @@ public final class ComputerSet implements ModelObject { public Computer getDynamic(String token, StaplerRequest req, StaplerResponse rsp) { return Hudson.getInstance().getComputer(token); } + + public void do_launchAll(StaplerRequest req, StaplerResponse rsp) throws IOException { + for(Computer c : get_all()) { + if(c.isJnlpAgent()) + continue; + c.launch(); + } + rsp.sendRedirect("."); + } } diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 16c0f4dfa1..9e76ac72ea 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -1719,6 +1719,10 @@ public final class Hudson extends View implements ItemGroup, Node rsp.sendError(HttpServletResponse.SC_NOT_FOUND); } + public void launch() { + // noop + } + /** * {@link LocalChannel} instance that can be used to execute programs locally. */ diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index f90092225d..91f6c71bad 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -406,13 +406,18 @@ public final class Slave implements Node, Serializable { return; } - launch(getNode()); + launch(); // TODO: would be nice to redirect the user to "launching..." wait page, // then spend a few seconds there and poll for the completion periodically. rsp.sendRedirect("log"); } + public void launch() { + if(channel==null) + launch(getNode()); + } + /** * Gets the string representation of the slave log. */