summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-12 15:19:27 (EDT)
committer Henrik Lynggaard Hansen2012-07-12 15:19:27 (EDT)
commit7f7e8b528400c06dc1abec218a50a4e644a79e45 (patch)
treeac6b759ee3bd905e4568721620f5158745bcc63c
parent2e3f55d880a7c54c95afb2f243678f960c79c6bf (diff)
downloadorg.eclipse.hudson.core-7f7e8b528400c06dc1abec218a50a4e644a79e45.zip
org.eclipse.hudson.core-7f7e8b528400c06dc1abec218a50a4e644a79e45.tar.gz
org.eclipse.hudson.core-7f7e8b528400c06dc1abec218a50a4e644a79e45.tar.bz2
Reformat hudson.slavedrefs/changes/45/6745/1
Change-Id: Ide2967f105d2c953e0afc7b0364126119b12bf70 Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/slaves/AbstractCloudComputer.java9
-rw-r--r--hudson-core/src/main/java/hudson/slaves/AbstractCloudImpl.java27
-rw-r--r--hudson-core/src/main/java/hudson/slaves/AbstractCloudSlave.java13
-rw-r--r--hudson-core/src/main/java/hudson/slaves/Channels.java120
-rw-r--r--hudson-core/src/main/java/hudson/slaves/Cloud.java79
-rw-r--r--hudson-core/src/main/java/hudson/slaves/CloudRetentionStrategy.java21
-rw-r--r--hudson-core/src/main/java/hudson/slaves/CommandConnector.java10
-rw-r--r--hudson-core/src/main/java/hudson/slaves/CommandLauncher.java48
-rw-r--r--hudson-core/src/main/java/hudson/slaves/ComputerConnector.java20
-rw-r--r--hudson-core/src/main/java/hudson/slaves/ComputerConnectorDescriptor.java5
-rw-r--r--hudson-core/src/main/java/hudson/slaves/ComputerLauncher.java113
-rw-r--r--hudson-core/src/main/java/hudson/slaves/ComputerLauncherFilter.java17
-rw-r--r--hudson-core/src/main/java/hudson/slaves/ComputerListener.java113
-rw-r--r--hudson-core/src/main/java/hudson/slaves/ComputerRetentionWork.java13
-rw-r--r--hudson-core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java57
-rw-r--r--hudson-core/src/main/java/hudson/slaves/DelegatingComputerLauncher.java24
-rw-r--r--hudson-core/src/main/java/hudson/slaves/DumbSlave.java22
-rw-r--r--hudson-core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java58
-rw-r--r--hudson-core/src/main/java/hudson/slaves/EphemeralNode.java9
-rw-r--r--hudson-core/src/main/java/hudson/slaves/JNLPLauncher.java27
-rw-r--r--hudson-core/src/main/java/hudson/slaves/NodeDescriptor.java53
-rw-r--r--hudson-core/src/main/java/hudson/slaves/NodeList.java21
-rw-r--r--hudson-core/src/main/java/hudson/slaves/NodeProperty.java86
-rw-r--r--hudson-core/src/main/java/hudson/slaves/NodePropertyDescriptor.java15
-rw-r--r--hudson-core/src/main/java/hudson/slaves/NodeProvisioner.java192
-rw-r--r--hudson-core/src/main/java/hudson/slaves/NodeSpecific.java12
-rw-r--r--hudson-core/src/main/java/hudson/slaves/OfflineCause.java36
-rw-r--r--hudson-core/src/main/java/hudson/slaves/RetentionStrategy.java86
-rw-r--r--hudson-core/src/main/java/hudson/slaves/SimpleScheduledRetentionStrategy.java15
-rw-r--r--hudson-core/src/main/java/hudson/slaves/SlaveComputer.java264
-rw-r--r--hudson-core/src/main/java/hudson/slaves/WorkspaceList.java83
-rw-r--r--hudson-core/src/main/java/hudson/slaves/package.html4
32 files changed, 868 insertions, 804 deletions
diff --git a/hudson-core/src/main/java/hudson/slaves/AbstractCloudComputer.java b/hudson-core/src/main/java/hudson/slaves/AbstractCloudComputer.java
index ab62b65..83af3b1 100644
--- a/hudson-core/src/main/java/hudson/slaves/AbstractCloudComputer.java
+++ b/hudson-core/src/main/java/hudson/slaves/AbstractCloudComputer.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -31,6 +31,7 @@ import java.io.IOException;
* @since 1.382
*/
public class AbstractCloudComputer<T extends AbstractCloudSlave> extends SlaveComputer {
+
public AbstractCloudComputer(T slave) {
super(slave);
}
@@ -50,7 +51,7 @@ public class AbstractCloudComputer<T extends AbstractCloudSlave> extends SlaveCo
getNode().terminate();
return new HttpRedirect("..");
} catch (InterruptedException e) {
- return HttpResponses.error(500,e);
+ return HttpResponses.error(500, e);
}
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/AbstractCloudImpl.java b/hudson-core/src/main/java/hudson/slaves/AbstractCloudImpl.java
index 0c3b969..0ef95a4 100644
--- a/hudson-core/src/main/java/hudson/slaves/AbstractCloudImpl.java
+++ b/hudson-core/src/main/java/hudson/slaves/AbstractCloudImpl.java
@@ -8,24 +8,24 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
package hudson.slaves;
/**
- * Additional convenience implementation on top of {@link Cloud} that are likely useful to
- * typical {@link Cloud} implementations.
+ * Additional convenience implementation on top of {@link Cloud} that are likely
+ * useful to typical {@link Cloud} implementations.
*
- * <p>
- * Whereas {@link Cloud} is the contract between the rest of Hudson and a cloud implementation,
- * this class focuses on providing a convenience to minimize the effort it takes to integrate
- * a new cloud to Hudson.
+ * <p> Whereas {@link Cloud} is the contract between the rest of Hudson and a
+ * cloud implementation, this class focuses on providing a convenience to
+ * minimize the effort it takes to integrate a new cloud to Hudson.
*
* @author Kohsuke Kawaguchi
*/
public abstract class AbstractCloudImpl extends Cloud {
+
/**
* Upper bound on how many instances we may provision.
*/
@@ -38,24 +38,27 @@ public abstract class AbstractCloudImpl extends Cloud {
}
protected void setInstanceCapStr(String value) {
- if(value==null || value.equals(""))
+ if (value == null || value.equals("")) {
this.instanceCap = Integer.MAX_VALUE;
- else
+ } else {
this.instanceCap = Integer.parseInt(value);
+ }
}
/**
* Gets the instance cap as string. Used primarily for form binding.
*/
public String getInstanceCapStr() {
- if(instanceCap==Integer.MAX_VALUE)
+ if (instanceCap == Integer.MAX_VALUE) {
return "";
- else
+ } else {
return String.valueOf(instanceCap);
+ }
}
/**
- * Gets the instance cap as int, where the capless is represented as {@link Integer#MAX_VALUE}
+ * Gets the instance cap as int, where the capless is represented as
+ * {@link Integer#MAX_VALUE}
*/
public int getInstanceCap() {
return instanceCap;
diff --git a/hudson-core/src/main/java/hudson/slaves/AbstractCloudSlave.java b/hudson-core/src/main/java/hudson/slaves/AbstractCloudSlave.java
index 446014b..4fffb89 100644
--- a/hudson-core/src/main/java/hudson/slaves/AbstractCloudSlave.java
+++ b/hudson-core/src/main/java/hudson/slaves/AbstractCloudSlave.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -29,12 +29,14 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Partial implementation of {@link Slave} to be used by {@link AbstractCloudImpl}.
+ * Partial implementation of {@link Slave} to be used by
+ * {@link AbstractCloudImpl}.
*
* @author Kohsuke Kawaguchi
* @since 1.382
*/
public abstract class AbstractCloudSlave extends Slave {
+
public AbstractCloudSlave(String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException {
super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);
}
@@ -57,7 +59,7 @@ public abstract class AbstractCloudSlave extends Slave {
try {
Hudson.getInstance().removeNode(this);
} catch (IOException e) {
- LOGGER.log(Level.WARNING, "Failed to remove "+name,e);
+ LOGGER.log(Level.WARNING, "Failed to remove " + name, e);
}
}
}
@@ -66,6 +68,5 @@ public abstract class AbstractCloudSlave extends Slave {
* Performs the removal of the underlying resource from the cloud.
*/
protected abstract void _terminate(TaskListener listener) throws IOException, InterruptedException;
-
private static final Logger LOGGER = Logger.getLogger(AbstractCloudSlave.class.getName());
}
diff --git a/hudson-core/src/main/java/hudson/slaves/Channels.java b/hudson-core/src/main/java/hudson/slaves/Channels.java
index 069c57c..f70de46 100644
--- a/hudson-core/src/main/java/hudson/slaves/Channels.java
+++ b/hudson-core/src/main/java/hudson/slaves/Channels.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -44,21 +44,22 @@ import java.util.logging.Logger;
/**
* Various convenient subtype of {@link Channel}s.
- *
+ *
* @author Kohsuke Kawaguchi
*/
public class Channels {
+
/**
- * @deprecated since 2009-04-13.
- * Use {@link #forProcess(String, ExecutorService, InputStream, OutputStream, OutputStream, Proc)}
+ * @deprecated since 2009-04-13. Use
+ * {@link #forProcess(String, ExecutorService, InputStream, OutputStream, OutputStream, Proc)}
*/
public static Channel forProcess(String name, ExecutorService execService, InputStream in, OutputStream out, Proc proc) throws IOException {
- return forProcess(name,execService,in,out,null,proc);
+ return forProcess(name, execService, in, out, null, proc);
}
/**
- * Creates a channel that wraps a remote process, so that when we shut down the connection
- * we kill the process.
+ * Creates a channel that wraps a remote process, so that when we shut down
+ * the connection we kill the process.
*/
public static Channel forProcess(String name, ExecutorService execService, InputStream in, OutputStream out, OutputStream header, final Proc proc) throws IOException {
return new Channel(name, execService, in, out, header) {
@@ -72,7 +73,7 @@ public class Channels {
proc.kill();
} catch (IOException x) {
// we are already in the error recovery mode, so just record it and move on
- LOGGER.log(Level.INFO, "Failed to terminate the severed connection",x);
+ LOGGER.log(Level.INFO, "Failed to terminate the severed connection", x);
} catch (InterruptedException x) {
// process the interrupt later
Thread.currentThread().interrupt();
@@ -124,84 +125,85 @@ public class Channels {
}
/**
- * Launches a new JVM with the given classpath and system properties, establish a communication channel,
- * and return a {@link Channel} to it.
+ * Launches a new JVM with the given classpath and system properties,
+ * establish a communication channel, and return a {@link Channel} to it.
*
- * @param displayName
- * Human readable name of what this JVM represents. For example "Selenium grid" or "Hadoop".
- * This token is used for messages to {@code listener}.
- * @param listener
- * The progress of the launcher and the failure information will be sent here. Must not be null.
- * @param workDir
- * If non-null, the new JVM will have this directory as the working directory. This must be a local path.
- * @param classpath
- * The classpath of the new JVM. Can be null if you just need {@code slave.jar} (and everything else
- * can be sent over the channel.) But if you have jars that are known to be necessary by the new JVM,
- * setting it here will improve the classloading performance (by avoiding remote class file transfer.)
- * Classes in this classpath will also take precedence over any other classes that's sent via the channel
- * later, so it's also useful for making sure you get the version of the classes you want.
- * @param systemProperties
- * If the new JVM should have a certain system properties set. Can be null.
+ * @param displayName Human readable name of what this JVM represents. For
+ * example "Selenium grid" or "Hadoop". This token is used for messages to
+ * {@code listener}.
+ * @param listener The progress of the launcher and the failure information
+ * will be sent here. Must not be null.
+ * @param workDir If non-null, the new JVM will have this directory as the
+ * working directory. This must be a local path.
+ * @param classpath The classpath of the new JVM. Can be null if you just
+ * need {@code slave.jar} (and everything else can be sent over the
+ * channel.) But if you have jars that are known to be necessary by the new
+ * JVM, setting it here will improve the classloading performance (by
+ * avoiding remote class file transfer.) Classes in this classpath will also
+ * take precedence over any other classes that's sent via the channel later,
+ * so it's also useful for making sure you get the version of the classes
+ * you want.
+ * @param systemProperties If the new JVM should have a certain system
+ * properties set. Can be null.
*
- * @return
- * never null
+ * @return never null
* @since 1.300
*/
- public static Channel newJVM(String displayName, TaskListener listener, FilePath workDir, ClasspathBuilder classpath, Map<String,String> systemProperties) throws IOException {
+ public static Channel newJVM(String displayName, TaskListener listener, FilePath workDir, ClasspathBuilder classpath, Map<String, String> systemProperties) throws IOException {
JVMBuilder vmb = new JVMBuilder();
vmb.systemProperties(systemProperties);
- return newJVM(displayName,listener,vmb,workDir,classpath);
+ return newJVM(displayName, listener, vmb, workDir, classpath);
}
/**
- * Launches a new JVM with the given classpath, establish a communication channel,
- * and return a {@link Channel} to it.
+ * Launches a new JVM with the given classpath, establish a communication
+ * channel, and return a {@link Channel} to it.
*
- * @param displayName
- * Human readable name of what this JVM represents. For example "Selenium grid" or "Hadoop".
- * This token is used for messages to {@code listener}.
- * @param listener
- * The progress of the launcher and the failure information will be sent here. Must not be null.
- * @param workDir
- * If non-null, the new JVM will have this directory as the working directory. This must be a local path.
- * @param classpath
- * The classpath of the new JVM. Can be null if you just need {@code slave.jar} (and everything else
- * can be sent over the channel.) But if you have jars that are known to be necessary by the new JVM,
- * setting it here will improve the classloading performance (by avoiding remote class file transfer.)
- * Classes in this classpath will also take precedence over any other classes that's sent via the channel
- * later, so it's also useful for making sure you get the version of the classes you want.
- * @param vmb
- * A partially configured {@link JVMBuilder} that allows the caller to fine-tune the launch parameter.
+ * @param displayName Human readable name of what this JVM represents. For
+ * example "Selenium grid" or "Hadoop". This token is used for messages to
+ * {@code listener}.
+ * @param listener The progress of the launcher and the failure information
+ * will be sent here. Must not be null.
+ * @param workDir If non-null, the new JVM will have this directory as the
+ * working directory. This must be a local path.
+ * @param classpath The classpath of the new JVM. Can be null if you just
+ * need {@code slave.jar} (and everything else can be sent over the
+ * channel.) But if you have jars that are known to be necessary by the new
+ * JVM, setting it here will improve the classloading performance (by
+ * avoiding remote class file transfer.) Classes in this classpath will also
+ * take precedence over any other classes that's sent via the channel later,
+ * so it's also useful for making sure you get the version of the classes
+ * you want.
+ * @param vmb A partially configured {@link JVMBuilder} that allows the
+ * caller to fine-tune the launch parameter.
*
- * @return
- * never null
+ * @return never null
* @since 1.361
*/
public static Channel newJVM(String displayName, TaskListener listener, JVMBuilder vmb, FilePath workDir, ClasspathBuilder classpath) throws IOException {
ServerSocket serverSocket = new ServerSocket();
- serverSocket.bind(new InetSocketAddress("localhost",0));
- serverSocket.setSoTimeout(10*1000);
+ serverSocket.bind(new InetSocketAddress("localhost", 0));
+ serverSocket.setSoTimeout(10 * 1000);
// use -cp + FQCN instead of -jar since remoting.jar can be rebundled (like in the case of the swarm plugin.)
vmb.classpath().addJarOf(Channel.class);
vmb.mainClass(Launcher.class);
- if(classpath!=null)
+ if (classpath != null) {
vmb.args().add("-cp").add(classpath);
- vmb.args().add("-connectTo","localhost:"+serverSocket.getLocalPort());
+ }
+ vmb.args().add("-connectTo", "localhost:" + serverSocket.getLocalPort());
- listener.getLogger().println("Starting "+displayName);
+ listener.getLogger().println("Starting " + displayName);
Proc p = vmb.launch(new LocalLauncher(listener)).stdout(listener).pwd(workDir).start();
Socket s = serverSocket.accept();
serverSocket.close();
- return forProcess("Channel to "+displayName, Computer.threadPoolForRemoting,
+ return forProcess("Channel to " + displayName, Computer.threadPoolForRemoting,
new BufferedInputStream(new SocketInputStream(s)),
- new BufferedOutputStream(new SocketOutputStream(s)),null,p);
+ new BufferedOutputStream(new SocketOutputStream(s)), null, p);
}
-
-
private static final Logger LOGGER = Logger.getLogger(Channels.class.getName());
}
diff --git a/hudson-core/src/main/java/hudson/slaves/Cloud.java b/hudson-core/src/main/java/hudson/slaves/Cloud.java
index dcac2cb..60fabeb 100644
--- a/hudson-core/src/main/java/hudson/slaves/Cloud.java
+++ b/hudson-core/src/main/java/hudson/slaves/Cloud.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -35,11 +35,11 @@ import java.util.Collection;
import org.eclipse.hudson.security.HudsonSecurityEntitiesHolder;
/**
- * Creates {@link Node}s to dynamically expand/shrink the slaves attached to Hudson.
+ * Creates {@link Node}s to dynamically expand/shrink the slaves attached to
+ * Hudson.
*
- * <p>
- * Put another way, this class encapsulates different communication protocols
- * needed to start a new slave programmatically.
+ * <p> Put another way, this class encapsulates different communication
+ * protocols needed to start a new slave programmatically.
*
* @author Kohsuke Kawaguchi
* @see NodeProvisioner
@@ -48,7 +48,8 @@ import org.eclipse.hudson.security.HudsonSecurityEntitiesHolder;
public abstract class Cloud extends AbstractModelObject implements ExtensionPoint, Describable<Cloud>, AccessControlled {
/**
- * Uniquely identifies this {@link Cloud} instance among other instances in {@link Hudson#clouds}.
+ * Uniquely identifies this {@link Cloud} instance among other instances in
+ * {@link Hudson#clouds}.
*/
public final String name;
@@ -63,7 +64,7 @@ public abstract class Cloud extends AbstractModelObject implements ExtensionPoin
@Override
public String getSearchUrl() {
- return "cloud/"+name;
+ return "cloud/" + name;
}
@Override
@@ -84,61 +85,55 @@ public abstract class Cloud extends AbstractModelObject implements ExtensionPoin
/**
* Provisions new {@link Node}s from this cloud.
*
- * <p>
- * {@link NodeProvisioner} performs a trend analysis on the load,
- * and when it determines that it <b>really</b> needs to bring up
- * additional nodes, this method is invoked.
+ * <p> {@link NodeProvisioner} performs a trend analysis on the load, and
+ * when it determines that it <b>really</b> needs to bring up additional
+ * nodes, this method is invoked.
*
- * <p>
- * The implementation of this method asynchronously starts
- * node provisioning.
+ * <p> The implementation of this method asynchronously starts node
+ * provisioning.
*
- * @param label
- * The label that indicates what kind of nodes are needed now.
- * Newly launched node needs to have this label.
- * Only those {@link Label}s that this instance returned true
- * from the {@link #canProvision(Label)} method will be passed here.
- * This parameter is null if Hudson needs to provision a new {@link Node}
- * for jobs that don't have any tie to any label.
- * @param excessWorkload
- * Number of total executors needed to meet the current demand.
- * Always >= 1. For example, if this is 3, the implementation
- * should launch 3 slaves with 1 executor each, or 1 slave with
- * 3 executors, etc.
+ * @param label The label that indicates what kind of nodes are needed now.
+ * Newly launched node needs to have this label. Only those {@link Label}s
+ * that this instance returned true from the {@link #canProvision(Label)}
+ * method will be passed here. This parameter is null if Hudson needs to
+ * provision a new {@link Node} for jobs that don't have any tie to any
+ * label.
+ * @param excessWorkload Number of total executors needed to meet the
+ * current demand. Always >= 1. For example, if this is 3, the
+ * implementation should launch 3 slaves with 1 executor each, or 1 slave
+ * with 3 executors, etc.
*
- * @return
- * {@link PlannedNode}s that represent asynchronous {@link Node}
- * provisioning operations. Can be empty but must not be null.
- * {@link NodeProvisioner} will be responsible for adding the resulting {@link Node}
- * into Hudson via {@link Hudson#addNode(Node)}, so a {@link Cloud} implementation
- * just needs to create a new node object.
+ * @return {@link PlannedNode}s that represent asynchronous {@link Node}
+ * provisioning operations. Can be empty but must not be null.
+ * {@link NodeProvisioner} will be responsible for adding the resulting
+ * {@link Node} into Hudson via {@link Hudson#addNode(Node)}, so a
+ * {@link Cloud} implementation just needs to create a new node object.
*/
public abstract Collection<PlannedNode> provision(Label label, int excessWorkload);
/**
- * Returns true if this cloud is capable of provisioning new nodes for the given label.
+ * Returns true if this cloud is capable of provisioning new nodes for the
+ * given label.
*/
public abstract boolean canProvision(Label label);
public Descriptor<Cloud> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
}
-
/**
* All registered {@link Cloud} implementations.
*
- * @deprecated as of 1.286
- * Use {@link #all()} for read access, and {@link Extension} for registration.
+ * @deprecated as of 1.286 Use {@link #all()} for read access, and
+ * {@link Extension} for registration.
*/
public static final DescriptorList<Cloud> ALL = new DescriptorList<Cloud>(Cloud.class);
/**
* Returns all the registered {@link Cloud} descriptors.
*/
- public static DescriptorExtensionList<Cloud,Descriptor<Cloud>> all() {
- return Hudson.getInstance().<Cloud,Descriptor<Cloud>>getDescriptorList(Cloud.class);
+ public static DescriptorExtensionList<Cloud, Descriptor<Cloud>> all() {
+ return Hudson.getInstance().<Cloud, Descriptor<Cloud>>getDescriptorList(Cloud.class);
}
-
/**
* Permission constant to control mutation operations on {@link Cloud}.
*
diff --git a/hudson-core/src/main/java/hudson/slaves/CloudRetentionStrategy.java b/hudson-core/src/main/java/hudson/slaves/CloudRetentionStrategy.java
index a3ec384..5b230aa 100644
--- a/hudson-core/src/main/java/hudson/slaves/CloudRetentionStrategy.java
+++ b/hudson-core/src/main/java/hudson/slaves/CloudRetentionStrategy.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -23,13 +23,14 @@ import static hudson.util.TimeUnit2.*;
import static java.util.logging.Level.*;
/**
- * {@link RetentionStrategy} implementation for {@link AbstractCloudComputer} that terminates
- * it if it remains idle for X minutes.
+ * {@link RetentionStrategy} implementation for {@link AbstractCloudComputer}
+ * that terminates it if it remains idle for X minutes.
*
* @author Kohsuke Kawaguchi
* @since 1.382
*/
public class CloudRetentionStrategy extends RetentionStrategy<AbstractCloudComputer> {
+
private int idleMinutes;
public CloudRetentionStrategy(int idleMinutes) {
@@ -40,13 +41,13 @@ public class CloudRetentionStrategy extends RetentionStrategy<AbstractCloudCompu
if (c.isIdle() && !disabled) {
final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds();
if (idleMilliseconds > MINUTES.toMillis(idleMinutes)) {
- LOGGER.info("Disconnecting "+c.getName());
+ LOGGER.info("Disconnecting " + c.getName());
try {
c.getNode().terminate();
} catch (InterruptedException e) {
- LOGGER.log(WARNING,"Failed to terminate "+c.getName(),e);
+ LOGGER.log(WARNING, "Failed to terminate " + c.getName(), e);
} catch (IOException e) {
- LOGGER.log(WARNING,"Failed to terminate "+c.getName(),e);
+ LOGGER.log(WARNING, "Failed to terminate " + c.getName(), e);
}
}
}
@@ -60,8 +61,6 @@ public class CloudRetentionStrategy extends RetentionStrategy<AbstractCloudCompu
public void start(AbstractCloudComputer c) {
c.connect(false);
}
-
private static final Logger LOGGER = Logger.getLogger(CloudRetentionStrategy.class.getName());
-
- public static boolean disabled = Boolean.getBoolean(CloudRetentionStrategy.class.getName()+".disabled");
+ public static boolean disabled = Boolean.getBoolean(CloudRetentionStrategy.class.getName() + ".disabled");
}
diff --git a/hudson-core/src/main/java/hudson/slaves/CommandConnector.java b/hudson-core/src/main/java/hudson/slaves/CommandConnector.java
index 66fe868..bf7cd93 100644
--- a/hudson-core/src/main/java/hudson/slaves/CommandConnector.java
+++ b/hudson-core/src/main/java/hudson/slaves/CommandConnector.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -29,6 +29,7 @@ import java.io.IOException;
* @author Kohsuke Kawaguchi
*/
public class CommandConnector extends ComputerConnector {
+
public final String command;
@DataBoundConstructor
@@ -38,11 +39,12 @@ public class CommandConnector extends ComputerConnector {
@Override
public CommandLauncher launch(String host, TaskListener listener) throws IOException, InterruptedException {
- return new CommandLauncher(command,new EnvVars("SLAVE",host));
+ return new CommandLauncher(command, new EnvVars("SLAVE", host));
}
@Extension
public static class DescriptorImpl extends ComputerConnectorDescriptor {
+
@Override
public String getDisplayName() {
return Messages.CommandLauncher_displayName();
diff --git a/hudson-core/src/main/java/hudson/slaves/CommandLauncher.java b/hudson-core/src/main/java/hudson/slaves/CommandLauncher.java
index d52eb08..8ad6963 100644
--- a/hudson-core/src/main/java/hudson/slaves/CommandLauncher.java
+++ b/hudson-core/src/main/java/hudson/slaves/CommandLauncher.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Stephen Connolly
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Stephen Connolly
+ *
*
*******************************************************************************/
@@ -40,17 +40,17 @@ import org.kohsuke.stapler.QueryParameter;
*
* @author Stephen Connolly
* @author Kohsuke Kawaguchi
-*/
+ */
public class CommandLauncher extends ComputerLauncher {
/**
- * Command line to launch the agent, like
- * "ssh myslave java -jar /path/to/hudson-remoting.jar"
+ * Command line to launch the agent, like "ssh myslave java -jar
+ * /path/to/hudson-remoting.jar"
*/
private final String agentCommand;
-
/**
- * Optional environment variables to add to the current environment. Can be null.
+ * Optional environment variables to add to the current environment. Can be
+ * null.
*/
private final EnvVars env;
@@ -58,10 +58,10 @@ public class CommandLauncher extends ComputerLauncher {
public CommandLauncher(String command) {
this(command, null);
}
-
+
public CommandLauncher(String command, EnvVars env) {
- this.agentCommand = command;
- this.env = env;
+ this.agentCommand = command;
+ this.env = env;
}
public String getCommand() {
@@ -81,7 +81,7 @@ public class CommandLauncher extends ComputerLauncher {
Process _proc = null;
try {
listener.getLogger().println(hudson.model.Messages.Slave_Launching(getTimestamp()));
- if(getCommand().trim().length()==0) {
+ if (getCommand().trim().length() == 0) {
listener.getLogger().println(Messages.CommandLauncher_NoLaunchCommand());
return;
}
@@ -93,16 +93,16 @@ public class CommandLauncher extends ComputerLauncher {
{// system defined variables
String rootUrl = Hudson.getInstance().getRootUrl();
- if (rootUrl!=null) {
+ if (rootUrl != null) {
pb.environment().put("HUDSON_URL", rootUrl);
- pb.environment().put("SLAVEJAR_URL", rootUrl+"/jnlpJars/slave.jar");
+ pb.environment().put("SLAVEJAR_URL", rootUrl + "/jnlpJars/slave.jar");
}
}
if (env != null) {
- pb.environment().putAll(env);
+ pb.environment().putAll(env);
}
-
+
final Process proc = _proc = pb.start();
// capture error information from stderr. this will terminate itself
@@ -115,8 +115,8 @@ public class CommandLauncher extends ComputerLauncher {
public void onClosed(Channel channel, IOException cause) {
try {
int exitCode = proc.exitValue();
- if (exitCode!=0) {
- listener.error("Process terminated with exit code "+exitCode);
+ if (exitCode != 0) {
+ listener.error("Process terminated with exit code " + exitCode);
}
} catch (IllegalThreadStateException e) {
// hasn't terminated yet
@@ -150,28 +150,30 @@ public class CommandLauncher extends ComputerLauncher {
LOGGER.log(Level.SEVERE, msg, e);
e.printStackTrace(listener.error(msg));
- if(_proc!=null)
+ if (_proc != null) {
try {
ProcessTree.get().killAll(_proc, _cookie);
} catch (InterruptedException x) {
x.printStackTrace(listener.error(Messages.ComputerLauncher_abortedLaunch()));
}
+ }
}
}
-
private static final Logger LOGGER = Logger.getLogger(CommandLauncher.class.getName());
@Extension
public static class DescriptorImpl extends Descriptor<ComputerLauncher> {
+
public String getDisplayName() {
return Messages.CommandLauncher_displayName();
}
public FormValidation doCheckCommand(@QueryParameter String value) {
- if(Util.fixEmptyAndTrim(value)==null)
+ if (Util.fixEmptyAndTrim(value) == null) {
return FormValidation.error("Command is empty");
- else
+ } else {
return FormValidation.ok();
+ }
}
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/ComputerConnector.java b/hudson-core/src/main/java/hudson/slaves/ComputerConnector.java
index 34403b6..f5d357b 100644
--- a/hudson-core/src/main/java/hudson/slaves/ComputerConnector.java
+++ b/hudson-core/src/main/java/hudson/slaves/ComputerConnector.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -25,26 +25,26 @@ import java.io.IOException;
/**
* Factory of {@link ComputerLauncher}.
*
- * When writing a {@link Cloud} implementation, one needs to dynamically create {@link ComputerLauncher}
- * by supplying a host name. This is the abstraction for that.
+ * When writing a {@link Cloud} implementation, one needs to dynamically create
+ * {@link ComputerLauncher} by supplying a host name. This is the abstraction
+ * for that.
*
* @author Kohsuke Kawaguchi
* @since 1.383
* @see ComputerLauncher
*/
public abstract class ComputerConnector extends AbstractDescribableImpl<ComputerConnector> implements ExtensionPoint {
+
/**
* Creates a {@link ComputerLauncher} for connecting to the given host.
*
- * @param host
- * The host name / IP address of the machine to connect to.
- * @param listener
- * If
+ * @param host The host name / IP address of the machine to connect to.
+ * @param listener If
*/
public abstract ComputerLauncher launch(String host, TaskListener listener) throws IOException, InterruptedException;
@Override
public ComputerConnectorDescriptor getDescriptor() {
- return (ComputerConnectorDescriptor)super.getDescriptor();
+ return (ComputerConnectorDescriptor) super.getDescriptor();
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/ComputerConnectorDescriptor.java b/hudson-core/src/main/java/hudson/slaves/ComputerConnectorDescriptor.java
index 1a618b2..dd56e4a 100644
--- a/hudson-core/src/main/java/hudson/slaves/ComputerConnectorDescriptor.java
+++ b/hudson-core/src/main/java/hudson/slaves/ComputerConnectorDescriptor.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -25,7 +25,8 @@ import hudson.model.Hudson;
* @since 1.383
*/
public abstract class ComputerConnectorDescriptor extends Descriptor<ComputerConnector> {
- public static DescriptorExtensionList<ComputerConnector,ComputerConnectorDescriptor> all() {
+
+ public static DescriptorExtensionList<ComputerConnector, ComputerConnectorDescriptor> all() {
return Hudson.getInstance().getDescriptorList(ComputerConnector.class);
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/ComputerLauncher.java b/hudson-core/src/main/java/hudson/slaves/ComputerLauncher.java
index 610bd8d..8d4d927 100644
--- a/hudson-core/src/main/java/hudson/slaves/ComputerLauncher.java
+++ b/hudson-core/src/main/java/hudson/slaves/ComputerLauncher.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Stephen Connolly
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Stephen Connolly
+ *
*
*******************************************************************************/
@@ -28,22 +28,19 @@ import java.io.IOException;
* Extension point to allow control over how {@link Computer}s are "launched",
* meaning how they get connected to their slave agent program.
*
- * <h2>Associated View</h2>
- * <dl>
- * <dt>main.jelly</dt>
- * <dd>
- * This page will be rendered into the top page of the computer (/computer/NAME/)
- * Useful for showing launch related commands and status reports.
- * </dl>
+ * <h2>Associated View</h2> <dl> <dt>main.jelly</dt> <dd> This page will be
+ * rendered into the top page of the computer (/computer/NAME/) Useful for
+ * showing launch related commands and status reports. </dl>
*
* @author Stephen Connolly
* @since 24-Apr-2008 22:12:35
* @see ComputerConnector
*/
public abstract class ComputerLauncher extends AbstractDescribableImpl<ComputerLauncher> implements ExtensionPoint {
+
/**
- * Returns true if this {@link ComputerLauncher} supports
- * programatic launch of the slave agent in the target {@link Computer}.
+ * Returns true if this {@link ComputerLauncher} supports programatic launch
+ * of the slave agent in the target {@link Computer}.
*/
public boolean isLaunchSupported() {
return true;
@@ -52,56 +49,56 @@ public abstract class ComputerLauncher extends AbstractDescribableImpl<ComputerL
/**
* Launches the slave agent for the given {@link Computer}.
*
- * <p>
- * If the slave agent is launched successfully, {@link SlaveComputer#setChannel(java.io.InputStream, java.io.OutputStream, TaskListener, hudson.remoting.Channel.Listener)}
- * should be invoked in the end to notify Hudson of the established connection.
- * The operation could also fail, in which case there's no need to make any callback notification,
- * (except to notify the user of the failure through {@link StreamTaskListener}.)
+ * <p> If the slave agent is launched successfully,
+ * {@link SlaveComputer#setChannel(java.io.InputStream, java.io.OutputStream, TaskListener, hudson.remoting.Channel.Listener)}
+ * should be invoked in the end to notify Hudson of the established
+ * connection. The operation could also fail, in which case there's no need
+ * to make any callback notification, (except to notify the user of the
+ * failure through {@link StreamTaskListener}.)
*
- * <p>
- * This method must operate synchronously. Asynchrony is provided by {@link Computer#connect(boolean)} and
- * its correct operation depends on this.
+ * <p> This method must operate synchronously. Asynchrony is provided by
+ * {@link Computer#connect(boolean)} and its correct operation depends on
+ * this.
*
- * @param listener
- * The progress of the launch, as well as any error, should be sent to this listener.
+ * @param listener The progress of the launch, as well as any error, should
+ * be sent to this listener.
*
- * @throws IOException
- * if the method throws an {@link IOException} or {@link InterruptedException}, the launch was considered
- * a failure and the stack trace is reported into the listener. This handling is just so that the implementation
- * of this method doesn't have to dilligently catch those exceptions.
+ * @throws IOException if the method throws an {@link IOException} or
+ * {@link InterruptedException}, the launch was considered a failure and the
+ * stack trace is reported into the listener. This handling is just so that
+ * the implementation of this method doesn't have to dilligently catch those
+ * exceptions.
*/
- public void launch(SlaveComputer computer, TaskListener listener) throws IOException , InterruptedException {
+ public void launch(SlaveComputer computer, TaskListener listener) throws IOException, InterruptedException {
// to remain compatible with the legacy implementation that overrides the old signature
- launch(computer,cast(listener));
+ launch(computer, cast(listener));
}
/**
- * @deprecated as of 1.304
- * Use {@link #launch(SlaveComputer, TaskListener)}
+ * @deprecated as of 1.304 Use {@link #launch(SlaveComputer, TaskListener)}
*/
- public void launch(SlaveComputer computer, StreamTaskListener listener) throws IOException , InterruptedException {
- throw new UnsupportedOperationException(getClass()+" must implement the launch method");
+ public void launch(SlaveComputer computer, StreamTaskListener listener) throws IOException, InterruptedException {
+ throw new UnsupportedOperationException(getClass() + " must implement the launch method");
}
/**
* Allows the {@link ComputerLauncher} to tidy-up after a disconnect.
*
- * <p>
- * This method is invoked after the {@link Channel} to this computer is terminated.
+ * <p> This method is invoked after the {@link Channel} to this computer is
+ * terminated.
*
- * <p>
- * Disconnect operation is performed asynchronously, so there's no guarantee
- * that the corresponding {@link SlaveComputer} exists for the duration of the
- * operation.
+ * <p> Disconnect operation is performed asynchronously, so there's no
+ * guarantee that the corresponding {@link SlaveComputer} exists for the
+ * duration of the operation.
*/
public void afterDisconnect(SlaveComputer computer, TaskListener listener) {
// to remain compatible with the legacy implementation that overrides the old signature
- afterDisconnect(computer,cast(listener));
+ afterDisconnect(computer, cast(listener));
}
/**
- * @deprecated as of 1.304
- * Use {@link #afterDisconnect(SlaveComputer, TaskListener)}
+ * @deprecated as of 1.304 Use
+ * {@link #afterDisconnect(SlaveComputer, TaskListener)}
*/
public void afterDisconnect(SlaveComputer computer, StreamTaskListener listener) {
}
@@ -109,41 +106,39 @@ public abstract class ComputerLauncher extends AbstractDescribableImpl<ComputerL
/**
* Allows the {@link ComputerLauncher} to prepare for a disconnect.
*
- * <p>
- * This method is invoked before the {@link Channel} to this computer is terminated,
- * thus the channel is still accessible from {@link SlaveComputer#getChannel()}.
- * If the channel is terminated unexpectedly, this method will not be invoked,
- * as the channel is already gone.
+ * <p> This method is invoked before the {@link Channel} to this computer is
+ * terminated, thus the channel is still accessible from
+ * {@link SlaveComputer#getChannel()}. If the channel is terminated
+ * unexpectedly, this method will not be invoked, as the channel is already
+ * gone.
*
- * <p>
- * Disconnect operation is performed asynchronously, so there's no guarantee
- * that the corresponding {@link SlaveComputer} exists for the duration of the
- * operation.
+ * <p> Disconnect operation is performed asynchronously, so there's no
+ * guarantee that the corresponding {@link SlaveComputer} exists for the
+ * duration of the operation.
*/
public void beforeDisconnect(SlaveComputer computer, TaskListener listener) {
// to remain compatible with the legacy implementation that overrides the old signature
- beforeDisconnect(computer,cast(listener));
+ beforeDisconnect(computer, cast(listener));
}
/**
- * @deprecated as of 1.304
- * Use {@link #beforeDisconnect(SlaveComputer, TaskListener)}
+ * @deprecated as of 1.304 Use
+ * {@link #beforeDisconnect(SlaveComputer, TaskListener)}
*/
public void beforeDisconnect(SlaveComputer computer, StreamTaskListener listener) {
}
private StreamTaskListener cast(TaskListener listener) {
- if (listener instanceof StreamTaskListener)
+ if (listener instanceof StreamTaskListener) {
return (StreamTaskListener) listener;
+ }
return new StreamTaskListener(listener.getLogger());
}
-
/**
* All registered {@link ComputerLauncher} implementations.
*
- * @deprecated as of 1.281
- * Use {@link Extension} for registration, and use
- * {@link Hudson#getDescriptorList(Class)} for read access.
+ * @deprecated as of 1.281 Use {@link Extension} for registration, and use
+ * {@link Hudson#getDescriptorList(Class)} for read access.
*/
public static final DescriptorList<ComputerLauncher> LIST = new DescriptorList<ComputerLauncher>(ComputerLauncher.class);
}
diff --git a/hudson-core/src/main/java/hudson/slaves/ComputerLauncherFilter.java b/hudson-core/src/main/java/hudson/slaves/ComputerLauncherFilter.java
index b84c170..3ae917a 100644
--- a/hudson-core/src/main/java/hudson/slaves/ComputerLauncherFilter.java
+++ b/hudson-core/src/main/java/hudson/slaves/ComputerLauncherFilter.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -22,16 +22,17 @@ import hudson.model.TaskListener;
import java.io.IOException;
/**
- * {@link ComputerLauncher} filter that can be used as a base class for decorators.
+ * {@link ComputerLauncher} filter that can be used as a base class for
+ * decorators.
*
- * <p>
- * Using this class also protects you from method additions in {@link ComputerLauncher},
- * since these two classes are updated in sync.
+ * <p> Using this class also protects you from method additions in
+ * {@link ComputerLauncher}, since these two classes are updated in sync.
*
* @author Kohsuke Kawaguchi
* @see SlaveComputer#grabLauncher(Node)
*/
public abstract class ComputerLauncherFilter extends ComputerLauncher {
+
protected volatile ComputerLauncher core;
public ComputerLauncherFilter(ComputerLauncher core) {
diff --git a/hudson-core/src/main/java/hudson/slaves/ComputerListener.java b/hudson-core/src/main/java/hudson/slaves/ComputerListener.java
index 47c23c4..31445b5 100644
--- a/hudson-core/src/main/java/hudson/slaves/ComputerListener.java
+++ b/hudson-core/src/main/java/hudson/slaves/ComputerListener.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -35,36 +35,31 @@ import java.io.IOException;
* @since 1.246
*/
public abstract class ComputerListener implements ExtensionPoint {
+
/**
* Called before a {@link Computer} is marked online.
*
- * <p>
- * This enables you to do some work on all the slaves
- * as they get connected. Unlike {@link #onOnline(Computer, TaskListener)},
- * a failure to carry out this function normally will prevent
- * a computer from marked as online.
+ * <p> This enables you to do some work on all the slaves as they get
+ * connected. Unlike {@link #onOnline(Computer, TaskListener)}, a failure to
+ * carry out this function normally will prevent a computer from marked as
+ * online.
*
- * @param channel
- * This is the channel object to talk to the slave.
- * (This is the same object returned by {@link Computer#getChannel()} once
- * it's connected.
- * @param root
- * The directory where this slave stores files.
- * The same as {@link Node#getRootPath()}, except that method returns
- * null until the slave is connected. So this parameter is passed explicitly instead.
- * @param listener
- * This is connected to the launch log of the computer.
- * Since this method is called synchronously from the thread
- * that launches a computer, if this method performs a time-consuming
- * operation, this listener should be notified of the progress.
- * This is also a good listener for reporting problems.
+ * @param channel This is the channel object to talk to the slave. (This is
+ * the same object returned by {@link Computer#getChannel()} once it's
+ * connected.
+ * @param root The directory where this slave stores files. The same as
+ * {@link Node#getRootPath()}, except that method returns null until the
+ * slave is connected. So this parameter is passed explicitly instead.
+ * @param listener This is connected to the launch log of the computer.
+ * Since this method is called synchronously from the thread that launches a
+ * computer, if this method performs a time-consuming operation, this
+ * listener should be notified of the progress. This is also a good listener
+ * for reporting problems.
*
- * @throws IOException
- * Exceptions will be recorded to the listener, and
- * the computer will not become online.
- * @throws InterruptedException
- * Exceptions will be recorded to the listener, and
- * the computer will not become online.
+ * @throws IOException Exceptions will be recorded to the listener, and the
+ * computer will not become online.
+ * @throws InterruptedException Exceptions will be recorded to the listener,
+ * and the computer will not become online.
*
* @since 1.295
* @see #onOnline(Computer, TaskListener)
@@ -75,34 +70,30 @@ public abstract class ComputerListener implements ExtensionPoint {
/**
* Called right after a {@link Computer} comes online.
*
- * @deprecated as of 1.292
- * Use {@link #onOnline(Computer, TaskListener)}
+ * @deprecated as of 1.292 Use {@link #onOnline(Computer, TaskListener)}
*/
- public void onOnline(Computer c) {}
+ public void onOnline(Computer c) {
+ }
/**
* Called right after a {@link Computer} comes online.
*
- * <p>
- * This enables you to do some work on all the slaves
- * as they get connected.
+ * <p> This enables you to do some work on all the slaves as they get
+ * connected.
*
- * <p>
- * Starting Hudson 1.312, this method is also invoked for the master, not just for slaves.
+ * <p> Starting Hudson 1.312, this method is also invoked for the master,
+ * not just for slaves.
*
- * @param listener
- * This is connected to the launch log of the computer.
- * Since this method is called synchronously from the thread
- * that launches a computer, if this method performs a time-consuming
- * operation, this listener should be notified of the progress.
- * This is also a good listener for reporting problems.
+ * @param listener This is connected to the launch log of the computer.
+ * Since this method is called synchronously from the thread that launches a
+ * computer, if this method performs a time-consuming operation, this
+ * listener should be notified of the progress. This is also a good listener
+ * for reporting problems.
*
- * @throws IOException
- * Exceptions will be recorded to the listener. Note that
- * throwing an exception doesn't put the computer offline.
- * @throws InterruptedException
- * Exceptions will be recorded to the listener. Note that
- * throwing an exception doesn't put the computer offline.
+ * @throws IOException Exceptions will be recorded to the listener. Note
+ * that throwing an exception doesn't put the computer offline.
+ * @throws InterruptedException Exceptions will be recorded to the listener.
+ * Note that throwing an exception doesn't put the computer offline.
*
* @see #preOnline(Computer, Channel, FilePath, TaskListener)
*/
@@ -114,29 +105,35 @@ public abstract class ComputerListener implements ExtensionPoint {
/**
* Called right after a {@link Computer} went offline.
*/
- public void onOffline(Computer c) {}
+ public void onOffline(Computer c) {
+ }
/**
- * Called when configuration of the node was changed, a node is added/removed, etc.
+ * Called when configuration of the node was changed, a node is
+ * added/removed, etc.
+ *
* @since 1.377
*/
- public void onConfigurationChange() {}
+ public void onConfigurationChange() {
+ }
/**
- * Registers this {@link ComputerListener} so that it will start receiving events.
+ * Registers this {@link ComputerListener} so that it will start receiving
+ * events.
*
- * @deprecated as of 1.286
- * put {@link Extension} on your class to have it auto-registered.
+ * @deprecated as of 1.286 put {@link Extension} on your class to have it
+ * auto-registered.
*/
public final void register() {
all().add(this);
}
/**
- * Unregisters this {@link ComputerListener} so that it will never receive further events.
+ * Unregisters this {@link ComputerListener} so that it will never receive
+ * further events.
*
- * <p>
- * Unless {@link ComputerListener} is unregistered, it will never be a subject of GC.
+ * <p> Unless {@link ComputerListener} is unregistered, it will never be a
+ * subject of GC.
*/
public final boolean unregister() {
return all().remove(this);
diff --git a/hudson-core/src/main/java/hudson/slaves/ComputerRetentionWork.java b/hudson-core/src/main/java/hudson/slaves/ComputerRetentionWork.java
index 5100382..32af894 100644
--- a/hudson-core/src/main/java/hudson/slaves/ComputerRetentionWork.java
+++ b/hudson-core/src/main/java/hudson/slaves/ComputerRetentionWork.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Stephen Connolly
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Stephen Connolly
+ *
*
*******************************************************************************/
@@ -51,13 +51,14 @@ public class ComputerRetentionWork extends PeriodicWork {
final long startRun = System.currentTimeMillis();
for (Computer c : Hudson.getInstance().getComputers()) {
Node n = c.getNode();
- if (n!=null && n.isHoldOffLaunchUntilSave())
+ if (n != null && n.isHoldOffLaunchUntilSave()) {
continue;
+ }
if (!nextCheck.containsKey(c) || startRun > nextCheck.get(c)) {
// at the moment I don't trust strategies to wait more than 60 minutes
// strategies need to wait at least one minute
final long waitInMins = Math.min(1, Math.max(60, c.getRetentionStrategy().check(c)));
- nextCheck.put(c, startRun + waitInMins*1000*60 /*MINS->MILLIS*/);
+ nextCheck.put(c, startRun + waitInMins * 1000 * 60 /*MINS->MILLIS*/);
}
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java b/hudson-core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java
index 5c463c8..294c922 100644
--- a/hudson-core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java
+++ b/hudson-core/src/main/java/hudson/slaves/ConnectionActivityMonitor.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -30,45 +30,50 @@ import java.io.IOException;
import java.util.logging.Logger;
/**
- * Makes sure that connections to slaves are alive, and if they are not, cut them off.
+ * Makes sure that connections to slaves are alive, and if they are not, cut
+ * them off.
*
- * <p>
- * If we only rely on TCP retransmission time out for this, the time it takes to detect a bad connection
- * is in the order of 10s of minutes, so we take the matters to our own hands.
+ * <p> If we only rely on TCP retransmission time out for this, the time it
+ * takes to detect a bad connection is in the order of 10s of minutes, so we
+ * take the matters to our own hands.
*
* @author Kohsuke Kawaguchi
* @since 1.325
*/
@Extension
public class ConnectionActivityMonitor extends AsyncPeriodicWork {
+
public ConnectionActivityMonitor() {
super("Connection Activity monitoring to slaves");
}
protected void execute(TaskListener listener) throws IOException, InterruptedException {
- if (!enabled) return;
+ if (!enabled) {
+ return;
+ }
long now = System.currentTimeMillis();
- for (Computer c: Hudson.getInstance().getComputers()) {
+ for (Computer c : Hudson.getInstance().getComputers()) {
VirtualChannel ch = c.getChannel();
if (ch instanceof Channel) {
Channel channel = (Channel) ch;
- if (now-channel.getLastHeard() > TIME_TILL_PING) {
+ if (now - channel.getLastHeard() > TIME_TILL_PING) {
// haven't heard from this slave for a while.
- Long lastPing = (Long)channel.getProperty(ConnectionActivityMonitor.class);
+ Long lastPing = (Long) channel.getProperty(ConnectionActivityMonitor.class);
- if (lastPing!=null && now-lastPing > TIMEOUT) {
- LOGGER.info("Repeated ping attempts failed on "+c.getName()+". Disconnecting");
+ if (lastPing != null && now - lastPing > TIMEOUT) {
+ LOGGER.info("Repeated ping attempts failed on " + c.getName() + ". Disconnecting");
c.disconnect(OfflineCause.create(Messages._ConnectionActivityMonitor_OfflineCause()));
} else {
// send a ping. if we receive a reply, it will be reflected in the next getLastHeard() call.
channel.callAsync(PING_COMMAND);
- if (lastPing==null)
- channel.setProperty(ConnectionActivityMonitor.class,now);
+ if (lastPing == null) {
+ channel.setProperty(ConnectionActivityMonitor.class, now);
+ }
}
} else {
// we are receiving data nicely
- channel.setProperty(ConnectionActivityMonitor.class,null);
+ channel.setProperty(ConnectionActivityMonitor.class, null);
}
}
}
@@ -77,31 +82,25 @@ public class ConnectionActivityMonitor extends AsyncPeriodicWork {
public long getRecurrencePeriod() {
return enabled ? FREQUENCY : TimeUnit2.DAYS.toMillis(30);
}
-
/**
* Time till initial ping
*/
- private static final long TIME_TILL_PING = Long.getLong(ConnectionActivityMonitor.class.getName()+".timeToPing",TimeUnit2.MINUTES.toMillis(3));
-
- private static final long FREQUENCY = Long.getLong(ConnectionActivityMonitor.class.getName()+".frequency",TimeUnit2.SECONDS.toMillis(10));
-
+ private static final long TIME_TILL_PING = Long.getLong(ConnectionActivityMonitor.class.getName() + ".timeToPing", TimeUnit2.MINUTES.toMillis(3));
+ private static final long FREQUENCY = Long.getLong(ConnectionActivityMonitor.class.getName() + ".frequency", TimeUnit2.SECONDS.toMillis(10));
/**
* When do we abandon the effort and cut off?
*/
- private static final long TIMEOUT = Long.getLong(ConnectionActivityMonitor.class.getName()+".timeToPing",TimeUnit2.MINUTES.toMillis(4));
-
-
+ private static final long TIMEOUT = Long.getLong(ConnectionActivityMonitor.class.getName() + ".timeToPing", TimeUnit2.MINUTES.toMillis(4));
// disabled by default until proven in the production
- public boolean enabled = Boolean.getBoolean(ConnectionActivityMonitor.class.getName()+".enabled");
-
+ public boolean enabled = Boolean.getBoolean(ConnectionActivityMonitor.class.getName() + ".enabled");
private static final PingCommand PING_COMMAND = new PingCommand();
- private static final class PingCommand implements Callable<Void,RuntimeException> {
+
+ private static final class PingCommand implements Callable<Void, RuntimeException> {
+
public Void call() throws RuntimeException {
return null;
}
-
private static final long serialVersionUID = 1L;
}
-
private static final Logger LOGGER = Logger.getLogger(ConnectionActivityMonitor.class.getName());
}
diff --git a/hudson-core/src/main/java/hudson/slaves/DelegatingComputerLauncher.java b/hudson-core/src/main/java/hudson/slaves/DelegatingComputerLauncher.java
index fa36af4..71f1bb1 100644
--- a/hudson-core/src/main/java/hudson/slaves/DelegatingComputerLauncher.java
+++ b/hudson-core/src/main/java/hudson/slaves/DelegatingComputerLauncher.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -26,14 +26,15 @@ import java.util.List;
/**
* Convenient base implementation of {@link ComputerLauncher} that allows
- * subtypes to perform some initialization (typically something cloud/v12n related
- * to power up the machine), then to delegate to another {@link ComputerLauncher}
- * to connect.
+ * subtypes to perform some initialization (typically something cloud/v12n
+ * related to power up the machine), then to delegate to another
+ * {@link ComputerLauncher} to connect.
*
* @author Kohsuke Kawaguchi
* @since 1.382
*/
public abstract class DelegatingComputerLauncher extends ComputerLauncher {
+
protected ComputerLauncher launcher;
protected DelegatingComputerLauncher(ComputerLauncher launcher) {
@@ -60,18 +61,21 @@ public abstract class DelegatingComputerLauncher extends ComputerLauncher {
}
public static abstract class DescriptorImpl extends Descriptor<ComputerLauncher> {
+
/**
- * Returns the applicable nested computer launcher types.
- * The default implementation avoids all delegating descriptors, as that creates infinite recursion.
+ * Returns the applicable nested computer launcher types. The default
+ * implementation avoids all delegating descriptors, as that creates
+ * infinite recursion.
*/
public List<Descriptor<ComputerLauncher>> getApplicableDescriptors() {
List<Descriptor<ComputerLauncher>> r = new ArrayList<Descriptor<ComputerLauncher>>();
for (Descriptor<ComputerLauncher> d : Functions.getComputerLauncherDescriptors()) {
- if (DelegatingComputerLauncher.class.isInstance(d)) continue;
+ if (DelegatingComputerLauncher.class.isInstance(d)) {
+ continue;
+ }
r.add(d);
}
return r;
}
}
-
}
diff --git a/hudson-core/src/main/java/hudson/slaves/DumbSlave.java b/hudson-core/src/main/java/hudson/slaves/DumbSlave.java
index 5a236dc..09c9851 100644
--- a/hudson-core/src/main/java/hudson/slaves/DumbSlave.java
+++ b/hudson-core/src/main/java/hudson/slaves/DumbSlave.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Seiji Sogabe
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Seiji Sogabe
+ *
*
*******************************************************************************/
@@ -27,27 +27,29 @@ import java.util.List;
import org.kohsuke.stapler.DataBoundConstructor;
/**
- * Default {@link Slave} implementation for computers that do not belong to a higher level structure,
- * like grid or cloud.
+ * Default {@link Slave} implementation for computers that do not belong to a
+ * higher level structure, like grid or cloud.
*
* @author Kohsuke Kawaguchi
*/
public final class DumbSlave extends Slave {
+
/**
- * @deprecated as of 1.286.
- * Use {@link #DumbSlave(String, String, String, String, Mode, String, ComputerLauncher, RetentionStrategy, List)}
+ * @deprecated as of 1.286. Use
+ * {@link #DumbSlave(String, String, String, String, Mode, String, ComputerLauncher, RetentionStrategy, List)}
*/
public DumbSlave(String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy) throws FormException, IOException {
this(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, new ArrayList());
}
-
+
@DataBoundConstructor
public DumbSlave(String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws IOException, FormException {
- super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);
+ super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);
}
@Extension
public static final class DescriptorImpl extends SlaveDescriptor {
+
public String getDisplayName() {
return Messages.DumbSlave_displayName();
}
diff --git a/hudson-core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java b/hudson-core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java
index 0b58f45..bcd892a 100644
--- a/hudson-core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java
+++ b/hudson-core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Tom Huybrechts
- *
+ * Contributors:
+ *
+ * Tom Huybrechts
+ *
*
*******************************************************************************/
@@ -42,7 +42,7 @@ public class EnvironmentVariablesNodeProperty extends NodeProperty<Node> {
* Slave-specific environment variables
*/
private final EnvVars envVars;
-
+
@DataBoundConstructor
public EnvironmentVariablesNodeProperty(List<Entry> env) {
this.envVars = toMap(env);
@@ -51,24 +51,24 @@ public class EnvironmentVariablesNodeProperty extends NodeProperty<Node> {
public EnvironmentVariablesNodeProperty(Entry... env) {
this(Arrays.asList(env));
}
-
+
public EnvVars getEnvVars() {
- return envVars;
+ return envVars;
}
@Override
public Environment setUp(AbstractBuild build, Launcher launcher,
- BuildListener listener) throws IOException, InterruptedException {
- return Environment.create(envVars);
+ BuildListener listener) throws IOException, InterruptedException {
+ return Environment.create(envVars);
}
@Extension
public static class DescriptorImpl extends NodePropertyDescriptor {
@Override
- public String getDisplayName() {
- return Messages.EnvironmentVariablesNodeProperty_displayName();
- }
+ public String getDisplayName() {
+ return Messages.EnvironmentVariablesNodeProperty_displayName();
+ }
public String getHelpPage() {
// yes, I know this is a work around.
@@ -82,16 +82,17 @@ public class EnvironmentVariablesNodeProperty extends NodeProperty<Node> {
}
}
}
-
- public static class Entry {
+
+ public static class Entry {
//TODO: review and check whether we can do it private
- public String key, value;
- @DataBoundConstructor
- public Entry(String key, String value) {
- this.key = key;
- this.value = value;
- }
+ public String key, value;
+
+ @DataBoundConstructor
+ public Entry(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
public String getKey() {
return key;
@@ -101,13 +102,14 @@ public class EnvironmentVariablesNodeProperty extends NodeProperty<Node> {
return value;
}
}
-
- private static EnvVars toMap(List<Entry> entries) {
- EnvVars map = new EnvVars();
- if (entries!=null)
- for (Entry entry: entries)
- map.put(entry.key,entry.value);
- return map;
- }
+ private static EnvVars toMap(List<Entry> entries) {
+ EnvVars map = new EnvVars();
+ if (entries != null) {
+ for (Entry entry : entries) {
+ map.put(entry.key, entry.value);
+ }
+ }
+ return map;
+ }
}
diff --git a/hudson-core/src/main/java/hudson/slaves/EphemeralNode.java b/hudson-core/src/main/java/hudson/slaves/EphemeralNode.java
index b60b615..139c21c 100644
--- a/hudson-core/src/main/java/hudson/slaves/EphemeralNode.java
+++ b/hudson-core/src/main/java/hudson/slaves/EphemeralNode.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -24,6 +24,7 @@ import hudson.model.Node;
* @author Kohsuke Kawaguchi
*/
public interface EphemeralNode {
+
/**
* Type-safe cast.
*/
diff --git a/hudson-core/src/main/java/hudson/slaves/JNLPLauncher.java b/hudson-core/src/main/java/hudson/slaves/JNLPLauncher.java
index 7d43f27..66180d2 100644
--- a/hudson-core/src/main/java/hudson/slaves/JNLPLauncher.java
+++ b/hudson-core/src/main/java/hudson/slaves/JNLPLauncher.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Stephen Connolly
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Stephen Connolly
+ *
*
*******************************************************************************/
@@ -27,23 +27,22 @@ import org.kohsuke.stapler.DataBoundConstructor;
*
* @author Stephen Connolly
* @author Kohsuke Kawaguchi
-*/
+ */
public class JNLPLauncher extends ComputerLauncher {
+
/**
- * If the slave needs to tunnel the connection to the master,
- * specify the "host:port" here. This can include the special
- * syntax "host:" and ":port" to indicate the default host/port
- * shall be used.
+ * If the slave needs to tunnel the connection to the master, specify the
+ * "host:port" here. This can include the special syntax "host:" and ":port"
+ * to indicate the default host/port shall be used.
*
- * <p>
- * Null if no tunneling is necessary.
+ * <p> Null if no tunneling is necessary.
*
* @since 1.250
*/
public final String tunnel;
-
/**
* Additional JVM arguments. Can be null.
+ *
* @since 1.297
*/
public final String vmargs;
@@ -55,7 +54,7 @@ public class JNLPLauncher extends ComputerLauncher {
}
public JNLPLauncher() {
- this(null,null);
+ this(null, null);
}
@Override
@@ -67,12 +66,10 @@ public class JNLPLauncher extends ComputerLauncher {
public void launch(SlaveComputer computer, TaskListener listener) {
// do nothing as we cannot self start
}
-
@Extension
public static final Descriptor<ComputerLauncher> DESCRIPTOR = new Descriptor<ComputerLauncher>() {
public String getDisplayName() {
return Messages.JNLPLauncher_displayName();
}
};
-
}
diff --git a/hudson-core/src/main/java/hudson/slaves/NodeDescriptor.java b/hudson-core/src/main/java/hudson/slaves/NodeDescriptor.java
index d5f42a4..0ce8ef6 100644
--- a/hudson-core/src/main/java/hudson/slaves/NodeDescriptor.java
+++ b/hudson-core/src/main/java/hudson/slaves/NodeDescriptor.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -41,16 +41,16 @@ import javax.servlet.ServletException;
/**
* {@link Descriptor} for {@link Slave}.
*
- * <h2>Views</h2>
- * <p>
- * This object needs to have <tt>newInstanceDetail.jelly</tt> view, which shows up in
- * <tt>http://server/hudson/computers/new</tt> page as an explanation of this job type.
+ * <h2>Views</h2> <p> This object needs to have <tt>newInstanceDetail.jelly</tt>
+ * view, which shows up in <tt>http://server/hudson/computers/new</tt> page as
+ * an explanation of this job type.
*
* <h2>Other Implementation Notes</h2>
*
* @author Kohsuke Kawaguchi
*/
public abstract class NodeDescriptor extends Descriptor<Node> {
+
protected NodeDescriptor(Class<? extends Node> clazz) {
super(clazz);
}
@@ -61,27 +61,29 @@ public abstract class NodeDescriptor extends Descriptor<Node> {
/**
* Can the administrator create this type of nodes from UI?
*
- * Return false if it only makes sense for programs to create it, not through the "new node" UI.
+ * Return false if it only makes sense for programs to create it, not
+ * through the "new node" UI.
*/
public boolean isInstantiable() {
return true;
}
public final String newInstanceDetailPage() {
- return '/'+clazz.getName().replace('.','/').replace('$','/')+"/newInstanceDetail.jelly";
+ return '/' + clazz.getName().replace('.', '/').replace('$', '/') + "/newInstanceDetail.jelly";
}
/**
- * Handles the form submission from the "/computer/new" page, which is the first form for creating a new node.
- * By default, it shows the configuration page for entering details, but subtypes can override this differently.
+ * Handles the form submission from the "/computer/new" page, which is the
+ * first form for creating a new node. By default, it shows the
+ * configuration page for entering details, but subtypes can override this
+ * differently.
*
- * @param name
- * Name of the new node.
+ * @param name Name of the new node.
*/
public void handleNewNodePage(ComputerSet computerSet, String name, StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
computerSet.checkName(name);
req.setAttribute("descriptor", this);
- req.getView(computerSet,"_new.jelly").forward(req,rsp);
+ req.getView(computerSet, "_new.jelly").forward(req, rsp);
}
@Override
@@ -89,10 +91,11 @@ public abstract class NodeDescriptor extends Descriptor<Node> {
return getViewPage(clazz, "configure-entries.jelly");
}
- public FormValidation doCheckName(@QueryParameter String value ) {
+ public FormValidation doCheckName(@QueryParameter String value) {
String name = Util.fixEmptyAndTrim(value);
- if(name==null)
+ if (name == null) {
return FormValidation.error(Messages.NodeDescripter_CheckName_Mandatory());
+ }
try {
Hudson.checkGoodName(name);
} catch (Failure f) {
@@ -104,22 +107,24 @@ public abstract class NodeDescriptor extends Descriptor<Node> {
/**
* Returns all the registered {@link NodeDescriptor} descriptors.
*/
- public static DescriptorExtensionList<Node,NodeDescriptor> all() {
- return Hudson.getInstance().<Node,NodeDescriptor>getDescriptorList(Node.class);
+ public static DescriptorExtensionList<Node, NodeDescriptor> all() {
+ return Hudson.getInstance().<Node, NodeDescriptor>getDescriptorList(Node.class);
}
-
/**
* All the registered instances.
- * @deprecated as of 1.286
- * Use {@link #all()} for read access, and {@link Extension} for registration.
+ *
+ * @deprecated as of 1.286 Use {@link #all()} for read access, and
+ * {@link Extension} for registration.
*/
public static final DescriptorList<Node> ALL = new DescriptorList<Node>(Node.class);
public static List<NodeDescriptor> allInstantiable() {
List<NodeDescriptor> r = new ArrayList<NodeDescriptor>();
- for (NodeDescriptor d : all())
- if(d.isInstantiable())
+ for (NodeDescriptor d : all()) {
+ if (d.isInstantiable()) {
r.add(d);
+ }
+ }
return r;
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/NodeList.java b/hudson-core/src/main/java/hudson/slaves/NodeList.java
index 0cb4045..f9eb640 100644
--- a/hudson-core/src/main/java/hudson/slaves/NodeList.java
+++ b/hudson-core/src/main/java/hudson/slaves/NodeList.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -31,12 +31,13 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
- * {@link CopyOnWriteArrayList} for {@link Node} that has special serialization semantics
- * of not serializing {@link EphemeralNode}s.
+ * {@link CopyOnWriteArrayList} for {@link Node} that has special serialization
+ * semantics of not serializing {@link EphemeralNode}s.
*
* @author Kohsuke Kawaguchi
*/
public final class NodeList extends CopyOnWriteArrayList<Node> {
+
public NodeList() {
}
@@ -54,20 +55,22 @@ public final class NodeList extends CopyOnWriteArrayList<Node> {
* Serializaion form is compatible with plain {@link List}.
*/
public static final class ConverterImpl extends RobustCollectionConverter {
+
public ConverterImpl(XStream xstream) {
super(xstream);
}
@Override
public boolean canConvert(Class type) {
- return type==NodeList.class;
+ return type == NodeList.class;
}
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
for (Node o : (NodeList) source) {
- if(o instanceof EphemeralNode)
+ if (o instanceof EphemeralNode) {
continue; // skip
+ }
writeItem(o, context, writer);
}
}
@@ -79,7 +82,7 @@ public final class NodeList extends CopyOnWriteArrayList<Node> {
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
- return new NodeList((List<Node>)super.unmarshal(reader, context));
+ return new NodeList((List<Node>) super.unmarshal(reader, context));
}
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/NodeProperty.java b/hudson-core/src/main/java/hudson/slaves/NodeProperty.java
index 25228c1..f222b10 100644
--- a/hudson-core/src/main/java/hudson/slaves/NodeProperty.java
+++ b/hudson-core/src/main/java/hudson/slaves/NodeProperty.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Tom Huybrechts
- *
+ * Contributors:
+ *
+ * Tom Huybrechts
+ *
*
*******************************************************************************/
@@ -35,24 +35,19 @@ import java.util.List;
/**
* Extensible property of {@link Node}.
*
- * <p>
- * Plugins can contribute this extension point to add additional data or UI actions to {@link Node}.
- * {@link NodeProperty}s show up in the configuration screen of a node, and they are persisted with the {@link Node} object.
+ * <p> Plugins can contribute this extension point to add additional data or UI
+ * actions to {@link Node}. {@link NodeProperty}s show up in the configuration
+ * screen of a node, and they are persisted with the {@link Node} object.
*
*
- * <h2>Views</h2>
- * <dl>
- * <dt>config.jelly</dt>
- * <dd>Added to the configuration page of the node.
- * <dt>global.jelly</dt>
- * <dd>Added to the system configuration page.
- * <dt>summary.jelly (optional)</dt>
- * <dd>Added to the index page of the {@link hudson.model.Computer} associated with the node
- * </dl>
+ * <h2>Views</h2> <dl> <dt>config.jelly</dt> <dd>Added to the configuration page
+ * of the node. <dt>global.jelly</dt> <dd>Added to the system configuration
+ * page. <dt>summary.jelly (optional)</dt> <dd>Added to the index page of the
+ * {@link hudson.model.Computer} associated with the node </dl>
*
- * @param <N>
- * {@link NodeProperty} can choose to only work with a certain subtype of {@link Node}, and this 'N'
- * represents that type. Also see {@link NodePropertyDescriptor#isApplicable(Class)}.
+ * @param <N> {@link NodeProperty} can choose to only work with a certain
+ * subtype of {@link Node}, and this 'N' represents that type. Also see
+ * {@link NodePropertyDescriptor#isApplicable(Class)}.
*
* @since 1.286
*/
@@ -60,17 +55,20 @@ public abstract class NodeProperty<N extends Node> implements Describable<NodePr
protected transient N node;
- protected void setNode(N node) { this.node = node; }
+ protected void setNode(N node) {
+ this.node = node;
+ }
public NodePropertyDescriptor getDescriptor() {
- return (NodePropertyDescriptor)Hudson.getInstance().getDescriptorOrDie(getClass());
+ return (NodePropertyDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass());
}
/**
* Called by the {@link Node} to help determine whether or not it should
* take the given task. Individual properties can return a non-null value
* here if there is some reason the given task should not be run on its
- * associated node. By default, this method returns <code>null</code>.
+ * associated node. By default, this method returns
+ * <code>null</code>.
*
* @since 1.360
*/
@@ -79,34 +77,32 @@ public abstract class NodeProperty<N extends Node> implements Describable<NodePr
}
/**
- * Runs before the {@link SCM#checkout(AbstractBuild, Launcher, FilePath, BuildListener, File)} runs, and performs a set up.
- * Can contribute additional properties to the environment.
- *
- * @param build
- * The build in progress for which an {@link Environment} object is created.
- * Never null.
- * @param launcher
- * This launcher can be used to launch processes for this build.
- * If the build runs remotely, launcher will also run a job on that remote machine.
- * Never null.
- * @param listener
- * Can be used to send any message.
- * @return
- * non-null if the build can continue, null if there was an error
- * and the build needs to be aborted.
- * @throws IOException
- * terminates the build abnormally. Hudson will handle the exception
- * and reports a nice error message.
+ * Runs before the
+ * {@link SCM#checkout(AbstractBuild, Launcher, FilePath, BuildListener, File)}
+ * runs, and performs a set up. Can contribute additional properties to the
+ * environment.
+ *
+ * @param build The build in progress for which an {@link Environment}
+ * object is created. Never null.
+ * @param launcher This launcher can be used to launch processes for this
+ * build. If the build runs remotely, launcher will also run a job on that
+ * remote machine. Never null.
+ * @param listener Can be used to send any message.
+ * @return non-null if the build can continue, null if there was an error
+ * and the build needs to be aborted.
+ * @throws IOException terminates the build abnormally. Hudson will handle
+ * the exception and reports a nice error message.
*/
- public Environment setUp( AbstractBuild build, Launcher launcher, BuildListener listener ) throws IOException, InterruptedException {
- return new Environment() {};
+ public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
+ return new Environment() {
+ };
}
/**
* Lists up all the registered {@link NodeDescriptor}s in the system.
*/
- public static DescriptorExtensionList<NodeProperty<?>,NodePropertyDescriptor> all() {
- return (DescriptorExtensionList)Hudson.getInstance().getDescriptorList(NodeProperty.class);
+ public static DescriptorExtensionList<NodeProperty<?>, NodePropertyDescriptor> all() {
+ return (DescriptorExtensionList) Hudson.getInstance().getDescriptorList(NodeProperty.class);
}
/**
@@ -114,6 +110,6 @@ public abstract class NodeProperty<N extends Node> implements Describable<NodePr
* given project.
*/
public static List<NodePropertyDescriptor> for_(Node node) {
- return NodePropertyDescriptor.for_(all(),node);
+ return NodePropertyDescriptor.for_(all(), node);
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/NodePropertyDescriptor.java b/hudson-core/src/main/java/hudson/slaves/NodePropertyDescriptor.java
index 8371509..39a4692 100644
--- a/hudson-core/src/main/java/hudson/slaves/NodePropertyDescriptor.java
+++ b/hudson-core/src/main/java/hudson/slaves/NodePropertyDescriptor.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Tom Huybrechts
- *
+ * Contributors:
+ *
+ * Tom Huybrechts
+ *
*
*******************************************************************************/
@@ -23,13 +23,14 @@ import hudson.tools.PropertyDescriptor;
/**
* Descriptor for {@link NodeProperty}.
*
- * <p>
- * Put {@link Extension} on your descriptor implementation to have it auto-registered.
+ * <p> Put {@link Extension} on your descriptor implementation to have it
+ * auto-registered.
*
* @since 1.286
* @see NodeProperty
*/
-public abstract class NodePropertyDescriptor extends PropertyDescriptor<NodeProperty<?>,Node> {
+public abstract class NodePropertyDescriptor extends PropertyDescriptor<NodeProperty<?>, Node> {
+
protected NodePropertyDescriptor(Class<? extends NodeProperty<?>> clazz) {
super(clazz);
}
diff --git a/hudson-core/src/main/java/hudson/slaves/NodeProvisioner.java b/hudson-core/src/main/java/hudson/slaves/NodeProvisioner.java
index c34b0b1..3260f5d 100644
--- a/hudson-core/src/main/java/hudson/slaves/NodeProvisioner.java
+++ b/hudson-core/src/main/java/hudson/slaves/NodeProvisioner.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
*
* Kohsuke Kawaguchi, Winston Prakash
- *
+ *
*
*******************************************************************************/
@@ -38,20 +38,24 @@ import org.eclipse.hudson.graph.MultiStageTimeSeries;
import org.eclipse.hudson.graph.MultiStageTimeSeries.TimeScale;
/**
- * Uses the {@link LoadStatistics} and determines when we need to allocate
- * new {@link Node}s through {@link Cloud}.
+ * Uses the {@link LoadStatistics} and determines when we need to allocate new
+ * {@link Node}s through {@link Cloud}.
*
* @author Kohsuke Kawaguchi
*/
public class NodeProvisioner {
+
/**
* The node addition activity in progress.
*/
public static final class PlannedNode {
+
/**
- * Used to display this planned node to UI. Should ideally include the identifier unique to the node
- * being provisioned (like the instance ID), but if such an identifier doesn't readily exist, this
- * can be just a name of the template being provisioned (like the machine image ID.)
+ * Used to display this planned node to UI. Should ideally include the
+ * identifier unique to the node being provisioned (like the instance
+ * ID), but if such an identifier doesn't readily exist, this can be
+ * just a name of the template being provisioned (like the machine image
+ * ID.)
*/
//TODO: review and check whether we can do it private
public final String displayName;
@@ -71,36 +75,35 @@ public class NodeProvisioner {
}
public PlannedNode(String displayName, Future<Node> future, int numExecutors) {
- if(displayName==null || future==null || numExecutors<1) throw new IllegalArgumentException();
+ if (displayName == null || future == null || numExecutors < 1) {
+ throw new IllegalArgumentException();
+ }
this.displayName = displayName;
this.future = future;
this.numExecutors = numExecutors;
}
}
-
/**
* Load for the label.
*/
private final LoadStatistics stat;
-
/**
- * For which label are we working?
- * Null if this {@link NodeProvisioner} is working for the entire Hudson,
- * for jobs that are unassigned to any particular node.
+ * For which label are we working? Null if this {@link NodeProvisioner} is
+ * working for the entire Hudson, for jobs that are unassigned to any
+ * particular node.
*/
private final Label label;
-
private List<PlannedNode> pendingLaunches = new ArrayList<PlannedNode>();
-
/**
- * Exponential moving average of the "planned capacity" over time, which is the number of
- * additional executors being brought up.
+ * Exponential moving average of the "planned capacity" over time, which is
+ * the number of additional executors being brought up.
*
- * This is used to filter out high-frequency components from the planned capacity, so that
- * the comparison with other low-frequency only variables won't leave spikes.
+ * This is used to filter out high-frequency components from the planned
+ * capacity, so that the comparison with other low-frequency only variables
+ * won't leave spikes.
*/
private final MultiStageTimeSeries plannedCapacitiesEMA =
- new MultiStageTimeSeries(Messages._NodeProvisioner_EmptyString(),Color.WHITE,0,DECAY);
+ new MultiStageTimeSeries(Messages._NodeProvisioner_EmptyString(), Color.WHITE, 0, DECAY);
public NodeProvisioner(Label label, LoadStatistics loadStatistics) {
this.label = label;
@@ -108,8 +111,8 @@ public class NodeProvisioner {
}
/**
- * Periodically invoked to keep track of the load.
- * Launches additional nodes if necessary.
+ * Periodically invoked to keep track of the load. Launches additional nodes
+ * if necessary.
*/
private void update() {
Hudson hudson = Hudson.getInstance();
@@ -118,84 +121,86 @@ public class NodeProvisioner {
float plannedCapacity = 0;
for (Iterator<PlannedNode> itr = pendingLaunches.iterator(); itr.hasNext();) {
PlannedNode f = itr.next();
- if(f.future.isDone()) {
+ if (f.future.isDone()) {
try {
hudson.addNode(f.future.get());
- LOGGER.info(f.displayName+" provisioning successfully completed. We have now "+hudson.getComputers().length+" computer(s)");
+ LOGGER.info(f.displayName + " provisioning successfully completed. We have now " + hudson.getComputers().length + " computer(s)");
} catch (InterruptedException e) {
throw new AssertionError(e); // since we confirmed that the future is already done
} catch (ExecutionException e) {
- LOGGER.log(Level.WARNING, "Provisioned slave "+f.displayName+" failed to launch",e.getCause());
+ LOGGER.log(Level.WARNING, "Provisioned slave " + f.displayName + " failed to launch", e.getCause());
} catch (IOException e) {
- LOGGER.log(Level.WARNING, "Provisioned slave "+f.displayName+" failed to launch",e);
+ LOGGER.log(Level.WARNING, "Provisioned slave " + f.displayName + " failed to launch", e);
}
itr.remove();
- } else
+ } else {
plannedCapacity += f.numExecutors;
+ }
}
plannedCapacitiesEMA.update(plannedCapacity);
/*
- Here we determine how many additional slaves we need to keep up with the load (if at all),
- which involves a simple math.
+ Here we determine how many additional slaves we need to keep up with the load (if at all),
+ which involves a simple math.
- Broadly speaking, first we check that all the executors are fully utilized before attempting
- to start any new slave (this also helps to ignore the temporary gap between different numbers,
- as changes in them are not necessarily synchronized --- for example, there's a time lag between
- when a slave launches (thus bringing the planned capacity down) and the time when its executors
- pick up builds (thus bringing the queue length down.)
+ Broadly speaking, first we check that all the executors are fully utilized before attempting
+ to start any new slave (this also helps to ignore the temporary gap between different numbers,
+ as changes in them are not necessarily synchronized --- for example, there's a time lag between
+ when a slave launches (thus bringing the planned capacity down) and the time when its executors
+ pick up builds (thus bringing the queue length down.)
- Once we confirm that, we compare the # of buildable items against the additional slaves
- that are being brought online. If we have more jobs than our executors can handle, we'll launch a new slave.
+ Once we confirm that, we compare the # of buildable items against the additional slaves
+ that are being brought online. If we have more jobs than our executors can handle, we'll launch a new slave.
- So this computation involves three stats:
+ So this computation involves three stats:
- 1. # of idle executors
- 2. # of jobs that are starving for executors
- 3. # of additional slaves being provisioned (planned capacities.)
+ 1. # of idle executors
+ 2. # of jobs that are starving for executors
+ 3. # of additional slaves being provisioned (planned capacities.)
- To ignore a temporary surge/drop, we make conservative estimates on each one of them. That is,
- we take the current snapshot value, and we take the current exponential moving average (EMA) value,
- and use the max/min.
+ To ignore a temporary surge/drop, we make conservative estimates on each one of them. That is,
+ we take the current snapshot value, and we take the current exponential moving average (EMA) value,
+ and use the max/min.
- This is another measure to be robust against temporary surge/drop in those indicators, and helps
- us avoid over-reacting to stats.
+ This is another measure to be robust against temporary surge/drop in those indicators, and helps
+ us avoid over-reacting to stats.
- If we only use the snapshot value or EMA value, tests confirmed that the gap creates phantom
- excessive loads and Hudson ends up firing excessive capacities. In a static system, over the time
- EMA and the snapshot value becomes the same, so this makes sure that in a long run this conservative
- estimate won't create a starvation.
+ If we only use the snapshot value or EMA value, tests confirmed that the gap creates phantom
+ excessive loads and Hudson ends up firing excessive capacities. In a static system, over the time
+ EMA and the snapshot value becomes the same, so this makes sure that in a long run this conservative
+ estimate won't create a starvation.
*/
int idleSnapshot = stat.computeIdleExecutors();
int totalSnapshot = stat.computeTotalExecutors();
float idle = Math.max(stat.getLatestIdleExecutors(TIME_SCALE), idleSnapshot);
- if(idle<MARGIN) {
+ if (idle < MARGIN) {
// make sure the system is fully utilized before attempting any new launch.
// this is the amount of work left to be done
float qlen = Math.min(stat.queueLength.getLatest(TIME_SCALE), stat.computeQueueLength());
// ... and this is the additional executors we've already provisioned.
- plannedCapacity = Math.max(plannedCapacitiesEMA.getLatest(TIME_SCALE),plannedCapacity);
+ plannedCapacity = Math.max(plannedCapacitiesEMA.getLatest(TIME_SCALE), plannedCapacity);
float excessWorkload = qlen - plannedCapacity;
float m = calcThresholdMargin(totalSnapshot);
- if(excessWorkload>1-m) {// and there's more work to do...
- LOGGER.fine("Excess workload "+excessWorkload+" detected. (planned capacity="+plannedCapacity+",Qlen="+qlen+",idle="+idle+"&"+idleSnapshot+",total="+totalSnapshot+"m,="+m+")");
- for( Cloud c : hudson.clouds ) {
- if(excessWorkload<0) break; // enough slaves allocated
-
+ if (excessWorkload > 1 - m) {// and there's more work to do...
+ LOGGER.fine("Excess workload " + excessWorkload + " detected. (planned capacity=" + plannedCapacity + ",Qlen=" + qlen + ",idle=" + idle + "&" + idleSnapshot + ",total=" + totalSnapshot + "m,=" + m + ")");
+ for (Cloud c : hudson.clouds) {
+ if (excessWorkload < 0) {
+ break; // enough slaves allocated
+ }
// provisioning a new node should be conservative --- for example if exceeWorkload is 1.4,
// we don't want to allocate two nodes but just one.
// OTOH, because of the exponential decay, even when we need one slave, excess workload is always
// something like 0.95, in which case we want to allocate one node.
// so the threshold here is 1-MARGIN, and hence floor(excessWorkload+MARGIN) is needed to handle this.
- Collection<PlannedNode> additionalCapacities = c.provision(label, (int)Math.round(Math.floor(excessWorkload+m)));
+ Collection<PlannedNode> additionalCapacities = c.provision(label, (int) Math.round(Math.floor(excessWorkload + m)));
for (PlannedNode ac : additionalCapacities) {
excessWorkload -= ac.numExecutors;
- LOGGER.info("Started provisioning "+ac.displayName+" from "+c.name+" with "+ac.numExecutors+" executors. Remaining excess workload:"+excessWorkload);
+ LOGGER.info("Started provisioning " + ac.displayName + " from " + c.name + " with " + ac.numExecutors + " executors. Remaining excess workload:" + excessWorkload);
}
pendingLaunches.addAll(additionalCapacities);
}
@@ -206,27 +211,28 @@ public class NodeProvisioner {
/**
* Computes the threshold for triggering an allocation.
*
- * <p>
- * Because the excessive workload value is EMA, even when the snapshot value of the excessive
- * workload is 1, the value never really gets to 1. So we need to introduce a notion of the margin M,
- * where we provision a new node if the EMA of the excessive workload goes beyond 1-M (where M is a small value
- * in the (0,1) range.)
+ * <p> Because the excessive workload value is EMA, even when the snapshot
+ * value of the excessive workload is 1, the value never really gets to 1.
+ * So we need to introduce a notion of the margin M, where we provision a
+ * new node if the EMA of the excessive workload goes beyond 1-M (where M is
+ * a small value in the (0,1) range.)
*
- * <p>
- * M effectively controls how long Hudson waits until allocating a new node, in the face of workload.
- * This delay is justified for absorbing temporary ups and downs, and can be interpreted as Hudson
- * holding off provisioning in the hope that one of the existing nodes will become available.
+ * <p> M effectively controls how long Hudson waits until allocating a new
+ * node, in the face of workload. This delay is justified for absorbing
+ * temporary ups and downs, and can be interpreted as Hudson holding off
+ * provisioning in the hope that one of the existing nodes will become
+ * available.
*
- * <p>
- * M can be a constant value, but there's a benefit in adjusting M based on the total current capacity,
- * based on the above justification; that is, if there's no existing capacity at all, holding off
- * an allocation doesn't make much sense, as there won't be any executors available no matter how long we wait.
- * On the other hand, if we have a large number of existing executors, chances are good that some
- * of them become available &mdash; the chance gets better and better as the number of current total
- * capacity increases.
+ * <p> M can be a constant value, but there's a benefit in adjusting M based
+ * on the total current capacity, based on the above justification; that is,
+ * if there's no existing capacity at all, holding off an allocation doesn't
+ * make much sense, as there won't be any executors available no matter how
+ * long we wait. On the other hand, if we have a large number of existing
+ * executors, chances are good that some of them become available &mdash;
+ * the chance gets better and better as the number of current total capacity
+ * increases.
*
- * <p>
- * Therefore, we compute the threshold margin as follows:
+ * <p> Therefore, we compute the threshold margin as follows:
*
* <pre>
* M(t) = M* + (M0 - M*) alpha ^ t
@@ -234,17 +240,16 @@ public class NodeProvisioner {
*
* ... where:
*
- * <ul>
- * <li>M* is the ultimate margin value that M(t) converges to with t->inf,
- * <li>M0 is the value of M(0), the initial value.
- * <li>alpha is the decay factor in (0,1). M(t) converges to M* faster if alpha is smaller.
+ * <ul> <li>M* is the ultimate margin value that M(t) converges to with
+ * t->inf, <li>M0 is the value of M(0), the initial value. <li>alpha is the
+ * decay factor in (0,1). M(t) converges to M* faster if alpha is smaller.
* </ul>
*/
private float calcThresholdMargin(int totalSnapshot) {
float f = (float) (MARGIN + (MARGIN0 - MARGIN) * Math.pow(MARGIN_DECAY, totalSnapshot));
// defensively ensure that the threshold margin is in (0,1)
- f = Math.max(f,0);
- f = Math.min(f,1);
+ f = Math.max(f, 0);
+ f = Math.min(f, 1);
return f;
}
@@ -253,13 +258,14 @@ public class NodeProvisioner {
*/
@Extension
public static class NodeProvisionerInvoker extends PeriodicWork {
+
/**
* Give some initial warm up time so that statically connected slaves
* can be brought online before we start allocating more.
*/
- public static int INITIALDELAY = Integer.getInteger(NodeProvisioner.class.getName()+".initialDelay",LoadStatistics.CLOCK*10);
- public static int RECURRENCEPERIOD = Integer.getInteger(NodeProvisioner.class.getName()+".recurrencePeriod",LoadStatistics.CLOCK);
-
+ public static int INITIALDELAY = Integer.getInteger(NodeProvisioner.class.getName() + ".initialDelay", LoadStatistics.CLOCK * 10);
+ public static int RECURRENCEPERIOD = Integer.getInteger(NodeProvisioner.class.getName() + ".recurrencePeriod", LoadStatistics.CLOCK);
+
@Override
public long getInitialDelay() {
return INITIALDELAY;
@@ -273,27 +279,27 @@ public class NodeProvisioner {
protected void doRun() {
Hudson h = Hudson.getInstance();
h.overallNodeProvisioner.update();
- for( Label l : h.getLabels() )
+ for (Label l : h.getLabels()) {
l.nodeProvisioner.update();
+ }
}
}
-
private static final Logger LOGGER = Logger.getLogger(NodeProvisioner.class.getName());
- private static final float MARGIN = Integer.getInteger(NodeProvisioner.class.getName()+".MARGIN",10)/100f;
- private static final float MARGIN0 = Math.max(MARGIN, getFloatSystemProperty(NodeProvisioner.class.getName()+".MARGIN0",0.5f));
- private static final float MARGIN_DECAY = getFloatSystemProperty(NodeProvisioner.class.getName()+".MARGIN_DECAY",0.5f);
-
+ private static final float MARGIN = Integer.getInteger(NodeProvisioner.class.getName() + ".MARGIN", 10) / 100f;
+ private static final float MARGIN0 = Math.max(MARGIN, getFloatSystemProperty(NodeProvisioner.class.getName() + ".MARGIN0", 0.5f));
+ private static final float MARGIN_DECAY = getFloatSystemProperty(NodeProvisioner.class.getName() + ".MARGIN_DECAY", 0.5f);
// TODO: picker should be selectable
private static final TimeScale TIME_SCALE = TimeScale.SEC10;
private static float getFloatSystemProperty(String propName, float defaultValue) {
String v = System.getProperty(propName);
- if (v!=null)
+ if (v != null) {
try {
return Float.parseFloat(v);
} catch (NumberFormatException e) {
- LOGGER.warning("Failed to parse a float value from system property "+propName+". value was "+v);
+ LOGGER.warning("Failed to parse a float value from system property " + propName + ". value was " + v);
}
+ }
return defaultValue;
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/NodeSpecific.java b/hudson-core/src/main/java/hudson/slaves/NodeSpecific.java
index 084fff2..0b6b6bb 100644
--- a/hudson-core/src/main/java/hudson/slaves/NodeSpecific.java
+++ b/hudson-core/src/main/java/hudson/slaves/NodeSpecific.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Tom Huybrechts
- *
+ * Contributors:
+ *
+ * Tom Huybrechts
+ *
*
*******************************************************************************/
@@ -29,10 +29,10 @@ import java.io.IOException;
* @author huybrechts
* @since 1.286
* @see EnvironmentSpecific
- * @param <T>
- * Concrete type that represents the thing that can be adapted.
+ * @param <T> Concrete type that represents the thing that can be adapted.
*/
public interface NodeSpecific<T extends NodeSpecific<T>> {
+
/**
* Returns a specialized copy of T for functioning in the given node.
*/
diff --git a/hudson-core/src/main/java/hudson/slaves/OfflineCause.java b/hudson-core/src/main/java/hudson/slaves/OfflineCause.java
index aed40ec..803bf48 100644
--- a/hudson-core/src/main/java/hudson/slaves/OfflineCause.java
+++ b/hudson-core/src/main/java/hudson/slaves/OfflineCause.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -22,25 +22,26 @@ import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;
/**
- * Represents a cause that puts a {@linkplain Computer#isOffline() computer offline}.
+ * Represents a cause that puts a
+ * {@linkplain Computer#isOffline() computer offline}.
*
- * <h2>Views</h2>
- * <p>
- * {@link OfflineCause} must have <tt>cause.jelly</tt> that renders a cause
- * into HTML. This is used to tell users why the node is put offline.
- * This view should render a block element like DIV.
+ * <h2>Views</h2> <p> {@link OfflineCause} must have <tt>cause.jelly</tt> that
+ * renders a cause into HTML. This is used to tell users why the node is put
+ * offline. This view should render a block element like DIV.
*
* @author Kohsuke Kawaguchi
* @since 1.320
*/
@ExportedBean
public abstract class OfflineCause {
+
/**
- * {@link OfflineCause} that renders a static text,
- * but without any further UI.
+ * {@link OfflineCause} that renders a static text, but without any further
+ * UI.
*/
public static class SimpleOfflineCause extends OfflineCause {
//TODO: review and check whether we can do it private
+
public final Localizable description;
public Localizable getDescription() {
@@ -51,14 +52,17 @@ public abstract class OfflineCause {
this.description = description;
}
- @Exported(name="description") @Override
+ @Exported(name = "description")
+ @Override
public String toString() {
return description.toString();
}
}
public static OfflineCause create(Localizable d) {
- if (d==null) return null;
+ if (d == null) {
+ return null;
+ }
return new SimpleOfflineCause(d);
}
@@ -67,6 +71,7 @@ public abstract class OfflineCause {
*/
public static class ChannelTermination extends OfflineCause {
//TODO: review and check whether we can do it private
+
@Exported
public final Exception cause;
@@ -87,6 +92,7 @@ public abstract class OfflineCause {
* Caused by failure to launch.
*/
public static class LaunchFailed extends OfflineCause {
+
@Override
public String toString() {
return Messages.OfflineCause_LaunchFailed();
@@ -95,6 +101,7 @@ public abstract class OfflineCause {
public static class ByCLI extends OfflineCause {
//TODO: review and check whether we can do it private
+
@Exported
public final String message;
@@ -108,8 +115,9 @@ public abstract class OfflineCause {
@Override
public String toString() {
- if (message==null)
+ if (message == null) {
return Messages.OfflineCause_DisconnectedFromCLI();
+ }
return message;
}
}
diff --git a/hudson-core/src/main/java/hudson/slaves/RetentionStrategy.java b/hudson-core/src/main/java/hudson/slaves/RetentionStrategy.java
index 06299bf..907a260 100644
--- a/hudson-core/src/main/java/hudson/slaves/RetentionStrategy.java
+++ b/hudson-core/src/main/java/hudson/slaves/RetentionStrategy.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Stephen Connolly
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Stephen Connolly
+ *
*
*******************************************************************************/
@@ -28,7 +28,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Controls when to take {@link Computer} offline, bring it back online, or even to destroy it.
+ * Controls when to take {@link Computer} offline, bring it back online, or even
+ * to destroy it.
*
* @author Stephen Connolly
* @author Kohsuke Kawaguchi
@@ -36,33 +37,39 @@ import java.util.logging.Logger;
public abstract class RetentionStrategy<T extends Computer> extends AbstractDescribableImpl<RetentionStrategy<?>> implements ExtensionPoint {
/**
- * This method will be called periodically to allow this strategy to decide what to do with it's owning slave.
+ * This method will be called periodically to allow this strategy to decide
+ * what to do with it's owning slave.
*
- * @param c {@link Computer} for which this strategy is assigned. This computer may be online or offline.
- * This object also exposes a bunch of properties that the callee can use to decide what action to take.
- * @return The number of minutes after which the strategy would like to be checked again. The strategy may be
- * rechecked earlier or later that this!
+ * @param c {@link Computer} for which this strategy is assigned. This
+ * computer may be online or offline. This object also exposes a bunch of
+ * properties that the callee can use to decide what action to take.
+ * @return The number of minutes after which the strategy would like to be
+ * checked again. The strategy may be rechecked earlier or later that this!
*/
public abstract long check(T c);
/**
- * This method is called to determine whether manual launching of the slave is allowed at this point in time.
- * @param c {@link Computer} for which this strategy is assigned. This computer may be online or offline.
- * This object also exposes a bunch of properties that the callee can use to decide if manual launching is
+ * This method is called to determine whether manual launching of the slave
+ * is allowed at this point in time.
+ *
+ * @param c {@link Computer} for which this strategy is assigned. This
+ * computer may be online or offline. This object also exposes a bunch of
+ * properties that the callee can use to decide if manual launching is
* allowed at this time.
- * @return {@code true} if manual launching of the slave is allowed at this point in time.
+ * @return {@code true} if manual launching of the slave is allowed at this
+ * point in time.
*/
public boolean isManualLaunchAllowed(T c) {
return true;
}
/**
- * Called when a new {@link Computer} object is introduced (such as when Hudson started, or when
- * a new slave is added.)
+ * Called when a new {@link Computer} object is introduced (such as when
+ * Hudson started, or when a new slave is added.)
*
- * <p>
- * The default implementation of this method delegates to {@link #check(Computer)},
- * but this allows {@link RetentionStrategy} to distinguish the first time invocation from the rest.
+ * <p> The default implementation of this method delegates to
+ * {@link #check(Computer)}, but this allows {@link RetentionStrategy} to
+ * distinguish the first time invocation from the rest.
*
* @since 1.275
*/
@@ -73,17 +80,16 @@ public abstract class RetentionStrategy<T extends Computer> extends AbstractDesc
/**
* Returns all the registered {@link RetentionStrategy} descriptors.
*/
- public static DescriptorExtensionList<RetentionStrategy<?>,Descriptor<RetentionStrategy<?>>> all() {
- return (DescriptorExtensionList)Hudson.getInstance().getDescriptorList(RetentionStrategy.class);
+ public static DescriptorExtensionList<RetentionStrategy<?>, Descriptor<RetentionStrategy<?>>> all() {
+ return (DescriptorExtensionList) Hudson.getInstance().getDescriptorList(RetentionStrategy.class);
}
-
/**
* All registered {@link RetentionStrategy} implementations.
- * @deprecated as of 1.286
- * Use {@link #all()} for read access, and {@link Extension} for registration.
+ *
+ * @deprecated as of 1.286 Use {@link #all()} for read access, and
+ * {@link Extension} for registration.
*/
- public static final DescriptorList<RetentionStrategy<?>> LIST = new DescriptorList<RetentionStrategy<?>>((Class)RetentionStrategy.class);
-
+ public static final DescriptorList<RetentionStrategy<?>> LIST = new DescriptorList<RetentionStrategy<?>>((Class) RetentionStrategy.class);
/**
* Dummy instance that doesn't do any attempt to retention.
*/
@@ -101,25 +107,27 @@ public abstract class RetentionStrategy<T extends Computer> extends AbstractDesc
public Descriptor<RetentionStrategy<?>> getDescriptor() {
return DESCRIPTOR;
}
-
private final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
class DescriptorImpl extends Descriptor<RetentionStrategy<?>> {
+
public String getDisplayName() {
return "";
}
}
};
-
/**
- * Convenient singleton instance, since this {@link RetentionStrategy} is stateless.
+ * Convenient singleton instance, since this {@link RetentionStrategy} is
+ * stateless.
*/
public static final Always INSTANCE = new Always();
/**
- * {@link RetentionStrategy} that tries to keep the node online all the time.
+ * {@link RetentionStrategy} that tries to keep the node online all the
+ * time.
*/
public static class Always extends RetentionStrategy<SlaveComputer> {
+
/**
* Constructs a new Always.
*/
@@ -128,13 +136,15 @@ public abstract class RetentionStrategy<T extends Computer> extends AbstractDesc
}
public long check(SlaveComputer c) {
- if (c.isOffline() && !c.isConnecting() && c.isLaunchSupported())
+ if (c.isOffline() && !c.isConnecting() && c.isLaunchSupported()) {
c.tryReconnect();
+ }
return 1;
}
- @Extension(ordinal=100)
+ @Extension(ordinal = 100)
public static class DescriptorImpl extends Descriptor<RetentionStrategy<?>> {
+
public String getDisplayName() {
return Messages.RetentionStrategy_Always_displayName();
}
@@ -142,19 +152,20 @@ public abstract class RetentionStrategy<T extends Computer> extends AbstractDesc
}
/**
- * {@link hudson.slaves.RetentionStrategy} that tries to keep the node offline when not in use.
+ * {@link hudson.slaves.RetentionStrategy} that tries to keep the node
+ * offline when not in use.
*/
public static class Demand extends RetentionStrategy<SlaveComputer> {
private static final Logger logger = Logger.getLogger(Demand.class.getName());
-
/**
- * The delay (in minutes) for which the slave must be in demand before tring to launch it.
+ * The delay (in minutes) for which the slave must be in demand before
+ * tring to launch it.
*/
private final long inDemandDelay;
-
/**
- * The delay (in minutes) for which the slave must be idle before taking it offline.
+ * The delay (in minutes) for which the slave must be idle before taking
+ * it offline.
*/
private final long idleDelay;
@@ -205,6 +216,7 @@ public abstract class RetentionStrategy<T extends Computer> extends AbstractDesc
@Extension
public static class DescriptorImpl extends Descriptor<RetentionStrategy<?>> {
+
public String getDisplayName() {
return Messages.RetentionStrategy_Demand_displayName();
}
diff --git a/hudson-core/src/main/java/hudson/slaves/SimpleScheduledRetentionStrategy.java b/hudson-core/src/main/java/hudson/slaves/SimpleScheduledRetentionStrategy.java
index 3e63e56..7546648 100644
--- a/hudson-core/src/main/java/hudson/slaves/SimpleScheduledRetentionStrategy.java
+++ b/hudson-core/src/main/java/hudson/slaves/SimpleScheduledRetentionStrategy.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Stephen Connolly
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Stephen Connolly
+ *
*
*******************************************************************************/
@@ -36,7 +36,7 @@ import static java.util.logging.Level.INFO;
import org.antlr.runtime.RecognitionException;
/**
- * {@link RetentionStrategy} that controls the slave based on a schedule.
+ * {@link RetentionStrategy} that controls the slave based on a schedule.
*
* @author Stephen Connolly
* @since 1.275
@@ -44,7 +44,6 @@ import org.antlr.runtime.RecognitionException;
public class SimpleScheduledRetentionStrategy extends RetentionStrategy<SlaveComputer> {
private static final Logger LOGGER = Logger.getLogger(SimpleScheduledRetentionStrategy.class.getName());
-
private final String startTimeSpec;
private transient CronTabList tabs;
private transient Calendar lastChecked;
@@ -216,6 +215,7 @@ public class SimpleScheduledRetentionStrategy extends RetentionStrategy<SlaveCom
@Extension
public static class DescriptorImpl extends Descriptor<RetentionStrategy<?>> {
+
public String getDisplayName() {
return Messages.SimpleScheduledRetentionStrategy_displayName();
}
@@ -226,8 +226,9 @@ public class SimpleScheduledRetentionStrategy extends RetentionStrategy<SlaveCom
public FormValidation doCheck(@QueryParameter String value) {
try {
String msg = CronTabList.create(fixNull(value)).checkSanity();
- if (msg != null)
+ if (msg != null) {
return FormValidation.warning(msg);
+ }
return FormValidation.ok();
} catch (RecognitionException e) {
return FormValidation.error(e.getMessage());
diff --git a/hudson-core/src/main/java/hudson/slaves/SlaveComputer.java b/hudson-core/src/main/java/hudson/slaves/SlaveComputer.java
index 3c7ca35..630b1ce 100644
--- a/hudson-core/src/main/java/hudson/slaves/SlaveComputer.java
+++ b/hudson-core/src/main/java/hudson/slaves/SlaveComputer.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi, Stephen Connolly
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi, Stephen Connolly
+ *
*
*******************************************************************************/
@@ -66,44 +66,39 @@ import org.eclipse.hudson.security.HudsonSecurityManager;
* @author Kohsuke Kawaguchi
*/
public class SlaveComputer extends Computer {
+
private volatile Channel channel;
private volatile transient boolean acceptingTasks = true;
private Charset defaultCharset;
private Boolean isUnix;
/**
- * Effective {@link ComputerLauncher} that hides the details of
- * how we launch a slave agent on this computer.
+ * Effective {@link ComputerLauncher} that hides the details of how we
+ * launch a slave agent on this computer.
*
- * <p>
- * This is normally the same as {@link Slave#getLauncher()} but
- * can be different. See {@link #grabLauncher(Node)}.
+ * <p> This is normally the same as {@link Slave#getLauncher()} but can be
+ * different. See {@link #grabLauncher(Node)}.
*/
private ComputerLauncher launcher;
-
/**
* Perpetually writable log file.
*/
private final ReopenableFileOutputStream log;
-
/**
- * {@link StreamTaskListener} that wraps {@link #log}, hence perpetually writable.
+ * {@link StreamTaskListener} that wraps {@link #log}, hence perpetually
+ * writable.
*/
private final TaskListener taskListener;
-
-
/**
- * Number of failed attempts to reconnect to this node
- * (so that if we keep failing to reconnect, we can stop
- * trying.)
+ * Number of failed attempts to reconnect to this node (so that if we keep
+ * failing to reconnect, we can stop trying.)
*/
private transient int numRetryAttempt;
-
/**
- * Tracks the status of the last launch operation, which is always asynchronous.
- * This can be used to wait for the completion, or cancel the launch activity.
+ * Tracks the status of the last launch operation, which is always
+ * asynchronous. This can be used to wait for the completion, or cancel the
+ * launch activity.
*/
private volatile Future<?> lastConnectActivity = null;
-
private Object constructed = new Object();
public SlaveComputer(Slave slave) {
@@ -121,8 +116,9 @@ public class SlaveComputer extends Computer {
}
/**
- * Allows a {@linkplain hudson.slaves.ComputerLauncher} or a {@linkplain hudson.slaves.RetentionStrategy} to
- * suspend tasks being accepted by the slave computer.
+ * Allows a {@linkplain hudson.slaves.ComputerLauncher} or a
+ * {@linkplain hudson.slaves.RetentionStrategy} to suspend tasks being
+ * accepted by the slave computer.
*
* @param acceptingTasks {@code true} if the slave can accept tasks.
*/
@@ -133,8 +129,8 @@ public class SlaveComputer extends Computer {
/**
* True if this computer is a Unix machine (as opposed to Windows machine).
*
- * @return
- * null if the computer is disconnected and therefore we don't know whether it is Unix or not.
+ * @return null if the computer is disconnected and therefore we don't know
+ * whether it is Unix or not.
*/
public Boolean isUnix() {
return isUnix;
@@ -142,21 +138,23 @@ public class SlaveComputer extends Computer {
@Override
public Slave getNode() {
- return (Slave)super.getNode();
+ return (Slave) super.getNode();
}
@Override
public String getIcon() {
Future<?> l = lastConnectActivity;
- if(l!=null && !l.isDone())
+ if (l != null && !l.isDone()) {
return "computer-flash.gif";
+ }
return super.getIcon();
}
/**
* @deprecated since 2008-05-20.
*/
- @Deprecated @Override
+ @Deprecated
+ @Override
public boolean isJnlpAgent() {
return launcher instanceof JNLPLauncher;
}
@@ -171,11 +169,15 @@ public class SlaveComputer extends Computer {
}
protected Future<?> _connect(boolean forceReconnect) {
- if(channel!=null) return Futures.precomputed(null);
- if(!forceReconnect && isConnecting())
+ if (channel != null) {
+ return Futures.precomputed(null);
+ }
+ if (!forceReconnect && isConnecting()) {
return lastConnectActivity;
- if(forceReconnect && isConnecting())
- logger.fine("Forcing a reconnect on "+getName());
+ }
+ if (forceReconnect && isConnecting()) {
+ logger.fine("Forcing a reconnect on " + getName());
+ }
closeChannel();
return lastConnectActivity = Computer.threadPoolForRemoting.submit(new java.util.concurrent.Callable<Object>() {
@@ -191,7 +193,7 @@ public class SlaveComputer extends Computer {
taskListener.error(e.getMessage());
throw e;
} catch (IOException e) {
- Util.displayIOException(e,taskListener);
+ Util.displayIOException(e, taskListener);
e.printStackTrace(taskListener.error(Messages.ComputerLauncher_unexpectedError()));
throw e;
} catch (InterruptedException e) {
@@ -199,8 +201,9 @@ public class SlaveComputer extends Computer {
throw e;
}
} finally {
- if (channel==null)
+ if (channel == null) {
offlineCause = new OfflineCause.LaunchFailed();
+ }
}
}
});
@@ -213,10 +216,10 @@ public class SlaveComputer extends Computer {
public void taskAccepted(Executor executor, Queue.Task task) {
super.taskAccepted(executor, task);
if (launcher instanceof ExecutorListener) {
- ((ExecutorListener)launcher).taskAccepted(executor, task);
+ ((ExecutorListener) launcher).taskAccepted(executor, task);
}
if (getNode().getRetentionStrategy() instanceof ExecutorListener) {
- ((ExecutorListener)getNode().getRetentionStrategy()).taskAccepted(executor, task);
+ ((ExecutorListener) getNode().getRetentionStrategy()).taskAccepted(executor, task);
}
}
@@ -227,7 +230,7 @@ public class SlaveComputer extends Computer {
public void taskCompleted(Executor executor, Queue.Task task, long durationMS) {
super.taskCompleted(executor, task, durationMS);
if (launcher instanceof ExecutorListener) {
- ((ExecutorListener)launcher).taskCompleted(executor, task, durationMS);
+ ((ExecutorListener) launcher).taskCompleted(executor, task, durationMS);
}
RetentionStrategy r = getRetentionStrategy();
if (r instanceof ExecutorListener) {
@@ -242,7 +245,7 @@ public class SlaveComputer extends Computer {
public void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems) {
super.taskCompletedWithProblems(executor, task, durationMS, problems);
if (launcher instanceof ExecutorListener) {
- ((ExecutorListener)launcher).taskCompletedWithProblems(executor, task, durationMS, problems);
+ ((ExecutorListener) launcher).taskCompletedWithProblems(executor, task, durationMS, problems);
}
RetentionStrategy r = getRetentionStrategy();
if (r instanceof ExecutorListener) {
@@ -253,7 +256,7 @@ public class SlaveComputer extends Computer {
@Override
public boolean isConnecting() {
Future<?> l = lastConnectActivity;
- return isOffline() && l!=null && !l.isDone();
+ return isOffline() && l != null && !l.isDone();
}
public OutputStream openLogFile() {
@@ -261,85 +264,86 @@ public class SlaveComputer extends Computer {
log.rewind();
return log;
} catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to create log file "+getLogFile(),e);
+ logger.log(Level.SEVERE, "Failed to create log file " + getLogFile(), e);
return new NullStream();
}
}
-
private final Object channelLock = new Object();
public void setChannel(InputStream in, OutputStream out, TaskListener taskListener, Channel.Listener listener) throws IOException, InterruptedException {
- setChannel(in,out,taskListener.getLogger(),listener);
+ setChannel(in, out, taskListener.getLogger(), listener);
}
/**
- * Creates a {@link Channel} from the given stream and sets that to this slave.
+ * Creates a {@link Channel} from the given stream and sets that to this
+ * slave.
*
- * @param in
- * Stream connected to the remote "slave.jar". It's the caller's responsibility to do
- * buffering on this stream, if that's necessary.
- * @param out
- * Stream connected to the remote peer. It's the caller's responsibility to do
- * buffering on this stream, if that's necessary.
- * @param launchLog
- * If non-null, receive the portion of data in <tt>is</tt> before
- * the data goes into the "binary mode". This is useful
- * when the established communication channel might include some data that might
- * be useful for debugging/trouble-shooting.
- * @param listener
- * Gets a notification when the channel closes, to perform clean up. Can be null.
- * By the time this method is called, the cause of the termination is reported to the user,
- * so the implementation of the listener doesn't need to do that again.
+ * @param in Stream connected to the remote "slave.jar". It's the caller's
+ * responsibility to do buffering on this stream, if that's necessary.
+ * @param out Stream connected to the remote peer. It's the caller's
+ * responsibility to do buffering on this stream, if that's necessary.
+ * @param launchLog If non-null, receive the portion of data in <tt>is</tt>
+ * before the data goes into the "binary mode". This is useful when the
+ * established communication channel might include some data that might be
+ * useful for debugging/trouble-shooting.
+ * @param listener Gets a notification when the channel closes, to perform
+ * clean up. Can be null. By the time this method is called, the cause of
+ * the termination is reported to the user, so the implementation of the
+ * listener doesn't need to do that again.
*/
public void setChannel(InputStream in, OutputStream out, OutputStream launchLog, Channel.Listener listener) throws IOException, InterruptedException {
- if(this.channel!=null)
+ if (this.channel != null) {
throw new IllegalStateException("Already connected");
+ }
final TaskListener taskListener = new StreamTaskListener(launchLog);
PrintStream log = taskListener.getLogger();
- Channel channel = new Channel(nodeName,threadPoolForRemoting, Channel.Mode.NEGOTIATE,
- in,out, launchLog);
+ Channel channel = new Channel(nodeName, threadPoolForRemoting, Channel.Mode.NEGOTIATE,
+ in, out, launchLog);
channel.addListener(new Channel.Listener() {
@Override
public void onClosed(Channel c, IOException cause) {
SlaveComputer.this.channel = null;
// Orderly shutdown will have null exception
- if (cause!=null) {
+ if (cause != null) {
offlineCause = new ChannelTermination(cause);
- cause.printStackTrace(taskListener.error("Connection terminated"));
+ cause.printStackTrace(taskListener.error("Connection terminated"));
} else {
taskListener.getLogger().println("Connection terminated");
}
launcher.afterDisconnect(SlaveComputer.this, taskListener);
}
});
- if(listener!=null)
+ if (listener != null) {
channel.addListener(listener);
+ }
String slaveVersion = channel.call(new SlaveVersion());
log.println("Slave.jar version: " + slaveVersion);
boolean _isUnix = channel.call(new DetectOS());
- log.println(_isUnix? hudson.model.Messages.Slave_UnixSlave():hudson.model.Messages.Slave_WindowsSlave());
+ log.println(_isUnix ? hudson.model.Messages.Slave_UnixSlave() : hudson.model.Messages.Slave_WindowsSlave());
String defaultCharsetName = channel.call(new DetectDefaultCharset());
String remoteFs = getNode().getRemoteFS();
- if(_isUnix && !remoteFs.contains("/") && remoteFs.contains("\\"))
- log.println("WARNING: "+remoteFs+" looks suspiciously like Windows path. Maybe you meant "+remoteFs.replace('\\','/')+"?");
- FilePath root = new FilePath(channel,getNode().getRemoteFS());
+ if (_isUnix && !remoteFs.contains("/") && remoteFs.contains("\\")) {
+ log.println("WARNING: " + remoteFs + " looks suspiciously like Windows path. Maybe you meant " + remoteFs.replace('\\', '/') + "?");
+ }
+ FilePath root = new FilePath(channel, getNode().getRemoteFS());
channel.call(new SlaveInitializer());
channel.call(new WindowsSlaveInstaller(remoteFs));
- for (ComputerListener cl : ComputerListener.all())
- cl.preOnline(this,channel,root,taskListener);
+ for (ComputerListener cl : ComputerListener.all()) {
+ cl.preOnline(this, channel, root, taskListener);
+ }
offlineCause = null;
// update the data structure atomically to prevent others from seeing a channel that's not properly initialized yet
- synchronized(channelLock) {
- if(this.channel!=null) {
+ synchronized (channelLock) {
+ if (this.channel != null) {
// check again. we used to have this entire method in a big sycnhronization block,
// but Channel constructor blocks for an external process to do the connection
// if CommandLauncher is used, and that cannot be interrupted because it blocks at InputStream.
@@ -354,8 +358,9 @@ public class SlaveComputer extends Computer {
this.channel = channel;
defaultCharset = Charset.forName(defaultCharsetName);
}
- for (ComputerListener cl : ComputerListener.all())
- cl.onOnline(this,taskListener);
+ for (ComputerListener cl : ComputerListener.all()) {
+ cl.onOnline(this, taskListener);
+ }
log.println("Slave successfully connected and online");
Hudson.getInstance().getQueue().scheduleMaintenance();
}
@@ -370,25 +375,25 @@ public class SlaveComputer extends Computer {
}
public List<LogRecord> getLogRecords() throws IOException, InterruptedException {
- if(channel==null)
+ if (channel == null) {
return Collections.emptyList();
- else
- return channel.call(new Callable<List<LogRecord>,RuntimeException>() {
+ } else {
+ return channel.call(new Callable<List<LogRecord>, RuntimeException>() {
public List<LogRecord> call() {
return new ArrayList<LogRecord>(SLAVE_LOG_HANDLER.getView());
}
});
+ }
}
public HttpResponse doDoDisconnect(@QueryParameter String offlineMessage) throws IOException, ServletException {
- if (channel!=null) {
+ if (channel != null) {
//does nothing in case computer is already disconnected
checkPermission(Hudson.ADMINISTER);
offlineMessage = Util.fixEmptyAndTrim(offlineMessage);
disconnect(OfflineCause.create(Messages._SlaveComputer_DisconnectedBy(
HudsonSecurityManager.getAuthentication().getName(),
- offlineMessage!=null ? " : " + offlineMessage : "")
- ));
+ offlineMessage != null ? " : " + offlineMessage : "")));
}
return new HttpRedirect(".");
}
@@ -408,7 +413,7 @@ public class SlaveComputer extends Computer {
}
public void doLaunchSlaveAgent(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
- if(channel!=null) {
+ if (channel != null) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
@@ -422,9 +427,9 @@ public class SlaveComputer extends Computer {
public void tryReconnect() {
numRetryAttempt++;
- if(numRetryAttempt<6 || (numRetryAttempt%12)==0) {
+ if (numRetryAttempt < 6 || (numRetryAttempt % 12) == 0) {
// initially retry several times quickly, and after that, do it infrequently.
- logger.info("Attempting to reconnect "+nodeName);
+ logger.info("Attempting to reconnect " + nodeName);
connect(true);
}
}
@@ -432,9 +437,9 @@ public class SlaveComputer extends Computer {
/**
* Serves jar files for JNLP slave agents.
*
- * @deprecated since 2008-08-18.
- * This URL binding is no longer used and moved up directly under to {@link Hudson},
- * but it's left here for now just in case some old JNLP slave agents request it.
+ * @deprecated since 2008-08-18. This URL binding is no longer used and
+ * moved up directly under to {@link Hudson}, but it's left here for now
+ * just in case some old JNLP slave agents request it.
*/
public Slave.JnlpJar getJnlpJars(String fileName) {
return new Slave.JnlpJar(fileName);
@@ -448,7 +453,7 @@ public class SlaveComputer extends Computer {
public RetentionStrategy getRetentionStrategy() {
Slave n = getNode();
- return n==null ? RetentionStrategy.INSTANCE : n.getRetentionStrategy();
+ return n == null ? RetentionStrategy.INSTANCE : n.getRetentionStrategy();
}
/**
@@ -466,8 +471,9 @@ public class SlaveComputer extends Computer {
logger.log(Level.SEVERE, "Failed to terminate channel to " + getDisplayName(), e);
}
}
- for (ComputerListener cl : ComputerListener.all())
+ for (ComputerListener cl : ComputerListener.all()) {
cl.onOffline(this);
+ }
}
@Override
@@ -478,70 +484,82 @@ public class SlaveComputer extends Computer {
// maybe the configuration was changed to relaunch the slave, so try to re-launch now.
// "constructed==null" test is an ugly work around to avoid launching before the object is fully
// constructed.
- if(constructed!=null) {
- if (node instanceof Slave)
- ((Slave)node).getRetentionStrategy().check(this);
- else
+ if (constructed != null) {
+ if (node instanceof Slave) {
+ ((Slave) node).getRetentionStrategy().check(this);
+ } else {
connect(false);
+ }
}
}
/**
- * Grabs a {@link ComputerLauncher} out of {@link Node} to keep it in this {@link Computer}.
- * The returned launcher will be set to {@link #launcher} and used to carry out the actual launch operation.
+ * Grabs a {@link ComputerLauncher} out of {@link Node} to keep it in this
+ * {@link Computer}. The returned launcher will be set to {@link #launcher}
+ * and used to carry out the actual launch operation.
*
- * <p>
- * Subtypes that needs to decorate {@link ComputerLauncher} can do so by overriding this method.
- * This is useful for {@link SlaveComputer}s for clouds for example, where one normally needs
- * additional pre-launch step (such as waiting for the provisioned node to become available)
- * before the user specified launch step (like SSH connection) kicks in.
+ * <p> Subtypes that needs to decorate {@link ComputerLauncher} can do so by
+ * overriding this method. This is useful for {@link SlaveComputer}s for
+ * clouds for example, where one normally needs additional pre-launch step
+ * (such as waiting for the provisioned node to become available) before the
+ * user specified launch step (like SSH connection) kicks in.
*
* @see ComputerLauncherFilter
*/
protected ComputerLauncher grabLauncher(Node node) {
- return ((Slave)node).getLauncher();
+ return ((Slave) node).getLauncher();
}
-
private static final Logger logger = Logger.getLogger(SlaveComputer.class.getName());
- private static final class SlaveVersion implements Callable<String,IOException> {
+ private static final class SlaveVersion implements Callable<String, IOException> {
+
public String call() throws IOException {
- try { return Launcher.VERSION; }
- catch (Throwable ex) { return "< 1.335"; } // Older slave.jar won't have VERSION
+ try {
+ return Launcher.VERSION;
+ } catch (Throwable ex) {
+ return "< 1.335";
+ } // Older slave.jar won't have VERSION
}
}
- private static final class DetectOS implements Callable<Boolean,IOException> {
+
+ private static final class DetectOS implements Callable<Boolean, IOException> {
+
public Boolean call() throws IOException {
- return File.pathSeparatorChar==':';
+ return File.pathSeparatorChar == ':';
}
}
- private static final class DetectDefaultCharset implements Callable<String,IOException> {
+ private static final class DetectDefaultCharset implements Callable<String, IOException> {
+
public String call() throws IOException {
return Charset.defaultCharset().name();
}
}
/**
- * Puts the {@link #SLAVE_LOG_HANDLER} into a separate class so that loading this class
- * in JVM doesn't end up loading tons of additional classes.
+ * Puts the {@link #SLAVE_LOG_HANDLER} into a separate class so that loading
+ * this class in JVM doesn't end up loading tons of additional classes.
*/
static final class LogHolder {
+
/**
- * This field is used on each slave node to record log records on the slave.
+ * This field is used on each slave node to record log records on the
+ * slave.
*/
static final RingBufferLogHandler SLAVE_LOG_HANDLER = new RingBufferLogHandler();
}
- private static class SlaveInitializer implements Callable<Void,RuntimeException> {
+ private static class SlaveInitializer implements Callable<Void, RuntimeException> {
+
public Void call() {
// avoid double installation of the handler. JNLP slaves can reconnect to the master multiple times
// and each connection gets a different RemoteClassLoader, so we need to evict them by class name,
// not by their identity.
Logger logger = Logger.getLogger("hudson");
for (Handler h : logger.getHandlers()) {
- if (h.getClass().getName().equals(SLAVE_LOG_HANDLER.getClass().getName()))
+ if (h.getClass().getName().equals(SLAVE_LOG_HANDLER.getClass().getName())) {
logger.removeHandler(h);
+ }
}
logger.addHandler(SLAVE_LOG_HANDLER);
@@ -552,30 +570,34 @@ public class SlaveComputer extends Computer {
// ignore this error.
}
- Channel.current().setProperty("slave",Boolean.TRUE); // indicate that this side of the channel is the slave side.
-
+ Channel.current().setProperty("slave", Boolean.TRUE); // indicate that this side of the channel is the slave side.
+
return null;
}
private static final long serialVersionUID = 1L;
}
/**
- * Obtains a {@link VirtualChannel} that allows some computation to be performed on the master.
- * This method can be called from any thread on the master, or from slave (more precisely,
- * it only works from the remoting request-handling thread in slaves, which means if you've started
- * separate thread on slaves, that'll fail.)
+ * Obtains a {@link VirtualChannel} that allows some computation to be
+ * performed on the master. This method can be called from any thread on the
+ * master, or from slave (more precisely, it only works from the remoting
+ * request-handling thread in slaves, which means if you've started separate
+ * thread on slaves, that'll fail.)
*
- * @return null if the calling thread doesn't have any trace of where its master is.
+ * @return null if the calling thread doesn't have any trace of where its
+ * master is.
* @since 1.362
*/
public static VirtualChannel getChannelToMaster() {
- if (Hudson.getInstance()!=null)
+ if (Hudson.getInstance() != null) {
return MasterComputer.localChannel;
+ }
// if this method is called from within the slave computation thread, this should work
Channel c = Channel.current();
- if (c!=null && c.getProperty("slave")==Boolean.TRUE)
+ if (c != null && c.getProperty("slave") == Boolean.TRUE) {
return c;
+ }
return null;
}
diff --git a/hudson-core/src/main/java/hudson/slaves/WorkspaceList.java b/hudson-core/src/main/java/hudson/slaves/WorkspaceList.java
index 8b28532..e6a669b 100644
--- a/hudson-core/src/main/java/hudson/slaves/WorkspaceList.java
+++ b/hudson-core/src/main/java/hudson/slaves/WorkspaceList.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -26,10 +26,10 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Used by {@link Computer} to keep track of workspaces that are actively in use.
+ * Used by {@link Computer} to keep track of workspaces that are actively in
+ * use.
*
- * <p>
- * SUBJECT TO CHANGE! Do not use this from plugins directly.
+ * <p> SUBJECT TO CHANGE! Do not use this from plugins directly.
*
* @author Kohsuke Kawaguchi
* @since 1.319
@@ -43,31 +43,28 @@ public final class WorkspaceList {
* Book keeping for workspace allocation.
*/
public static final class Entry {
+
/**
* Who acquired this workspace?
*/
//TODO: review and check whether we can do it private
public final Thread holder = Thread.currentThread();
-
/**
* When?
*/
//TODO: review and check whether we can do it private
public final long time = System.currentTimeMillis();
-
/**
* From where?
*/
//TODO: review and check whether we can do it private
public final Exception source = new Exception();
-
/**
- * True makes the caller of {@link WorkspaceList#allocate(FilePath)} wait
- * for this workspace.
+ * True makes the caller of {@link WorkspaceList#allocate(FilePath)}
+ * wait for this workspace.
*/
//TODO: review and check whether we can do it private
public final boolean quick;
-
//TODO: review and check whether we can do it private
public final FilePath path;
@@ -98,9 +95,11 @@ public final class WorkspaceList {
@Override
public String toString() {
- String s = path+" owned by "+holder.getName()+" from "+new Date(time);
- if(quick) s+=" (quick)";
- s+="\n"+Functions.printThrowable(source);
+ String s = path + " owned by " + holder.getName() + " from " + new Date(time);
+ if (quick) {
+ s += " (quick)";
+ }
+ s += "\n" + Functions.printThrowable(source);
return s;
}
}
@@ -110,6 +109,7 @@ public final class WorkspaceList {
*/
public static abstract class Lease {
//TODO: review and check whether we can do it private
+
public final FilePath path;
protected Lease(FilePath path) {
@@ -136,35 +136,38 @@ public final class WorkspaceList {
};
}
}
-
- private final Map<FilePath,Entry> inUse = new HashMap<FilePath,Entry>();
+ private final Map<FilePath, Entry> inUse = new HashMap<FilePath, Entry>();
public WorkspaceList() {
}
/**
- * Allocates a workspace by adding some variation to the given base to make it unique.
+ * Allocates a workspace by adding some variation to the given base to make
+ * it unique.
*/
public synchronized Lease allocate(FilePath base) throws InterruptedException {
- for (int i=1; ; i++) {
+ for (int i = 1;; i++) {
//Workspace suffix was changed from @ to _, because of some issues with SCMs.
//see http://issues.hudson-ci.org/browse/HUDSON-4791
- FilePath candidate = i==1 ? base : base.withSuffix(WORKSPACE_NAME_SUFFIX + i);
+ FilePath candidate = i == 1 ? base : base.withSuffix(WORKSPACE_NAME_SUFFIX + i);
Entry e = inUse.get(candidate);
- if(e!=null && !e.quick)
+ if (e != null && !e.quick) {
continue;
+ }
return acquire(candidate);
}
}
/**
- * Just record that this workspace is being used, without paying any attention to the sycnhronization support.
+ * Just record that this workspace is being used, without paying any
+ * attention to the sycnhronization support.
*/
public synchronized Lease record(FilePath p) {
- log("recorded "+p);
+ log("recorded " + p);
Entry old = inUse.put(p, new Entry(p, false));
- if (old!=null)
- throw new AssertionError("Tried to record a workspace already owned: "+old);
+ if (old != null) {
+ throw new AssertionError("Tried to record a workspace already owned: " + old);
+ }
return lease(p);
}
@@ -173,33 +176,35 @@ public final class WorkspaceList {
*/
private synchronized void _release(FilePath p) {
Entry old = inUse.remove(p);
- if (old==null)
- throw new AssertionError("Releasing unallocated workspace "+p);
+ if (old == null) {
+ throw new AssertionError("Releasing unallocated workspace " + p);
+ }
notifyAll();
}
/**
- * Acquires the given workspace. If necessary, this method blocks until it's made available.
+ * Acquires the given workspace. If necessary, this method blocks until it's
+ * made available.
*
- * @return
- * The same {@link FilePath} as given to this method.
+ * @return The same {@link FilePath} as given to this method.
*/
public synchronized Lease acquire(FilePath p) throws InterruptedException {
- return acquire(p,false);
+ return acquire(p, false);
}
/**
* See {@link #acquire(FilePath)}
*
- * @param quick
- * If true, indicates that the acquired workspace will be returned quickly.
- * This makes other calls to {@link #allocate(FilePath)} to wait for the release of this workspace.
+ * @param quick If true, indicates that the acquired workspace will be
+ * returned quickly. This makes other calls to {@link #allocate(FilePath)}
+ * to wait for the release of this workspace.
*/
public synchronized Lease acquire(FilePath p, boolean quick) throws InterruptedException {
- while (inUse.containsKey(p))
+ while (inUse.containsKey(p)) {
wait();
- log("acquired "+p);
- inUse.put(p,new Entry(p,quick));
+ }
+ log("acquired " + p);
+ inUse.put(p, new Entry(p, quick));
return lease(p);
}
@@ -215,9 +220,9 @@ public final class WorkspaceList {
}
private void log(String msg) {
- if (LOGGER.isLoggable(Level.FINE))
+ if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(Thread.currentThread().getName() + " " + msg);
+ }
}
-
private static final Logger LOGGER = Logger.getLogger(WorkspaceList.class.getName());
}
diff --git a/hudson-core/src/main/java/hudson/slaves/package.html b/hudson-core/src/main/java/hudson/slaves/package.html
index 1eb3e11..1bdee80 100644
--- a/hudson-core/src/main/java/hudson/slaves/package.html
+++ b/hudson-core/src/main/java/hudson/slaves/package.html
@@ -16,5 +16,5 @@
-->
<html><head/><body>
-Code related to slaves.
-</body></html> \ No newline at end of file
+ Code related to slaves.
+ </body></html> \ No newline at end of file