hudson.slaves
Class SlaveComputer

java.lang.Object
  extended by hudson.model.AbstractModelObject
      extended by hudson.model.Actionable
          extended by hudson.model.Computer
              extended by hudson.slaves.SlaveComputer
All Implemented Interfaces:
ExecutorListener, ModelObject, SearchableModelObject, SearchItem, AccessControlled, ModelObjectWithContextMenu
Direct Known Subclasses:
AbstractCloudComputer

public class SlaveComputer
extends Computer

Computer for Slaves.

Author:
Kohsuke Kawaguchi

Nested Class Summary
 
Nested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.MenuItem
 
Field Summary
 
Fields inherited from class hudson.model.Computer
CONFIGURE, CONNECT, CREATE, DELETE, DISCONNECT, nodeName, offlineCause, PERMISSIONS, statusChangeLock, threadPoolForRemoting, transientActions
 
Constructor Summary
SlaveComputer(Slave slave)
           
 
Method Summary
protected  Future<?> _connect(boolean forceReconnect)
          Allows implementing-classes to provide an implementation for the connect method.
 Future<?> disconnect(OfflineCause cause)
          Disconnect this computer.
 org.kohsuke.stapler.HttpResponse doDoDisconnect(String offlineMessage)
           
 void doLaunchSlaveAgent(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          If Computer.getChannel()==null, attempts to relaunch the slave agent.
 void doSlaveAgentJnlp(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse res)
           
 hudson.remoting.Channel getChannel()
          Gets the channel that can be used to run a program on this computer.
static hudson.remoting.VirtualChannel getChannelToMaster()
          Obtains a VirtualChannel that allows some computation to be performed on the master.
 int getClassLoadingCount()
          Shows Channel.classLoadingCount.
 long getClassLoadingTime()
          Shows Channel.classLoadingTime.
 Charset getDefaultCharset()
          Gets the default charset of this computer.
 String getIcon()
           
 Slave.JnlpJar getJnlpJars(String fileName)
          Deprecated. since 2008-08-18. This URL binding is no longer used and moved up directly under to Jenkins, but it's left here for now just in case some old JNLP slave agents request it.
 String getJnlpMac()
           
 ComputerLauncher getLauncher()
           
 List<LogRecord> getLogRecords()
          Gets the logs recorded by this slave.
 Slave getNode()
          Returns the Node that this computer represents.
 String getOSDescription()
          Get the OS description.
 int getResourceLoadingCount()
          Shows Channel.resourceLoadingCount.
 long getResourceLoadingTime()
          Shows Channel.resourceLoadingTime.
 RetentionStrategy getRetentionStrategy()
          RetentionStrategy associated with this computer.
 String getSlaveVersion()
          Get the slave version
protected  ComputerLauncher grabLauncher(Node node)
          Grabs a ComputerLauncher out of Node to keep it in this Computer.
 boolean isAcceptingTasks()
          Returns true if the computer is accepting tasks.
 boolean isConnecting()
          Is a Computer.connect(boolean) operation in progress?
 boolean isJnlpAgent()
          Deprecated. since 2008-05-20.
 boolean isLaunchSupported()
          Returns true if this computer can be launched by Hudson proactively and automatically.
 Boolean isUnix()
          True if this computer is a Unix machine (as opposed to Windows machine).
protected  void kill()
          Called by Jenkins.updateComputerList() to notify Computer that it will be discarded.
 OutputStream openLogFile()
           
 void setAcceptingTasks(boolean acceptingTasks)
          Allows a ComputerLauncher or a RetentionStrategy to suspend tasks being accepted by the slave computer.
 void setChannel(hudson.remoting.Channel channel, OutputStream launchLog, hudson.remoting.Channel.Listener listener)
          Sets up the connection through an exsting channel.
 void setChannel(InputStream in, OutputStream out, OutputStream launchLog, hudson.remoting.Channel.Listener listener)
          Creates a Channel from the given stream and sets that to this slave.
 void setChannel(InputStream in, OutputStream out, TaskListener taskListener, hudson.remoting.Channel.Listener listener)
           
protected  void setNode(Node node)
          Called to notify Computer that its corresponding Node configuration is updated.
 void taskAccepted(Executor executor, Queue.Task task)
          Called whenever a task is accepted by an executor.
 void taskCompleted(Executor executor, Queue.Task task, long durationMS)
          Called whenever a task is completed without any problems by an executor.
 void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems)
          Called whenever a task is completed without any problems by an executor.
 void tryReconnect()
           
 
