Class AgentRecycler

java.lang.Object
org.jenkinsci.plugins.vsphere.AgentRecycler

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @Extension public final class AgentRecycler extends Object
Recycles the agents that have used all the builds they are allowed, once nothing is using them: disconnects them, which does to their machines what the agents are set to do when idle, and starts their count again when that is done.

An agent is looked at soon after a run that was counted on it ends, and all of them every minute. An agent that is not online, or was taken offline by someone else, is left alone. A recycle that does not work is tried again later, further and further apart, and the agent is left at its limit meanwhile.

  • Constructor Details

    • AgentRecycler

      public AgentRecycler()
  • Method Details

    • get

      public static AgentRecycler get()
    • setClock

      public void setClock(LongSupplier clock)
      For tests only.
    • setCheckDelayMs

      public void setCheckDelayMs(long checkDelayMs)
      For tests only.
    • scheduleCheck

      public void scheduleCheck(String node)
      Looks at the agent soon: it may have just become free.
    • sweepOnce

      public Set<String> sweepOnce()
      Looks at every vSphere agent and starts recycling those that are due. Returns their names.
    • check

      public boolean check(String name)
      Starts recycling the agent if it is due, and says whether it did. The recycling itself is done on another thread.

      The agent is marked offline here, once it is known to be free, and not when it reaches its limit. Until then UsageGate keeps new work away from it and lets through what a run counted on it needs, such as the next node {} blocks of a Pipeline; the queue does not offer work to an offline agent, so the run would wait for an agent that waits for the run to end. Every change of the mark also saves the configuration of the node. From the moment the recycle is taken (under the lock of the queue) UsageGate refuses everything, so the agent is not offered work in the time before it is marked.

    • isRecycling

      public static boolean isRecycling(String node)
      Whether the recycle of the agent has not ended.
    • isAwaitingDisconnect

      public static boolean isAwaitingDisconnect(String node)
      Whether the agent is being recycled by a disconnect that has not said yet how it went.
    • idleActionDone

      public static void idleActionDone(String node, AgentUsageRegistry.RecycleOutcome outcome)
      What is done to the machine of an agent when it is disconnected is over (or went wrong). Said by the launcher every time it disconnects, which can be more than once: only what comes while an agent is being recycled counts.