Initial Import

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor-api@111655 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-02-04 11:33:45 +00:00
parent 76f9ff971d
commit c0e0f46738
31 changed files with 1057 additions and 0 deletions

37
.classpath Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

36
.project Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>smart-executor-api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="smart-executor-api">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.7"/>
<installed facet="jst.utility" version="1.0"/>
</faceted-project>

1
distro/INSTALL Normal file
View File

@ -0,0 +1 @@
Used as library in the gCube Framework

8
distro/LICENSE Normal file
View File

@ -0,0 +1,8 @@
gCube System - License
------------------------------------------------------------
The gCube/gCore software is licensed as Free Open Source software conveying to
the EUPL (http://ec.europa.eu/idabc/eupl).
The software and documentation is provided by its authors/distributors "as is"
and no expressed or implied warranty is given for its use, quality or fitness
for a particular case.

2
distro/MANTAINERS Normal file
View File

@ -0,0 +1,2 @@
Luca Frosini (luca.frosini@isti.cnr.it), CNR Pisa,
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo".

44
distro/README Normal file
View File

@ -0,0 +1,44 @@
The gCube System - Smart Executor Service
------------------------------------------------------------
This work has been partially supported by the following European projects: DILIGENT (FP6-2003-IST-2),
D4Science (FP7-INFRA-2007-1.2.2), D4Science-II (FP7-INFRA-2008-1.2.2), iMarine (FP7-INFRASTRUCTURES-2011-2),
and EUBrazilOpenBio (FP7-ICT-2011-EU-Brazil).
Authors
-------
* Luca Frosini (luca.frosini@isti.cnr.it), CNR Pisa,
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo".
Version and Release Date
------------------------
v. 1.0.0 * First release
Description
-----------
Download information
--------------------
Documentation
-------------
Licensing
---------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

5
distro/changelog.xml Normal file
View File

@ -0,0 +1,5 @@
<ReleaseNotes>
<Changeset component="org.gcube.vremanagement.smart-executor-api.1-0-0" date="2015-01-26">
<Change>first release</Change>
</Changeset>
</ReleaseNotes>

42
distro/descriptor.xml Normal file
View File

@ -0,0 +1,42 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
<file>
<source>${distroDirectory}/svnpath.txt</source>
<outputDirectory>/${artifactId}</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>

28
distro/profile.xml Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>VREManagement</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${description}</Description>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Type>library</Type>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

0
distro/svnpath.txt Normal file
View File

91
pom.xml Normal file
View File

@ -0,0 +1,91 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<distroDirectory>distro</distroDirectory>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-smartgears-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,56 @@
package org.gcube.vremanagement.executor.api;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.exception.ExecutorException;
import org.gcube.vremanagement.executor.exception.InputsNullException;
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;
/**
* Service Endpoint Interface
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@WebService(targetNamespace=Executor.TNS)
@SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL)
public interface Executor {
public static final String SERVICE_NAME = "gcube/vremanagement/executor";
public static final String TNS = "http://gcube-system.org/";
/**
* Launch the plugin identified by the name provided as parameters
* with the provided inputs. Inputs cannot be null. If you need to launch
* an execution with no inputs provide an empty Map.
* This method return as soon as the plugin has been launched.
* The execution is made in a separated Thread.
* @param name the name of the plugin to launch.
* @param inputs the input to be provided to plugin.
* @return the UUID which identify the execution of the plugin.
* @throws Exception if the launch fails.
*/
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
public String launch(LaunchParameter launchParameter) throws
InputsNullException, PluginNotFoundException,
LaunchException, ExecutorException;
/**
* The method use the provided {@link #UUID} to retrieve the status of the
* associated execution
* @param executionIdentifier which identify ana execution
* @return {@link #PluginState} which contains the state of the execution
* @throws Exception if there is no execution identified by the provided
* {@link #UUID}
*/
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
public PluginState getState(String executionIdentifier)
throws PluginInstanceNotFoundException, ExecutorException;
}

View File

