diff --git a/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPlugin.java b/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPlugin.java index fd0232a..8498803 100644 --- a/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPlugin.java +++ b/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPlugin.java @@ -19,17 +19,20 @@ import org.slf4j.LoggerFactory; */ public class ISSweeperPlugin extends Plugin { + public static final String EXPIRING_MINUTES_TIMEOUT = "expiringMinutesTimeout"; /** * Indicate the default minutes timeout so that Hosting Node is * considered expired and can be set to {@link Sweeper#UNREACHABLE} */ - public static final int EXPIRING_MINUTES_TIMEOUT = 30; + public static final int DEFAULT_EXPIRING_MINUTES_TIMEOUT = 30; + public static final String DEAD_DAYS_TIMEOUT = "deadDaysTimeout"; /** * Indicate the default days timeout so that Hosting Node is considered * dead and can be removed from IS */ - public static final int DEAD_DAYS_TIMEOUT = 15; + public static final int DEFAULT_DEAD_DAYS_TIMEOUT = 15; + /** * Logger @@ -54,17 +57,54 @@ public class ISSweeperPlugin extends Plugin { logger.debug("Launching {} execution on scope {}", ISSweeperPluginDeclaration.NAME, scope); + + int expiringMinutesTimeout = DEFAULT_EXPIRING_MINUTES_TIMEOUT; + int deadDaysTimeout = DEFAULT_DEAD_DAYS_TIMEOUT; + + if(inputs != null) { + if(inputs.containsKey(EXPIRING_MINUTES_TIMEOUT)){ + try { + expiringMinutesTimeout = new Integer(inputs.get(EXPIRING_MINUTES_TIMEOUT).toString()); + } catch(Exception e){ + logger.warn("The provided value {} for {} is not an int. Default value {} will be used", + inputs.get(EXPIRING_MINUTES_TIMEOUT), EXPIRING_MINUTES_TIMEOUT, DEFAULT_EXPIRING_MINUTES_TIMEOUT, e); + } + } else { + logger.debug("No provided value for {}. Default value {} will be used", + EXPIRING_MINUTES_TIMEOUT, DEFAULT_EXPIRING_MINUTES_TIMEOUT); + } + + if(inputs.containsKey(DEAD_DAYS_TIMEOUT)){ + try { + deadDaysTimeout = new Integer(inputs.get(DEAD_DAYS_TIMEOUT).toString()); + } catch(Exception e){ + logger.warn("The provided value {} for {} is not an int. Default value {} will be used", + inputs.get(DEAD_DAYS_TIMEOUT), DEAD_DAYS_TIMEOUT, DEFAULT_DEAD_DAYS_TIMEOUT, e); + } + } else { + logger.debug("No provided value for {}. Default value {} will be used", + DEAD_DAYS_TIMEOUT, DEFAULT_DEAD_DAYS_TIMEOUT); + } + + } + + + + + + + Sweeper sweeper = new Sweeper(); try { - sweeper.sweepDeadGHNs(Calendar.DAY_OF_YEAR, -DEAD_DAYS_TIMEOUT); + sweeper.sweepDeadGHNs(Calendar.DAY_OF_YEAR, -deadDaysTimeout); } catch(Exception e){ logger.error("Error removing Dead HostingNodes", e); } logger.trace("---------------------------------\n\n"); try { - sweeper.sweepExpiredGHNs(Calendar.MINUTE, -EXPIRING_MINUTES_TIMEOUT); + sweeper.sweepExpiredGHNs(Calendar.MINUTE, -expiringMinutesTimeout); logger.trace("---------------------------------\n\n"); } catch(Exception e){ logger.error("Error sweeping Expired HostingNodes", e); diff --git a/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPluginDeclaration.java b/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPluginDeclaration.java index fdf62b6..41b4ee1 100644 --- a/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPluginDeclaration.java +++ b/src/main/java/org/gcube/informationsystem/sweeper/ISSweeperPluginDeclaration.java @@ -30,9 +30,9 @@ public class ISSweeperPluginDeclaration implements PluginDeclaration { public static final String NAME = "ISSweeper"; public static final String DESCRIPTION = "IS Sweeper find expired (not updated for " - + ISSweeperPlugin.EXPIRING_MINUTES_TIMEOUT + " minutes) Hosting Nodes " + + ISSweeperPlugin.DEFAULT_EXPIRING_MINUTES_TIMEOUT + " minutes) Hosting Nodes " + "and set their status to " + Sweeper.UNREACHABLE + ", dead (not " - + "updated for " + ISSweeperPlugin.DEAD_DAYS_TIMEOUT + " days) Hosting " + + "updated for " + ISSweeperPlugin.DEFAULT_DEAD_DAYS_TIMEOUT + " days) Hosting " + "Nodes and remove them from IS. Moreover it find orphan Running " + "Instances and remove them from IS."; public static final String VERSION = "1.0.0";