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.
Everything here happens in memory under one lock and calls nothing back into Jenkins, 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 enumWhat to do when a run that may have been counted is 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.intvoidThe agent is gone, or a new one takes its name: forget it.static AgentUsageRegistryget()booleanstatic 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.voidThe limit of the agent may have changed.The run is over.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.
-
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. Only a run that was counted can make its agent be recycled, and only if that agent is still the one it was counted on and has reached itslimit(the one it has now; none means never). -
nodeOf
The name of the agent the run is counted on, or null if it is not counted. -
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 at or over its limit with no run using it would never be recycled, so it starts again (one that has runs using it is recycled when the first of them to end finds it at its limit). -
snapshot
A copy of the usage of the agents that have any. -
loadAtStartup
Takes the saved usage once the agents are known. -
saveAtShutdown
Saves what is pending before Jenkins stops.
-