Version 2.0.0

This commit is contained in:
Luca Frosini 2019-12-04 09:56:54 +01:00
parent 519fa9d69f
commit fda62b6576
8 changed files with 74 additions and 98 deletions

View File

@ -27,7 +27,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

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,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

93
pom.xml
View File

@ -11,7 +11,7 @@
<groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
<name>SmartExecutor</name>
<description>Smart Executor Service</description>
<packaging>war</packaging>
@ -22,7 +22,12 @@
<distroDirectory>${project.basedir}/distro</distroDirectory>
<serviceClass>VREManagement</serviceClass>
<wiki>https://wiki.gcube-system.org/gcube/SmartExecutor</wiki>
<jackson.version>2.2.3</jackson.version>
<orientdb.version>3.0.15</orientdb.version>
<!-- OrientDB version has impact on jackson and thinkerpop version.
When OrientDB version is changed jackson and thinkerpop version
must be coherent with the one declared by orientdb -->
<jackson.version>2.6.0</jackson.version>
<thinkerpop.version>2.6.0</thinkerpop.version>
</properties>
<scm>
@ -33,24 +38,10 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>information-system-bom</artifactId>
<version>LATEST</version>
<version>1.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -62,84 +53,42 @@
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>discovery-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId>
<scope>provided</scope>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>provided</scope>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>${orientdb.version}</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>provided</scope>
<groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor-api</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor-client</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-generic-clients</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor-api</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<!-- Jersey -->
<dependency>
@ -161,7 +110,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
@ -209,7 +157,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warName>${artifactId}</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>

View File

