Implementing new IS publisher
This commit is contained in:
parent
90512acf7b
commit
36a4e6684d
|
@ -33,6 +33,9 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
|
|
||||||
public static final long JOIN_TIMEOUT = 1000;
|
public static final long JOIN_TIMEOUT = 1000;
|
||||||
|
|
||||||
|
protected static GCoreISPublisher gCoreISPublisher;
|
||||||
|
protected static RestISPublisher restISPublisher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* The method discover the plugins available on classpath and their own
|
* The method discover the plugins available on classpath and their own
|
||||||
|
|
|
@ -3,11 +3,14 @@ package org.gcube.vremanagement.executor.ispublisher;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||||
|
@ -37,18 +40,18 @@ public class RestISPublisher extends ISPublisher {
|
||||||
private static Logger logger = LoggerFactory.getLogger(RestISPublisher.class);
|
private static Logger logger = LoggerFactory.getLogger(RestISPublisher.class);
|
||||||
|
|
||||||
protected final UUID eServiceUUID;
|
protected final UUID eServiceUUID;
|
||||||
|
protected ResourceRegistryClient resourceRegistryClient;
|
||||||
|
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||||
|
|
||||||
public RestISPublisher(ApplicationContext applicationContext) {
|
public RestISPublisher(ApplicationContext applicationContext) {
|
||||||
super(applicationContext);
|
super(applicationContext);
|
||||||
this.eServiceUUID = UUID.fromString(applicationContext.id());
|
this.eServiceUUID = UUID.fromString(applicationContext.id());
|
||||||
|
this.resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||||
|
this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("unused")
|
||||||
public void publishPlugins(Map<String, Class<? extends Plugin>> availablePlugins) throws Exception {
|
protected RunningPlugin publishRunningPluginWithRelations(String pluginName) throws Exception {
|
||||||
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
||||||
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
|
||||||
|
|
||||||
for(String pluginName : availablePlugins.keySet()) {
|
|
||||||
Plugin plugin = PluginManager.getPlugin(pluginName);
|
Plugin plugin = PluginManager.getPlugin(pluginName);
|
||||||
|
|
||||||
RunningPlugin runningPlugin = new RunningPluginImpl();
|
RunningPlugin runningPlugin = new RunningPluginImpl();
|
||||||
|
@ -68,7 +71,6 @@ public class RestISPublisher extends ISPublisher {
|
||||||
runningPlugin.addFacet(simplePropertyFacet);
|
runningPlugin.addFacet(simplePropertyFacet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EService smartExecutorEService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
EService smartExecutorEService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||||
PropagationConstraint usesPropagationConstraint = new PropagationConstraintImpl();
|
PropagationConstraint usesPropagationConstraint = new PropagationConstraintImpl();
|
||||||
usesPropagationConstraint.setAddConstraint(AddConstraint.propagate);
|
usesPropagationConstraint.setAddConstraint(AddConstraint.propagate);
|
||||||
|
@ -96,6 +98,32 @@ public class RestISPublisher extends ISPublisher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return runningPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publishPlugins(Map<String, Class<? extends Plugin>> availablePlugins) throws Exception {
|
||||||
|
|
||||||
|
UUID contextUUID = resourceRegistryClient.getCurrentContext().getHeader().getUUID();
|
||||||
|
|
||||||
|
for(String pluginName : availablePlugins.keySet()) {
|
||||||
|
|
||||||
|
UUID uuid = PluginManager.getPluginUUID(pluginName);
|
||||||
|
|
||||||
|
RunningPlugin runningPlugin;
|
||||||
|
|
||||||
|
try {
|
||||||
|
runningPlugin = resourceRegistryClient.getInstance(RunningPlugin.class, uuid);
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
runningPlugin = publishRunningPluginWithRelations(pluginName);
|
||||||
|
} catch (AvailableInAnotherContextException e) {
|
||||||
|
runningPlugin = new RunningPluginImpl();
|
||||||
|
runningPlugin.setHeader(new HeaderImpl(uuid));
|
||||||
|
resourceRegistryPublisher.addToContext(contextUUID, runningPlugin);
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.vremanagement.executor.pluginmanager;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.vremanagement.executor.exception.ExecutorException;
|
import org.gcube.vremanagement.executor.exception.ExecutorException;
|
||||||
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
|
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
|
||||||
|
@ -34,6 +35,8 @@ public class PluginManager {
|
||||||
*/
|
*/
|
||||||
private Map<String, Class<? extends Plugin>> availablePlugins;
|
private Map<String, Class<? extends Plugin>> availablePlugins;
|
||||||
|
|
||||||
|
private Map<String, UUID> uuids;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the singleton instance of {@link #PluginManager}.
|
* Get the singleton instance of {@link #PluginManager}.
|
||||||
* The first time this function is invoked the instance is null
|
* The first time this function is invoked the instance is null
|
||||||
|
@ -53,13 +56,15 @@ public class PluginManager {
|
||||||
*/
|
*/
|
||||||
protected PluginManager(){
|
protected PluginManager(){
|
||||||
logger.debug("Loading plugins available on classpath");
|
logger.debug("Loading plugins available on classpath");
|
||||||
this.availablePlugins = new HashMap<String, Class<? extends Plugin>>();
|
this.availablePlugins = new HashMap<>();
|
||||||
|
this.uuids = new HashMap<>();
|
||||||
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class);
|
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class);
|
||||||
for (Plugin plugin : serviceLoader) {
|
for (Plugin plugin : serviceLoader) {
|
||||||
try {
|
try {
|
||||||
logger.debug(String.format("%s plugin found", plugin.getName()));
|
logger.debug(String.format("%s plugin found", plugin.getName()));
|
||||||
String name = plugin.getName();
|
String name = plugin.getName();
|
||||||
this.availablePlugins.put(name, plugin.getClass());
|
this.availablePlugins.put(name, plugin.getClass());
|
||||||
|
this.uuids.put(name, UUID.randomUUID());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.debug(String.format("%s not initialized correctly. It will not be used", plugin.getName()));
|
logger.debug(String.format("%s not initialized correctly. It will not be used", plugin.getName()));
|
||||||
}
|
}
|
||||||
|
@ -84,10 +89,17 @@ public class PluginManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static UUID getPluginUUID(String pluginName) {
|
||||||
|
return PluginManager.getInstance().uuids.get(pluginName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the availablePlugins
|
* @return the availablePlugins
|
||||||
*/
|
*/
|
||||||
public static Map<String, Class<? extends Plugin>> getAvailablePlugins() {
|
public static Map<String, Class<? extends Plugin>> getAvailablePlugins() {
|
||||||
return PluginManager.getInstance().availablePlugins;
|
return PluginManager.getInstance().availablePlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue