Added possibility to specify timeouts to delete ghn and running instance

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/is-sweeper-se-plugin@126680 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-04-04 07:58:44 +00:00
parent a938051e97
commit a41236500b
2 changed files with 46 additions and 6 deletions

View File

@ -19,17 +19,20 @@ import org.slf4j.LoggerFactory;
*/
public class ISSweeperPlugin extends Plugin<ISSweeperPluginDeclaration> {
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<ISSweeperPluginDeclaration> {
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);

View File

@ -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";