hudson.model
Class Computer

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

@ExportedBean
public abstract class Computer
extends Actionable
implements AccessControlled, ExecutorListener

Represents the running state of a remote computer that holds Executors.

Executors on one Computer are transparently interchangeable (that is the definition of Computer.)

This object is related to Node but they have some significant difference. Computer primarily works as a holder of Executors, so if a Node is configured (probably temporarily) with 0 executors, you won't have a Computer object for it. Also, even if you remove a Node, it takes time for the corresponding Computer to be removed, if some builds are already in progress on that node. Or when the node configuration is changed, unaffected Computer object remains intact, while all the Node objects will go away.

This object also serves UI (since Node is an interface and can't have related side pages.)

Author:
Kohsuke Kawaguchi

Field Summary
static Permission CONFIGURE
          Permission to configure slaves.
static Permission DELETE
           
static PermissionGroup PERMISSIONS
           
static ExecutorService threadPoolForRemoting
           
 
Constructor Summary
Computer(Node node)
           
 
Method Summary
 void checkPermission(Permission permission)
          Convenient short-cut for getACL().checkPermission(permission)
 void cliConnect(boolean force)
          CLI command to reconnect this node.
 void cliDisconnect(String cause)
          CLI command to disconnects this node.
 void cliOffline(String cause)
          CLI command to mark the node offline.
 void cliOnline()
           
 Future<?> connect(boolean forceReconnect)
          Do the same as doLaunchSlaveAgent(StaplerRequest, StaplerResponse) but outside the context of serving a request.
 int countBusy()
          Returns the number of Executors that are doing some work right now.
 int countExecutors()
          Returns the current size of the executor pool for this computer.
 int countIdle()
          Returns the number of idle Executors that can start working immediately.
static Computer currentComputer()
          Gets the current Computer that the build is running.
 Future<?> disconnect()
          Deprecated. as of 1.320. Use disconnect(OfflineCause) and specify the cause.
 Future<?> disconnect(OfflineCause cause)
          Disconnect this computer.
 void doConfigSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Accepts the update to the node configuration.
 org.kohsuke.stapler.HttpResponse doDeleteWithParam(org.kohsuke.stapler.StaplerRequest req)
          Delete the slave.
 org.kohsuke.stapler.HttpResponse doDoDelete()
          Really deletes the slave.
 void doDumpExportTable(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Dumps the contents of the export table.
abstract  void doLaunchSlaveAgent(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          If getChannel()==null, attempts to relaunch the slave agent.
 void doProgressiveLog(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Handles incremental log.
 void doRssAll(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
           
 void doRssFailed(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
           
 void doScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          For system diagnostics.
 void doScriptText(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Run the arbitrary script and return result as plain text.
 org.kohsuke.stapler.HttpResponse doToggleOffline(String offlineMessage)
           
 ACL getACL()
          Obtains the ACL associated with this object.
 Api getApi()
           
 RunList getBuilds()
           
 int getBusyCount()
           
 String getCaption()
           
abstract  hudson.remoting.VirtualChannel getChannel()
          Gets the channel that can be used to run a program on this computer.
 long getConnectTime()
          Gets the time (since epoch) when this computer connected.
abstract  Charset getDefaultCharset()
          Gets the default charset of this computer.
 long getDemandStartMilliseconds()
          Returns the time when this computer first became in demand.
 String getDisplayName()
           
 EnvVars getEnvironment()
          Gets the environment variables of the JVM on this computer.
 Map<String,String> getEnvVars()
          Deprecated. as of 1.292 Use getEnvironment() instead.
 List<Executor> getExecutors()
          Gets the read-only snapshot view of all Executors.
 int getExecutorsCount()
           
 RemotingDiagnostics.HeapDump getHeapDump()
          Obtains the heap dump.
 String getHostName()
          This method tries to compute the name of the host that's reachable by all the other nodes.
 String getIcon()
           
 String getIconAltText()
           
 int getIdleCount()
           
 long getIdleStartMilliseconds()
          Returns the time when this computer last became idle.
 LoadStatistics getLoadStatistics()
           
 String getLog()
          Gets the string representation of the slave log.
abstract  List<LogRecord> getLogRecords()
          Gets the logs recorded by this slave.
 AnnotatedLargeText<Computer> getLogText()
          Used to URL-bind AnnotatedLargeText.
 Map<String,Object> getMonitorData()
          Expose monitoring data for the remote API.
 String getName()
          Returns the name of the node.
 Node getNode()
          Returns the Node that this computer represents.
 int getNumExecutors()
          Number of Executors that are configured for this computer.
 OfflineCause getOfflineCause()
          If the computer was offline (either temporarily or not), this method will return the cause.
 List<OneOffExecutor> getOneOffExecutors()
          Gets the read-only snapshot view of all OneOffExecutors.
 int getOneOffExecutorsCount()
           
abstract  RetentionStrategy getRetentionStrategy()
          RetentionStrategy associated with this computer.
 List<AbstractProject> getRunningJobs()
          Returns jobs that running on current computer.
 String getSearchUrl()
          Returns the URL of this item relative to the parent SearchItem.
 Map<Object,Object> getSystemProperties()
          Gets the system properties of the JVM on this computer.
 Map<String,String> getThreadDump()
          Gets the thread dump of the slave JVM.
 List<AbstractProject> getTiedJobs()
          Returns projects that are tied on this node.
 BuildTimelineWidget getTimeline()
           
 String getUrl()
           
 WorkspaceList getWorkspaceList()
          Gets the object that coordinates the workspace allocation on this computer.
 boolean hasPermission(Permission permission)
          Convenient short-cut for getACL().hasPermission(permission)
 void interrupt()
          Interrupt all Executors.
 boolean isAcceptingTasks()
          Returns true if the computer is accepting tasks.
abstract  boolean isConnecting()
          Is a connect(boolean) operation in progress?
 boolean isIdle()
          Returns true if all the executors of this computer are idle.
 boolean isJnlpAgent()
          Deprecated. since 2008-05-18. See isLaunchSupported() and ComputerLauncher
 boolean isLaunchSupported()
          Returns true if this computer can be launched by Hudson proactively and automatically.
 boolean isManualLaunchAllowed()
          This method is called to determine whether manual launching of the slave is allowed at this point in time.
 boolean isOffline()
           
 boolean isOnline()
           
 boolean isTemporarilyOffline()
          Deprecated. You should almost always want isOffline(). This method is marked as deprecated to warn people when they accidentally call this method.
 void launch()
          Deprecated. since 2009-01-06. Use connect(boolean)
 void setTemporarilyOffline(boolean temporarilyOffline)
          Deprecated. as of 1.320. Use setTemporarilyOffline(boolean, OfflineCause)
 void setTemporarilyOffline(boolean temporarilyOffline, OfflineCause cause)
          Marks the computer as temporarily offline.
 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.
 
Methods inherited from class hudson.model.Actionable
addAction, getAction, getAction, getActions, getActions, getDynamic
 
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadPoolForRemoting

public static final ExecutorService threadPoolForRemoting

PERMISSIONS

public static final PermissionGroup PERMISSIONS

CONFIGURE

public static final Permission CONFIGURE
Permission to configure slaves.


DELETE

public static final Permission DELETE
Constructor Detail

Computer

public Computer(Node node)
Method Detail

getWorkspaceList

public WorkspaceList getWorkspaceList()
Gets the object that coordinates the workspace allocation on this computer.


getLog

public String getLog()
              throws IOException
Gets the string representation of the slave log.

Throws:
IOException

getLogText

public AnnotatedLargeText<Computer> getLogText()
Used to URL-bind AnnotatedLargeText.


getACL

public ACL getACL()
Description copied from interface: AccessControlled
Obtains the ACL associated with this object.

Specified by:
getACL in interface AccessControlled
Returns:
never null.

checkPermission

public void checkPermission(Permission permission)
Description copied from interface: AccessControlled
Convenient short-cut for getACL().checkPermission(permission)

Specified by:
checkPermission in interface AccessControlled

hasPermission

public boolean hasPermission(Permission permission)
Description copied from interface: AccessControlled
Convenient short-cut for getACL().hasPermission(permission)

Specified by:
hasPermission in interface AccessControlled

getOfflineCause

@Exported
public OfflineCause getOfflineCause()
If the computer was offline (either temporarily or not), this method will return the cause.

Returns:
null if the system was put offline without given a cause.

getChannel

public abstract hudson.remoting.VirtualChannel getChannel()
Gets the channel that can be used to run a program on this computer.

Returns:
never null when isOffline()==false.

getDefaultCharset

public abstract Charset getDefaultCharset()
Gets the default charset of this computer.

Returns:
never null when isOffline()==false.

getLogRecords

public abstract List<LogRecord> getLogRecords()
                                       throws IOException,
                                              InterruptedException
Gets the logs recorded by this slave.

Throws:
IOException
InterruptedException

doLaunchSlaveAgent

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

Throws:
IOException
javax.servlet.ServletException

launch

public final void launch()
Deprecated. since 2009-01-06. Use connect(boolean)


connect

public final Future<?> connect(boolean forceReconnect)
Do the same as doLaunchSlaveAgent(StaplerRequest, StaplerResponse) but outside the context of serving a request.

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.

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:
disconnect()

cliConnect

@CLIMethod(name="connect-node")
public void cliConnect(boolean force)
                throws ExecutionException,
                       InterruptedException
CLI command to reconnect this node.

Throws:
ExecutionException
InterruptedException

getConnectTime

public final long getConnectTime()
Gets the time (since epoch) when this computer connected.

Returns:
The time in ms since epoch when this computer last connected.

disconnect

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

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

disconnect

public Future<?> disconnect()
Deprecated. as of 1.320. Use disconnect(OfflineCause) and specify the cause.

Equivalent to disconnect(null)


cliDisconnect

@CLIMethod(name="disconnect-node")
public void cliDisconnect(String cause)
                   throws ExecutionException,
                          InterruptedException
CLI command to disconnects this node.

Throws:
ExecutionException
InterruptedException

cliOffline

@CLIMethod(name="offline-node")
public void cliOffline(String cause)
                throws ExecutionException,
                       InterruptedException
CLI command to mark the node offline.

Throws:
ExecutionException
InterruptedException

cliOnline

@CLIMethod(name="online-node")
public void cliOnline()
               throws ExecutionException,
                      InterruptedException
Throws:
ExecutionException
InterruptedException

getNumExecutors

@Exported
public int getNumExecutors()
Number of Executors that are configured for this computer.

When this value is decreased, it is temporarily possible for executors to have a larger number than this.


getName

public String getName()
Returns the name of the node.


getNode

public Node getNode()
Returns the Node that this computer represents.

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

getLoadStatistics

@Exported
public LoadStatistics getLoadStatistics()

getTimeline

public BuildTimelineWidget getTimeline()

taskAccepted

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

Specified by:
taskAccepted in interface ExecutorListener
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
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
Parameters:
executor - The executor.
task - The task.
durationMS - The number of milliseconds that the task took to complete.
problems - The exception that was thrown.

isOffline

@Exported
public boolean isOffline()

isOnline

public final boolean isOnline()

isManualLaunchAllowed

@Exported
public boolean isManualLaunchAllowed()
This method is called to determine whether manual launching of the slave is allowed at this point in time.

Returns:
true if manual launching of the slave is allowed at this point in time.

isConnecting

public abstract boolean isConnecting()
Is a connect(boolean) operation in progress?


isJnlpAgent

@Exported
@Deprecated
public boolean isJnlpAgent()
Deprecated. since 2008-05-18. See isLaunchSupported() and ComputerLauncher

Returns true if this computer is supposed to be launched via JNLP.


isLaunchSupported

@Exported
public boolean isLaunchSupported()
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.


isTemporarilyOffline

@Exported
public boolean isTemporarilyOffline()
Deprecated. You should almost always want isOffline(). This method is marked as deprecated to warn people when they accidentally call this method.

Returns true if this node is marked temporarily offline by the user.

In contrast, isOffline() represents the actual online/offline state. For example, this method may return false while isOffline() returns true if the slave agent failed to launch.


setTemporarilyOffline

public void setTemporarilyOffline(boolean temporarilyOffline)
Deprecated. as of 1.320. Use setTemporarilyOffline(boolean, OfflineCause)


setTemporarilyOffline

public void setTemporarilyOffline(boolean temporarilyOffline,
                                  OfflineCause cause)
Marks the computer as temporarily offline. This retains the underlying Channel connection, but prevent builds from executing.

Parameters:
cause - If the first argument is true, specify the reason why the node is being put offline.

getIcon

@Exported
public String getIcon()

getIconAltText

public String getIconAltText()

getDisplayName

@Exported
public String getDisplayName()
Specified by:
getDisplayName in interface ModelObject

getCaption

public String getCaption()

getUrl

public String getUrl()

getTiedJobs

public List<AbstractProject> getTiedJobs()
Returns projects that are tied on this node.


getBuilds

public RunList getBuilds()

getRunningJobs

@Exported
public List<AbstractProject> getRunningJobs()
Returns jobs that running on current computer.

Returns:
List.

getIdleCount

public int getIdleCount()
Since:
2.1.0

countIdle

public int countIdle()
Returns the number of idle Executors that can start working immediately.


countBusy

public final int countBusy()
Returns the number of Executors that are doing some work right now.


getBusyCount

public int getBusyCount()
Since:
2.1.0

countExecutors

public final int countExecutors()
Returns the current size of the executor pool for this computer. This number may temporarily differ from getNumExecutors() if there are busy tasks when the configured size is decreased. OneOffExecutors are not included in this count.


getExecutorsCount

public int getExecutorsCount()
Since:
2.1.0

getOneOffExecutorsCount

public int getOneOffExecutorsCount()
Since:
2.1.0

getExecutors

@Exported
public List<Executor> getExecutors()
Gets the read-only snapshot view of all Executors.


getOneOffExecutors

@Exported
public List<OneOffExecutor> getOneOffExecutors()
Gets the read-only snapshot view of all OneOffExecutors.


isIdle

@Exported
public final boolean isIdle()
Returns true if all the executors of this computer are idle.


getIdleStartMilliseconds

public final long getIdleStartMilliseconds()
Returns the time when this computer last became idle.

If this computer is already idle, the return value will point to the time in the past since when this computer has been idle.

If this computer is busy, the return value will point to the time in the future where this computer will be expected to become free.


getDemandStartMilliseconds

public final long getDemandStartMilliseconds()
Returns the time when this computer first became in demand.


interrupt

public void interrupt()
Interrupt all Executors.


getSearchUrl

public String getSearchUrl()
Description copied from interface: SearchItem
Returns the URL of this item relative to the parent SearchItem.

Specified by:
getSearchUrl in interface SearchItem
Returns:
URL like "foo" or "foo/bar". The path can end with '/'. The path that starts with '/' will be interpreted as the absolute path (within the context path of Hudson.)

getRetentionStrategy

public abstract RetentionStrategy getRetentionStrategy()
RetentionStrategy associated with this computer.

Returns:
never null. This method return RetentionStrategy<? super T> where T=this.getClass().

getMonitorData

@Exported(inline=true)
public Map<String,Object> getMonitorData()
Expose monitoring data for the remote API.


getSystemProperties

public Map<Object,Object> getSystemProperties()
                                       throws IOException,
                                              InterruptedException
Gets the system properties of the JVM on this computer. If this is the master, it returns the system property of the master computer.

Throws:
IOException
InterruptedException

getEnvVars

public Map<String,String> getEnvVars()
                              throws IOException,
                                     InterruptedException
Deprecated. as of 1.292 Use getEnvironment() instead.

Throws:
IOException
InterruptedException

getEnvironment

public EnvVars getEnvironment()
                       throws IOException,
                              InterruptedException
Gets the environment variables of the JVM on this computer. If this is the master, it returns the system property of the master computer.

Throws:
IOException
InterruptedException

getThreadDump

public Map<String,String> getThreadDump()
                                 throws IOException,
                                        InterruptedException
Gets the thread dump of the slave JVM.

Returns:
key is the thread name, and the value is the pre-formatted dump.
Throws:
IOException
InterruptedException

getHeapDump

public RemotingDiagnostics.HeapDump getHeapDump()
                                         throws IOException
Obtains the heap dump.

Throws:
IOException

getHostName

public String getHostName()
                   throws IOException,
                          InterruptedException
This method tries to compute the name of the host that's reachable by all the other nodes.

Since it's possible that the slave is not reachable from the master (it may be behind a firewall, connecting to master via JNLP), this method may return null. It's surprisingly tricky for a machine to know a name that other systems can get to, especially between things like DNS search suffix, the hosts file, and YP.

So the technique here is to compute possible interfaces and names on the slave, then try to ping them from the master, and pick the one that worked.

The computation may take some time, so it employs caching to make the successive lookups faster.

Returns:
null if the host name cannot be computed (for example because this computer is offline, because the slave is behind the firewall, etc.)
Throws:
IOException
InterruptedException
Since:
1.300

doRssAll

public void doRssAll(org.kohsuke.stapler.StaplerRequest req,
                     org.kohsuke.stapler.StaplerResponse rsp)
              throws IOException,
                     javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

doRssFailed

public void doRssFailed(org.kohsuke.stapler.StaplerRequest req,
                        org.kohsuke.stapler.StaplerResponse rsp)
                 throws IOException,
                        javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

doToggleOffline

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

getApi

public Api getApi()

doDumpExportTable

public void doDumpExportTable(org.kohsuke.stapler.StaplerRequest req,
                              org.kohsuke.stapler.StaplerResponse rsp)
                       throws IOException,
                              javax.servlet.ServletException,
                              InterruptedException
Dumps the contents of the export table.

Throws:
IOException
javax.servlet.ServletException
InterruptedException

doScript

public void doScript(org.kohsuke.stapler.StaplerRequest req,
                     org.kohsuke.stapler.StaplerResponse rsp)
              throws IOException,
                     javax.servlet.ServletException
For system diagnostics. Run arbitrary script.

Throws:
IOException
javax.servlet.ServletException

doScriptText

public void doScriptText(org.kohsuke.stapler.StaplerRequest req,
                         org.kohsuke.stapler.StaplerResponse rsp)
                  throws IOException,
                         javax.servlet.ServletException
Run the arbitrary script and return result as plain text.

Throws:
IOException
javax.servlet.ServletException

doConfigSubmit

public void doConfigSubmit(org.kohsuke.stapler.StaplerRequest req,
                           org.kohsuke.stapler.StaplerResponse rsp)
                    throws IOException,
                           javax.servlet.ServletException,
                           Descriptor.FormException
Accepts the update to the node configuration.

Throws:
IOException
javax.servlet.ServletException
Descriptor.FormException

doDoDelete

@CLIMethod(name="delete-node")
public org.kohsuke.stapler.HttpResponse doDoDelete()
                                            throws IOException
Really deletes the slave.

Throws:
IOException

doDeleteWithParam

public org.kohsuke.stapler.HttpResponse doDeleteWithParam(org.kohsuke.stapler.StaplerRequest req)
                                                   throws IOException,
                                                          javax.servlet.ServletException
Delete the slave. If request have parameter 'deleteMode' than deleting performs in according with this parameter.

Parameters:
req - StaplerRequest
Returns:
HttpResponse
Throws:
IOException - if any.
javax.servlet.ServletException - if any.

doProgressiveLog

public void doProgressiveLog(org.kohsuke.stapler.StaplerRequest req,
                             org.kohsuke.stapler.StaplerResponse rsp)
                      throws IOException
Handles incremental log.

Throws:
IOException

currentComputer

public static Computer currentComputer()
Gets the current Computer that the build is running. This method only works when called during a build, such as by Publisher, BuildWrapper, etc.


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.

Returns:
true if the computer is accepting tasks


Copyright © 2004-2013 Hudson. All Rights Reserved.