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 Summary
Modifier and TypeMethodDescriptionvoidaddMaintenanceWindow(String computerName, MaintenanceWindow mw) Adds a maintenance window to a computer.voidaddRecurringMaintenanceWindow(String computerName, RecurringMaintenanceWindow mw) Adds a maintenance window to a computer.voidcheckRecurring(String computerName) Converts for an agent any of the recurring maintenance windows into scheduled maintenance windows if the lead time is reached.voidcreateAgent(String nodeName) voiddeleteAgent(String computerName) voiddeleteMaintenanceWindow(String computerName, String id) Delete maintenance window from computer.voiddeleteRecurringMaintenanceWindow(String computerName, String id) Delete maintenance window from computer.static MaintenanceHelpergetMaintenance(String computerName) Returns the first maintenance that is currently active ornullif configured maintenance windows are not active.getMaintenanceDefinitions(String computerName) Returns the maintenance definitions for an agent.getMaintenanceWindow(String computerName, String id) Returns the maintenance window with the given id that is connected to the given computer.getMaintenanceWindows(String computerName) Returns the list of all configured maintenance windows for the computer with the given name.getRecurringMaintenanceWindows(String computerName) Returns the list of all configured recurring maintenance windows for the computer with the given name.static StringChecks it the given string is a valid UUID.booleanhasActiveMaintenanceWindows(String computerName) Return whether there are active maintenance windows for a computer.booleanhasMaintenanceWindows(String computerName) booleanInject the agent maintenance retention strategy from the given computer.static intparseDurationString(String input) Parses a duration like string into an integer with the corresponding minutes.booleanRemove the agent maintenance retention strategy from the given computer.voidrenameAgent(String oldName, String newName) Keeps track of agent renames.voidsaveMaintenanceWindows(String computerName, MaintenanceDefinitions md) Save maintenance window for computer.
-
Method Details
-
getUuid
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
- Throws:
IOException
-
hasActiveMaintenanceWindows
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
Adds a maintenance window to a computer.- Parameters:
computerName- Name of the computer for which to add the maintenance windowmw- 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 windowmw- The maintance windows- Throws:
IOException- when writing the xml failed
-
deleteMaintenanceWindow
Delete maintenance window from computer.- Parameters:
computerName- Name of the computerid- Id of the maintenance window- Throws:
IOException- when writing the xml failed
-
deleteRecurringMaintenanceWindow
Delete maintenance window from computer.- Parameters:
computerName- Name of the computerid- 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
Returns the maintenance definitions for an agent.- Parameters:
computerName- name of the agent for which to return maintenance definitions- Returns:
- The
MaintenanceDefinitionsof the agent - Throws:
IOException- when an error occurred reading the xml
-
getMaintenanceWindow
Returns the maintenance window with the given id that is connected to the given computer.- Parameters:
computerName- name of the computerid- id of the maintenance- Returns:
- The maintenance window or null if not found
-
getMaintenance
Returns the first maintenance that is currently active ornullif 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
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
-
saveMaintenanceWindows
public void saveMaintenanceWindows(String computerName, MaintenanceDefinitions md) throws IOException Save maintenance window for computer.- Parameters:
computerName- Name of computermd- A set of maintenance windows- Throws:
IOException- when writing the xml failed
-
deleteAgent
-
renameAgent
Keeps track of agent renames.- Parameters:
oldName- Old name of the agentnewName- new name of the agent
-
createAgent
-
injectRetentionStrategy
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
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
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 ofm (minutes),h (hours)ord (days). Each unit must appear not more than once.- Parameters:
input- The string to parse- Returns:
- the parsed minutes
-