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
This commit is contained in:
Luca Frosini 2015-10-06 12:45:06 +00:00
parent bccb75077c
commit dac74aed74
6 changed files with 53 additions and 68 deletions

View File

@ -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();
}
}
*/
}

View File

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

View File

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

View File

@ -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);
}

View File

@ -92,11 +92,11 @@ public class RunnablePluginTest {
pluginStateNotifications.add(persistenceConnector);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd);
RunnablePlugin<HelloWorldPlugin> rp = new RunnablePlugin<HelloWorldPlugin>(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));
}

View File

@ -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<expectedStates.length; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(uuid, i+1);
Assert.assertEquals(expectedStates[i], pluginState);
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(uuid, 5);
Assert.assertEquals(PluginState.DISCARDED, pluginState);
}
@ -327,11 +318,11 @@ public class SmartExecutorSchedulerTest {
}
for(int i=0; i<3; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(uuid, i+1);
Assert.assertEquals(PluginState.DONE, pluginState);
}
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 4);
pc.getPluginInstanceState(uuid, 4);
}
@ -356,10 +347,10 @@ public class SmartExecutorSchedulerTest {
endTime = Calendar.getInstance().getTimeInMillis();
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1);
PluginState pluginState = pc.getPluginInstanceState(uuid, 1);
Assert.assertEquals(PluginState.DONE, pluginState);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 2);
pc.getPluginInstanceState(uuid, 2);
}
@ -386,12 +377,12 @@ 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);
}
try{
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(uuid, 5);
Assert.assertEquals(PluginState.STOPPED, pluginState);
}catch(PluginStateNotRetrievedException e){
// OK
@ -420,7 +411,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{
@ -428,7 +419,7 @@ public class SmartExecutorSchedulerTest {
}
}
try{
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(uuid, 5);
Assert.assertEquals(PluginState.STOPPED, pluginState);
}catch(PluginStateNotRetrievedException e){
// OK
@ -465,12 +456,12 @@ public class SmartExecutorSchedulerTest {
for(int i=0; i<expectedStates.length; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(uuid, i+1);
Assert.assertEquals(expectedStates[i], pluginState);
}
try{
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(uuid, 5);
Assert.assertEquals(PluginState.DISCARDED, pluginState);
}catch(PluginStateNotRetrievedException e){
// OK
@ -490,11 +481,11 @@ public class SmartExecutorSchedulerTest {
}
for(int i=0; i<3; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(uuid, i+1);
Assert.assertEquals(PluginState.DONE, pluginState);
}
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 4);
pc.getPluginInstanceState(uuid, 4);
}
@ -518,10 +509,10 @@ public class SmartExecutorSchedulerTest {
endTime = Calendar.getInstance().getTimeInMillis();
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1);
PluginState pluginState = pc.getPluginInstanceState(uuid, 1);
Assert.assertEquals(PluginState.DONE, pluginState);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 2);
pc.getPluginInstanceState(uuid, 2);
}