Class RestartDrain

java.lang.Object
org.jenkins.ci.plugins.saferestart.RestartDrain
All Implemented Interfaces:
ExtensionPoint

@Extension public class RestartDrain extends Object implements ExtensionPoint
Drain mode: block new top-level builds, let running builds finish, then trigger a safe restart.

Core quiet-down cannot be used for this. It also blocks the Pipeline node steps of builds that are already running, so those builds could never finish and the restart would never happen. Drain mode only holds back new builds, see RestartDrainQueueTaskDispatcher, and enters core quiet-down through Jenkins.safeRestart(String) once nothing is running.

The state is transient. A restart or crash while draining resets it.

  • Constructor Details

    • RestartDrain

      public RestartDrain()
  • Method Details

    • get

      public static RestartDrain get()
    • isActive

      public boolean isActive()
      Returns:
      true while new builds are held back and the restart is pending
    • getMessage

      @CheckForNull public String getMessage()
      Returns:
      the message shown in the shutdown banner once the restart starts, or null
    • getStartedBy

      @CheckForNull public String getStartedBy()
      Returns:
      name of the user who started the drain, or null when not active
    • getSince

      public long getSince()
      Returns:
      epoch milliseconds when the drain started, or 0 when not active
    • start

      public void start(@CheckForNull String message)
      Starts holding back new builds. Restarts right away if nothing is running. Does nothing if already active.
      Parameters:
      message - optional message for the shutdown banner
    • cancel

      public void cancel()
      Stops holding back new builds. No restart happens.
    • checkAndRestart

      public void checkAndRestart()
      Triggers the restart if the drain is active and nothing is running. Safe to call from any thread; the drain is deactivated before the restart is triggered so it fires only once.
    • getRunningBuilds

      @NonNull public List<Run<?,?>> getRunningBuilds()
      Builds that are still running. For lazy-loading job types only builds already in memory are inspected: a running build is always loaded, and this avoids reading build records from disk on every check.
      Returns:
      running builds, never null