@ -0,0 +1,56 @@
/**
*
*/
package org.gcube.vremanagement.executor.api.types;
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 class LaunchParameter {
@XmlElement
private String name;
@XmlJavaTypeAdapter(MapAdapter.class)
private Map<String, Object> inputs;
@SuppressWarnings("unused")
private LaunchParameter(){}
/**
* @param name
* @param inputs
*/
public LaunchParameter(String name, Map<String, Object> inputs) {
this.name = name;
this.inputs = inputs;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the inputs
*/
public Map<String, Object> getInputs() {
return inputs;
}
}

View File

@ -0,0 +1,26 @@
package org.gcube.vremanagement.executor.api.types.adapter;
import java.util.Map;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.thoughtworks.xstream.XStream;
/**
* @author Lucio Leii (ISTI - CNR)
*/
public class MapAdapter extends XmlAdapter<String, Map<String, Object>>{
private static XStream xstream = new XStream();
@Override
public String marshal(Map<String, Object> oi) throws Exception {
return xstream.toXML(oi);
}
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> unmarshal(String oi) throws Exception {
return (Map<String, Object>) xstream.fromXML(oi);
}
}

View File

@ -0,0 +1,36 @@
package org.gcube.vremanagement.executor.api.types.adapter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
* @author Lucio Lelii (ISTI - CNR)
*/
public class ThrowableAdapter extends XmlAdapter<String, Throwable> {
private HexBinaryAdapter hexAdapter = new HexBinaryAdapter();
@Override
public String marshal(Throwable v) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(v);
oos.close();
byte[] serializedBytes = baos.toByteArray();
return hexAdapter.marshal(serializedBytes);
}
@Override
public Throwable unmarshal(String v) throws Exception {
byte[] serializedBytes = hexAdapter.unmarshal(v);
ByteArrayInputStream bais = new ByteArrayInputStream(serializedBytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Throwable result = (Throwable) ois.readObject();
return result;
}
}

View File

@ -0,0 +1,64 @@
/**
*
*/
package org.gcube.vremanagement.executor.exception;
import javax.xml.ws.WebFault;
import org.gcube.vremanagement.executor.exception.beans.ExceptionBean;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@WebFault
public class ExecutorException extends Exception {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 150353533672078736L;
private static final String DEFAULT_MESSAGE = "Executor Exception";
protected ExceptionBean faultInfo;
public ExecutorException() {
super(DEFAULT_MESSAGE);
this.faultInfo = new ExceptionBean(DEFAULT_MESSAGE);
}
public ExecutorException(Throwable cause) {
this(DEFAULT_MESSAGE, cause);
}
public ExecutorException(String message) {
super(message);
this.faultInfo = new ExceptionBean(message);
}
public ExecutorException(ExceptionBean faultInfo){
super(faultInfo.getMessage(), faultInfo.getCause());
this.faultInfo = faultInfo;
}
public ExecutorException(String message, Throwable cause){
super(message, cause);
this.faultInfo = new ExceptionBean(message, cause);
}
public ExecutorException(String message, ExceptionBean faultInfo){
super(message);
this.faultInfo = faultInfo;
}
public ExecutorException(String message, ExceptionBean faultInfo, Throwable cause){
super(message, cause);
this.faultInfo = faultInfo;
}
public ExceptionBean getFaultInfo(){
return faultInfo;
}
}

View File

@ -0,0 +1,60 @@
/**
*
*/
package org.gcube.vremanagement.executor.exception;
import javax.xml.ws.WebFault;
import org.gcube.vremanagement.executor.exception.beans.ExceptionBean;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@WebFault
public class InputsNullException extends ExecutorException {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 7578814354528161119L;
private static final String DEFAULT_MESSAGE = "Inputs cannot be null. Use an Empty Map instead.";
public InputsNullException(){
super(DEFAULT_MESSAGE);
this.faultInfo = new ExceptionBean(DEFAULT_MESSAGE);
}
public InputsNullException(String message) {
super(message);
}
public InputsNullException(Throwable cause) {
this(DEFAULT_MESSAGE, cause);
}
public InputsNullException(ExceptionBean faultInfo){
super(faultInfo);
}
public InputsNullException(String message, Throwable cause){
super(message, cause);
}
public InputsNullException(String message, ExceptionBean faultInfo){
super(message, faultInfo);
}
public InputsNullException(String message, ExceptionBean faultInfo, Throwable cause){
super(message, faultInfo, cause);
}
@Override
public ExceptionBean getFaultInfo(){
return faultInfo;
}
}

View File

@ -0,0 +1,59 @@
/**
*
*/
package org.gcube.vremanagement.executor.exception;
import javax.xml.ws.WebFault;
import org.gcube.vremanagement.executor.exception.beans.ExceptionBean;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@WebFault
public class LaunchException extends ExecutorException {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -4805436085852176907L;
private static final String DEFAULT_MESSAGE = "Error trying to launch the plugin execution";
public LaunchException(){
super(DEFAULT_MESSAGE);
this.faultInfo = new ExceptionBean(DEFAULT_MESSAGE);
}
public LaunchException(String message) {
super(message);
}
public LaunchException(Throwable cause) {
this(DEFAULT_MESSAGE, cause);
}
public LaunchException(ExceptionBean faultInfo){
super(faultInfo);
}
public LaunchException(String message, Throwable cause){
super(message, cause);
}
public LaunchException(String message, ExceptionBean faultInfo){
super(message, faultInfo);
}
public LaunchException(String message, ExceptionBean faultInfo, Throwable cause){
super(message, faultInfo, cause);
}
@Override
public ExceptionBean getFaultInfo(){
return faultInfo;
}
}

View File

@ -0,0 +1,60 @@
/**
*
*/
package org.gcube.vremanagement.executor.exception;
import javax.xml.ws.WebFault;
import org.gcube.vremanagement.executor.exception.beans.ExceptionBean;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@WebFault
public class PluginInstanceNotFoundException extends ExecutorException {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -7609491801703267843L;
private static final String DEFAULT_MESSAGE = "The requested plugin instance does not exists";
public PluginInstanceNotFoundException(){
super(DEFAULT_MESSAGE);
this.faultInfo = new ExceptionBean(DEFAULT_MESSAGE);
}
public PluginInstanceNotFoundException(String message) {
super(message);
}
public PluginInstanceNotFoundException(Throwable cause) {
this(DEFAULT_MESSAGE, cause);
}
public PluginInstanceNotFoundException(ExceptionBean faultInfo){
super(faultInfo);
}
public PluginInstanceNotFoundException(String message, Throwable cause){
super(message, cause);
}
public PluginInstanceNotFoundException(String message, ExceptionBean faultInfo){
super(message, faultInfo);
}
public PluginInstanceNotFoundException(String message, ExceptionBean faultInfo, Throwable cause){
super(message, faultInfo, cause);
}
@Override
public ExceptionBean getFaultInfo(){
return faultInfo;
}
}

View File

@ -0,0 +1,60 @@
/**
*
*/
package org.gcube.vremanagement.executor.exception;
import javax.xml.ws.WebFault;
import org.gcube.vremanagement.executor.exception.beans.ExceptionBean;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@WebFault
public class PluginNotFoundException extends ExecutorException {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 6591994140867585229L;
private static final String DEFAULT_MESSAGE = "The requested plugin does not exist on container";
public PluginNotFoundException(){
super(DEFAULT_MESSAGE);
this.faultInfo = new ExceptionBean(DEFAULT_MESSAGE);
}
public PluginNotFoundException(String message) {
super(message);
}
public PluginNotFoundException(Throwable cause) {
this(DEFAULT_MESSAGE, cause);
}
public PluginNotFoundException(ExceptionBean faultInfo){
super(faultInfo);
}
public PluginNotFoundException(String message, Throwable cause){
super(message, cause);
}
public PluginNotFoundException(String message, ExceptionBean faultInfo){
super(message, faultInfo);
}
public PluginNotFoundException(String message, ExceptionBean faultInfo, Throwable cause){
super(message, faultInfo, cause);
}
@Override
public ExceptionBean getFaultInfo(){
return faultInfo;
}
}

View File

@ -0,0 +1,48 @@
package org.gcube.vremanagement.executor.exception.beans;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gcube.vremanagement.executor.api.types.adapter.ThrowableAdapter;
/**
* @author Lucio Leii (ISTI - CNR)
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ExceptionBean {
protected String message;
@XmlJavaTypeAdapter(ThrowableAdapter.class)
protected Throwable cause;
protected ExceptionBean(){}
public ExceptionBean(String message){
this.message = message;
}
public ExceptionBean(String message, Throwable cause){
this.message = message;
this.cause = cause;
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @return the cause
*/
public Throwable getCause() {
return cause;
}
}

