Switched the service to the use of new APi which does not require the

PluginDeclaration class
This commit is contained in:
Luca Frosini 2020-09-30 11:19:49 +02:00
parent 8c3c2b9b41
commit 43328f5cfe
23 changed files with 165 additions and 488 deletions

View File

@ -1,40 +1,18 @@
package org.gcube.vremanagement.executor;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.ClientType;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Profile;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.smartgears.ApplicationManager;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.ispublisher.GCoreISPublisher;
import org.gcube.vremanagement.executor.ispublisher.RestISPublisher;
import org.gcube.vremanagement.executor.json.ExtendedSEMapper;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler;
@ -55,241 +33,6 @@ public class SmartExecutorInitializator implements ApplicationManager {
public static final long JOIN_TIMEOUT = 1000;
public static String getCurrentScope(){
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch (Exception e) {
logger.trace("Context was not retrieved from token. Going to get it from {}", ScopeProvider.class.getSimpleName());
return ScopeProvider.instance.get();
}
String context = authorizationEntry.getContext();
logger.trace("Context retrieved from token is {}. Context in {} is {}",
context, ScopeProvider.class.getSimpleName(), ScopeProvider.instance.get());
return context;
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context);
return context;
}
public static void setContext(String token) throws ObjectNotFound, Exception{
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(getCurrentScope(token));
}
public static ClientInfo getClientInfo() {
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch (Exception e) {
return new ClientInfo() {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 8311873203596762883L;
@Override
public ClientType getType() {
return ClientType.USER;
}
@Override
public List<String> getRoles() {
return new ArrayList<>();
}
@Override
public String getId() {
return "UNKNOWN";
}
};
}
return authorizationEntry.getClientInfo();
}
/**
* Publish the provided resource on all Service Scopes retrieved from
* Context
* @param resource to be published
* @throws RegistryNotFoundException if the Registry is not found so the
* resource has not be published
*/
private static void publishResource(Resource resource) throws Exception {
StringWriter stringWriter = new StringWriter();
Resources.marshal(resource, stringWriter);
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
try {
logger.debug("Trying to publish to {}:\n{}", getCurrentScope(), stringWriter);
registryPublisher.create(resource);
} catch (Exception e) {
logger.error("The resource was not published", e);
throw e;
}
}
/**
* Remove the resource from IS
* @param resource to be unpublished
* @throws RegistryNotFoundException if the Registry is not found so the
* resource has not be published
*/
private static void unPublishResource(Resource resource) throws Exception {
//StringWriter stringWriter = new StringWriter();
//Resources.marshal(resource, stringWriter);
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
String id = resource.id();
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, getCurrentScope());
registryPublisher.remove(resource);
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
}
/**
* Return the parsed version string as array of short.
* @param version the version as String
* @param wantedLenght if the length is equals to dot (.) separated
* number in the string. Otherwise the version is padded or truncated to
* the required version
* @return the parsed version as array of short. If on slicing some of the
* version cannot be parsed as short 1 is used for the first number, 0 is
* used instead or for padding
*/
private static short[] getVersionSlice(String version, int wantedLenght){
logger.trace("Trying to parse {}", version);
short[] versionSlices = new short[wantedLenght];
for(int j=0; j<wantedLenght; j++){
versionSlices[j] = (short) (j==0 ? 1 : 0);
}
try {
String[] stringSlices = version.split("[.-]");
for(int i=0; i<stringSlices.length; i++){
logger.trace("Parsing version slice n. {} wich is '{}'", i, stringSlices[i]);
if(i>=wantedLenght){
break;
}
try {
short n = Short.parseShort(stringSlices[i]);
versionSlices[i] = n;
logger.trace("Version slice n. {} wich is '{}' parsed as short {}", i, stringSlices[i], n);
} catch(NumberFormatException nfe){
logger.trace("Version slice n. {} wich is '{}' failed to parse. The default value {} will be used", i, stringSlices[i], versionSlices[i]);
}
}
} catch(Exception e){
logger.trace("Error parsing the supplied version the default will be used", versionSlices);
}
logger.trace("Version {} parsed as {}", version, versionSlices);
return versionSlices;
}
private static String getRunningOn(ContainerConfiguration containerConfiguration){
return String.format("%s:%s", containerConfiguration.hostname(), containerConfiguration.port());
}
/**
* Create the Service Endpoint using information related to discovered
* available plugins and their own discovered capabilities
* @return the created {@link ServiceEndpoint}
*/
protected static ServiceEndpoint createServiceEndpoint(Map<String, PluginDeclaration> availablePlugins){
logger.debug("Creating ServiceEndpoint to publish on IS available plugins and their own supported capabilities");
ServiceEndpoint serviceEndpoint = new ServiceEndpoint();
Profile profile = serviceEndpoint.newProfile();
profile.category(ContextProvider.get().configuration().serviceClass());
profile.name(ContextProvider.get().configuration().name());
String version = ContextProvider.get().configuration().version();
profile.version(version);
profile.description(ContextProvider.get().configuration().description());
String runningOn = getRunningOn(ContextProvider.get().container().configuration());
Platform platform = profile.newPlatform();
platform.name(runningOn);
short[] versionSlices = getVersionSlice(version, 4);
platform.version(versionSlices[0]);
platform.minorVersion(versionSlices[1]);
platform.buildVersion(versionSlices[2]);
platform.revisionVersion(versionSlices[3]);
Runtime runtime = profile.newRuntime();
runtime.hostedOn(runningOn);
runtime.status(ContextProvider.get().configuration().mode().toString());
Group<AccessPoint> accessPoints = profile.accessPoints();
for(String pluginName : availablePlugins.keySet()){
AccessPoint accessPointElement = new AccessPoint();
accessPointElement.name(pluginName);
PluginDeclaration pluginDeclaration = availablePlugins.get(pluginName);
accessPointElement.description(pluginDeclaration.getDescription());
Group<Property> properties = accessPointElement.properties();
Property propertyVersionElement = new Property();
propertyVersionElement.nameAndValue("Version", pluginDeclaration.getVersion());
properties.add(propertyVersionElement);
Map<String, String> pluginCapabilities = pluginDeclaration.getSupportedCapabilities();
for(String capabilityName : pluginCapabilities.keySet()){
Property propertyElement = new Property();
propertyElement.nameAndValue(capabilityName, pluginCapabilities.get(capabilityName));
properties.add(propertyElement);
}
accessPoints.add(accessPointElement);
}
StringWriter stringWriter = new StringWriter();
Resources.marshal(serviceEndpoint, stringWriter);
logger.debug("The created ServiceEndpoint profile is\n{}", stringWriter.toString());
return serviceEndpoint;
}
private void cleanServiceEndpoints(){
try {
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
.addCondition(String.format("$resource/Profile/Category/text() eq '%s'", ContextProvider.get().configuration().serviceClass()))
.addCondition(String.format("$resource/Profile/Name/text() eq '%s'", ContextProvider.get().configuration().name()))
.addCondition(String.format("$resource/Profile/RunTime/HostedOn/text() eq '%s'", getRunningOn(ContextProvider.get().container().configuration())))
.setResult("$resource");
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
try {
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}",
serviceEndpoint.id(), getCurrentScope());
unPublishResource(serviceEndpoint);
} catch(Exception e){
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}",
serviceEndpoint.id(), getCurrentScope(), e);
}
}
}catch(Exception e){
logger.debug("An Exception occur while checking and/or unpublishing old ServiceEndpoint", e);
}
}
/**
* {@inheritDoc}
* The method discover the plugins available on classpath and their own
@ -299,7 +42,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
*/
@Override
public void onInit() {
String scope = getCurrentScope();
String scope = ContextUtility.getCurrentScope();
logger.trace(
"\n-------------------------------------------------------\n"
@ -308,14 +51,16 @@ public class SmartExecutorInitializator implements ApplicationManager {
scope);
logger.debug("Getting Available Plugins and their own supported capabilities");
PluginManager pluginManager = PluginManager.getInstance();
Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
ServiceEndpoint serviceEndpoint = createServiceEndpoint(availablePlugins);
cleanServiceEndpoints();
Map<String, Class<? extends Plugin>> availablePlugins = PluginManager.getAvailablePlugins();
ApplicationContext applicationContext = ContextProvider.get();
try {
publishResource(serviceEndpoint);
GCoreISPublisher gCoreISPublisher = new GCoreISPublisher(applicationContext);
gCoreISPublisher.publishPlugins(availablePlugins);
RestISPublisher restISPublisher = new RestISPublisher(applicationContext);
restISPublisher.publishPlugins(availablePlugins);
} catch (Exception e) {
logger.error("Unable to Create ServiceEndpoint for scope {}. The Service will be aborted", scope, e);
throw new RuntimeException(e);
@ -335,8 +80,8 @@ public class SmartExecutorInitializator implements ApplicationManager {
try {
logger.debug("Going to get Orphan Scheduled Tasks in scope {}", scope);
List<ScheduledTask> scheduledTasks = smartExecutorPersistenceConnector.getOrphanScheduledTasks(availablePlugins.values());
List<ScheduledTask> scheduledTasks = smartExecutorPersistenceConnector.getOrphanScheduledTasks(PluginManager.getAvailablePlugins().keySet());
if(scheduledTasks.size()==0){
logger.debug("No Orphan Scheduled Tasks this instance can take in charge in scope {}", scope);
}
@ -368,7 +113,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
String scheduledTasktoken = scheduledTask.getToken();
try {
setContext(scheduledTasktoken);
ContextUtility.setContext(scheduledTasktoken);
SmartExecutorScheduler smartExecutorScheduler = SmartExecutorSchedulerFactory.getSmartExecutorScheduler();
// A new Scheduled Task will be persisted due to launch. Removing it
@ -417,7 +162,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
"\n-------------------------------------------------------\n"
+ "Smart Executor is Stopping on scope {}\n"
+ "-------------------------------------------------------",
getCurrentScope());
ContextUtility.getCurrentScope());
SmartExecutorScheduler scheduler;
@ -429,20 +174,25 @@ public class SmartExecutorInitializator implements ApplicationManager {
logger.error("", e);
}
cleanServiceEndpoints();
ApplicationContext applicationContext = ContextProvider.get();
GCoreISPublisher gCoreISPublisher = new GCoreISPublisher(applicationContext);
gCoreISPublisher.unpublishPlugins();
RestISPublisher restISPublisher = new RestISPublisher(applicationContext);
restISPublisher.unpublishPlugins();
try {
SmartExecutorPersistenceFactory.closePersistenceConnector();
} catch (Throwable e) {
logger.error("Unable to correctly close {} for scope {}",
SmartExecutorPersistenceConnector.class.getSimpleName(),
getCurrentScope(), e);
ContextUtility.getCurrentScope(), e);
}
logger.trace(
"\n-------------------------------------------------------\n"
+ "Smart Executor Stopped Successfully on scope {}\n"
+ "-------------------------------------------------------",
getCurrentScope());
ContextUtility.getCurrentScope());
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.vremanagement.executor;
package org.gcube.vremanagement.executor.ispublisher;
import java.io.StringWriter;
import java.util.List;
@ -23,7 +23,11 @@ import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.context.container.ContainerContext;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.exception.ExecutorException;
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -128,8 +132,10 @@ public class GCoreISPublisher extends ISPublisher {
* Create the Service Endpoint using information related to discovered
* available plugins and their own discovered capabilities
* @return the created {@link ServiceEndpoint}
* @throws ExecutorException
* @throws PluginNotFoundException
*/
protected ServiceEndpoint createServiceEndpoint(Map<String,PluginDeclaration> availablePlugins) {
protected ServiceEndpoint createServiceEndpoint(Map<String,Class<? extends Plugin>> availablePlugins) throws PluginNotFoundException, ExecutorException {
logger.debug(
"Creating ServiceEndpoint to publish on IS available plugins and their own supported capabilities");
@ -159,11 +165,12 @@ public class GCoreISPublisher extends ISPublisher {
Group<AccessPoint> accessPoints = profile.accessPoints();
for(String pluginName : availablePlugins.keySet()) {
AccessPoint accessPointElement = new AccessPoint();
accessPointElement.name(pluginName);
PluginDeclaration pluginDeclaration = availablePlugins.get(pluginName);
Plugin pluginDeclaration = PluginManager.getPlugin(pluginName);
accessPointElement.description(pluginDeclaration.getDescription());
@ -221,12 +228,10 @@ public class GCoreISPublisher extends ISPublisher {
}
@Override
public void publishPlugins(Map<String,PluginDeclaration> availablePlugins) {
ServiceEndpoint serviceEndpoint = createServiceEndpoint(availablePlugins);
cleanServiceEndpoints();
public void publishPlugins(Map<String,Class<? extends Plugin>> availablePlugins) {
try {
ServiceEndpoint serviceEndpoint = createServiceEndpoint(availablePlugins);
cleanServiceEndpoints();
publishResource(serviceEndpoint);
} catch(Exception e) {
logger.error("Unable to Create ServiceEndpoint for scope {}. The Service will be aborted",

View File

@ -1,9 +1,9 @@
package org.gcube.vremanagement.executor;
package org.gcube.vremanagement.executor.ispublisher;
import java.util.Map;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.Plugin;
public abstract class ISPublisher {
@ -13,7 +13,7 @@ public abstract class ISPublisher {
this.applicationContext = applicationContext;
}
public abstract void publishPlugins(Map<String, PluginDeclaration> availablePlugins) throws Exception;
public abstract void publishPlugins(Map<String, Class<? extends Plugin>> availablePlugins) throws Exception;
public abstract void unpublishPlugins();

View File

@ -1,4 +1,4 @@
package org.gcube.vremanagement.executor;
package org.gcube.vremanagement.executor.ispublisher;
import java.util.Map;
import java.util.UUID;
@ -23,7 +23,8 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Uses;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -39,25 +40,25 @@ public class RestISPublisher extends ISPublisher {
}
@Override
public void publishPlugins(Map<String,PluginDeclaration> availablePlugins) throws Exception {
public void publishPlugins(Map<String, Class<? extends Plugin>> availablePlugins) throws Exception {
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
EService smartExecutorEService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
for(String pluginName : availablePlugins.keySet()) {
PluginDeclaration pluginDeclaration = availablePlugins.get(pluginName);
Plugin plugin = PluginManager.getPlugin(pluginName);
RunningPlugin runningPlugin = new RunningPluginImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("SmartExecutorPlugin");
softwareFacet.setName(pluginName);
softwareFacet.setVersion(pluginDeclaration.getVersion());
softwareFacet.setDescription(pluginDeclaration.getDescription());
softwareFacet.setVersion(plugin.getVersion());
softwareFacet.setDescription(plugin.getDescription());
runningPlugin.addFacet(softwareFacet);
Map<String,String> pluginCapabilities = pluginDeclaration.getSupportedCapabilities();
Map<String,String> pluginCapabilities = plugin.getSupportedCapabilities();
for(String capabilityName : pluginCapabilities.keySet()) {
SimplePropertyFacet simplePropertyFacet = new SimplePropertyFacetImpl();
simplePropertyFacet.setName(capabilityName);

View File

@ -16,7 +16,7 @@ import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
import org.gcube.vremanagement.executor.ContextUtility;
/**
* @author Luca Frosini (ISTI - CNR)
@ -131,7 +131,7 @@ public class SmartExecutorPersistenceConfiguration {
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
if(serviceEndpoints.size()>1){
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", SmartExecutorInitializator.getCurrentScope()));
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", ContextUtility.getCurrentScope()));
serviceEndpoints = client.submit(query);
}
return serviceEndpoints.get(0);

View File

@ -6,7 +6,7 @@ package org.gcube.vremanagement.executor.persistence;
import java.util.HashMap;
import java.util.Map;
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.persistence.orientdb.OrientDBPersistenceConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,7 +47,7 @@ public abstract class SmartExecutorPersistenceFactory {
new SmartExecutorPersistenceConfiguration(className);
persistence = new OrientDBPersistenceConnector(configuration);
persistenceConnectors.put(SmartExecutorInitializator.getCurrentScope(),
persistenceConnectors.put(ContextUtility.getCurrentScope(),
persistence);
}
@ -58,12 +58,12 @@ public abstract class SmartExecutorPersistenceFactory {
* @return the persistenceConnector
*/
public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
String scope = SmartExecutorInitializator.getCurrentScope();
String scope = ContextUtility.getCurrentScope();
return getPersistenceConnector(scope);
}
public static synchronized void closePersistenceConnector() throws Exception {
String scope = SmartExecutorInitializator.getCurrentScope();
String scope = ContextUtility.getCurrentScope();
SmartExecutorPersistenceConnector persistence =
getPersistenceConnector(scope);
if(persistence!=null){

View File

@ -11,7 +11,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.exception.ExecutorException;
import org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException;
@ -19,7 +19,6 @@ import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
import org.gcube.vremanagement.executor.json.ExtendedSEMapper;
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.PluginStateEvolution;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.slf4j.Logger;
@ -75,7 +74,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
String type = PluginStateEvolution.class.getSimpleName();
Map<String,Object> params = new HashMap<String,Object>();
params.put(UUID, uuid.toString());
params.put(SCOPE, SmartExecutorInitializator.getCurrentScope());
params.put(SCOPE, ContextUtility.getCurrentScope());
OSQLSynchQuery<ODocument> query = null;
if(iterationNumber != null && iterationNumber > 0) {
@ -138,7 +137,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
ODocument doc = new ODocument(PluginStateEvolution.class.getSimpleName());
String json = ExtendedSEMapper.getInstance().marshal(pluginStateEvolution);
doc.fromJSON(json);
doc.field(SCOPE, SmartExecutorInitializator.getCurrentScope());
doc.field(SCOPE, ContextUtility.getCurrentScope());
doc.save();
oDatabaseSession.commit();
@ -184,7 +183,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
}
@Override
public List<ScheduledTask> getOrphanScheduledTasks(Collection<? extends PluginDeclaration> pluginDeclarations)
public List<ScheduledTask> getOrphanScheduledTasks(Collection<String> plugins)
throws SchedulePersistenceException {
ODatabaseSession oDatabaseSession = null;
try {
@ -192,19 +191,19 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
String type = ScheduledTask.class.getSimpleName();
String queryString = String.format("SELECT * FROM %s WHERE %s = '%s'", type, "scope",
SmartExecutorInitializator.getCurrentScope());
if(pluginDeclarations != null && pluginDeclarations.size() != 0) {
ContextUtility.getCurrentScope());
if(plugins != null && plugins.size() != 0) {
boolean first = true;
for(PluginDeclaration pluginDeclaration : pluginDeclarations) {
for(String pluginName : plugins) {
if(first) {
first = false;
queryString = String.format("%s AND ( (%s = '%s') ", queryString,
ScheduledTask.LAUNCH_PARAMETER + "." + LaunchParameter.PLUGIN_NAME,
pluginDeclaration.getName());
pluginName);
} else {
queryString = String.format("%s OR (%s = '%s') ", queryString,
ScheduledTask.LAUNCH_PARAMETER + "." + LaunchParameter.PLUGIN_NAME,
pluginDeclaration.getName());
pluginName);
}
}
queryString = queryString + ")";

View File

@ -6,13 +6,12 @@ package org.gcube.vremanagement.executor.pluginmanager;
import org.gcube.vremanagement.executor.exception.InvalidPluginStateEvolutionException;
import org.gcube.vremanagement.executor.plugin.PercentageSetter;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class PercentageSetterImpl<T extends Plugin<? extends PluginDeclaration>> implements PercentageSetter {
public class PercentageSetterImpl<T extends Plugin> implements PercentageSetter {
private final RunnablePlugin<T> runnablePlugin;

View File

@ -1,14 +1,12 @@
package org.gcube.vremanagement.executor.pluginmanager;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import org.gcube.vremanagement.executor.exception.InputsNullException;
import org.gcube.vremanagement.executor.exception.ExecutorException;
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,69 +32,7 @@ public class PluginManager {
* Contains mapping between plugin name and the instance of its declaration
* class
*/
private Map<String, PluginDeclaration> availablePlugins;
/**
* Retrieve the PluginDeclaration class representing the plugin which
* have the name provided as input
* @param pluginName the name of the plugin
* @return the PluginDeclaration
* @throws PluginNotFoundException if the plugin is not available
*/
public static PluginDeclaration getPluginDeclaration(String pluginName) throws PluginNotFoundException {
logger.debug(String.format("Trying to instantiate a Plugin named %s",
pluginName));
PluginDeclaration pluginDeclaration = PluginManager.getInstance()
.getPlugin(pluginName);
if (pluginDeclaration == null) {
throw new PluginNotFoundException();
}
return pluginDeclaration;
}
public static Plugin<? extends PluginDeclaration> instantiatePlugin(
String pluginName) throws InputsNullException,
PluginNotFoundException {
PluginDeclaration pluginDeclaration = getPluginDeclaration(pluginName);
// Retrieving the plugin instance class to be run from PluginDeclaration
Class<? extends Plugin<? extends PluginDeclaration>> plugin = pluginDeclaration
.getPluginImplementation();
logger.debug(String.format(
"The class which will run the execution will be %s",
plugin.getName()));
// Retrieve the Constructor of Plugin to instantiate it
@SuppressWarnings("rawtypes")
Class[] argTypes = { pluginDeclaration.getClass()};
// Creating the Argument to pass to constructor
Object[] arguments = { pluginDeclaration};
// logger.debug(String.format("Plugin named %s once instantiated will be identified by the UUID %s",
// name, executionIdentifier));
Constructor<? extends Plugin<? extends PluginDeclaration>> executorPluginConstructor;
try {
executorPluginConstructor = plugin.getDeclaredConstructor(argTypes);
} catch (Exception e) {
throw new PluginNotFoundException();
}
// Instancing the plugin
Plugin<? extends PluginDeclaration> instantiatedPlugin;
try {
instantiatedPlugin = executorPluginConstructor
.newInstance(arguments);
} catch (Exception e) {
throw new PluginNotFoundException();
}
logger.debug(String
.format("Plugin named %s has been instantiated", pluginName));
return instantiatedPlugin;
}
private Map<String, Class<? extends Plugin>> availablePlugins;
/**
* Get the singleton instance of {@link #PluginManager}.
@ -104,7 +40,7 @@ public class PluginManager {
* so it is created. Otherwise the already created instance is returned
* @return singleton instance of {@link #PluginManager}
*/
public static PluginManager getInstance(){
private static PluginManager getInstance(){
if(pluginManager== null){
pluginManager = new PluginManager();
}
@ -117,33 +53,41 @@ public class PluginManager {
*/
protected PluginManager(){
logger.debug("Loading plugins available on classpath");
this.availablePlugins = new HashMap<String, PluginDeclaration>();
ServiceLoader<PluginDeclaration> serviceLoader = ServiceLoader.load(PluginDeclaration.class);
for (PluginDeclaration pluginDeclaration : serviceLoader) {
this.availablePlugins = new HashMap<String, Class<? extends Plugin>>();
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class);
for (Plugin plugin : serviceLoader) {
try {
logger.debug(String.format("%s plugin found", pluginDeclaration.getName()));
pluginDeclaration.init();
String name = pluginDeclaration.getName();
this.availablePlugins.put(name, pluginDeclaration);
logger.debug(String.format("%s plugin found", plugin.getName()));
String name = plugin.getName();
this.availablePlugins.put(name, plugin.getClass());
} catch (Exception e) {
logger.debug(String.format("%s not initialized correctly. It will not be used", pluginDeclaration.getName()));
logger.debug(String.format("%s not initialized correctly. It will not be used", plugin.getName()));
}
}
}
/**
*
* @param name The name of the plugin
* @param pluginName The name of the plugin
* @return The plugin declaration if available, null otherwise
* @throws PluginNotFoundException
*/
public PluginDeclaration getPlugin(String name){
return this.availablePlugins.get(name);
public static Plugin getPlugin(String pluginName) throws PluginNotFoundException, ExecutorException {
Class<? extends Plugin> pluginClass = getAvailablePlugins().get(pluginName);
if (pluginClass== null) {
throw new PluginNotFoundException("Plugin " + pluginName + " not available in this smart-executor instance");
}
try {
return pluginClass.getDeclaredConstructor().newInstance();
}catch (Exception e) {
throw new ExecutorException("Unable to instatiate plugin " + pluginName, e);
}
}
/**
* @return the availablePlugins
*/
public Map<String, PluginDeclaration> getAvailablePlugins() {
return availablePlugins;
public static Map<String, Class<? extends Plugin>> getAvailablePlugins() {
return PluginManager.getInstance().availablePlugins;
}
}

View File

@ -18,11 +18,10 @@ import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.smartgears.ContextProvider;
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.exception.AlreadyInFinalStateException;
import org.gcube.vremanagement.executor.exception.InvalidPluginStateEvolutionException;
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;
@ -36,7 +35,7 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR)
*
*/
public class RunnablePlugin<T extends Plugin<? extends PluginDeclaration>> implements Runnable {
public class RunnablePlugin<T extends Plugin> implements Runnable {
/**
* Logger
@ -81,10 +80,10 @@ public class RunnablePlugin<T extends Plugin<? extends PluginDeclaration>> imple
@Override
public void run(){
String pluginName = plugin.getPluginDeclaration().getName();
String pluginName = plugin.getName();
logger.info("{} : {} is going to be launched (UUID={}, iterationNumber={}) with the following inputs {}",
pluginName, plugin.getPluginDeclaration().getVersion(),
pluginName, plugin.getVersion(),
uuid, iterationNumber, inputs);
JobUsageRecord jobUsageRecord = new JobUsageRecord();
@ -92,7 +91,7 @@ public class RunnablePlugin<T extends Plugin<? extends PluginDeclaration>> imple
long startTime = actualStateEvolution.getTimestamp();
try {
SmartExecutorInitializator.setContext(token);
ContextUtility.setContext(token);
setState(PluginState.RUNNING);
@ -103,7 +102,7 @@ public class RunnablePlugin<T extends Plugin<? extends PluginDeclaration>> imple
jobUsageRecord.setHost(hnRef.getAddress());
ClientInfo clientInfo = SmartExecutorInitializator.getClientInfo();
ClientInfo clientInfo = ContextUtility.getClientInfo();
String consumerId = clientInfo.getId();
jobUsageRecord.setConsumerId(consumerId);
@ -222,7 +221,7 @@ public class RunnablePlugin<T extends Plugin<? extends PluginDeclaration>> imple
throw new AlreadyInFinalStateException();
}
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, iterationNumber, timestamp, plugin.getPluginDeclaration(), pluginState, percentage);
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, iterationNumber, timestamp, plugin, pluginState, percentage);
for(PluginStateNotification pluginStateNotification : pluginStateNotifications){
String pluginStateNotificationName = pluginStateNotification.getClass().getSimpleName();
@ -241,7 +240,7 @@ public class RunnablePlugin<T extends Plugin<? extends PluginDeclaration>> imple
public String toString(){
return String.format("UUID : %s, Iteration : %d, Plugin : %s",
uuid.toString(), iterationNumber,
plugin.getPluginDeclaration().getName());
plugin.getName());
}
/**

View File

@ -35,7 +35,8 @@ import org.gcube.vremanagement.executor.json.ExtendedSEMapper;
import org.gcube.vremanagement.executor.json.SEMapper;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.plugin.PluginDefinition;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
@ -76,10 +77,12 @@ public class RestSmartExecutor {
//setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART);
setCalledMethod("getAvailablePlugins");
try {
PluginManager pluginManager = PluginManager.getInstance();
Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
List<PluginDeclaration> plugins = new ArrayList<PluginDeclaration>(availablePlugins.values());
return ExtendedSEMapper.getInstance().marshal(PluginDeclaration.class, plugins);
Map<String, Class<? extends Plugin>> availablePlugins = PluginManager.getAvailablePlugins();
List<PluginDefinition> plugins = new ArrayList<>();
for(String pluginName : availablePlugins.keySet()) {
plugins.add(PluginManager.getPlugin(pluginName));
}
return ExtendedSEMapper.getInstance().marshal(PluginDefinition.class, plugins);
}catch (Exception e) {
throw new ExecutorException(e);
}
@ -95,24 +98,15 @@ public class RestSmartExecutor {
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory
.getPersistenceConnector();
List<PluginDeclaration> pluginDeclarations = new ArrayList<>();
List<String> plugins = new ArrayList<>();
if(pluginName.compareTo(RestConstants.ORPHAN_PATH_PARAM)!=0) {
PluginManager pluginManager = PluginManager.getInstance();
Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
PluginDeclaration pluginDeclaration = availablePlugins.get(pluginName);
if(pluginDeclaration==null) {
String error = String.format("This SmartExecutor instace does not manage any plugin with name %s", pluginName);
logger.error(error);
throw new ExecutorException(error);
}else {
pluginDeclarations.add(pluginDeclaration);
}
plugins.addAll(PluginManager.getAvailablePlugins().keySet());
}else {
// TODO check role
}
List<ScheduledTask> scheduledTasks = persistenceConnector.getOrphanScheduledTasks(pluginDeclarations);
List<ScheduledTask> scheduledTasks = persistenceConnector.getOrphanScheduledTasks(plugins);
/*
@ -202,10 +196,10 @@ public class RestSmartExecutor {
throw new ExecutorException(e);
}
if(pluginName.compareTo(pluginStateEvolution.getPluginDeclaration().getName()) != 0) {
if(pluginName.compareTo(pluginStateEvolution.getPluginDefinition().getName()) != 0) {
String error = String.format(
"Plugin Name provided in the URL (%s) does not match with the one got from %s (%s)", pluginName,
PluginStateEvolution.class.getSimpleName(), pluginStateEvolution.getPluginDeclaration().getName());
PluginStateEvolution.class.getSimpleName(), pluginStateEvolution.getPluginDefinition().getName());
throw new InvalidInputsException(error);
}

View File

@ -14,7 +14,7 @@ import org.gcube.common.resources.gcore.HostingNode;
import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.smartgears.Constants;
import org.gcube.smartgears.ContextProvider;
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.json.ExtendedSEMapper;
import org.gcube.vremanagement.executor.json.SEMapper;
@ -42,8 +42,8 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
this.uuid = uuid;
this.launchParameter = launchParameter;
this.token = SecurityTokenProvider.instance.get();
this.scope = SmartExecutorInitializator.getCurrentScope();
this.clientInfo = SmartExecutorInitializator.getClientInfo();
this.scope = ContextUtility.getCurrentScope();
this.clientInfo = ContextUtility.getClientInfo();
this.runOn = runOn;
}

View File

@ -8,7 +8,6 @@ import java.util.List;
import java.util.UUID;
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
/**
* @author Luca Frosini (ISTI - CNR)
@ -18,13 +17,12 @@ public interface ScheduledTaskPersistence {
/**
* Retrieve from the #SmartExecutorPersistenceConnector the orphaned
* Scheduled tasks
* @param pluginDeclarations
* @param plugins
* @return the list of orphaned Scheduled
* @throws SchedulePersistenceException
* if fails
*/
public List<ScheduledTask> getOrphanScheduledTasks(
Collection<? extends PluginDeclaration> pluginDeclarations)
public List<ScheduledTask> getOrphanScheduledTasks(Collection<String> plugins)
throws SchedulePersistenceException;
/**

View File

@ -14,6 +14,7 @@ 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;
@ -192,7 +193,14 @@ public class SmartExecutorScheduler {
* Checking if the requested plugin is available on this smart executor
* instance
*/
PluginManager.getPluginDeclaration(parameter.getPluginName());
try {
PluginManager.getPlugin(parameter.getPluginName());
} catch (PluginNotFoundException e) {
throw e;
} catch (ExecutorException e) {
throw new LaunchException(e);
}
if(uuid == null) {
uuid = UUID.randomUUID();

View File

@ -3,7 +3,7 @@ package org.gcube.vremanagement.executor.scheduler;
import java.util.HashMap;
import java.util.Map;
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
@ -45,7 +45,7 @@ public class SmartExecutorSchedulerFactory {
Scheduler scheduler = schedulerFactory.getScheduler();
smartExecutorScheduler = new SmartExecutorScheduler(scheduler);
smartExecutorSchedulers.put(SmartExecutorInitializator.getCurrentScope(),
smartExecutorSchedulers.put(ContextUtility.getCurrentScope(),
smartExecutorScheduler);
}
@ -57,13 +57,12 @@ public class SmartExecutorSchedulerFactory {
* @throws SchedulerException
*/
public static synchronized SmartExecutorScheduler getSmartExecutorScheduler() throws SchedulerException {
String scope = SmartExecutorInitializator.getCurrentScope();
String scope = ContextUtility.getCurrentScope();
return getSmartExecutorScheduler(scope);
}
public static void remove(){
String scope = SmartExecutorInitializator.getCurrentScope();
String scope = ContextUtility.getCurrentScope();
smartExecutorSchedulers.remove(scope);
}

View File

@ -13,13 +13,10 @@ import java.util.UUID;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.exception.AlreadyInFinalStateException;
import org.gcube.vremanagement.executor.exception.InputsNullException;
import org.gcube.vremanagement.executor.exception.InvalidPluginStateEvolutionException;
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
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;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
@ -74,9 +71,9 @@ public class SmartExecutorTask implements InterruptableJob {
/* Derived from launchParameter*/
protected int executionCount;
protected String pluginName;
protected Plugin<? extends PluginDeclaration> plugin;
protected Plugin plugin;
protected Map<String, Object> inputs;
protected RunnablePlugin<Plugin<? extends PluginDeclaration>> runnablePlugin;
protected RunnablePlugin<Plugin> runnablePlugin;
protected boolean mustPreviousExecutionsCompleted;
protected int maxExecutionNumber;
/**/
@ -90,8 +87,8 @@ public class SmartExecutorTask implements InterruptableJob {
pluginName = launchParameter.getPluginName();
try {
plugin = PluginManager.instantiatePlugin(pluginName);
} catch (InputsNullException | PluginNotFoundException e) {
plugin = PluginManager.getPlugin(pluginName);
} catch (Exception e) {
throw new JobExecutionException(e);
}
@ -216,7 +213,7 @@ public class SmartExecutorTask implements InterruptableJob {
return;
}
runnablePlugin = new RunnablePlugin<Plugin<? extends PluginDeclaration>>(
runnablePlugin = new RunnablePlugin<Plugin>(
plugin, inputs, uuid, executionCount, pluginStateNotifications, token);
logger.debug("Going to run Job with ID {} (iteration {})", uuid, executionCount);

View File

@ -19,14 +19,15 @@ import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.exception.InvalidPluginStateEvolutionException;
import org.gcube.vremanagement.executor.json.ExtendedSEMapper;
import org.gcube.vremanagement.executor.json.SEMapper;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.plugin.PluginDefinition;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.gcube.vremanagement.executor.plugin.Ref;
import org.gcube.vremanagement.executor.plugin.RunOn;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.gcube.vremanagement.helloworld.HelloWorldPluginDeclaration;
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -93,7 +94,7 @@ public class SerializationTest extends ContextTest {
throws JsonGenerationException, JsonMappingException, IOException, InvalidPluginStateEvolutionException {
PluginStateEvolution pes = new PluginStateEvolution(UUID.randomUUID(), 1,
Calendar.getInstance().getTimeInMillis(), new HelloWorldPluginDeclaration(), PluginState.RUNNING, 10);
Calendar.getInstance().getTimeInMillis(), new HelloWorldPlugin(), PluginState.RUNNING, 10);
logger.debug("{} to be Marshalled : {}", pes.getClass().getSimpleName(), pes);
ObjectMapper objectMapper = new ObjectMapper();
@ -107,13 +108,12 @@ public class SerializationTest extends ContextTest {
@Test
public void testAvailablePluginMarshalling() throws Exception {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
logger.debug("{}", ExtendedSEMapper.getInstance().marshal(helloWorldPluginDeclaration));
PluginManager pluginManager = PluginManager.getInstance();
Map<String,PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
List<PluginDeclaration> plugins = new ArrayList<PluginDeclaration>(availablePlugins.values());
String list = ExtendedSEMapper.getInstance().marshal(PluginDeclaration.class, plugins);
Map<String, Class<? extends Plugin>> availablePlugins = PluginManager.getAvailablePlugins();
List<PluginDefinition> plugins = new ArrayList<>();
for(String pluginName : availablePlugins.keySet()) {
plugins.add(PluginManager.getPlugin(pluginName));
}
String list = ExtendedSEMapper.getInstance().marshal(PluginDefinition.class, plugins);
logger.debug("Plugins are :\n{}", list);
}

View File

@ -8,10 +8,8 @@ import java.util.HashMap;
import java.util.Map;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
import org.gcube.vremanagement.helloworld.HelloWorldPluginDeclaration;
import org.junit.Test;
/**
@ -25,17 +23,9 @@ public class SmartExecutorImplTest {
Map<String, Object> inputs = new HashMap<String, Object>();
long sleepTime = 10000;
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
Plugin<? extends PluginDeclaration> runnablePlugin = PluginManager.instantiatePlugin(HelloWorldPluginDeclaration.NAME);
runnablePlugin.launch(inputs);
}
@Test
public void helloWorldFullTest() throws Exception{
Map<String, Object> inputs = new HashMap<String, Object>();
long sleepTime = 10000;
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
Plugin<? extends PluginDeclaration> runnablePlugin = PluginManager.instantiatePlugin(HelloWorldPluginDeclaration.NAME);
runnablePlugin.launch(inputs);
String name = (new HelloWorldPlugin()).getName();
Plugin plugin = PluginManager.getPlugin(name);
plugin.launch(inputs);
}
}

View File

@ -88,11 +88,11 @@ public class SmartExecutorInizializatorTest {
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
try {
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} ({}) from scope {}",
serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), SmartExecutorInitializator.getCurrentScope());
serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentScope());
// unPublishResource(serviceEndpoint);
} catch(Exception e){
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} ({}) from scope {}",
serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), SmartExecutorInitializator.getCurrentScope(), e);
serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentScope(), e);
}
}
}catch(Exception e){

View File

@ -15,7 +15,7 @@ import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTaskPersistence;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTaskPersistenceFactory;
import org.gcube.vremanagement.helloworld.HelloWorldPluginDeclaration;
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@ -47,7 +47,7 @@ public class SmartExecutorPersistenceConnectorTest extends ContextTest {
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], 0);
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, 1, timestamp, HelloWorldPlugin.class.newInstance(), states[i], 0);
persistenceConnector.pluginStateEvolution(pluginStateEvolution, null);
long startTime = Calendar.getInstance().getTimeInMillis();

View File

@ -3,7 +3,9 @@ package org.gcube.vremanagement.executor.pluginmanager;
import java.util.UUID;
import org.gcube.vremanagement.executor.ContextTest;
import org.gcube.vremanagement.helloworld.HelloWorldPluginDeclaration;
import org.gcube.vremanagement.executor.exception.ExecutorException;
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
import org.junit.Assert;
import org.junit.Test;
@ -13,17 +15,13 @@ import org.junit.Test;
public class PluginManagerTest extends ContextTest {
@Test
public void getInstance(){
PluginManager pluginManager = PluginManager.getInstance();
Assert.assertNotNull(pluginManager);
}
@Test
public void getHelloWorldPlugin(){
PluginManager pluginManager = PluginManager.getInstance();
Assert.assertNotNull(pluginManager);
Assert.assertEquals(HelloWorldPluginDeclaration.class, pluginManager.getPlugin(HelloWorldPluginDeclaration.NAME).getClass());
Assert.assertNull(pluginManager.getPlugin(UUID.randomUUID().toString()));
public void getHelloWorldPlugin() throws ExecutorException {
Assert.assertEquals(HelloWorldPlugin.class, PluginManager.getPlugin(new HelloWorldPlugin().getName()).getClass());
try {
PluginManager.getPlugin(UUID.randomUUID().toString());
}catch (PluginNotFoundException e) {
// Ok. This is the expected behaviour
}
}
}

View File

@ -16,7 +16,6 @@ import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFact
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
import org.gcube.vremanagement.helloworld.HelloWorldPluginDeclaration;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@ -34,11 +33,11 @@ public class RunnablePluginTest extends ContextTest {
public void launchNullInputsTest() throws Exception {
logger.debug("Testing Null inputs");
UUID uuid = UUID.randomUUID();
HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration();
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
List<PluginStateNotification> pluginStateNotifications = new ArrayList<PluginStateNotification>();
pluginStateNotifications.add(persistenceConnector);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
try {
RunnablePlugin<HelloWorldPlugin> runnablePlugin = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, null, uuid, 1, pluginStateNotifications, SecurityTokenProvider.instance.get());
runnablePlugin.run();
@ -52,11 +51,10 @@ public class RunnablePluginTest extends ContextTest {
logger.debug("Testing Empty inputs");
Map<String, Object> inputs = new HashMap<String, Object>();
UUID uuid = UUID.randomUUID();
HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration();
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
List<PluginStateNotification> pluginStateNotifications = new ArrayList<PluginStateNotification>();
pluginStateNotifications.add(persistenceConnector);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
RunnablePlugin<HelloWorldPlugin> pt = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,SecurityTokenProvider.instance.get());
try {
@ -76,11 +74,10 @@ public class RunnablePluginTest extends ContextTest {
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
UUID uuid = UUID.randomUUID();
HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration();
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
List<PluginStateNotification> pluginStateNotifications = new ArrayList<PluginStateNotification>();
pluginStateNotifications.add(persistenceConnector);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
RunnablePlugin<HelloWorldPlugin> rp = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,SecurityTokenProvider.instance.get());
long startTime = Calendar.getInstance().getTimeInMillis();
long endTime = startTime;

View File

@ -20,7 +20,6 @@ import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler;
import org.gcube.vremanagement.executor.scheduler.SmartExecutorSchedulerFactory;
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
import org.gcube.vremanagement.helloworld.HelloWorldPluginDeclaration;
import org.junit.Assert;
import org.junit.Test;
import org.quartz.CronExpression;
@ -48,7 +47,7 @@ public class SmartExecutorSchedulerTest extends ContextTest {
inputs.put("Test UUID", UUID.randomUUID());
logger.debug("Inputs : {}", inputs);
LaunchParameter parameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
LaunchParameter parameter = new LaunchParameter(new HelloWorldPlugin().getName(), inputs);
parameter.setScheduling(scheduling);
SmartExecutorScheduler smartExecutorScheduler = SmartExecutorSchedulerFactory.getSmartExecutorScheduler();