refs #579: Use Persistence to persist Scheduled Task configuration on smart-executor

https://support.d4science.org/issues/579
Reorganizing Service;
Substituted argument "String pluginName" with "PluginDeclaration pluginDeclaration";

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@119438 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-10-06 12:32:36 +00:00
parent bc827fe06c
commit bccb75077c
17 changed files with 267 additions and 428 deletions

View File

@ -13,6 +13,7 @@ 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;
@ -94,11 +95,11 @@ public class SmartExecutorImpl implements SmartExecutor {
/**{@inheritDoc}*/
@Override
public PluginState getState(String pluginName, String executionIdentifier)
public PluginState getState(PluginDeclaration pluginDeclaration, String executionIdentifier)
throws PluginInstanceNotFoundException, ExecutorException {
try {
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector();
return persistenceConnector.getLastPluginInstanceState(pluginName, UUID.fromString(executionIdentifier));
return persistenceConnector.getLastPluginInstanceState(pluginDeclaration, UUID.fromString(executionIdentifier));
} catch (Exception e) {
throw new PluginInstanceNotFoundException();
}
@ -106,11 +107,11 @@ public class SmartExecutorImpl implements SmartExecutor {
/**{@inheritDoc}*/
@Override
public PluginState getIterationState(String pluginName, String executionIdentifier, int iterationNumber)
public PluginState getIterationState(PluginDeclaration pluginDeclaration, String executionIdentifier, int iterationNumber)
throws PluginInstanceNotFoundException, ExecutorException {
try {
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector();
return persistenceConnector.getPluginInstanceState(pluginName, UUID.fromString(executionIdentifier), iterationNumber);
return persistenceConnector.getPluginInstanceState(pluginDeclaration, UUID.fromString(executionIdentifier), iterationNumber);
} catch (Exception e) {
throw new PluginInstanceNotFoundException();
}

View File

@ -10,8 +10,11 @@ import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
/**
* Every implementation MUST take in account to store/query the records
* on the current scope which is not passed as argument but MUSt be retrieved
* using {#org.gcube.common.scope.api.ScopeProvider} facilities
* i.e. ScopeProvider.instance.get()
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public interface ScheduledTaskConfiguration {

View File

@ -18,6 +18,7 @@ import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
import org.gcube.vremanagement.executor.exception.ScopeNotMatchException;
import org.gcube.vremanagement.executor.utils.IOUtility;
import org.json.JSONArray;
import org.json.JSONException;
@ -53,7 +54,7 @@ public class FileScheduledTaskConfiguration implements ScheduledTaskConfiguratio
}
protected Scheduling getScheduling(JSONObject jsonObject)
throws JSONException, ParseException{
throws JSONException, ParseException, ScopeNotMatchException {
return new JSONScheduling(jsonObject);
}

View File

@ -10,6 +10,7 @@ import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.exception.ScopeNotMatchException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -81,7 +82,7 @@ public class JSONLaunchParameter extends LaunchParameter {
this.scope = ScopeProvider.instance.get();
}
public JSONLaunchParameter(JSONObject jsonObject) throws JSONException, ParseException {
public JSONLaunchParameter(JSONObject jsonObject) throws JSONException, ParseException, ScopeNotMatchException {
super();
this.pluginName = jsonObject.getString(PLUGIN_NAME);
@ -158,7 +159,7 @@ public class JSONLaunchParameter extends LaunchParameter {
obj.put(INPUTS, inputJsonObject);
if(scheduling!=null){
obj.put(SCHEDULING, ((JSONScheduling) scheduling).toJSON());
obj.put(SCHEDULING, getScheduling().toJSON());
}
obj.put(PERSIST, true);

View File

@ -5,17 +5,23 @@ package org.gcube.vremanagement.executor.configuration.jsonbased;
import java.text.ParseException;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.exception.ScopeNotMatchException;
import org.json.JSONException;
import org.json.JSONObject;
import org.quartz.CronExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
class JSONScheduling extends Scheduling {
private static Logger logger = LoggerFactory.getLogger(JSONScheduling.class);
public static final String CRON_EXPRESSION = "cronExpression";
public static final String DELAY = "delay";
public static final String SCHEDULING_TIMES = "schedulingTimes";
@ -23,18 +29,19 @@ class JSONScheduling extends Scheduling {
public static final String END_TIME = "endTime";
public static final String PREVIUOS_EXECUTION_MUST_BE_COMPLETED = "previuosExecutionsMustBeCompleted";
@SuppressWarnings("unused")
private JSONScheduling(){}
public static final String SCOPE = "scope";
protected final String scope;
public JSONScheduling(Scheduling scheduling) throws ParseException {
super();
init(new CronExpression(scheduling.getCronExpression()), scheduling.getDelay(), scheduling.getSchedulingTimes(),
scheduling.getFirtStartTime(), scheduling.getEndTime(),
scheduling.mustPreviousExecutionsCompleted());
this.scope = ScopeProvider.instance.get();
}
public JSONScheduling(JSONObject jsonObject) throws JSONException,
ParseException {
ParseException, ScopeNotMatchException {
super();
CronExpression cronExpression = null;
@ -71,7 +78,18 @@ class JSONScheduling extends Scheduling {
init(cronExpression, delay, schedulingTimes.intValue(), firstStartTime,
endTime, previuosExecutionsMustBeCompleted);
this.scope = ScopeProvider.instance.get();
if(jsonObject.has(SCOPE)){
String jsonScope = jsonObject.getString(SCOPE);
if(jsonScope.compareTo(scope)!=0){
String message = String.format("The current scope %s differs from the one provide in %s provided as argument %s.",
scope, JSONObject.class.getSimpleName(), jsonScope);
logger.error(message);
throw new ScopeNotMatchException(message);
}
}
}
public JSONObject toJSON() throws JSONException {
@ -96,6 +114,8 @@ class JSONScheduling extends Scheduling {
obj.put(PREVIUOS_EXECUTION_MUST_BE_COMPLETED, this.previuosExecutionsMustBeCompleted);
obj.put(SCOPE, scope);
return obj;
}

View File

@ -0,0 +1,33 @@
/**
*
*/
package org.gcube.vremanagement.executor.exception;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class ScopeNotMatchException extends Exception {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 120445106456933848L;
public ScopeNotMatchException() {
super();
}
public ScopeNotMatchException(String message) {
super(message);
}
public ScopeNotMatchException(Throwable throwable){
super(throwable);
}
public ScopeNotMatchException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,260 +0,0 @@
/**
*
*/
package org.gcube.vremanagement.executor.persistence;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
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;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* INTERNAL USE ONLY for testing purpose
*/
class JDBCPersistenceConnector extends SmartExecutorPersistenceConnector {
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(JDBCPersistenceConnector.class);
protected Connection connection;
public static final String driverClass = "org.h2.Driver";
public static final String jdbcConnection = "jdbc:h2:";
public static final String username = "username";
public static final String password = "password";
public static final String dbName = "executor";
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE = "PluginInstanceEvolution";
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_ID_FIELD = "id";
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD = "uuid";
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_ITERATION_FIELD = "iteration";
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_PLUGIN_NAME_FIELD = "pluginName";
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD = "timestamp";
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD = "state";
public final static String CATALINA_HOME = "CATALINA_HOME";
public JDBCPersistenceConnector() throws Exception {
this(SmartExecutorInitalizator.getCtx().persistence().location());
}
/**
* This constructor is used to provide a location where creating persistence
* files
* @param location directory where creating the DB file
* @throws Exception if fails
*/
public JDBCPersistenceConnector(String location) throws Exception {
super();
try {
Class.forName(driverClass);
logger.debug(String.format("JDBC Driver (%s) Registered!", driverClass));
} catch (ClassNotFoundException e) {
logger.error(String.format("Driver Class (%s) NOT available : %s", driverClass, e));
throw e;
}
String dbFilePath = String.format("%s/%s", location, dbName);
String jdbcURL = String.format("%s%s", jdbcConnection, dbFilePath);
logger.debug(String.format("DB URL : %s", jdbcURL));
try{
connection = DriverManager.getConnection(jdbcURL, username, password);
} catch(SQLException e) {
logger.error(String.format("Unable to connect to JDBC URL : %s", jdbcURL));
}
try {
connection.setAutoCommit(false); // transaction block start
String createTable = String.format(
"CREATE TABLE IF NOT EXISTS `%s` ("
+ "`%s` INT PRIMARY KEY AUTO_INCREMENT NOT NULL,"
+ "`%s` VARCHAR(36) NOT NULL,"
+ "`%s` INT NOT NULL,"
+ "`%s` VARCHAR(255) NOT NULL,"
+ "`%s` BIGINT NOT NULL,"
+ "`%s` INT NOT NULL);",
PLUGIN_INSTANCE_EVOLUTION_TABLE,
PLUGIN_INSTANCE_EVOLUTION_TABLE_ID_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_ITERATION_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_PLUGIN_NAME_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD);
logger.info(String.format("Creating %s Table : %s.",
PLUGIN_INSTANCE_EVOLUTION_TABLE, createTable));
Statement createTableStatement = connection.createStatement();
createTableStatement.execute(createTable);
connection.commit(); //transaction block end
} catch(Exception e){
logger.error("Error while creating DB", e);
throw e;
}
}
/**
* @return the connection to the DB
*/
public Connection getConnection() {
return connection;
}
/**{@inheritDoc} */
@Override
@Deprecated
public PluginState getPluginInstanceState(UUID uuid, int iterationNumber) throws Exception {
String query = String.format(
"SELECT `%s`,`%s` FROM `%s` WHERE `%s`=? AND `%s`=? ORDER BY `%s` DESC LIMIT 1",
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE,
PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_ITERATION_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD);
logger.debug(query);
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, uuid.toString());
ps.setInt(2, iterationNumber);
ResultSet resultSet = ps.executeQuery();
try {
resultSet.first();
int stateOrdinal = resultSet.getInt(PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD);
return PluginState.values()[stateOrdinal];
}catch(SQLException e){
throw new PluginStateNotRetrievedException(e.getCause());
}
}
/**{@inheritDoc} */
@Override
@Deprecated
public PluginState getLastPluginInstanceState(UUID uuid) throws Exception {
String query = String.format(
"SELECT `%s`,`%s` FROM `%s` WHERE `%s`=? ORDER BY `%s` DESC LIMIT 1",
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE,
PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD);
logger.debug(query);
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, uuid.toString());
ResultSet resultSet = ps.executeQuery();
try {
resultSet.first();
int stateOrdinal = resultSet.getInt(PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD);
return PluginState.values()[stateOrdinal];
}catch(SQLException e){
throw new PluginStateNotRetrievedException(e.getCause());
}
}
/**{@inheritDoc} */
@Override
public PluginState getPluginInstanceState(String pluginName, UUID uuid, int iterationNumber) throws Exception {
String query = String.format(
"SELECT `%s`,`%s` FROM `%s` WHERE `%s`=? AND `%s`=? AND `%s`=? ORDER BY `%s` DESC LIMIT 1",
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE,
PLUGIN_INSTANCE_EVOLUTION_TABLE_PLUGIN_NAME_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_ITERATION_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD);
logger.debug(query);
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, pluginName);
ps.setString(2, uuid.toString());
ps.setInt(3, iterationNumber);
ResultSet resultSet = ps.executeQuery();
try {
resultSet.first();
int stateOrdinal = resultSet.getInt(PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD);
return PluginState.values()[stateOrdinal];
}catch(SQLException e){
throw new PluginStateNotRetrievedException(e.getCause());
}
}
/**{@inheritDoc} */
@Override
public PluginState getLastPluginInstanceState(String pluginName, UUID uuid) throws Exception {
String query = String.format(
"SELECT `%s`,`%s` FROM `%s` WHERE `%s`=? AND `%s`=? ORDER BY `%s` DESC LIMIT 1",
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE,
PLUGIN_INSTANCE_EVOLUTION_TABLE_PLUGIN_NAME_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD,
PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD);
logger.debug(query);
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, pluginName);
ps.setString(2, uuid.toString());
ResultSet resultSet = ps.executeQuery();
try {
resultSet.first();
int stateOrdinal = resultSet.getInt(PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD);
return PluginState.values()[stateOrdinal];
}catch(SQLException e){
throw new PluginStateNotRetrievedException(e.getCause());
}
}
@Override
public void pluginStateEvolution(UUID uuid, int iteration, long timestamp, String pluginName, PluginState pluginState)
throws Exception {
connection.setAutoCommit(false); // transaction block start
String insertPluginEvolution = String.format(
"INSERT INTO `%s` (`%s`,`%s`,`%s`,`%s`,`%s`) VALUES (?,?,?,?,?)",
JDBCPersistenceConnector.PLUGIN_INSTANCE_EVOLUTION_TABLE,
JDBCPersistenceConnector.PLUGIN_INSTANCE_EVOLUTION_TABLE_UUID_FIELD,
JDBCPersistenceConnector.PLUGIN_INSTANCE_EVOLUTION_TABLE_ITERATION_FIELD,
JDBCPersistenceConnector.PLUGIN_INSTANCE_EVOLUTION_TABLE_PLUGIN_NAME_FIELD,
JDBCPersistenceConnector.PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD,
JDBCPersistenceConnector.PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD);
logger.info(String.format("Base Query : %s. Parameters : %s,%d,%s,%s,%s",
insertPluginEvolution, uuid, iteration, pluginName, timestamp, pluginState.name()));
PreparedStatement psInsertPluginEvolution = connection
.prepareStatement(insertPluginEvolution);
psInsertPluginEvolution.setString(1, uuid.toString());
psInsertPluginEvolution.setInt(2, iteration);
psInsertPluginEvolution.setString(3, pluginName);
psInsertPluginEvolution.setLong(4, timestamp);
psInsertPluginEvolution.setInt(5, pluginState.ordinal());
psInsertPluginEvolution.executeUpdate();
connection.commit(); //transaction block end
}
/**{@inheritDoc} */
@Override
public void close() throws Exception {
connection.close();
}
}

View File

@ -5,12 +5,18 @@ package org.gcube.vremanagement.executor.persistence;
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;
/**
* Model the connector which create or open the connection to DB
* Model the connector which create or open the connection to DB.
* Every implementation MUST take in account to store/query the records
* on the current scope which is not passed as argument but MUSt be retrieved
* using {#org.gcube.common.scope.api.ScopeProvider} facilities
* i.e. ScopeProvider.instance.get()
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public abstract class SmartExecutorPersistenceConnector implements PluginStateNotification {
@ -20,7 +26,7 @@ public abstract class SmartExecutorPersistenceConnector implements PluginStateNo
/**
* @return the persistenceConnector
*/
public static SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
if(SmartExecutorPersistenceConnector.persistenceConnector==null){
SmartExecutorPersistenceConfiguration configuration =
new SmartExecutorPersistenceConfiguration(CouchDBPersistenceConnector.class.getSimpleName());
@ -32,7 +38,7 @@ public abstract class SmartExecutorPersistenceConnector implements PluginStateNo
/**
* @param persistenceConnector the persistenceConnector to set
*/
public static void setPersistenceConnector(
public static synchronized void setPersistenceConnector(
SmartExecutorPersistenceConnector persistenceConnector) {
SmartExecutorPersistenceConnector.persistenceConnector = persistenceConnector;
}
@ -44,23 +50,26 @@ 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 {@link Plugin} which is/was identified
* by the UUID passed as parameter
* 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.
* @param pluginDeclaration The Plugin Declaration class
* @param uuid the execution identifier of the running/run {@link Plugin}
* @param iterationNumber the
* @param iterationNumber the iteration number
* @return the actual/last {@link PluginState} of the Plugin
* @throws Exception if fails
*/
public abstract PluginState getPluginInstanceState(String pluginName, UUID uuid, int iterationNumber)
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(String pluginName, UUID uuid)
public abstract PluginState getLastPluginInstanceState(PluginDeclaration pluginDeclaration, UUID uuid)
throws Exception;
/**

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.vremanagement.executor.persistence;
package org.gcube.vremanagement.executor.persistence.couchdb;
import java.io.InputStream;
import java.io.StringWriter;
@ -27,15 +27,18 @@ import org.ektorp.http.StdHttpClient;
import org.ektorp.http.StdHttpClient.Builder;
import org.ektorp.impl.StdCouchDbConnector;
import org.ektorp.impl.StdCouchDbInstance;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
import org.gcube.vremanagement.executor.SmartExecutorInitalizator;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
import org.gcube.vremanagement.executor.configuration.jsonbased.JSONLaunchParameter;
import org.gcube.vremanagement.executor.exception.PluginStateNotRetrievedException;
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
import org.gcube.vremanagement.executor.exception.ScopeNotMatchException;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConfiguration;
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.plugin.PluginStateEvolution;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
@ -58,17 +61,6 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
protected static final String _REV_JSON_FIELD = "_rev";
protected static final String TYPE_JSON_FIELD = "type";
protected static final String USED_BY_FIELD = "usedBy";
protected static final String RESERVED_BY = "reservedBy";
protected static final String PREVIOUSLY_USED_BY = "previouslyUsedBy";
protected static final String RESERVATION_TIMESTAMP = "reservationTimestamp";
protected static final String EVOLUTION_TYPE = "evolution";
protected static final String SCHEDULED_TASK_TYPE = "scheduledTask";
public CouchDBPersistenceConnector(SmartExecutorPersistenceConfiguration configuration) throws Exception {
super();
prepareConnection(configuration);
@ -134,40 +126,12 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
couchDbConnector.delete(id, revision);
}
public final static String UUID_FIELD = "uuid";
public final static String ITERATION_FIELD = "iteration";
public final static String PLUGIN_NAME_FIELD = "pluginName";
public final static String TIMESTAMP_FIELD = "timestamp";
public final static String STATE_FIELD = "state";
protected static final String RUN_ON_FIELD = "runOn";
public final static String GHN_HOSTNAME_FIELD = "ghnHostname";
public final static String GHN_ID_FIELD = "ghnID";
protected static ObjectNode getRunOn(){
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();
GCoreEndpoint gCoreEndpoint = SmartExecutorInitalizator.getCtx().profile(GCoreEndpoint.class);
objectNode.put(GHN_ID_FIELD, gCoreEndpoint.profile().ghnId());
objectNode.put(GHN_HOSTNAME_FIELD, SmartExecutorInitalizator.getCtx().container().configuration().hostname());
return objectNode;
}
/**
* {@inheritDoc}
*/
@Override
public void pluginStateEvolution(UUID uuid, int iteration, long timestamp,
String pluginName, PluginState pluginState) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();
objectNode.put(UUID_FIELD, uuid.toString());
objectNode.put(ITERATION_FIELD, iteration);
objectNode.put(TIMESTAMP_FIELD, timestamp);
objectNode.put(PLUGIN_NAME_FIELD, pluginName);
objectNode.put(STATE_FIELD, pluginState.toString());
objectNode.put(TYPE_JSON_FIELD, EVOLUTION_TYPE);
objectNode.put(RUN_ON_FIELD, getRunOn());
public void pluginStateEvolution(PluginStateEvolution pluginStateEvolution) throws Exception {
ObjectNode objectNode = PluginStateEvolutionObjectNode.getObjectMapper(pluginStateEvolution);
createItem(objectNode, null);
}
@ -194,9 +158,9 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
* {@inheritDoc}
*/
@Override
public PluginState getPluginInstanceState(String pluginName, UUID uuid, int iterationNumber)
public PluginState getPluginInstanceState(PluginDeclaration pluginDeclaration, UUID uuid, int iterationNumber)
throws Exception {
return reallyQuery(pluginName, uuid, iterationNumber);
return reallyQuery(pluginDeclaration, uuid, iterationNumber);
}
protected final static int LAST = -1;
@ -205,8 +169,8 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
* {@inheritDoc}
*/
@Override
public PluginState getLastPluginInstanceState(String pluginName, UUID uuid) throws Exception {
return reallyQuery(pluginName, uuid, LAST);
public PluginState getLastPluginInstanceState(PluginDeclaration pluginDeclaration, UUID uuid) throws Exception {
return reallyQuery(pluginDeclaration, uuid, LAST);
}
protected static final String MAP_REDUCE__DESIGN = "_design/";
@ -219,20 +183,32 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
protected static final String ACTIVE_VIEW = "active";
protected static final String ORPHAN_VIEW = "orphan";
protected static final String USED_BY_FIELD = "usedBy";
protected static final String RESERVED_BY = "reservedBy";
protected static final String PREVIOUSLY_USED_BY = "previouslyUsedBy";
protected static final String RESERVATION_TIMESTAMP = "reservationTimestamp";
protected static final String SCHEDULED_TASK_TYPE = "scheduledTask";
/**
* @param uuid
* @param iterationNumber -1 means LAST
* @return
* @throws Exception
*/
protected PluginState reallyQuery(String pluginName, UUID uuid, int iterationNumber)
protected PluginState reallyQuery(PluginDeclaration pluginDeclaration, UUID uuid, int iterationNumber)
throws Exception {
ViewQuery query = new ViewQuery().designDocId(String.format("%s%s", MAP_REDUCE__DESIGN, PLUGIN_STATE_DOCUMENT));
String scope = ScopeProvider.instance.get();
ArrayNode startKey = new ObjectMapper().createArrayNode();
startKey.add(scope);
ArrayNode endKey = new ObjectMapper().createArrayNode();
endKey.add(scope);
String pluginName = pluginDeclaration.getName();
if(pluginName!=null && pluginName.compareTo("")!=0){
startKey.add(pluginName);
@ -307,7 +283,10 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
} catch (ParseException | JSONException e) {
logger.error("Unable to parse result Row", e.getCause());
continue;
}
} catch (ScopeNotMatchException ex){
logger.error("The result row does not macth the current Scope. This should indicate a query error.", ex.getCause());
continue;
}
}
return ret;

View File

@ -0,0 +1,67 @@
/**
*
*/
package org.gcube.vremanagement.executor.persistence.couchdb;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vremanagement.executor.SmartExecutorInitalizator;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class PluginStateEvolutionObjectNode {
protected static final String EVOLUTION_TYPE = "evolution";
public final static String UUID_FIELD = "uuid";
public final static String ITERATION_FIELD = "iteration";
public final static String PLUGIN_NAME_FIELD = "pluginName";
public final static String TIMESTAMP_FIELD = "timestamp";
public final static String STATE_FIELD = "state";
protected static final String RUN_ON_FIELD = "runOn";
public final static String GHN_HOSTNAME_FIELD = "ghnHostname";
public final static String GHN_ID_FIELD = "ghnID";
public final static String SCOPE_FIELD = "scope";
protected static ObjectNode getRunOn(){
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();
GCoreEndpoint gCoreEndpoint = SmartExecutorInitalizator.getCtx().profile(GCoreEndpoint.class);
objectNode.put(GHN_ID_FIELD, gCoreEndpoint.profile().ghnId());
objectNode.put(GHN_HOSTNAME_FIELD, SmartExecutorInitalizator.getCtx().container().configuration().hostname());
return objectNode;
}
public static void addScope(ObjectNode objectNode){
objectNode.put(SCOPE_FIELD, ScopeProvider.instance.get());
}
public static ObjectNode getObjectMapper(PluginStateEvolution pluginStateEvolution){
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();
objectNode.put(UUID_FIELD, pluginStateEvolution.getUuid().toString());
objectNode.put(ITERATION_FIELD, pluginStateEvolution.getIteration());
objectNode.put(TIMESTAMP_FIELD, pluginStateEvolution.getTimestamp());
objectNode.put(PLUGIN_NAME_FIELD, pluginStateEvolution.getPluginDeclaration().getName());
objectNode.put(STATE_FIELD, pluginStateEvolution.getPluginState().toString());
addScope(objectNode);
objectNode.put(CouchDBPersistenceConnector.TYPE_JSON_FIELD, EVOLUTION_TYPE);
try {
objectNode.put(RUN_ON_FIELD, getRunOn());
}catch(Exception e){
// TODO
}
return objectNode;
}
}

View File

@ -12,6 +12,7 @@ import org.gcube.vremanagement.executor.exception.AlreadyInFinalStateException;
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.PluginStateEvolution;
import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -107,18 +108,15 @@ public class RunnablePlugin<T extends Plugin<? extends PluginDeclaration>> imple
}
actualState = pluginState;
String pluginName = plugin.getPluginDeclaration().getName();
for(PluginStateNotification pluginStateNotification : pluginStateNotifications){
String pluginStateNotificationName = pluginStateNotification.getClass().getSimpleName();
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, iterationNumber, timestamp, plugin.getPluginDeclaration(), pluginState);
try {
logger.debug("Adding State Evolution with {} : {}, {}, {}, {}, {}",
pluginStateNotificationName, uuid, iterationNumber,
timestamp, pluginName, pluginState.name());
pluginStateNotification.pluginStateEvolution(uuid, iterationNumber, timestamp, pluginName, pluginState);
logger.debug("Adding Plugin State Evolution {} with {}.", pluginStateEvolution, pluginStateNotificationName);
pluginStateNotification.pluginStateEvolution(pluginStateEvolution);
} catch(Exception e) {
logger.error("Unable to persist State with {} : {}, {}, {}, {}, {}",
pluginStateNotificationName, uuid, iterationNumber,
timestamp, pluginName, pluginState.name());
logger.error("Unable to Persist Plugin State Evolution {} with {}.",
pluginStateEvolution, pluginStateNotificationName);
}
}
}

View File

@ -4,18 +4,26 @@
package org.gcube.vremanagement.executor.scheduler;
import java.util.Map;
import java.util.UUID;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
/**
* This class is useless is just used to simulate and indicate the code
* insertion point the possibility to add multiple notification of an event
* in the running plugin evolution.
* Future use of this possibility are possibility to send an email to
* the job owner, notify a registered process. Send a tweet and so on.
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@Deprecated
public class JobCompletedNotification implements PluginStateNotification {
/**
* Maintain the Execution State
* Iteration - State
*/
protected final Map<Integer, PluginState> executionsState;
public JobCompletedNotification(Map<Integer, PluginState> executionsState){
@ -23,9 +31,8 @@ public class JobCompletedNotification implements PluginStateNotification {
}
@Override
public void pluginStateEvolution(UUID uuid, int iteration, long timestamp,
String pluginName, PluginState pluginState) throws Exception {
executionsState.put(iteration, pluginState);
public void pluginStateEvolution(PluginStateEvolution pluginStateEvolution) throws Exception {
executionsState.put(pluginStateEvolution.getIteration(), pluginStateEvolution.getPluginState());
}
}

View File

@ -77,6 +77,7 @@ public class SmartExecutorJob implements InterruptableJob {
protected int maxExecutionNumber;
/**/
@SuppressWarnings("deprecation")
protected void init(JobDataMap jobDataMap) throws JobExecutionException{
uuid = (UUID) jobDataMap.get(UUID);
launchParameter = (LaunchParameter) jobDataMap.get(LAUNCH_PARAMETER);
@ -104,6 +105,10 @@ public class SmartExecutorJob implements InterruptableJob {
executionState.put(0, PluginState.DONE);
}
// TODO Insert code to dynamically discover notification to
// attach and attach the requested ones.
// The following line of code is just a placeholder and must be
// removed when the previous TO DO has done.
pluginStateNotifications.add(new JobCompletedNotification(executionState));
}

View File

@ -1,47 +0,0 @@
/**
*
*/
package org.gcube.vremanagement.executor.persistence;
import java.util.Date;
import java.util.UUID;
import org.acme.HelloWorldPluginDeclaration;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class JDBCPersistenceConnectorTest {
@Test
public void getConnectionTest() throws Exception {
JDBCPersistenceConnector jdbcPersistenceConnector = new JDBCPersistenceConnector(".");
Assert.assertNotNull(jdbcPersistenceConnector.getConnection());
jdbcPersistenceConnector.close();
}
@Test
public void getPluginInstanceStateTest() throws Exception {
UUID uuid = UUID.randomUUID();
JDBCPersistenceConnector jdbcPersistenceConnector = new JDBCPersistenceConnector(".");
PluginState[] states = PluginState.values();
for(int i=0; i<states.length; i++){
long timestamp = new Date().getTime();
jdbcPersistenceConnector.pluginStateEvolution(uuid, 1, timestamp, HelloWorldPluginDeclaration.NAME, states[i]);
PluginState ps = jdbcPersistenceConnector.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 1);
Assert.assertEquals(states[i], ps);
}
jdbcPersistenceConnector.close();
}
}

View File

@ -3,12 +3,18 @@
*/
package org.gcube.vremanagement.executor.persistence;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.acme.HelloWorldPluginDeclaration;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfigurationFactory;
import org.gcube.vremanagement.executor.persistence.couchdb.CouchDBPersistenceConnector;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@ -32,8 +38,27 @@ public class SmartExecutorPersistenceConnectorTest {
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector();
Assert.assertNotNull(persistenceConnector);
Assert.assertEquals(CouchDBPersistenceConnector.class, persistenceConnector.getClass());
persistenceConnector.close();
}
@Test
public void getPluginInstanceStateTest() throws Exception {
ScopeProvider.instance.set(GCUBE_DEVSEC_SCOPE);
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector();
UUID uuid = UUID.randomUUID();
PluginState[] states = PluginState.values();
for(int i=0; i<states.length; i++){
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);
Assert.assertEquals(states[i], ps);
}
persistenceConnector.close();
}
@Test
public void getAvailableScheduledTasksTest() throws Exception {
@ -45,7 +70,7 @@ public class SmartExecutorPersistenceConnectorTest {
List<LaunchParameter> lc = stc.getAvailableScheduledTasks();
logger.debug("Available Scheduled Tasks", lc);
logger.debug("Available Scheduled Tasks : {}", lc);
}

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.NAME, uuid, 1));
Assert.assertEquals(PluginState.CREATED, persistenceConnector.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1));
rp.run();
Assert.assertEquals(PluginState.DONE, persistenceConnector.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 1));
Assert.assertEquals(PluginState.DONE, persistenceConnector.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1));
}

