Package org.jenkinsci.plugins.vsphere
Class AgentUsageRegistry
java.lang.Object
org.jenkinsci.plugins.vsphere.AgentUsageRegistry
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
@Extension
public final class AgentUsageRegistry
extends Object
Owns how many "limited builds" each vSphere agent has done, so that the agent can be recycled once it reaches its
limit. All the agents of all the clouds share this one registry, which is keyed by the name of the agent (Jenkins
keeps those unique).
An agent that is replaced when its configuration is saved keeps its usage; one that is deleted, or created anew with a name that was used before, starts from nothing. What a run is counted against is remembered per entry, not per name, so a run that was counted on an agent that has since been replaced by a different one of the same name does not recycle the new one.
The state is kept in memory under one lock, which is never held while Jenkins is called (to find out whether a run is still building, for instance), so it is safe to use from the threads of any build. Recycling an agent is up to the caller, outside of that lock.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe outcome and the usage of the agent right after.static enumWhat happened when a run asked to be counted.static enumHow the recycling of an agent ended.static final classThe recycling of an agent that is under way, which only one thing at a time can do.static enumWhat happened when a run that may have been counted was over. -
Constructor Summary
ConstructorsConstructorDescriptionThe registry of Jenkins, which saves the usage in the home of Jenkins. -
Method Summary
Modifier and TypeMethodDescriptionCounts the run against the agent, unless the agent has no limit, the run is over, it is counted already or the agent is at its limit.booleancompleteRecycle(String node, AgentUsageRegistry.RecycleOutcome outcome) Says how the recycling of the agent went.intcountedRunIds(String node) The ids of the runs counted on the agent that have not ended.voidendRecycle(AgentUsageRegistry.RecycleToken token, boolean reset) The recycling is over.voidThe agent is gone, or a new one takes its name: forget it.static AgentUsageRegistryget()booleanholdsCountedRuns(String node) Some run counted on the agent has not ended.booleanisAwaitingDisconnect(String node) The agent is being recycled and the disconnect has not said yet how it went.booleanbooleanbooleanisCountedOn(String runId, String node) The run is counted on the agent as it is now, not on an earlier one of the same name.booleanisRecycling(String node) booleanisRetiring(String node, int limit) The agent has used all itslimituses (none means never).static voidTakes the saved usage once the agents are known.The name of the agent the run is counted on, or null if it is not counted.intprojectedCount(String node, Collection<String> busyRunIds) How many uses the agent will have once the work it was handed has started: what it has, and one for each run among thebusyRunIdsthat is not counted anywhere yet.static voidOnce the builds are loaded, the runs that were saved as counted and are not building are forgotten.voidForgets the counted runs that are not building any more, which did not get to say they were over.voidThe limit of the agent may have changed.The run is over: it is not counted as using its agent any more, which keeps the use it was counted for.Asrelease(Run), with the run known by its id.voidThe agent was renamed: its usage and the runs counted on it go with it.voidStarts the agent from nothing again, as if it were new.static voidSaves what is pending before Jenkins stops.snapshot()A copy of the usage of the agents that have any.tryBeginRecycle(String node, int limit) Takes the recycling of the agent, if it is due: it has used all itslimituses, no run counted on it is still using it, and it is not being recycled already.
-
Constructor Details
-
AgentUsageRegistry
public AgentUsageRegistry()The registry of Jenkins, which saves the usage in the home of Jenkins.
-
-
Method Details
-
get
-
acquire
Counts the run against the agent, unless the agent has no limit, the run is over, it is counted already or the agent is at its limit. -
release
The run is over: it is not counted as using its agent any more, which keeps the use it was counted for. -
release
Asrelease(Run), with the run known by its id. -
isRetiring
The agent has used all itslimituses (none means never). Whether it is busy is another matter. -
holdsCountedRuns
Some run counted on the agent has not ended. -
tryBeginRecycle
Takes the recycling of the agent, if it is due: it has used all itslimituses, no run counted on it is still using it, and it is not being recycled already. Null if not. The caller has to end it withendRecycle(org.jenkinsci.plugins.vsphere.AgentUsageRegistry.RecycleToken, boolean). -
countedRunIds
The ids of the runs counted on the agent that have not ended. -
isCountedOn
The run is counted on the agent as it is now, not on an earlier one of the same name. -
projectedCount
How many uses the agent will have once the work it was handed has started: what it has, and one for each run among thebusyRunIdsthat is not counted anywhere yet. A null is work that is not known to be of any run, which has to be taken as a use of its own. -
isRecycling
-
isAwaitingDisconnect
The agent is being recycled and the disconnect has not said yet how it went. -
completeRecycle
Says how the recycling of the agent went. Only the first to say it counts, so it may be said any number of times. The recycling goes on untilendRecycle(org.jenkinsci.plugins.vsphere.AgentUsageRegistry.RecycleToken, boolean). Returns whether this was the first. -
endRecycle
The recycling is over. If itreset, the agent starts from nothing again, unless it was replaced in the meantime by a different one of the same name. -
nodeOf
The name of the agent the run is counted on, or null if it is not counted. -
isCounted
-
isCounted
-
count
-
reset
Starts the agent from nothing again, as if it were new. The runs counted on it keep counting on it. -
forget
The agent is gone, or a new one takes its name: forget it. The runs counted on it become stale. -
rename
The agent was renamed: its usage and the runs counted on it go with it. -
reconcile
The limit of the agent may have changed. With no limit there is nothing to remember. An agent that is at or over its new limit keeps its count: it is recycled once nothing is using it. -
snapshot
A copy of the usage of the agents that have any. -
loadAtStartup
Takes the saved usage once the agents are known. -
pruneAtStartup
Once the builds are loaded, the runs that were saved as counted and are not building are forgotten. A Pipeline that has not been resumed yet is building, as far as its run is concerned, so it is kept. -
pruneFinishedRuns
public void pruneFinishedRuns()Forgets the counted runs that are not building any more, which did not get to say they were over. -
saveAtShutdown
Saves what is pending before Jenkins stops.
-