Class MaintenanceHelper

java.lang.Object
com.sap.prd.jenkins.plugins.agent_maintenance.MaintenanceHelper

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public class MaintenanceHelper extends Object
Helper class to manage maintenance windows.
  • Method Details

    • getUuid

      public static String getUuid(String id)
      Checks it the given string is a valid UUID. Returns the id if valid, otherwise it returns a new random UUID string.
      Parameters:
      id - The id to check
      Returns:
      A valid UUID string
    • hasMaintenanceWindows

      public boolean hasMaintenanceWindows(String computerName) throws IOException
      Throws:
      IOException
    • hasActiveMaintenanceWindows

      public boolean hasActiveMaintenanceWindows(String computerName) throws IOException
      Return whether there are active maintenance windows for a computer.
      Parameters:
      computerName - The computer to check
      Returns:
      true when the given computer has an active maintenance window
      Throws:
      IOException - when reading the xml failed
    • addMaintenanceWindow

      public void addMaintenanceWindow(String computerName, MaintenanceWindow mw) throws IOException
      Adds a maintenance window to a computer.
      Parameters:
      computerName - Name of the computer for which to add the maintenance window
      mw - The maintance windows
      Throws:
      IOException - when writing the xml failed
    • addRecurringMaintenanceWindow

      public void addRecurringMaintenanceWindow(String computerName, RecurringMaintenanceWindow mw) throws IOException
      Adds a maintenance window to a computer.
      Parameters:
      computerName - Name of the computer for which to add the maintenance window
      mw - The maintance windows
      Throws:
      IOException - when writing the xml failed
    • deleteMaintenanceWindow

      public void deleteMaintenanceWindow(String computerName, String id) throws IOException
      Delete maintenance window from computer.
      Parameters:
      computerName - Name of the computer
      id - Id of the maintenance window
      Throws:
      IOException - when writing the xml failed
    • deleteRecurringMaintenanceWindow

      public void deleteRecurringMaintenanceWindow(String computerName, String id) throws IOException
      Delete maintenance window from computer.
      Parameters:
      computerName - Name of the computer
      id - Id of the maintenance window
      Throws:
      IOException - when writing the xml failed
    • getMaintenanceWindows

      @NonNull public SortedSet<MaintenanceWindow> getMaintenanceWindows(String computerName) throws IOException
      Returns the list of all configured maintenance windows for the computer with the given name.
      Parameters:
      computerName - name of the agent for which to return maintenance windows
      Returns:
      Set of maintenance windows
      Throws:
      IOException - when an error occurred reading the xml
    • getRecurringMaintenanceWindows

      public Set<RecurringMaintenanceWindow> getRecurringMaintenanceWindows(String computerName) throws IOException
      Returns the list of all configured recurring maintenance windows for the computer with the given name.
      Parameters:
      computerName - name of the agent for which to return maintenance windows
      Returns:
      Set of recurring maintenance windows
      Throws:
      IOException - when an error occurred reading the xml
    • getMaintenanceDefinitions

      public MaintenanceDefinitions getMaintenanceDefinitions(String computerName) throws IOException
      Returns the maintenance definitions for an agent.
      Parameters:
      computerName - name of the agent for which to return maintenance definitions
      Returns:
      The MaintenanceDefinitions of the agent
      Throws:
      IOException - when an error occurred reading the xml
    • getMaintenanceWindow

      @CheckForNull public MaintenanceWindow getMaintenanceWindow(String computerName, String id)
      Returns the maintenance window with the given id that is connected to the given computer.
      Parameters:
      computerName - name of the computer
      id - id of the maintenance
      Returns:
      The maintenance window or null if not found
    • getMaintenance

      @CheckForNull public MaintenanceWindow getMaintenance(String computerName)
      Returns the first maintenance that is currently active or null if configured maintenance windows are not active. All maintenance windows that are finished are removed.
      Parameters:
      computerName - Name of computer
      Returns:
      active maintenance or null
    • checkRecurring

      public void checkRecurring(String computerName)
      Converts for an agent any of the recurring maintenance windows into scheduled maintenance windows if the lead time is reached.
      Parameters:
      computerName - name of the agent to check
    • getInstance

      public static MaintenanceHelper getInstance()
    • saveMaintenanceWindows

      public void saveMaintenanceWindows(String computerName, MaintenanceDefinitions md) throws IOException
      Save maintenance window for computer.
      Parameters:
      computerName - Name of computer
      md - A set of maintenance windows
      Throws:
      IOException - when writing the xml failed
    • deleteAgent

      public void deleteAgent(String computerName)
    • renameAgent

      public void renameAgent(String oldName, String newName)
      Keeps track of agent renames.
      Parameters:
      oldName - Old name of the agent
      newName - new name of the agent
    • createAgent

      public void createAgent(String nodeName)
    • injectRetentionStrategy

      public boolean injectRetentionStrategy(Computer c)
      Inject the agent maintenance retention strategy from the given computer.
      Parameters:
      c - The computer for which to inject the strategy
      Returns:
      true if strategy was injected, false otherwise
    • removeRetentionStrategy

      public boolean removeRetentionStrategy(Computer c)
      Remove the agent maintenance retention strategy from the given computer.
      Parameters:
      c - The computer for which to remove the strategy
      Returns:
      true if strategy was removed, false otherwise
    • parseDurationString

      public static int parseDurationString(String input)
      Parses a duration like string into an integer with the corresponding minutes. Takes a plain number or any combination of <int><unit> with unit being one of m (minutes), h (hours) or d (days). Each unit must appear not more than once.
      Parameters:
      input - The string to parse
      Returns:
      the parsed minutes