View File

@ -36,8 +36,6 @@ public class SmartExecutorSchedulerTest {
public static final String START = "START";
public static final String END = "END";
public static SmartExecutorPersistenceConnector pc;
@BeforeClass
@ -65,7 +63,6 @@ public class SmartExecutorSchedulerTest {
}
}
public UUID scheduleTest(Scheduling scheduling, Long sleepTime) throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
if(sleepTime==null){
@ -94,7 +91,7 @@ public class SmartExecutorSchedulerTest {
inputs.put("Test UUID", UUID.randomUUID());
logger.debug("Inputs : {}", inputs);
LaunchParameter parameter = new LaunchParameter(DeprecatedHelloWorldPluginDeclaration.NAME, inputs);
LaunchParameter parameter = new LaunchParameter(DeprecatedHelloWorldPluginDeclaration.class.newInstance(), inputs);
parameter.setScheduling(null);
SmartExecutorScheduler smartExecutorScheduler = SmartExecutorScheduler.getInstance();
@ -120,10 +117,9 @@ public class SmartExecutorSchedulerTest {
while(endTime <= (startTime + 12000)){
endTime = Calendar.getInstance().getTimeInMillis();
}
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid);
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid);
Assert.assertEquals(PluginState.DONE, pluginState);
@SuppressWarnings("deprecation")
PluginState pluginStateFromDeprecation = pc.getLastPluginInstanceState(uuid);
Assert.assertEquals(PluginState.DONE, pluginStateFromDeprecation);
@ -141,7 +137,7 @@ public class SmartExecutorSchedulerTest {
}
try{
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
Assert.assertEquals(PluginState.STOPPED, pluginState);
@SuppressWarnings("deprecation")
@ -150,6 +146,7 @@ public class SmartExecutorSchedulerTest {
}catch(PluginStateNotRetrievedException e){
// OK
logger.error("PluginStateNotRetrievedException this can be acceptable in some tests", e);
}
}
@ -172,7 +169,7 @@ public class SmartExecutorSchedulerTest {
while(endTime <= (startTime + 10000)){
endTime = Calendar.getInstance().getTimeInMillis();
}
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid);
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid);
Assert.assertEquals(PluginState.STOPPED, pluginState);
}
@ -187,7 +184,7 @@ public class SmartExecutorSchedulerTest {
}
smartExecutorScheduler.stop(uuid);
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid);
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid);
Assert.assertEquals(PluginState.DONE, pluginState);
}
@ -212,10 +209,10 @@ public class SmartExecutorSchedulerTest {
endTime = Calendar.getInstance().getTimeInMillis();
}
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.NAME, first);
PluginState pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), first);
Assert.assertEquals(PluginState.STOPPED, pluginState);
pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.NAME, second);
pluginState = pc.getLastPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), second);
Assert.assertEquals(PluginState.DONE, pluginState);
}
@ -239,11 +236,11 @@ public class SmartExecutorSchedulerTest {
}
for(int i=1; i<5; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i);
Assert.assertEquals(PluginState.DONE, pluginState);
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
Assert.assertEquals(PluginState.STOPPED, pluginState);
}
@ -268,7 +265,7 @@ public class SmartExecutorSchedulerTest {
}
for(int i=1; i<5; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i);
if(i%2!=0){
Assert.assertEquals(PluginState.DONE, pluginState);
}else{
@ -276,7 +273,7 @@ public class SmartExecutorSchedulerTest {
}
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
Assert.assertEquals(PluginState.STOPPED, pluginState);
}
@ -309,11 +306,11 @@ public class SmartExecutorSchedulerTest {
for(int i=0; i<expectedStates.length; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
Assert.assertEquals(expectedStates[i], pluginState);
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
Assert.assertEquals(PluginState.DISCARDED, pluginState);
}
@ -330,11 +327,11 @@ public class SmartExecutorSchedulerTest {
}
for(int i=0; i<3; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
Assert.assertEquals(PluginState.DONE, pluginState);
}
pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 4);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 4);
}
@ -359,10 +356,10 @@ public class SmartExecutorSchedulerTest {
endTime = Calendar.getInstance().getTimeInMillis();
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 1);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1);
Assert.assertEquals(PluginState.DONE, pluginState);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 2);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 2);
}
@ -389,12 +386,12 @@ public class SmartExecutorSchedulerTest {
}
for(int i=1; i<5; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i);
Assert.assertEquals(PluginState.DONE, pluginState);
}
try{
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
Assert.assertEquals(PluginState.STOPPED, pluginState);
}catch(PluginStateNotRetrievedException e){
// OK
@ -423,7 +420,7 @@ public class SmartExecutorSchedulerTest {
}
for(int i=1; i<5; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i);
if(i%2!=0){
Assert.assertEquals(PluginState.DONE, pluginState);
}else{
@ -431,7 +428,7 @@ public class SmartExecutorSchedulerTest {
}
}
try{
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
Assert.assertEquals(PluginState.STOPPED, pluginState);
}catch(PluginStateNotRetrievedException e){
// OK
@ -468,12 +465,12 @@ public class SmartExecutorSchedulerTest {
for(int i=0; i<expectedStates.length; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
Assert.assertEquals(expectedStates[i], pluginState);
}
try{
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 5);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 5);
Assert.assertEquals(PluginState.DISCARDED, pluginState);
}catch(PluginStateNotRetrievedException e){
// OK
@ -493,11 +490,11 @@ public class SmartExecutorSchedulerTest {
}
for(int i=0; i<3; i++){
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, i+1);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, i+1);
Assert.assertEquals(PluginState.DONE, pluginState);
}
pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 4);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 4);
}
@ -521,10 +518,10 @@ public class SmartExecutorSchedulerTest {
endTime = Calendar.getInstance().getTimeInMillis();
}
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 1);
PluginState pluginState = pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 1);
Assert.assertEquals(PluginState.DONE, pluginState);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.NAME, uuid, 2);
pc.getPluginInstanceState(HelloWorldPluginDeclaration.class.newInstance(), uuid, 2);
}