/* * The MIT License * * Copyright (c) 2004-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi, * Erik Ramfelt, Martin Eigenbrodt, Stephen Connolly, Tom Huybrechts * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package hudson.model; import hudson.FilePath; import hudson.Launcher; import hudson.Util; import hudson.Launcher.RemoteLauncher; import hudson.model.Descriptor.FormException; import hudson.remoting.Callable; import hudson.slaves.CommandLauncher; import hudson.slaves.ComputerLauncher; import hudson.slaves.DumbSlave; import hudson.slaves.JNLPLauncher; import hudson.slaves.NodeDescriptor; import hudson.slaves.NodeProperty; import hudson.slaves.NodePropertyDescriptor; import hudson.slaves.RetentionStrategy; import hudson.slaves.SlaveComputer; import hudson.util.ClockDifference; import hudson.util.DescribableList; import hudson.util.FormValidation; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import java.util.Set; import javax.servlet.ServletException; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import jenkins.model.Jenkins; import jenkins.slaves.WorkspaceLocator; import org.apache.commons.io.IOUtils; import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; /** * Information about a Hudson slave node. * *

* Ideally this would have been in the hudson.slaves package, * but for compatibility reasons, it can't. * *

* TODO: move out more stuff to {@link DumbSlave}. * * @author Kohsuke Kawaguchi */ public abstract class Slave extends Node implements Serializable { /** * Name of this slave node. */ protected String name; /** * Description of this node. */ private final String description; /** * Absolute path to the root of the workspace * from the view point of this node, such as "/hudson" */ protected final String remoteFS; /** * Number of executors of this node. */ private int numExecutors = 2; /** * Job allocation strategy. */ private Mode mode; /** * Slave availablility strategy. */ private RetentionStrategy retentionStrategy; /** * The starter that will startup this slave. */ private ComputerLauncher launcher; /** * Whitespace-separated labels. */ private String label=""; private /*almost final*/ DescribableList,NodePropertyDescriptor> nodeProperties = new DescribableList,NodePropertyDescriptor>(Jenkins.getInstance()); /** * Lazily computed set of labels from {@link #label}. */ private transient volatile Set

* This is a hack to wrap the whole thing into a simple {@link Callable}. * *

    *
  1. When the callable is sent to remote, we capture the time (on this side) in {@link GetClockDifference2#startTime} *
  2. When the other side receives the callable it is {@link GetClockDifference2}. *
  3. We capture the time on the other side and {@link GetClockDifference3} gets sent from the other side *
  4. When it's read on this side as a return value, it morphs itself into {@link ClockDifference}. *
*/ private static final class GetClockDifference1 implements Callable { public ClockDifference call() { // this method must be being invoked locally, which means the clock is in sync return new ClockDifference(0); } private Object writeReplace() { return new GetClockDifference2(); } private static final long serialVersionUID = 1L; } private static final class GetClockDifference2 implements Callable { /** * Capture the time on the master when this object is sent to remote, which is when * {@link GetClockDifference1#writeReplace()} is run. */ private final long startTime = System.currentTimeMillis(); public GetClockDifference3 call() { return new GetClockDifference3(startTime); } private static final long serialVersionUID = 1L; } private static final class GetClockDifference3 implements Serializable { private final long remoteTime = System.currentTimeMillis(); private final long startTime; public GetClockDifference3(long startTime) { this.startTime = startTime; } private Object readResolve() { long endTime = System.currentTimeMillis(); return new ClockDifference((startTime + endTime)/2-remoteTime); } } /** * Determines the workspace root file name for those who really really need the shortest possible path name. */ private static final String WORKSPACE_ROOT = System.getProperty(Slave.class.getName()+".workspaceRoot","workspace"); }