View File

@ -0,0 +1,44 @@
/**
*
*/
package org.gcube.vremanagement.executor.persistence;
import java.util.UUID;
import org.gcube.vremanagement.executor.plugin.PluginState;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public abstract class Persistence<P extends PersistenceConnector> {
protected final String name;
protected final P persistenceConnector;
protected final UUID uuid;
public Persistence(P persistenceConnector, String name, UUID uuid){
this.name = name;
this.persistenceConnector = persistenceConnector;
this.uuid = uuid;
}
/**
* Persist the new state of plugin
* @param timestamp
* @param pluginState
* @throws Exception
*/
public abstract void addEvolution(long timestamp, PluginState pluginState) throws Exception;
/**
* @return
* @throws Exception
*/
public PluginState getState() throws Exception {
return persistenceConnector.getPluginInstanceState(uuid);
}
}

View File

@ -0,0 +1,29 @@
/**
*
*/
package org.gcube.vremanagement.executor.persistence;
import java.util.UUID;
import org.gcube.vremanagement.executor.plugin.PluginState;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public abstract class PersistenceConnector {
/**
* @throws Exception
*/
public abstract void close() throws Exception;
/**
*
* @param uuid
* @return
* @throws Exception
*/
public abstract PluginState getPluginInstanceState(UUID uuid) throws Exception;
}

