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.

  • Constructor Details

    • AgentUsageRegistry

      public AgentUsageRegistry()
      The registry of Jenkins, which saves the usage in the home of Jenkins.
  • Method Details

    • get

      public static AgentUsageRegistry get()
    • acquire

      public AgentUsageRegistry.Acquired acquire(String node, int limit, Run<?,?> run)
      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

      public AgentUsageRegistry.Released release(Run<?,?> run, int limit)
      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 its limit (the one it has now; none means never).
    • nodeOf

      public String nodeOf(Run<?,?> run)
      The name of the agent the run is counted on, or null if it is not counted.
    • isCounted

      public boolean isCounted(Run<?,?> run)
    • count

      public int count(String node)
    • reset

      public void reset(String node)
      Starts the agent from nothing again, as if it were new. The runs counted on it keep counting on it.
    • forget

      public void forget(String node)
      The agent is gone, or a new one takes its name: forget it. The runs counted on it become stale.
    • rename

      public void rename(String from, String to)
      The agent was renamed: its usage and the runs counted on it go with it.
    • reconcile

      public void reconcile(String node, int limit)
      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

      public Map<String,Integer> snapshot()
      A copy of the usage of the agents that have any.
    • loadAtStartup

      @Initializer(after=SYSTEM_CONFIG_LOADED) public static void loadAtStartup()
      Takes the saved usage once the agents are known.
    • saveAtShutdown

      @Terminator public static void saveAtShutdown()
      Saves what is pending before Jenkins stops.