diff --git a/.project b/.project index 36a01d1..11d0d97 100644 --- a/.project +++ b/.project @@ -30,6 +30,11 @@ + + net.sf.eclipsecs.core.CheckstyleBuilder + + + org.eclipse.jem.workbench.JavaEMFNature @@ -38,5 +43,6 @@ org.eclipse.m2e.core.maven2Nature org.eclipse.wst.common.project.facet.core.nature org.eclipse.wst.jsdt.core.jsNature + net.sf.eclipsecs.core.CheckstyleNature diff --git a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitalizator.java b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitalizator.java index 35490d6..f2da8c4 100644 --- a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitalizator.java +++ b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitalizator.java @@ -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 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 configuredTaskList = configuredTasks.getConfiguredTasks(); + launchConfiguration = new FileLaunchConfiguration(); + List 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){ diff --git a/src/main/java/org/gcube/vremanagement/executor/configuration/LaunchConfiguration.java b/src/main/java/org/gcube/vremanagement/executor/configuration/LaunchConfiguration.java index a734822..906ee53 100644 --- a/src/main/java/org/gcube/vremanagement/executor/configuration/LaunchConfiguration.java +++ b/src/main/java/org/gcube/vremanagement/executor/configuration/LaunchConfiguration.java @@ -14,10 +14,40 @@ import org.gcube.vremanagement.executor.exception.SchedulePersistenceException; */ public interface LaunchConfiguration { - public List getScheduledLaunch() throws SchedulePersistenceException; + /** + * Retrieve from the #SmartExecutorPersistenceConnector the orphaned + * Scheduled tasks + * @return the list of orphaned Scheduled + * @throws SchedulePersistenceException if fails + */ + public List 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; } diff --git a/src/main/java/org/gcube/vremanagement/executor/configuration/LaunchConfigurationFactory.java b/src/main/java/org/gcube/vremanagement/executor/configuration/LaunchConfigurationFactory.java new file mode 100644 index 0000000..8380b0c --- /dev/null +++ b/src/main/java/org/gcube/vremanagement/executor/configuration/LaunchConfigurationFactory.java @@ -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(); + } + +} diff --git a/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileConfiguredTasks.java b/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileLaunchConfiguration.java similarity index 70% rename from src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileConfiguredTasks.java rename to src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileLaunchConfiguration.java index 40a06fc..8796a7f 100644 --- a/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileConfiguredTasks.java +++ b/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileLaunchConfiguration.java @@ -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 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(); 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 getScheduledLaunch() - throws SchedulePersistenceException { - return null; - } + /** * @return the configuredTasks @@ -150,5 +148,45 @@ public class FileConfiguredTasks implements LaunchConfiguration { public void setConfiguredTasks(List configuredTasks) { this.configuredTasks = configuredTasks; } + + /* (non-Javadoc) + * @see org.gcube.vremanagement.executor.configuration.LaunchConfiguration#getAvailableScheduledTasks() + */ + @Override + public List 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 + + } } diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/CouchDBPersistenceConnector.java b/src/main/java/org/gcube/vremanagement/executor/persistence/CouchDBPersistenceConnector.java index 8861a59..f3db6b5 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/CouchDBPersistenceConnector.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/CouchDBPersistenceConnector.java @@ -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 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 + + } + } diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/JDBCPersistenceConnector.java b/src/main/java/org/gcube/vremanagement/executor/persistence/JDBCPersistenceConnector.java index 2bac821..1bb7073 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/JDBCPersistenceConnector.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/JDBCPersistenceConnector.java @@ -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 diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java index 0a17a1e..4e4565f 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java @@ -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"; diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java index 7516233..dbd3ff3 100644 --- a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java +++ b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java @@ -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()); } diff --git a/src/test/java/org/gcube/vremanagement/executor/configuration/ConfiguredTasksTest.java b/src/test/java/org/gcube/vremanagement/executor/configuration/ConfiguredTasksTest.java index f134d7e..7d72a7d 100644 --- a/src/test/java/org/gcube/vremanagement/executor/configuration/ConfiguredTasksTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/configuration/ConfiguredTasksTest.java @@ -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 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 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); }