@ -66,6 +66,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
oDatabasePool.close();
}
@Override
public PluginStateEvolution getPluginInstanceState(UUID uuid, Integer iterationNumber)
throws PluginInstanceNotFoundException, ExecutorException {
ODatabaseSession oDatabaseSession = null;
@ -121,7 +122,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
return pluginStateEvolution;
} catch(Exception e) {
throw new PluginInstanceNotFoundException();
throw new PluginInstanceNotFoundException(uuid);
} finally {
if(oDatabaseSession != null) {
oDatabaseSession.close();

View File

@ -7,6 +7,11 @@ import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.gcube.vremanagement.executor.exception.InputsNullException;
import org.gcube.vremanagement.executor.exception.InvalidInputsException;
import org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException;
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@ -20,12 +25,21 @@ public class ExecutorExceptionMapper implements ExceptionMapper<Exception> {
String exceptionMessage = exception.getMessage();
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
Class<? extends Exception> clz = exception.getClass();
if(WebApplicationException.class.isAssignableFrom(exception.getClass())) {
if(WebApplicationException.class.isAssignableFrom(clz)) {
Response gotResponse = ((WebApplicationException) exception).getResponse();
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
}
if(PluginInstanceNotFoundException.class.isAssignableFrom(clz)|| PluginNotFoundException.class.isAssignableFrom(clz)) {
status = Status.NOT_FOUND;
}
if(InputsNullException.class.isAssignableFrom(clz) || InvalidInputsException.class.isAssignableFrom(clz)) {
status = Status.BAD_REQUEST;
}
return Response.status(status).entity(exceptionMessage).type(mediaType).build();
}

View File

@ -8,7 +8,6 @@ import java.util.UUID;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@ -16,14 +15,15 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.vremanagement.executor.ResourceInitializer;
import org.gcube.vremanagement.executor.annotation.PURGE;
import org.gcube.vremanagement.executor.api.rest.RestConstants;
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.exception.ExecutorException;
import org.gcube.vremanagement.executor.exception.InputsNullException;
@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
@Path(RestConstants.PLUGINS_PATH_PART)
public class RestSmartExecutor implements SmartExecutor {
public class RestSmartExecutor {
private static Logger logger = LoggerFactory.getLogger(RestSmartExecutor.class);
@ -73,9 +73,9 @@ public class RestSmartExecutor implements SmartExecutor {
@GET
@Path("")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String getAvailablePlugins() throws ExecutorException {
setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART);
//setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART);
setCalledMethod("getAvailablePlugins");
try {
PluginManager pluginManager = PluginManager.getInstance();
Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
@ -89,17 +89,16 @@ public class RestSmartExecutor implements SmartExecutor {
@GET
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART)
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String getScheduled(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName) throws ExecutorException {
setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART + "/"
+ pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART);
// setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART + "/" + pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART);
setCalledMethod("getScheduledExecution");
try {
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory
.getPersistenceConnector();
List<PluginDeclaration> pluginDeclarations = new ArrayList<>();
if(pluginName.compareTo(ORPHAN_PATH_PARAM)!=0) {
if(pluginName.compareTo(RestConstants.ORPHAN_PATH_PARAM)!=0) {
PluginManager pluginManager = PluginManager.getInstance();
Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
PluginDeclaration pluginDeclaration = availablePlugins.get(pluginName);
@ -146,11 +145,10 @@ public class RestSmartExecutor implements SmartExecutor {
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART)
@Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
@Produces(MediaType.TEXT_PLAIN)
@Override
public String launch(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName, String launchParameterString)
throws ExecutorException {
setCalledMethod(HttpMethod.POST + " /" + RestConstants.PLUGINS_PATH_PART + "/"
+ pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART);
//setCalledMethod(HttpMethod.POST + " /" + RestConstants.PLUGINS_PATH_PART + "/" + pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART);
setCalledMethod("execute");
try {
logger.info("Requested to launch {} ({})", pluginName, launchParameterString);
@ -184,13 +182,12 @@ public class RestSmartExecutor implements SmartExecutor {
@GET
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART + "/" + "{" + UUID_PATH_PARAM + "}")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String getLaunchState(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
@PathParam(UUID_PATH_PARAM) String executionIdentifier,
@QueryParam(RestConstants.ITERATION_PARAM) Integer iteration) throws ExecutorException {
setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART + "/"
+ pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART + "/{" + UUID_PATH_PARAM + "}");
// setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART + "/" + pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART + "/{" + UUID_PATH_PARAM + "}");
setCalledMethod("getState");
PluginStateEvolution pluginStateEvolution = null;
try {
@ -222,8 +219,7 @@ public class RestSmartExecutor implements SmartExecutor {
@DELETE
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART + "/" + "{" + UUID_PATH_PARAM + "}")
@Override
public boolean delete(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
public Response delete(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
@PathParam(UUID_PATH_PARAM) String executionIdentifier,
@QueryParam(RestConstants.UNSCHEDULE_PARAM) Boolean unschedule) throws ExecutorException {
@ -232,6 +228,7 @@ public class RestSmartExecutor implements SmartExecutor {
unschedule = false;
}
/*
if(unschedule) {
setCalledMethod(PURGE.class.getSimpleName() + " /" + RestConstants.PLUGINS_PATH_PART + "/" + pluginName
+ "/" + RestConstants.EXECUTIONS_PATH_PART + "/{" + UUID_PATH_PARAM + "}");
@ -239,6 +236,9 @@ public class RestSmartExecutor implements SmartExecutor {
setCalledMethod(HttpMethod.DELETE + " /" + RestConstants.PLUGINS_PATH_PART + "/"
+ pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART + "/{" + UUID_PATH_PARAM + "}");
}
*/
setCalledMethod("stop");
logger.info("Requested to delete for {} with UUID {}{}", pluginName, executionIdentifier,
unschedule ? "globally" : "");
@ -269,7 +269,11 @@ public class RestSmartExecutor implements SmartExecutor {
}
logger.info("{} with UUID {} was{} stopped successfully", pluginName, executionIdentifier,
currentStopped ? "" : " NOT");
return currentStopped;
if(currentStopped) {
return Response.status(Status.NO_CONTENT).build();
}else {
throw new ExecutorException(pluginName + " with UUID " + executionIdentifier + " was NOT stopped successfully");
}
} catch(ExecutorException e) {
throw e;
} catch(Exception e) {
@ -279,8 +283,7 @@ public class RestSmartExecutor implements SmartExecutor {
@PURGE
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART + "/" + "{" + UUID_PATH_PARAM + "}")
@Override
public boolean purge(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
public Response purge(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
@PathParam(UUID_PATH_PARAM) String executionIdentifier) throws ExecutorException {
return delete(pluginName, executionIdentifier, true);
}

View File

@ -14,9 +14,9 @@ import java.util.UUID;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
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.exception.SchedulerNotFoundException;
import org.gcube.vremanagement.executor.exception.UnableToInterruptTaskException;
@ -276,7 +276,7 @@ public class SmartExecutorScheduler {
}
}
throw new ExecutorException("No plugin with UUID " + uuid.toString() + " found.");
throw new PluginInstanceNotFoundException(uuid);
}
Scheduling scheduling = launchParameter.getScheduling();
boolean scheduled = scheduling != null ? true : false;