refs #521: Support Unscheduling of repetitive task on SmartExecutor

https://support.d4science.org/issues/521

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@119049 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-09-25 15:34:56 +00:00
parent c6df0384ca
commit 5ca1a0b641
10 changed files with 195 additions and 46 deletions

View File

@ -30,6 +30,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
@ -38,5 +43,6 @@
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>

View File

@ -35,7 +35,8 @@ import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent;
import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.configuration.jsonbased.FileConfiguredTasks;
import org.gcube.vremanagement.executor.configuration.LaunchConfiguration;
import org.gcube.vremanagement.executor.configuration.jsonbased.FileLaunchConfiguration;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
@ -65,7 +66,7 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
/**
* The application context
*/
protected static ApplicationContext ctx;
public static ApplicationContext ctx;
/**
* the Smart executor Scheduler used for task execution
@ -73,13 +74,13 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
protected static SmartExecutorScheduler smartExecutorScheduler;
protected static FileConfiguredTasks configuredTasks;
protected static LaunchConfiguration launchConfiguration;
/**
* @return the configuredTasks
*/
public static FileConfiguredTasks getConfiguredTasks() {
return configuredTasks;
public static LaunchConfiguration getConfiguredTasks() {
return launchConfiguration;
}
/**
@ -290,8 +291,8 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
smartExecutorScheduler = SmartExecutorScheduler.getInstance();
// checking if there are old unpublished ServiceEndpoint related to this
// vHN and try to unpublish them
// Checking if there are old unpublished ServiceEndpoints related to
// this vHN and trying to unpublish them
List<String> scopes = getScopes(ctx);
for(String scope : scopes){
@ -336,16 +337,7 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
logger.error("Unable to Create ServiceEndpoint. the Service will be aborted", e);
return;
}
/*
try {
SmartExecutorPersistenceConnector persistenceConnector = new JDBCPersistenceConnector(ctx.persistence().location());
SmartExecutorPersistenceConnector.setPersistenceConnector(persistenceConnector);
} catch (Exception e) {
logger.error("Unable to initialize JDBCPersistenceConnector as PersistenceConnector. Trying to use the Default", e);
}
*/
try {
SmartExecutorPersistenceConnector.getPersistenceConnector();
} catch (Exception e) {
@ -360,8 +352,12 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
logger.trace("Going to Run Configured Tasks");
try {
configuredTasks = new FileConfiguredTasks(ctx.persistence().location());
List<LaunchParameter> configuredTaskList = configuredTasks.getConfiguredTasks();
launchConfiguration = new FileLaunchConfiguration();
List<LaunchParameter> configuredTaskList = launchConfiguration.getAvailableScheduledTasks();
// TODO review this
// Get the launch that will start before the next time the scheduled
// internal thread will newly analyze the scheduling situation
SmartExecutorImpl smartExecutorImpl = new SmartExecutorImpl();
for(LaunchParameter parameter : configuredTaskList){

View File

@ -14,10 +14,40 @@ import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
*/
public interface LaunchConfiguration {
public List<LaunchParameter> getScheduledLaunch() throws SchedulePersistenceException;
/**
* Retrieve from the #SmartExecutorPersistenceConnector the orphaned
* Scheduled tasks
* @return the list of orphaned Scheduled
* @throws SchedulePersistenceException if fails
*/
public List<LaunchParameter> getAvailableScheduledTasks() throws SchedulePersistenceException;
public void addLaunch(LaunchParameter parameter) throws SchedulePersistenceException;
/**
*
* @param parameter
* @throws SchedulePersistenceException
*/
public void addScheduledTask(LaunchParameter parameter) throws SchedulePersistenceException;
public void removeLaunch(LaunchParameter parameter)throws SchedulePersistenceException;
/**
*
* @param parameter
* @throws SchedulePersistenceException
*/
public void reserveScheduledTask(LaunchParameter parameter) throws SchedulePersistenceException;
/**
*
* @param parameter
* @throws SchedulePersistenceException
*/
public void removeScheduledTask(LaunchParameter parameter)throws SchedulePersistenceException;
/**
*
* @param parameter
* @throws SchedulePersistenceException
*/
public void releaseScheduledTask(LaunchParameter parameter) throws SchedulePersistenceException;
}

View File

@ -0,0 +1,18 @@
/**
*
*/
package org.gcube.vremanagement.executor.configuration;
import org.gcube.vremanagement.executor.configuration.jsonbased.FileLaunchConfiguration;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class LaunchConfigurationFactory {
public static LaunchConfiguration getLaunchConfiguration() throws Exception {
return new FileLaunchConfiguration();
}
}

View File

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.gcube.vremanagement.executor.SmartExecutorInitalizator;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.configuration.LaunchConfiguration;
@ -27,12 +28,12 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class FileConfiguredTasks implements LaunchConfiguration {
public class FileLaunchConfiguration implements LaunchConfiguration {
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(FileConfiguredTasks.class);
private static Logger logger = LoggerFactory.getLogger(FileLaunchConfiguration.class);
protected String configurationFileLocation;
protected List<LaunchParameter> configuredTasks;
@ -40,8 +41,11 @@ public class FileConfiguredTasks implements LaunchConfiguration {
public static final String CONFIG_TASK_FILENAME = "definedTasks.json";
public FileLaunchConfiguration() throws Exception {
this(SmartExecutorInitalizator.ctx.persistence().location());
}
public FileConfiguredTasks(String location) throws IOException, JSONException {
public FileLaunchConfiguration(String location) throws IOException, JSONException {
this.configurationFileLocation = location;
this.configuredTasks = new ArrayList<LaunchParameter>();
this.configuredTasks = retriveConfiguredTask();
@ -98,7 +102,7 @@ public class FileConfiguredTasks implements LaunchConfiguration {
}
@Override
public synchronized void addLaunch(LaunchParameter parameter) throws SchedulePersistenceException{
public synchronized void addScheduledTask(LaunchParameter parameter) throws SchedulePersistenceException{
try {
addLaunch(new JSONLaunchParameter(parameter));
} catch (ParseException e) {
@ -115,8 +119,7 @@ public class FileConfiguredTasks implements LaunchConfiguration {
}
}
@Override
public void removeLaunch(LaunchParameter parameter)
public void releaseLaunch(LaunchParameter parameter)
throws SchedulePersistenceException {
try {
removeLaunch(new JSONLaunchParameter(parameter));
@ -130,12 +133,7 @@ public class FileConfiguredTasks implements LaunchConfiguration {
configuredTasks.remove(parameter);
writeOnConfigurationFile();
}
@Override
public List<LaunchParameter> getScheduledLaunch()
throws SchedulePersistenceException {
return null;
}
/**
* @return the configuredTasks
@ -150,5 +148,45 @@ public class FileConfiguredTasks implements LaunchConfiguration {
public void setConfiguredTasks(List<LaunchParameter> configuredTasks) {
this.configuredTasks = configuredTasks;
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#getAvailableScheduledTasks()
*/
@Override
public List<LaunchParameter> getAvailableScheduledTasks()
throws SchedulePersistenceException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#reserveScheduledTask(org.gcube.vremanagement.executor.api.types.LaunchParameter)
*/
@Override
public void reserveScheduledTask(LaunchParameter parameter)
throws SchedulePersistenceException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#removeScheduledTask(org.gcube.vremanagement.executor.api.types.LaunchParameter)
*/
@Override
public void removeScheduledTask(LaunchParameter parameter)
throws SchedulePersistenceException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#releaseScheduledTask(org.gcube.vremanagement.executor.api.types.LaunchParameter)
*/
@Override
public void releaseScheduledTask(LaunchParameter parameter)
throws SchedulePersistenceException {
// TODO Auto-generated method stub
}
}

View File

@ -4,6 +4,7 @@
package org.gcube.vremanagement.executor.persistence;
import java.net.URL;
import java.util.List;
import java.util.UUID;
import org.codehaus.jackson.JsonNode;
@ -19,7 +20,10 @@ import org.ektorp.http.StdHttpClient;
import org.ektorp.http.StdHttpClient.Builder;
import org.ektorp.impl.StdCouchDbConnector;
import org.ektorp.impl.StdCouchDbInstance;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.configuration.LaunchConfiguration;
import org.gcube.vremanagement.executor.exception.PluginStateNotRetrievedException;
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -28,7 +32,7 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnector {
public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnector implements LaunchConfiguration {
private static final Logger logger = LoggerFactory.getLogger(CouchDBPersistenceConnector.class);
@ -195,4 +199,55 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
return pluginState;
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#getAvailableScheduledTasks()
*/
@Override
public List<LaunchParameter> getAvailableScheduledTasks()
throws SchedulePersistenceException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#addScheduledTask(org.gcube.vremanagement.executor.api.types.LaunchParameter)
*/
@Override
public void addScheduledTask(LaunchParameter parameter)
throws SchedulePersistenceException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#reserveScheduledTask(org.gcube.vremanagement.executor.api.types.LaunchParameter)
*/
@Override
public void reserveScheduledTask(LaunchParameter parameter)
throws SchedulePersistenceException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#removeScheduledTask(org.gcube.vremanagement.executor.api.types.LaunchParameter)
*/
@Override
public void removeScheduledTask(LaunchParameter parameter)
throws SchedulePersistenceException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#releaseScheduledTask(org.gcube.vremanagement.executor.api.types.LaunchParameter)
*/
@Override
public void releaseScheduledTask(LaunchParameter parameter)
throws SchedulePersistenceException {
// TODO Auto-generated method stub
}
}

View File

@ -11,6 +11,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import org.gcube.vremanagement.executor.SmartExecutorInitalizator;
import org.gcube.vremanagement.executor.exception.PluginStateNotRetrievedException;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.slf4j.Logger;
@ -18,14 +19,14 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* INTERNAL USE ONLY for testing purpose
*/
public class JDBCPersistenceConnector extends SmartExecutorPersistenceConnector {
class JDBCPersistenceConnector extends SmartExecutorPersistenceConnector {
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(JDBCPersistenceConnector.class);
protected Connection connection;
public static final String driverClass = "org.h2.Driver";
@ -45,6 +46,10 @@ public class JDBCPersistenceConnector extends SmartExecutorPersistenceConnector
public final static String CATALINA_HOME = "CATALINA_HOME";
public JDBCPersistenceConnector() throws Exception {
this(SmartExecutorInitalizator.ctx.persistence().location());
}
/**
* This constructor is used to provide a location where creating persistence
* files

View File

@ -26,8 +26,9 @@ import org.gcube.resources.discovery.icclient.ICFactory;
public class SmartExecutorPersistenceConfiguration {
public final String SERVICE_ENDPOINT_CATEGORY = "VREManagement";
public final String SERVICE_ENDPOINT_NAME = "SmartExecutor";
//public final String SERVICE_ENDPOINT_NAME = "SmartExecutor";
public final String SERVICE_ENDPOINT_NAME = "SmartExecutorPersistenceConfiguration";
protected static final String PERSISTENCE_CLASS_NAME = "persistenceClassName";
protected static final String TARGET_SCOPE = "targetScope";

View File

@ -133,7 +133,7 @@ public class SmartExecutorScheduler {
}
try {
SmartExecutorInitalizator.getConfiguredTasks().addLaunch(parameter);
SmartExecutorInitalizator.getConfiguredTasks().addScheduledTask(parameter);
} catch (SchedulePersistenceException e) {
logger.error("Unable to persist the scheduling", e.getCause());
}

View File

@ -14,7 +14,7 @@ import org.acme.HelloWorldPlugin;
import org.acme.HelloWorldPluginDeclaration;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.configuration.jsonbased.FileConfiguredTasks;
import org.gcube.vremanagement.executor.configuration.jsonbased.FileLaunchConfiguration;
import org.gcube.vremanagement.executor.configuration.jsonbased.JSONLaunchParameter;
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
import org.json.JSONException;
@ -29,7 +29,7 @@ public class ConfiguredTasksTest {
public static final String TEST = "test";
public void checkOriginal(FileConfiguredTasks parser, int size){
public void checkOriginal(FileLaunchConfiguration parser, int size){
List<LaunchParameter> configuredTasks = parser.getConfiguredTasks();
Assert.assertEquals(size, configuredTasks.size());
@ -70,7 +70,7 @@ public class ConfiguredTasksTest {
public void testLaunchConfiguredTask() throws SchedulePersistenceException, IOException, JSONException, ParseException {
String location = new File(".").getAbsolutePath();
location = location + "/src/test/resources";
FileConfiguredTasks parser = new FileConfiguredTasks(location);
FileLaunchConfiguration parser = new FileLaunchConfiguration(location);
checkOriginal(parser, 3);
@ -80,7 +80,7 @@ public class ConfiguredTasksTest {
JSONLaunchParameter added = new JSONLaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, true);
parser.addLaunch(added);
parser = new FileConfiguredTasks(location);
parser = new FileLaunchConfiguration(location);
checkOriginal(parser, 4);
List<LaunchParameter> configuredTasks = parser.getConfiguredTasks();
@ -92,9 +92,9 @@ public class ConfiguredTasksTest {
Assert.assertEquals(null, parameter.getScheduling());
Assert.assertEquals(true, parameter.isPersist());
parser.removeLaunch(parameter);
parser.releaseLaunch(parameter);
parser = new FileConfiguredTasks(location);
parser = new FileLaunchConfiguration(location);
checkOriginal(parser, 3);
}