Merged from private branch for release 4.1.0
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor-api@131612 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c02825f79b
commit
f6347d5af3
13
pom.xml
13
pom.xml
|
@ -25,11 +25,22 @@
|
|||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.gcube.vremanagement.executor.exception.LaunchException;
|
|||
import org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException;
|
||||
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
||||
|
||||
/**
|
||||
* Service Endpoint Interface
|
||||
|
@ -64,31 +65,6 @@ public interface SmartExecutor {
|
|||
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
|
||||
public boolean stop(String executionIdentifier) throws ExecutorException;
|
||||
|
||||
/**
|
||||
* The method use the provided UUID execution identifier as String to
|
||||
* stop the last running execution of a Task (if any) and release the
|
||||
* the scheduling if the Task is a Scheduled Task.
|
||||
* After this method has been successfully executed, if the identified
|
||||
* Scheduled Task was global, another SmartExecutor instance will be
|
||||
* able to take in charge the Scheduling. If the identified Scheduled Task
|
||||
* was local no other SmartExecutor instances will be able to take in
|
||||
* charge the scheduling.
|
||||
* If the Task is not a Scheduled Task, the only effect is stopping the
|
||||
* current execution. In other word has the same side effect of invoking
|
||||
* {@link SmartExecutor#stop()} method.
|
||||
* Invoking this method has the same side effect of invoking
|
||||
* {@link SmartExecutor#unSchedule(String, boolean)} passing false
|
||||
* to the second argument
|
||||
* @param executionIdentifier UUID as String which identify the execution
|
||||
* @return return true if the current execution has been correctly
|
||||
* stopped and the Task was unscheduled. False otherwise.
|
||||
* @throws Exception if there is no Task identified by the
|
||||
* provided UUID execution identifier as String
|
||||
*/
|
||||
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
|
||||
public boolean unSchedule(String executionIdentifier)
|
||||
throws ExecutorException;
|
||||
|
||||
/**
|
||||
* The method use the provided UUID execution identifier as String to
|
||||
* stop the last running execution of a Task (if any) and release the
|
||||
|
@ -111,6 +87,7 @@ public interface SmartExecutor {
|
|||
throws ExecutorException;
|
||||
|
||||
/**
|
||||
* Deprecated Use {@link SmartExecutor#getStateEvolution(String)} instead
|
||||
* The method use the provided UUID as String to retrieve the status of the
|
||||
* associated execution
|
||||
* @param executionIdentifier UUID as String which identify the execution
|
||||
|
@ -119,10 +96,24 @@ public interface SmartExecutor {
|
|||
* UUID execution identifier as String
|
||||
*/
|
||||
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
|
||||
@Deprecated
|
||||
public PluginState getState(String executionIdentifier)
|
||||
throws PluginInstanceNotFoundException, ExecutorException;
|
||||
|
||||
/**
|
||||
* The method use the provided UUID as String to retrieve the status of the
|
||||
* associated execution
|
||||
* @param executionIdentifier UUID as String which identify the execution
|
||||
* @return {@link PluginState} which contains the state of the execution
|
||||
* @throws Exception if there is no execution identified by the provided
|
||||
* UUID execution identifier as String
|
||||
*/
|
||||
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
|
||||
public PluginStateEvolution getStateEvolution(String executionIdentifier)
|
||||
throws PluginInstanceNotFoundException, ExecutorException;
|
||||
|
||||
/**
|
||||
* Deprecated Use {@link SmartExecutor#getIterationStateEvolution(String)} instead
|
||||
* The method use the provided UUID as String and the iteration number
|
||||
* to retrieve the status of the associated execution
|
||||
* @param executionIdentifier UUID as String which identify the execution
|
||||
|
@ -131,9 +122,24 @@ public interface SmartExecutor {
|
|||
* @throws Exception if there is no execution identified by the provided
|
||||
* UUID execution identifier as String
|
||||
*/
|
||||
@Deprecated
|
||||
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
|
||||
public PluginState getIterationState(
|
||||
String executionIdentifier, int iterationNumber)
|
||||
throws PluginInstanceNotFoundException, ExecutorException;
|
||||
|
||||
|
||||
/**
|
||||
* The method use the provided UUID as String and the iteration number
|
||||
* to retrieve the status of the associated execution
|
||||
* @param executionIdentifier UUID as String which identify the execution
|
||||
* @param iterationNumber iteration number
|
||||
* @return {@link PluginStateEvolution} which contains the state of the execution
|
||||
* @throws Exception if there is no execution identified by the provided
|
||||
* UUID execution identifier as String
|
||||
*/
|
||||
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
|
||||
public PluginStateEvolution getIterationStateEvolution(
|
||||
String executionIdentifier, int iterationNumber)
|
||||
throws PluginInstanceNotFoundException, ExecutorException;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package org.gcube.vremanagement.executor.api.types;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
|
@ -12,6 +13,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.gcube.vremanagement.executor.api.types.adapter.MapAdapter;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
|
||||
import org.gcube.vremanagement.executor.utils.MapCompare;
|
||||
import org.gcube.vremanagement.executor.utils.ObjectCompare;
|
||||
|
||||
|
@ -55,6 +57,15 @@ public class LaunchParameter implements Comparable<LaunchParameter> {
|
|||
*/
|
||||
protected Map<String, Object> inputs;
|
||||
|
||||
|
||||
@XmlJavaTypeAdapter(MapAdapter.class)
|
||||
/**
|
||||
* Plugin State Notification to be used and inputs to be provided
|
||||
* when instantiated
|
||||
*/
|
||||
protected Map<String, Map<String, String>> pluginStateNotificationWithParameters;
|
||||
|
||||
|
||||
@XmlElement
|
||||
/**
|
||||
* Scheduling parameters. See {#Scheduling} for further details
|
||||
|
@ -85,6 +96,7 @@ public class LaunchParameter implements Comparable<LaunchParameter> {
|
|||
this.pluginCapabilities = pluginCapabilities;
|
||||
this.inputs = inputs;
|
||||
this.scheduling = scheduling;
|
||||
this.pluginStateNotificationWithParameters = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,13 +141,27 @@ public class LaunchParameter implements Comparable<LaunchParameter> {
|
|||
this.scheduling = scheduling;
|
||||
}
|
||||
|
||||
public void addPluginStateNotifications(Class<? extends PluginStateNotification> pluginStateNotification, Map<String, String> inputs){
|
||||
this.pluginStateNotificationWithParameters.put(pluginStateNotification.getName(), inputs);
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getPluginStateNotifications(){
|
||||
return this.pluginStateNotificationWithParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return String.format("%s : { Plugin : { Name: %s , Capabilites : %s}, Scheduling : {%s}, Inputs : %s}",
|
||||
this.getClass().getSimpleName(), pluginName, pluginCapabilities,
|
||||
scheduling, inputs);
|
||||
return String.format(
|
||||
"%s : "
|
||||
+ "{ Plugin : { Name: %s - Version : %s - Capabilites : %s} - "
|
||||
+ "Scheduling : {%s} - Inputs : %s - "
|
||||
+ "Notifications With Inputs : %s}",
|
||||
this.getClass().getSimpleName(),
|
||||
pluginName, pluginVersion, pluginCapabilities,
|
||||
scheduling, inputs,
|
||||
pluginStateNotificationWithParameters);
|
||||
}
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int compareTo(LaunchParameter launchParameter) {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.exception;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class InvalidPluginStateEvolutionException extends Exception {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = -7730594422282391883L;
|
||||
|
||||
public InvalidPluginStateEvolutionException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidPluginStateEvolutionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidPluginStateEvolutionException(Throwable throwable){
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public InvalidPluginStateEvolutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
package org.gcube.vremanagement.executor.persistence;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.vremanagement.executor.plugin.Plugin;
|
||||
|
@ -14,10 +16,17 @@ import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class PersistenceConnector implements PluginStateNotification {
|
||||
public abstract class PersistenceConnector extends PluginStateNotification {
|
||||
|
||||
protected static PersistenceConnector persistenceConnector;
|
||||
public PersistenceConnector(){
|
||||
super(new HashMap<String, String>());
|
||||
}
|
||||
|
||||
public PersistenceConnector(Map<String, String> inputs){
|
||||
super(inputs);
|
||||
}
|
||||
|
||||
protected static PersistenceConnector persistenceConnector;
|
||||
|
||||
/**
|
||||
* @return the persistenceConnector
|
||||
|
@ -34,20 +43,14 @@ public abstract class PersistenceConnector implements PluginStateNotification {
|
|||
PersistenceConnector.persistenceConnector = persistenceConnector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public PersistenceConnector(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used to provide a location where creating persistence
|
||||
* files
|
||||
* @param location directory where creating the DB file
|
||||
*/
|
||||
public PersistenceConnector(String location) {}
|
||||
|
||||
public PersistenceConnector(String location) {
|
||||
this();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection to DB
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.plugin;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public interface PercentageSetter {
|
||||
|
||||
public void setPercentageEvolution(Integer integer);
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import java.util.Map;
|
|||
public abstract class Plugin<T extends PluginDeclaration> {
|
||||
|
||||
private T pluginDeclaration;
|
||||
private PercentageSetter percentageSetter;
|
||||
|
||||
public Plugin(T pluginDeclaration){
|
||||
this.pluginDeclaration = pluginDeclaration;
|
||||
|
@ -22,6 +23,17 @@ public abstract class Plugin<T extends PluginDeclaration> {
|
|||
return pluginDeclaration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param percentageSetter the percentageSetter to set
|
||||
*/
|
||||
public void setPercentageSetter(PercentageSetter percentageSetter) {
|
||||
this.percentageSetter = percentageSetter;
|
||||
}
|
||||
|
||||
protected void setPercentageEvolution(Integer integer){
|
||||
this.percentageSetter.setPercentageEvolution(integer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the plugin with the provided input.
|
||||
* @param inputs
|
||||
|
|
|
@ -5,10 +5,20 @@ package org.gcube.vremanagement.executor.plugin;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.gcube.vremanagement.executor.api.types.adapter.MapAdapter;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
@XmlRootElement()
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public interface PluginDeclaration {
|
||||
|
||||
/**
|
||||
|
@ -23,6 +33,7 @@ public interface PluginDeclaration {
|
|||
* @return the name of the plugin used by the Executor to refer to the
|
||||
* plugin implementation class.
|
||||
*/
|
||||
@XmlElement
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
|
@ -30,6 +41,7 @@ public interface PluginDeclaration {
|
|||
* and it will be published on the ServiceEndpoint created by the executor
|
||||
* @return the plugin description.
|
||||
*/
|
||||
@XmlElement
|
||||
public String getDescription();
|
||||
|
||||
/**
|
||||
|
@ -37,6 +49,7 @@ public interface PluginDeclaration {
|
|||
* It will be published on the ServiceEndpoint created by the executor
|
||||
* @return the plugin version
|
||||
*/
|
||||
@XmlElement
|
||||
public String getVersion();
|
||||
|
||||
/**
|
||||
|
@ -46,6 +59,7 @@ public interface PluginDeclaration {
|
|||
* Resource in the proper way to obtain its own filtered list.
|
||||
* @return the {@link Map} with the supported capabilities
|
||||
*/
|
||||
@XmlJavaTypeAdapter(MapAdapter.class)
|
||||
public Map<String,String> getSupportedCapabilities();
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,4 +46,9 @@ public enum PluginState {
|
|||
return finalState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.name();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,17 +5,32 @@ package org.gcube.vremanagement.executor.plugin;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
import org.gcube.vremanagement.executor.exception.InvalidPluginStateEvolutionException;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class PluginStateEvolution {
|
||||
|
||||
protected final UUID uuid;
|
||||
protected final int iteration;
|
||||
protected final long timestamp;
|
||||
protected final PluginDeclaration pluginDeclaration;
|
||||
protected final PluginState pluginState;
|
||||
|
||||
@XmlElement
|
||||
protected UUID uuid;
|
||||
@XmlElement
|
||||
protected int iteration;
|
||||
@XmlElement
|
||||
protected long timestamp;
|
||||
protected PluginDeclaration pluginDeclaration;
|
||||
@XmlElement
|
||||
protected PluginState pluginState;
|
||||
@XmlElement
|
||||
protected int percentage;
|
||||
|
||||
public PluginStateEvolution(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -26,12 +41,25 @@ public class PluginStateEvolution {
|
|||
* @throws Exception if fails
|
||||
*/
|
||||
public PluginStateEvolution(UUID uuid, int iteration, long timestamp,
|
||||
PluginDeclaration pluginDeclaration, PluginState pluginState) {
|
||||
PluginDeclaration pluginDeclaration, PluginState pluginState, Integer percentage) throws InvalidPluginStateEvolutionException {
|
||||
this.uuid = uuid;
|
||||
this.iteration = iteration;
|
||||
this.timestamp = timestamp;
|
||||
this.pluginDeclaration = pluginDeclaration;
|
||||
this.pluginState = pluginState;
|
||||
switch (pluginState) {
|
||||
case CREATED:
|
||||
this.percentage = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(percentage<0 || percentage>100){
|
||||
throw new InvalidPluginStateEvolutionException("Percentage must be beetween 0 and 100");
|
||||
}
|
||||
this.percentage = percentage;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,12 +97,19 @@ public class PluginStateEvolution {
|
|||
return pluginState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Integer getPercentage() {
|
||||
return this.percentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return String.format("%s :: %s : %s - iteration : %d - timestamp - %d - [%s] - %s",
|
||||
return String.format("%s : { %s : %s - iteration : %d - timestamp - %d - {%s} - %s - Percentage : %d }}",
|
||||
this.getClass().getSimpleName(),
|
||||
uuid.getClass().getSimpleName(), uuid.toString(),
|
||||
iteration, timestamp, pluginDeclaration, pluginState.toString());
|
||||
iteration, timestamp, pluginDeclaration, pluginState.toString(), percentage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,18 +3,26 @@
|
|||
*/
|
||||
package org.gcube.vremanagement.executor.plugin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public interface PluginStateNotification {
|
||||
public abstract class PluginStateNotification {
|
||||
|
||||
protected Map<String, String> inputs;
|
||||
|
||||
public PluginStateNotification(Map<String, String> inputs){
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the new state of plugin
|
||||
* @param pluginStateEvolution the PluginStateEvolution record to persist
|
||||
* @throws Exception if fails
|
||||
*/
|
||||
public abstract void pluginStateEvolution(PluginStateEvolution pluginStateEvolution)
|
||||
public abstract void pluginStateEvolution(PluginStateEvolution pluginStateEvolution, Exception exception)
|
||||
throws Exception;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.vremanagement.executor.exception.InvalidPluginStateEvolutionException;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -21,7 +22,7 @@ public class PluginStateEvolutionTest {
|
|||
private static final Logger logger = LoggerFactory.getLogger(PluginStateEvolutionTest.class);
|
||||
|
||||
@Test
|
||||
public void testToString(){
|
||||
public void testToString() throws InvalidPluginStateEvolutionException{
|
||||
UUID uuid = UUID.randomUUID();
|
||||
int iteration = 2;
|
||||
long timestamp = Calendar.getInstance().getTimeInMillis();
|
||||
|
@ -55,17 +56,16 @@ public class PluginStateEvolutionTest {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return String.format("%s : %s - %s - %s - %s - %s",
|
||||
this.getClass().getSimpleName(),
|
||||
getName(), getVersion(), getDescription(),
|
||||
getSupportedCapabilities(),
|
||||
null);
|
||||
return String.format("%s :{ %s - %s - %s }",
|
||||
PluginDeclaration.class.getSimpleName(),
|
||||
getName(), getVersion(), getDescription());
|
||||
}
|
||||
|
||||
};
|
||||
PluginState pluginState = PluginState.DISCARDED;
|
||||
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, iteration, timestamp, pluginDeclaration, pluginState);
|
||||
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, iteration, timestamp, pluginDeclaration, pluginState, 0);
|
||||
logger.debug(pluginStateEvolution.toString());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue