From dac74aed749b59b46b0a10078488ab94c1e3bb49 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 6 Oct 2015 12:45:06 +0000 Subject: [PATCH] refs #579: Use Persistence to persist Scheduled Task configuration on smart-executor https://support.d4science.org/issues/579 Removed PluginDeclaration parameter which is not needed git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@119442 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../executor/SmartExecutorImpl.java | 8 +-- .../SmartExecutorPersistenceConnector.java | 12 ++-- .../couchdb/CouchDBPersistenceConnector.java | 34 +++++------ ...SmartExecutorPersistenceConnectorTest.java | 2 +- .../pluginmanager/RunnablePluginTest.java | 4 +- .../SmartExecutorSchedulerTest.java | 61 ++++++++----------- 6 files changed, 53 insertions(+), 68 deletions(-) diff --git a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java index f4e806c..0d70ad5 100644 --- a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java +++ b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java @@ -13,7 +13,6 @@ import org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundExceptio import org.gcube.vremanagement.executor.exception.PluginNotFoundException; import org.gcube.vremanagement.executor.exception.SchedulerNotFoundException; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; -import org.gcube.vremanagement.executor.plugin.PluginDeclaration; import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler; import org.quartz.SchedulerException; @@ -82,7 +81,6 @@ public class SmartExecutorImpl implements SmartExecutor { /**{@inheritDoc}*/ @Override - @Deprecated public PluginState getIterationState(String executionIdentifier, int iterationNumber) throws PluginInstanceNotFoundException, ExecutorException { try { @@ -93,7 +91,7 @@ public class SmartExecutorImpl implements SmartExecutor { } } - /**{@inheritDoc}*/ + /* *{@inheritDoc}* / @Override public PluginState getState(PluginDeclaration pluginDeclaration, String executionIdentifier) throws PluginInstanceNotFoundException, ExecutorException { @@ -105,7 +103,7 @@ public class SmartExecutorImpl implements SmartExecutor { } } - /**{@inheritDoc}*/ + /**{@inheritDoc}* / @Override public PluginState getIterationState(PluginDeclaration pluginDeclaration, String executionIdentifier, int iterationNumber) throws PluginInstanceNotFoundException, ExecutorException { @@ -116,6 +114,6 @@ public class SmartExecutorImpl implements SmartExecutor { throw new PluginInstanceNotFoundException(); } } - + */ } diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java index 6359ae9..a1199e2 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java @@ -7,7 +7,6 @@ import java.util.UUID; import org.gcube.vremanagement.executor.persistence.couchdb.CouchDBPersistenceConnector; import org.gcube.vremanagement.executor.plugin.Plugin; -import org.gcube.vremanagement.executor.plugin.PluginDeclaration; import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.plugin.PluginStateNotification; @@ -49,7 +48,7 @@ public abstract class SmartExecutorPersistenceConnector implements PluginStateNo */ public abstract void close() throws Exception; - /** + /* * * Retrieve the status of the iterationNumber (passed as parameter) of a * running/run plugin (using {@link PluginDeclaration}) which is/was * identified by the UUID passed as parameter. @@ -58,19 +57,20 @@ public abstract class SmartExecutorPersistenceConnector implements PluginStateNo * @param iterationNumber the iteration number * @return the actual/last {@link PluginState} of the Plugin * @throws Exception if fails - */ + * / public abstract PluginState getPluginInstanceState(PluginDeclaration pluginDeclaration, UUID uuid, int iterationNumber) throws Exception; - /** + /* * * Retrieve the status of the iterationNumber of the last running/run {@link Plugin} which is/was identified * by the UUID passed as parameter * @param pluginDeclaration The Plugin Declaration class * @param uuid the execution identifier of the running/run {@link Plugin} * @return the actual/last {@link PluginState} of the Plugin * @throws Exception if fails - */ + * / public abstract PluginState getLastPluginInstanceState(PluginDeclaration pluginDeclaration, UUID uuid) throws Exception; + */ /** * Retrieve the status of the iterationNumber (passed as parameter) of a running/run {@link Plugin} which is/was identified @@ -80,7 +80,6 @@ public abstract class SmartExecutorPersistenceConnector implements PluginStateNo * @return the actual/last {@link PluginState} of the Plugin * @throws Exception if fails */ - @Deprecated public abstract PluginState getPluginInstanceState(UUID uuid, int iterationNumber) throws Exception; /** @@ -90,7 +89,6 @@ public abstract class SmartExecutorPersistenceConnector implements PluginStateNo * @return the actual/last {@link PluginState} of the Plugin * @throws Exception if fails */ - @Deprecated public abstract PluginState getLastPluginInstanceState(UUID uuid) throws Exception; diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/CouchDBPersistenceConnector.java b/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/CouchDBPersistenceConnector.java index 0b90dc6..af05fe8 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/CouchDBPersistenceConnector.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/CouchDBPersistenceConnector.java @@ -154,30 +154,31 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect return reallyQuery(null, uuid, LAST); } - /** + protected final static int LAST = -1; + + /* * * {@inheritDoc} - */ + * / @Override public PluginState getPluginInstanceState(PluginDeclaration pluginDeclaration, UUID uuid, int iterationNumber) throws Exception { return reallyQuery(pluginDeclaration, uuid, iterationNumber); } - - protected final static int LAST = -1; - /** + /* * * {@inheritDoc} - */ + * / @Override public PluginState getLastPluginInstanceState(PluginDeclaration pluginDeclaration, UUID uuid) throws Exception { return reallyQuery(pluginDeclaration, uuid, LAST); } + */ protected static final String MAP_REDUCE__DESIGN = "_design/"; protected static final String PLUGIN_STATE_DOCUMENT = "pluginState"; - protected static final String PLUGIN_STATE_VIEW = "pluginState"; - protected static final String PLUGIN_STATE_DEPRECATED_VIEW = "pluginStateDeprecated"; + protected static final String PLUGIN_STATE = "pluginState"; + protected static final String PLUGIN_STATE_VIEW_ABANDONED = "pluginStateABANDONED"; protected static final String SCHEDULED_TASKS_DOCUMENT = "scheduledTasks"; protected static final String ACTIVE_VIEW = "active"; @@ -209,29 +210,26 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect endKey.add(scope); String pluginName = pluginDeclaration.getName(); - if(pluginName!=null && pluginName.compareTo("")!=0){ startKey.add(pluginName); endKey.add(pluginName); - query = query.viewName(PLUGIN_STATE_VIEW); + query = query.viewName(PLUGIN_STATE_VIEW_ABANDONED); }else{ - query = query.viewName(PLUGIN_STATE_DEPRECATED_VIEW); + query = query.viewName(PLUGIN_STATE); } startKey.add(uuid.toString()); endKey.add(uuid.toString()); - if(iterationNumber==LAST){ - startKey.add(1); - endKey.add("{}"); - }else{ + if(iterationNumber != LAST){ startKey.add(iterationNumber); endKey.add(iterationNumber); - - startKey.add(1); - endKey.add("{}"); } + // Adding time interval + startKey.add(1); + endKey.add("{}"); + query.startKey(startKey); query.endKey(endKey); diff --git a/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java b/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java index a0ac877..a96f177 100644 --- a/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java @@ -53,7 +53,7 @@ public class SmartExecutorPersistenceConnectorTest { long timestamp = new Date().getTime(); PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, 1, timestamp, HelloWorldPluginDeclaration.class.newInstance(), states[i]); persistenceConnector.pluginStateEvolution(pluginStateEvolution); - PluginState ps = persistenceConnector.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1); + PluginState ps = persistenceConnector.getPluginInstanceState(uuid, 1); Assert.assertEquals(states[i], ps); } diff --git a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java index 9d7860f..d67aeac 100644 --- a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java @@ -92,11 +92,11 @@ public class RunnablePluginTest { pluginStateNotifications.add(persistenceConnector); HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd); RunnablePlugin rp = new RunnablePlugin(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications); - Assert.assertEquals(PluginState.CREATED, persistenceConnector.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1)); + Assert.assertEquals(PluginState.CREATED, persistenceConnector.getPluginInstanceState(uuid, 1)); rp.run(); - Assert.assertEquals(PluginState.DONE, persistenceConnector.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1)); + Assert.assertEquals(PluginState.DONE, persistenceConnector.getPluginInstanceState(uuid, 1)); } diff --git a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java index e48811e..22743a6 100644 --- a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java @@ -117,12 +117,8 @@ public class SmartExecutorSchedulerTest { while(endTime <= (startTime + 12000)){ endTime = Calendar.getInstance().getTimeInMillis(); } - PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid); + PluginState pluginState = pc.getLastPluginInstanceState(uuid); Assert.assertEquals(PluginState.DONE, pluginState); - - @SuppressWarnings("deprecation") - PluginState pluginStateFromDeprecation = pc.getLastPluginInstanceState(uuid); - Assert.assertEquals(PluginState.DONE, pluginStateFromDeprecation); } @Test @@ -137,13 +133,8 @@ public class SmartExecutorSchedulerTest { } try{ - PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5); + PluginState pluginState = pc.getPluginInstanceState(uuid, 5); Assert.assertEquals(PluginState.STOPPED, pluginState); - - @SuppressWarnings("deprecation") - PluginState pluginStateFromDeprecation = pc.getPluginInstanceState(uuid, 5); - Assert.assertEquals(PluginState.STOPPED, pluginStateFromDeprecation); - }catch(PluginStateNotRetrievedException e){ // OK logger.error("PluginStateNotRetrievedException this can be acceptable in some tests", e); @@ -169,7 +160,7 @@ public class SmartExecutorSchedulerTest { while(endTime <= (startTime + 10000)){ endTime = Calendar.getInstance().getTimeInMillis(); } - PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid); + PluginState pluginState = pc.getLastPluginInstanceState(uuid); Assert.assertEquals(PluginState.STOPPED, pluginState); } @@ -184,7 +175,7 @@ public class SmartExecutorSchedulerTest { } smartExecutorScheduler.stop(uuid); - PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid); + PluginState pluginState = pc.getLastPluginInstanceState(uuid); Assert.assertEquals(PluginState.DONE, pluginState); } @@ -209,10 +200,10 @@ public class SmartExecutorSchedulerTest { endTime = Calendar.getInstance().getTimeInMillis(); } - PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), first); + PluginState pluginState = pc.getLastPluginInstanceState(first); Assert.assertEquals(PluginState.STOPPED, pluginState); - pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), second); + pluginState = pc.getLastPluginInstanceState(second); Assert.assertEquals(PluginState.DONE, pluginState); } @@ -236,11 +227,11 @@ public class SmartExecutorSchedulerTest { } for(int i=1; i<5; i++){ - PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i); + PluginState pluginState = pc.getPluginInstanceState(uuid, i); Assert.assertEquals(PluginState.DONE, pluginState); } - PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5); + PluginState pluginState = pc.getPluginInstanceState(uuid, 5); Assert.assertEquals(PluginState.STOPPED, pluginState); } @@ -265,7 +256,7 @@ public class SmartExecutorSchedulerTest { } for(int i=1; i<5; i++){ - PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i); + PluginState pluginState = pc.getPluginInstanceState(uuid, i); if(i%2!=0){ Assert.assertEquals(PluginState.DONE, pluginState); }else{ @@ -273,7 +264,7 @@ public class SmartExecutorSchedulerTest { } } - PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5); + PluginState pluginState = pc.getPluginInstanceState(uuid, 5); Assert.assertEquals(PluginState.STOPPED, pluginState); } @@ -306,11 +297,11 @@ public class SmartExecutorSchedulerTest { for(int i=0; i