Methods inherited from class hudson.model.Computer
_doScript, addAction, buildEnvironment, checkPermission, cliConnect, cliDisconnect, cliOffline, cliOnline, connect, countBusy, countExecutors, countIdle, currentComputer, disconnect, doChangeOfflineCause, doConfigDotXml, doConfigSubmit, doDoDelete, doDumpExportTable, doProgressiveLog, doRssAll, doRssFailed, doScript, doScriptText, doToggleOffline, getACL, getActions, getApi, getBuilds, getCaption, getComputerPanelBoxs, getConnectTime, getDemandStartMilliseconds, getDisplayName, getEnvironment, getEnvVars, getExecutors, getHeapDump, getHostName, getIconAltText, getIdleStartMilliseconds, getLoadStatistics, getLog, getLogFile, getLogText, getMonitorData, getName, getNumExecutors, getOfflineCause, getOfflineCauseReason, getOneOffExecutors, getSearchUrl, getSystemProperties, getThreadDump, getTiedJobs, getTimeline, getUrl, getWorkspaceList, hasPermission, interrupt, isAlive, isIdle, isManualLaunchAllowed, isOffline, isOnline, isPartiallyIdle, isTemporarilyOffline, launch, onRemoved, relocateOldLogs, resolveForCLI, setTemporarilyOffline, setTemporarilyOffline, waitUntilOffline, waitUntilOnline
 
Methods inherited from class hudson.model.Actionable
doContextMenu, getAction, getAction, getActions, getDynamic
 
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlaveComputer

public SlaveComputer(Slave slave)
Method Detail

isAcceptingTasks

public boolean isAcceptingTasks()
Returns true if the computer is accepting tasks. Needed to allow slaves programmatic suspension of task scheduling that does not overlap with being offline.

Overrides:
isAcceptingTasks in class Computer
Returns:
true if the computer is accepting tasks

getJnlpMac

public String getJnlpMac()
Since:
1.498

setAcceptingTasks

public void setAcceptingTasks(boolean acceptingTasks)
Allows a ComputerLauncher or a RetentionStrategy to suspend tasks being accepted by the slave computer.

Parameters:
acceptingTasks - true if the slave can accept tasks.

isUnix

public Boolean isUnix()
True if this computer is a Unix machine (as opposed to Windows machine).

Returns:
null if the computer is disconnected and therefore we don't know whether it is Unix or not.

getNode

public Slave getNode()
Description copied from class: Computer
Returns the Node that this computer represents.

Overrides:
getNode in class Computer
Returns:
null if the configuration has changed and the node is removed, yet the corresponding Computer is not yet gone.

getIcon

public String getIcon()
Overrides:
getIcon in class Computer

isJnlpAgent

@Deprecated
public boolean isJnlpAgent()
Deprecated. since 2008-05-20.

Description copied from class: Computer
Returns true if this computer is supposed to be launched via JNLP.

Overrides:
isJnlpAgent in class Computer

isLaunchSupported

public boolean isLaunchSupported()
Description copied from class: Computer
Returns true if this computer can be launched by Hudson proactively and automatically.

For example, JNLP slaves return false from this, because the launch process needs to be initiated from the slave side.

Overrides:
isLaunchSupported in class Computer

getLauncher

public ComputerLauncher getLauncher()

_connect

protected Future<?> _connect(boolean forceReconnect)
Description copied from class: Computer
Allows implementing-classes to provide an implementation for the connect method.

