90 lines
2.6 KiB
Java
90 lines
2.6 KiB
Java
package org.gcube.informationsystem.sweeper;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.common.authorization.client.Constants;
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.gcube.vremanagement.executor.plugin.Plugin;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
*/
|
|
public class ISSweeperPlugin extends Plugin<ISSweeperPluginDeclaration> {
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* Logger
|
|
*/
|
|
private static Logger logger = LoggerFactory.getLogger(ISSweeperPlugin.class);
|
|
|
|
public ISSweeperPlugin(ISSweeperPluginDeclaration pluginDeclaration) {
|
|
super(pluginDeclaration);
|
|
logger.debug("contructor");
|
|
}
|
|
|
|
/**{@inheritDoc}*/
|
|
@Override
|
|
public void launch(Map<String, Object> inputs) throws Exception {
|
|
logger.debug("Launching {} execution", ISSweeperPluginDeclaration.NAME);
|
|
// No inputs needed
|
|
|
|
String token = SecurityTokenProvider.instance.get();
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
String scope = authorizationEntry.getContext();
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
Sweeper sweeper = new Sweeper();
|
|
|
|
try {
|
|
sweeper.sweepDeadGHNs(Calendar.DAY_OF_YEAR, -DEAD_DAYS_TIMEOUT);
|
|
} catch(Exception e){
|
|
logger.error("Error removing Dead HostingNodes", e);
|
|
}
|
|
logger.trace("---------------------------------\n\n");
|
|
|
|
try {
|
|
sweeper.sweepExpiredGHNs(Calendar.MINUTE, -EXPIRING_MINUTES_TIMEOUT);
|
|
logger.trace("---------------------------------\n\n");
|
|
} catch(Exception e){
|
|
logger.error("Error sweeping Expired HostingNodes", e);
|
|
}
|
|
logger.trace("---------------------------------\n\n");
|
|
|
|
Thread.sleep(1000*90); // Waiting 90 sec
|
|
|
|
try {
|
|
sweeper.sweepOrphanRI();
|
|
logger.trace("---------------------------------\n\n");
|
|
} catch(Exception e){
|
|
logger.error("Error sweeping Orphan RunningInstances", e);
|
|
}
|
|
|
|
logger.debug("{} execution finished", ISSweeperPluginDeclaration.NAME);
|
|
}
|
|
|
|
/**{@inheritDoc}*/
|
|
@Override
|
|
protected void onStop() throws Exception {
|
|
logger.debug("onStop()");
|
|
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
|
|
}
|