Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
*
* Copyright (c) 2004-2009 Oracle Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*
* Kohsuke Kawaguchi, Stephen Connolly
*
*
*******************************************************************************/
package hudson.slaves;
import hudson.model.*;
import hudson.model.Hudson.MasterComputer;
import hudson.remoting.Channel;
import hudson.remoting.VirtualChannel;
import hudson.remoting.Callable;
import hudson.util.StreamTaskListener;
import hudson.util.NullStream;
import hudson.util.RingBufferLogHandler;
import hudson.util.Futures;
import hudson.FilePath;
import hudson.lifecycle.WindowsSlaveInstaller;
import hudson.Util;
import hudson.AbortException;
import hudson.remoting.Launcher;
import static hudson.slaves.SlaveComputer.LogHolder.SLAVE_LOG_HANDLER;
import hudson.slaves.OfflineCause.ChannelTermination;
import java.io.File;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.Handler;
import java.util.List;
import java.util.Collections;
import java.util.ArrayList;
import java.nio.charset.Charset;
import java.util.concurrent.Future;
import java.security.Security;
import hudson.util.io.ReopenableFileOutputStream;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpRedirect;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.hudson.security.HudsonSecurityManager;
/**
* {@link Computer} for {@link Slave}s.
*
* @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.
*
*
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.
*/
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.)
*/
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.
*/
private volatile Future> lastConnectActivity = null;
private Object constructed = new Object();
public SlaveComputer(Slave slave) {
super(slave);
this.log = new ReopenableFileOutputStream(getLogFile(), 5);
this.taskListener = new StreamTaskListener(log);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAcceptingTasks() {
return acceptingTasks;
}
/**
* 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.
*/
public void setAcceptingTasks(boolean acceptingTasks) {
this.acceptingTasks = acceptingTasks;
}
/**
* 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.
*/
public Boolean isUnix() {
return isUnix;
}
@Override
public Slave getNode() {
return (Slave) super.getNode();
}
@Override
public String getIcon() {
Future> l = lastConnectActivity;
if (l != null && !l.isDone()) {
return "computer-flash.gif";
}
return super.getIcon();
}
/**
* @deprecated since 2008-05-20.
*/
@Deprecated
@Override
public boolean isJnlpAgent() {
return launcher instanceof JNLPLauncher;
}
@Override
public boolean isLaunchSupported() {
return launcher.isLaunchSupported();
}
public ComputerLauncher getLauncher() {
return launcher;
}
protected Future> _connect(boolean forceReconnect) {
if (channel != null) {
return Futures.precomputed(null);
}
if (!forceReconnect && isConnecting()) {
return lastConnectActivity;
}
if (forceReconnect && isConnecting()) {
logger.fine("Forcing a reconnect on " + getName());
}
closeChannel();
return lastConnectActivity = Computer.threadPoolForRemoting.submit(new java.util.concurrent.Callable