If already connected or if this computer doesn't support proactive launching, no-op. This method may return immediately while the launch operation happens asynchronously.

Specified by:
_connect in class Computer
Parameters:
forceReconnect - If true and a connect activity is already in progress, it will be cancelled and the new one will be started. If false, and a connect activity is already in progress, this method will do nothing and just return the pending connection operation.
Returns:
A Future representing pending completion of the task. The 'completion' includes both a successful completion and a non-successful completion (such distinction typically doesn't make much sense because as soon as Computer is connected it can be disconnected by some other threads.)
See Also:
Computer.disconnect()

taskAccepted

public void taskAccepted(Executor executor,
                         Queue.Task task)
Called whenever a task is accepted by an executor.

Specified by:
taskAccepted in interface ExecutorListener
Overrides:
taskAccepted in class Computer
Parameters:
executor - The executor.
task - The task.

taskCompleted

public void taskCompleted(Executor executor,
                          Queue.Task task,
                          long durationMS)
Called whenever a task is completed without any problems by an executor.

Specified by:
taskCompleted in interface ExecutorListener
Overrides:
taskCompleted in class Computer
Parameters:
executor - The executor.
task - The task.
durationMS - The number of milliseconds that the task took to complete.

taskCompletedWithProblems

public void taskCompletedWithProblems(Executor executor,
                                      Queue.Task task,
                                      long durationMS,
                                      Throwable problems)
Called whenever a task is completed without any problems by an executor.

Specified by:
taskCompletedWithProblems in interface ExecutorListener
Overrides:
taskCompletedWithProblems in class Computer
Parameters:
executor - The executor.
task - The task.
durationMS - The number of milliseconds that the task took to complete.
problems - The exception that was thrown.

isConnecting

public boolean isConnecting()
Description copied from class: Computer
Is a Computer.connect(boolean) operation in progress?

Specified by:
isConnecting in class Computer

openLogFile

public OutputStream openLogFile()

setChannel

public void setChannel(InputStream in,
                       OutputStream out,
                       TaskListener taskListener,
                       hudson.remoting.Channel.Listener listener)
                throws IOException,
                       InterruptedException
Throws:
IOException
InterruptedException

setChannel

public void setChannel(InputStream in,
                       OutputStream out,
                       OutputStream launchLog,
                       hudson.remoting.Channel.Listener listener)
                throws IOException,
                       InterruptedException
Creates a Channel from the given stream and sets that to this slave.

Parameters:
in - Stream connected to the remote "slave.jar". It's the caller's responsibility to do buffering on this stream, if that's necessary.
out - Stream connected to the remote peer. It's the caller's responsibility to do buffering on this stream, if that's necessary.
launchLog - If non-null, receive the portion of data in is 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.
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.
Throws:
IOException
InterruptedException

getClassLoadingCount

public int getClassLoadingCount()
                         throws IOException,
                                InterruptedException
Shows Channel.classLoadingCount.

Throws:
IOException
InterruptedException
Since:
1.495

getResourceLoadingCount

public int getResourceLoadingCount()
                            throws IOException,
                                   InterruptedException
Shows Channel.resourceLoadingCount.

Throws:
IOException
InterruptedException
Since:
1.495

getClassLoadingTime

public long getClassLoadingTime()
                         throws IOException,
                                InterruptedException
Shows Channel.classLoadingTime.

Throws:
IOException
InterruptedException
Since:
1.495

getResourceLoadingTime

public long getResourceLoadingTime()
                            throws IOException,
                                   InterruptedException
Shows Channel.resourceLoadingTime.

Throws:
IOException
InterruptedException
Since:
1.495

setChannel

public void setChannel(hudson.remoting.Channel channel,
                       OutputStream launchLog,
                       hudson.remoting.Channel.Listener listener)
                throws IOException,
                       InterruptedException
Sets up the connection through an exsting channel.

Throws:
IOException
InterruptedException
Since:
1.444

getChannel

public hudson.remoting.Channel getChannel()
Description copied from class: Computer
Gets the channel that can be used to run a program on this computer.

Specified by:
getChannel in class Computer
Returns:
never null when Computer.isOffline()==false.

getDefaultCharset

public Charset getDefaultCharset()
Description copied from class: Computer
Gets the default charset of this computer.

Specified by:
getDefaultCharset in class Computer
Returns:
never null when Computer.isOffline()==false.

getLogRecords

public List<LogRecord> getLogRecords()
                              throws IOException,
                                     InterruptedException
Description copied from class: Computer
Gets the logs recorded by this slave.

Specified by:
getLogRecords in class Computer
Throws:
IOException
InterruptedException

doDoDisconnect

public org.kohsuke.stapler.HttpResponse doDoDisconnect(@QueryParameter
                                                       String offlineMessage)
                                                throws IOException,
                                                       javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

disconnect

public Future<?> disconnect(OfflineCause cause)
Description copied from class: Computer
Disconnect this computer. If this is the master, no-op. This method may return immediately while the launch operation happens asynchronously.

Overrides:
disconnect in class Computer
Parameters:
cause - Object that identifies the reason the node was disconnected.
Returns:
Future to track the asynchronous disconnect operation.
See Also:
Computer.connect(boolean)

doLaunchSlaveAgent

public void doLaunchSlaveAgent(org.kohsuke.stapler.StaplerRequest req,
                               org.kohsuke.stapler.StaplerResponse rsp)
                        throws IOException,
                               javax.servlet.ServletException
Description copied from class: Computer
If Computer.getChannel()==null, attempts to relaunch the slave agent.

Specified by:
doLaunchSlaveAgent in class Computer
Throws:
IOException
javax.servlet.ServletException

tryReconnect

public void tryReconnect()

getJnlpJars

public Slave.JnlpJar getJnlpJars(String fileName)
Deprecated. since 2008-08-18. This URL binding is no longer used and moved up directly under to Jenkins, but it's left here for now just in case some old JNLP slave agents request it.

Serves jar files for JNLP slave agents.


doSlaveAgentJnlp

@WebMethod(name="slave-agent.jnlp")
public void doSlaveAgentJnlp(org.kohsuke.stapler.StaplerRequest req,
                                       org.kohsuke.stapler.StaplerResponse res)
                      throws IOException,
                             javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

kill

protected void kill()
Description copied from class: Computer
Called by Jenkins.updateComputerList() to notify Computer that it will be discarded.

Note that at this point Computer.getNode() returns null.

Overrides:
kill in class Computer
See Also:
Computer.onRemoved()

getRetentionStrategy

public RetentionStrategy getRetentionStrategy()
Description copied from class: Computer
RetentionStrategy associated with this computer.

Specified by:
getRetentionStrategy in class Computer
Returns:
never null. This method return RetentionStrategy<? super T> where T=this.getClass().

setNode

protected void setNode(Node node)
Description copied from class: Computer
Called to notify Computer that its corresponding Node configuration is updated.

Overrides:
setNode in class Computer

grabLauncher

protected ComputerLauncher grabLauncher(Node node)
Grabs a ComputerLauncher out of Node to keep it in this Computer. The returned launcher will be set to launcher and used to carry out the actual launch operation.

Subtypes that needs to decorate ComputerLauncher can do so by overriding this method. This is useful for SlaveComputers 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 Also:
ComputerLauncherFilter

getSlaveVersion

public String getSlaveVersion()
                       throws IOException,
                              InterruptedException
Get the slave version

Throws:
IOException
InterruptedException

getOSDescription

public String getOSDescription()
                        throws IOException,
                               InterruptedException
Get the OS description.

Throws:
IOException
InterruptedException

getChannelToMaster

public static hudson.remoting.VirtualChannel getChannelToMaster()
Obtains a 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.)

Returns:
null if the calling thread doesn't have any trace of where its master is.
Since:
1.362


Copyright © 2004-2013. All Rights Reserved.