View File

@ -0,0 +1,88 @@
package org.gcube.vremanagement.executor.plugin;
import java.util.Date;
import java.util.Map;
import org.gcube.vremanagement.executor.persistence.Persistence;
import org.gcube.vremanagement.executor.persistence.PersistenceConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This interface represent the contract for a plugin runnable by the executor.
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public abstract class Plugin<T extends PluginDeclaration> {
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(Plugin.class);
/**
* Instance of the class which log the plugin state evolution
*/
private Persistence<? extends PersistenceConnector> persistence;
private T pluginDeclaration;
public Plugin(T pluginDeclaration, Persistence<? extends PersistenceConnector> persistence){
this.pluginDeclaration = pluginDeclaration;
this.persistence = persistence;
}
/**
* @return the pluginDeclaration
*/
public T getPluginDeclaration() {
return pluginDeclaration;
}
/**
* It is up to the plugin update the State of the Running Plugin using
* this facilities function.
* @param pluginState
* @throws Exception
*/
public void setState(PluginState pluginState) {
long timestamp = new Date().getTime();
try {
persistence.addEvolution(timestamp, pluginState);
} catch(Exception e) {
logger.error(String.format("Unable to persist State : %d,%s", timestamp, pluginState.name()));
}
}
/**
* Launch the plugin with the provided input.
* @param inputs
* @throws Exception if the launch fails
*/
public abstract void launch(Map<String,Object> inputs) throws Exception;
/**
* This function is used to correctly stop the plugin
* @throws Exception if the launch fails
*/
protected abstract void onStop() throws Exception;
/**
* Stop the Plugin setting state to {@link #PluginState.SUSPENDED}
* @throws Exception
*/
public void stop() throws Exception {
setState(PluginState.SUSPENDED);
onStop();
}
/**
* Used to retrieve the state of the execution
* @return the {@link #PluginState}
* @throws Exception
*/
public PluginState getState() throws Exception {
return persistence.getState();
}
}

View File

@ -0,0 +1,36 @@
/**
*
*/
package org.gcube.vremanagement.executor.plugin;
import java.util.Map;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public interface PluginDeclaration {
/**
* This method is used by executor to retrieve the name of the Plugin
* @return the name of the plugin used by the Executor to refer to the
* plugin implementation class.
*/
public String getName();
/**
* This method is used by the Executor to get a key-value {@link #Map}
* to be published on IS (on Generic Resource), so a client which want to
* launch a Plugin only under certain condition can query the Generic
* Resource in the proper way to obtain its own filtered list.
* @return
*/
public Map<String,String> getSupportedCapabilities();
/**
* Used to retrieve the class which run the plugin
* @return the class which run the plugin
*/
public Class<? extends Plugin<? extends PluginDeclaration>> getPluginImplementation();
}

View File

@ -0,0 +1,12 @@
/**
*
*/
package org.gcube.vremanagement.executor.plugin;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public enum PluginState {
CREATED, RUNNING, SUSPENDED, DONE, FAILED
}