@ExportedBean public abstract class Computer extends Actionable implements AccessControlled, ExecutorListener
Executor
s.
Executor
s on one Computer
are transparently interchangeable
(that is the definition of Computer
).
This object is related to Node
but they have some significant differences.
Computer
primarily works as a holder of Executor
s, so
if a Node
is configured (probably temporarily) with 0 executors,
you won't have a Computer
object for it (except for the master node,
which always gets its Computer
in case we have no static executors and
we need to run a Queue.FlyweightTask
- see JENKINS-7291 for more discussion.)
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 (unlike Node
), and can be used along with
TransientComputerActionFactory
to add Action
s to Computer
s.
Modifier and Type | Class and Description |
---|---|
static class |
Computer.DisplayExecutor
A value class to provide a consistent snapshot view of the state of an executor to avoid race conditions
during rendering of the executors list.
|
static class |
Computer.TerminationRequest
Used to trace requests to terminate a computer.
|
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem
Modifier and Type | Field and Description |
---|---|
static Permission |
BUILD |
static Permission |
CONFIGURE |
static Permission |
CONNECT |
static Permission |
CREATE |
static Permission |
DELETE |
static Permission |
DISCONNECT |
static Permission |
EXTENDED_READ |
protected String |
nodeName
Node object may be created and deleted independently
from this object. |
protected OfflineCause |
offlineCause
Contains info about reason behind computer being offline.
|
static PermissionGroup |
PERMISSIONS |
protected Object |
statusChangeLock |
static ExecutorService |
threadPoolForRemoting |
protected List<Action> |
transientActions |
Modifier and Type | Method and Description |
---|---|
protected abstract Future<?> |
_connect(boolean forceReconnect)
Allows implementing-classes to provide an implementation for the connect method.
|
protected void |
_doScript(org.kohsuke.stapler.StaplerRequest req,
org.kohsuke.stapler.StaplerResponse rsp,
String view) |
void |
addAction(Action a)
Adds a new action.
|
EnvVars |
buildEnvironment(TaskListener listener)
Creates an environment variable override to be used for launching processes on this node.
|
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
Executor s 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
Executor s 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.
|
org.kohsuke.stapler.HttpResponse |
doChangeOfflineCause(String offlineMessage) |
void |
doConfigDotXml(org.kohsuke.stapler.StaplerRequest req,
org.kohsuke.stapler.StaplerResponse rsp)
Accepts config.xml submission, as well as serve it.
|
void |
doConfigSubmit(org.kohsuke.stapler.StaplerRequest req,
org.kohsuke.stapler.StaplerResponse rsp)
Accepts the update to the node configuration.
|
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 arbitrary Groovy script and return result as plain text.
|
org.kohsuke.stapler.HttpResponse |
doToggleOffline(String offlineMessage) |
ACL |
getACL()
Obtains the ACL associated with this object.
|
List<Action> |
getActions()
Returns the transient
Action s associated with the computer. |
Api |
getApi() |
RunList |
getBuilds() |
String |
getCaption() |
abstract hudson.remoting.VirtualChannel |
getChannel()
Gets the channel that can be used to run a program on this computer.
|
List<ComputerPanelBox> |
getComputerPanelBoxs()
Returns list of all boxes
ComputerPanelBox s. |
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.
|
List<Computer.DisplayExecutor> |
getDisplayExecutors()
Used to render the list of executors.
|
String |
getDisplayName() |
EnvVars |
getEnvironment()
Returns cached environment variables (copy to prevent modification) for 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
Executor s. |
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() |
String |
getIconClassName() |
long |
getIdleStartMilliseconds()
Returns the time when this computer last became idle.
|
LoadStatistics |
getLoadStatistics() |
String |
getLog()
Gets the string representation of the slave log.
|
protected File |
getLogDir()
Directory where rotated slave logs are stored.
|
File |
getLogFile()
This is where the log from the remote agent goes.
|
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
Executor s that are configured for this computer. |
OfflineCause |
getOfflineCause()
If the computer was offline (either temporarily or not),
this method will return the cause.
|
String |
getOfflineCauseReason()
If the computer was offline (either temporarily or not),
this method will return the cause as a string (without user info).
|
List<OneOffExecutor> |
getOneOffExecutors()
Gets the read-only snapshot view of all
OneOffExecutor s. |
abstract RetentionStrategy |
getRetentionStrategy()
RetentionStrategy associated with this 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.
|
List<Computer.TerminationRequest> |
getTerminatedBy()
Returns the list of captured termination requests for 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
Executor s. |
boolean |
isAcceptingTasks()
Returns
true if the computer is accepting tasks. |
protected boolean |
isAlive()
Returns true if any of the executors are active.
|
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 |
isPartiallyIdle()
Returns true if this computer has some idle executors that can take more workload.
|
boolean |
isTemporarilyOffline()
Deprecated.
You should almost always want
isOffline() .
This method is marked as deprecated to warn people when they
accidentally call this method. |
abstract 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. |
void |
launch()
Deprecated.
since 2009-01-06. Use
connect(boolean) |
protected void |
onRemoved()
Called by
Jenkins when this computer is removed. |
void |
recordTermination()
This method captures the information of a request to terminate a computer instance.
|
static void |
relocateOldLogs()
Relocate log files in the old location to the new location.
|
static Computer |
resolveForCLI(String name)
Used for CLI binding.
|
protected void |
setNode(Node node)
|
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 with some problems by an executor.
|
void |
updateByXml(InputStream source)
Updates Job by its XML definition.
|
void |
waitUntilOffline() |
void |
waitUntilOnline()
Blocks until the node becomes online/offline.
|
doContextMenu, getAction, getAction, getActions, getAllActions, getDynamic, replaceAction
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
protected volatile OfflineCause offlineCause
protected String nodeName
Node
object may be created and deleted independently
from this object.protected final Object statusChangeLock
public static final ExecutorService threadPoolForRemoting
public static final PermissionGroup PERMISSIONS
public static final Permission CONFIGURE
public static final Permission EXTENDED_READ
public static final Permission DELETE
public static final Permission CREATE
public static final Permission DISCONNECT
public static final Permission CONNECT
public static final Permission BUILD
public Computer(Node node)
public void recordTermination()
AbstractCloudSlave
and Nodes
. In general you should
not need to call this method directly, however if implementing a custom node type or a different path
for removing nodes, it may make sense to call this method in order to capture the originating request.public List<Computer.TerminationRequest> getTerminatedBy()
Executor
to provide details on why a Computer was removed in-between work being scheduled against the Executor
and the Executor
starting to execute the task.Executor.resetWorkUnit(String)
public List<ComputerPanelBox> getComputerPanelBoxs()
ComputerPanelBox
s.public List<Action> getActions()
Action
s associated with the computer.getActions
in class Actionable
public void addAction(Action a)
Actionable
getActions().add(a)
.addAction
in class Actionable
@Nonnull public File getLogFile()
#getLogDir(), #relocateOldLogs()
@Nonnull protected File getLogDir()
public WorkspaceList getWorkspaceList()
public String getLog() throws IOException
IOException
public AnnotatedLargeText<Computer> getLogText()
AnnotatedLargeText
.public ACL getACL()
AccessControlled
getACL
in interface AccessControlled
public void checkPermission(Permission permission)
AccessControlled
getACL().checkPermission(permission)
checkPermission
in interface AccessControlled
public boolean hasPermission(Permission permission)
AccessControlled
getACL().hasPermission(permission)
hasPermission
in interface AccessControlled
@Exported public OfflineCause getOfflineCause()
@Exported public String getOfflineCauseReason()
@Nullable public abstract hudson.remoting.VirtualChannel getChannel()
isOffline()
==false.public abstract Charset getDefaultCharset()
isOffline()
==false.public abstract List<LogRecord> getLogRecords() throws IOException, InterruptedException
IOException
InterruptedException
public abstract void doLaunchSlaveAgent(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
getChannel()
==null, attempts to relaunch the slave agent.IOException
javax.servlet.ServletException
@Deprecated public final void launch()
connect(boolean)
public final Future<?> connect(boolean forceReconnect)
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.
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.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.)disconnect()
protected abstract Future<?> _connect(boolean forceReconnect)
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.
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.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.)disconnect()
@CLIMethod(name="connect-node") public void cliConnect(boolean force) throws ExecutionException, InterruptedException
public final long getConnectTime()
public Future<?> disconnect(OfflineCause cause)
cause
- Object that identifies the reason the node was disconnected.Future
to track the asynchronous disconnect operation.connect(boolean)
@Deprecated public Future<?> disconnect()
disconnect(OfflineCause)
and specify the cause.disconnect(null)
@CLIMethod(name="disconnect-node") public void cliDisconnect(String cause) throws ExecutionException, InterruptedException
@CLIMethod(name="offline-node") public void cliOffline(String cause) throws ExecutionException, InterruptedException
public void cliOnline() throws ExecutionException, InterruptedException
@Exported public int getNumExecutors()
@Nonnull public String getName()
the name of the node
.@CheckForNull public abstract Boolean isUnix()
@CheckForNull public Node getNode()
Node
that this computer represents.Computer
is not yet gone.@Exported public LoadStatistics getLoadStatistics()
public BuildTimelineWidget getTimeline()
public void taskAccepted(Executor executor, Queue.Task task)
taskAccepted
in interface ExecutorListener
executor
- The executor.task
- The task.public void taskCompleted(Executor executor, Queue.Task task, long durationMS)
taskCompleted
in interface ExecutorListener
executor
- The executor.task
- The task.durationMS
- The number of milliseconds that the task took to complete.public void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems)
taskCompletedWithProblems
in interface ExecutorListener
executor
- The executor.task
- The task.durationMS
- The number of milliseconds that the task took to complete.problems
- The exception that was thrown.@Exported public boolean isOffline()
public final boolean isOnline()
@Exported public boolean isManualLaunchAllowed()
true
if manual launching of the slave is allowed at this point in time.public abstract boolean isConnecting()
connect(boolean)
operation in progress?@Exported @Deprecated public boolean isJnlpAgent()
@Exported public boolean isLaunchSupported()
For example, JNLP slaves return false
from this, because the launch process
needs to be initiated from the slave side.
@Exported @Deprecated public boolean isTemporarilyOffline()
isOffline()
.
This method is marked as deprecated to warn people when they
accidentally call this method.
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.
@Deprecated public void setTemporarilyOffline(boolean temporarilyOffline)
setTemporarilyOffline(boolean, OfflineCause)
public void setTemporarilyOffline(boolean temporarilyOffline, OfflineCause cause)
Channel
connection, but prevent builds from executing.cause
- If the first argument is true, specify the reason why the node is being put
offline.@Exported public String getIcon()
@Exported public String getIconClassName()
public String getIconAltText()
@Exported @Nonnull public String getDisplayName()
getDisplayName
in interface ModelObject
public String getCaption()
public String getUrl()
public List<AbstractProject> getTiedJobs()
public RunList getBuilds()
protected void setNode(Node node)
protected void kill()
Jenkins.updateComputerList()
to notify Computer
that it will be discarded.
Note that at this point getNode()
returns null.
onRemoved()
protected void onRemoved()
Jenkins
when this computer is removed.
This happens when list of nodes are updated (for example by Jenkins.setNodes(List)
and
the computer becomes redundant. Such Computer
s get killed, then
after all its executors are finished, this method is called.
Note that at this point getNode()
returns null.
kill()
public int countIdle()
Executor
s that can start working immediately.public final int countBusy()
Executor
s that are doing some work right now.public final int countExecutors()
getNumExecutors()
if there
are busy tasks when the configured size is decreased. OneOffExecutors are
not included in this count.@Exported public List<Executor> getExecutors()
Executor
s.@Exported public List<OneOffExecutor> getOneOffExecutors()
OneOffExecutor
s.@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public List<Computer.DisplayExecutor> getDisplayExecutors()
@Exported public final boolean isIdle()
public final boolean isPartiallyIdle()
public final long getIdleStartMilliseconds()
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.
public final long getDemandStartMilliseconds()
protected boolean isAlive()
executors
until
the administrator yanks it out, so that we can see why it died.public void interrupt()
Executor
s.
Called from Jenkins.cleanUp()
.public String getSearchUrl()
SearchItem
SearchItem
.getSearchUrl
in interface SearchItem
public abstract RetentionStrategy getRetentionStrategy()
RetentionStrategy
associated with this computer.RetentionStrategy<? super T>
where
T=this.getClass()
.@Exported(inline=true) public Map<String,Object> getMonitorData()
public Map<Object,Object> getSystemProperties() throws IOException, InterruptedException
IOException
InterruptedException
@Deprecated public Map<String,String> getEnvVars() throws IOException, InterruptedException
getEnvironment()
instead.IOException
InterruptedException
public EnvVars getEnvironment() throws IOException, InterruptedException
IOException
InterruptedException
@Nonnull public EnvVars buildEnvironment(@Nonnull TaskListener listener) throws IOException, InterruptedException
IOException
InterruptedException
Launcher.ProcStarter.envs(Map)
public Map<String,String> getThreadDump() throws IOException, InterruptedException
IOException
InterruptedException
public RemotingDiagnostics.HeapDump getHeapDump() throws IOException
IOException
public String getHostName() throws IOException, InterruptedException
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.
IOException
InterruptedException
public void doRssAll(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void doRssFailed(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public org.kohsuke.stapler.HttpResponse doToggleOffline(@QueryParameter String offlineMessage) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public org.kohsuke.stapler.HttpResponse doChangeOfflineCause(@QueryParameter String offlineMessage) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public Api getApi()
public void doDumpExportTable(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException, InterruptedException
IOException
javax.servlet.ServletException
InterruptedException
public void doScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void doScriptText(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
protected void _doScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String view) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void doConfigSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException, Descriptor.FormException
IOException
javax.servlet.ServletException
Descriptor.FormException
@WebMethod(name="config.xml") public void doConfigDotXml(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void updateByXml(InputStream source) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public org.kohsuke.stapler.HttpResponse doDoDelete() throws IOException
IOException
@CLIMethod(name="wait-node-online") public void waitUntilOnline() throws InterruptedException
InterruptedException
@CLIMethod(name="wait-node-offline") public void waitUntilOffline() throws InterruptedException
InterruptedException
public void doProgressiveLog(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
IOException
@Nullable public static Computer currentComputer()
Computer
that the build is running.
This method only works when called during a build, such as by
Publisher
, BuildWrapper
, etc.Computer
associated with Executor.currentExecutor()
, or (consistently as of 1.591) null if not on an executor thread@OverrideMustInvoke(value=ANYTIME) public boolean isAcceptingTasks()
true
if the computer is accepting tasks. Needed to allow slaves programmatic suspension of task
scheduling that does not overlap with being offline.true
if the computer is accepting tasksRetentionStrategy.isAcceptingTasks(Computer)
,
Node.isAcceptingTasks()
@CLIResolver public static Computer resolveForCLI(String name) throws org.kohsuke.args4j.CmdLineException
org.kohsuke.args4j.CmdLineException
@Initializer public static void relocateOldLogs()
getLogFile()
Copyright © 2016. All rights reserved.