Implementing new IS publisher
This commit is contained in:
parent
36a4e6684d
commit
2e04364edc
|
@ -7,8 +7,7 @@ import org.gcube.smartgears.ApplicationManager;
|
|||
import org.gcube.smartgears.ContextProvider;
|
||||
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.ispublisher.ISPublisher;
|
||||
import org.gcube.vremanagement.executor.json.ExtendedSEMapper;
|
||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
||||
|
@ -33,9 +32,6 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
|||
|
||||
public static final long JOIN_TIMEOUT = 1000;
|
||||
|
||||
protected static GCoreISPublisher gCoreISPublisher;
|
||||
protected static RestISPublisher restISPublisher;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* The method discover the plugins available on classpath and their own
|
||||
|
@ -59,11 +55,15 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
|||
ApplicationContext applicationContext = ContextProvider.get();
|
||||
|
||||
try {
|
||||
GCoreISPublisher gCoreISPublisher = new GCoreISPublisher(applicationContext);
|
||||
gCoreISPublisher.publishPlugins(availablePlugins);
|
||||
|
||||
RestISPublisher restISPublisher = new RestISPublisher(applicationContext);
|
||||
restISPublisher.publishPlugins(availablePlugins);
|
||||
List<ISPublisher> isPublishers = ISPublisher.getISPublishers(applicationContext);
|
||||
for(ISPublisher isPublisher : isPublishers) {
|
||||
try {
|
||||
isPublisher.unpublishPlugins(true);
|
||||
}catch (Exception e) {
|
||||
logger.error("unable to unpublish plugind from IS using {}", isPublisher.getClass().getName());
|
||||
}
|
||||
isPublisher.publishPlugins(availablePlugins);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to Create ServiceEndpoint for scope {}. The Service will be aborted", scope, e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -178,11 +178,14 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
|||
}
|
||||
|
||||
ApplicationContext applicationContext = ContextProvider.get();
|
||||
GCoreISPublisher gCoreISPublisher = new GCoreISPublisher(applicationContext);
|
||||
gCoreISPublisher.unpublishPlugins();
|
||||
|
||||
RestISPublisher restISPublisher = new RestISPublisher(applicationContext);
|
||||
restISPublisher.unpublishPlugins();
|
||||
List<ISPublisher> isPublishers = ISPublisher.getISPublishers(applicationContext);
|
||||
for(ISPublisher isPublisher : isPublishers) {
|
||||
try {
|
||||
isPublisher.unpublishPlugins(false);
|
||||
}catch (Exception e) {
|
||||
logger.error("unable to unpublish plugind from IS using {}", isPublisher.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
SmartExecutorPersistenceFactory.closePersistenceConnector();
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GCoreISPublisher extends ISPublisher {
|
||||
class GCoreISPublisher extends ISPublisher {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GCoreISPublisher.class);
|
||||
|
||||
|
@ -241,7 +241,7 @@ public class GCoreISPublisher extends ISPublisher {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void unpublishPlugins() {
|
||||
public void unpublishPlugins(boolean force) throws Exception {
|
||||
cleanServiceEndpoints();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.vremanagement.executor.ispublisher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
|
@ -7,6 +9,17 @@ import org.gcube.vremanagement.executor.plugin.Plugin;
|
|||
|
||||
public abstract class ISPublisher {
|
||||
|
||||
protected static List<ISPublisher> isPublishers;
|
||||
|
||||
public static List<ISPublisher> getISPublishers(ApplicationContext applicationContext){
|
||||
if(isPublishers==null) {
|
||||
List<ISPublisher> isPublishers = new ArrayList<>();
|
||||
isPublishers.add(new GCoreISPublisher(applicationContext));
|
||||
isPublishers.add(new RestISPublisher(applicationContext));
|
||||
}
|
||||
return isPublishers;
|
||||
}
|
||||
|
||||
protected ApplicationContext applicationContext;
|
||||
|
||||
public ISPublisher(ApplicationContext applicationContext) {
|
||||
|
@ -15,6 +28,6 @@ public abstract class ISPublisher {
|
|||
|
||||
public abstract void publishPlugins(Map<String, Class<? extends Plugin>> availablePlugins) throws Exception;
|
||||
|
||||
public abstract void unpublishPlugins();
|
||||
public abstract void unpublishPlugins(boolean force) throws Exception ;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.vremanagement.executor.ispublisher;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -12,6 +13,7 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
|
|||
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.client.Direction;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
||||
|
@ -35,7 +37,7 @@ import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RestISPublisher extends ISPublisher {
|
||||
class RestISPublisher extends ISPublisher {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RestISPublisher.class);
|
||||
|
||||
|
@ -43,6 +45,8 @@ public class RestISPublisher extends ISPublisher {
|
|||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
|
||||
|
||||
|
||||
public RestISPublisher(ApplicationContext applicationContext) {
|
||||
super(applicationContext);
|
||||
this.eServiceUUID = UUID.fromString(applicationContext.id());
|
||||
|
@ -51,14 +55,14 @@ public class RestISPublisher extends ISPublisher {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected RunningPlugin publishRunningPluginWithRelations(String pluginName) throws Exception {
|
||||
Plugin plugin = PluginManager.getPlugin(pluginName);
|
||||
protected RunningPlugin publishRunningPluginWithRelations(Plugin plugin, UUID pluginUUID) throws Exception {
|
||||
|
||||
RunningPlugin runningPlugin = new RunningPluginImpl();
|
||||
runningPlugin.setHeader(new HeaderImpl(pluginUUID));
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup(plugin.getGroup());
|
||||
softwareFacet.setName(pluginName);
|
||||
softwareFacet.setName(plugin.getName());
|
||||
softwareFacet.setVersion(plugin.getVersion());
|
||||
softwareFacet.setDescription(plugin.getDescription());
|
||||
runningPlugin.addFacet(softwareFacet);
|
||||
|
@ -80,7 +84,7 @@ public class RestISPublisher extends ISPublisher {
|
|||
try {
|
||||
resourceRegistryPublisher.createIsRelatedTo(uses);
|
||||
} catch (ResourceRegistryException e) {
|
||||
logger.error("Unable to publish %s instace %s for plugin %s. I'm going to stop the service.", Resource.NAME, RunningPlugin.NAME, pluginName);
|
||||
logger.error("Unable to publish %s instace %s for plugin %s. I'm going to stop the service.", Resource.NAME, RunningPlugin.NAME, plugin.getName());
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
@ -93,7 +97,7 @@ public class RestISPublisher extends ISPublisher {
|
|||
try {
|
||||
resourceRegistryPublisher.createIsRelatedTo(enables);
|
||||
} catch (ResourceRegistryException e) {
|
||||
logger.error("Unable to publish %s instace %s for plugin %s. I'm going to stop the service.", Resource.NAME, RunningPlugin.NAME, pluginName);
|
||||
logger.error("Unable to publish %s instace %s for plugin %s. I'm going to stop the service.", Resource.NAME, RunningPlugin.NAME, plugin.getName());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -108,17 +112,18 @@ public class RestISPublisher extends ISPublisher {
|
|||
|
||||
for(String pluginName : availablePlugins.keySet()) {
|
||||
|
||||
UUID uuid = PluginManager.getPluginUUID(pluginName);
|
||||
Plugin plugin = PluginManager.getPlugin(pluginName);
|
||||
UUID pluginUUID = PluginManager.getPluginUUID(pluginName);
|
||||
|
||||
RunningPlugin runningPlugin;
|
||||
|
||||
try {
|
||||
runningPlugin = resourceRegistryClient.getInstance(RunningPlugin.class, uuid);
|
||||
runningPlugin = resourceRegistryClient.getInstance(RunningPlugin.class, pluginUUID);
|
||||
} catch (NotFoundException e) {
|
||||
runningPlugin = publishRunningPluginWithRelations(pluginName);
|
||||
runningPlugin = publishRunningPluginWithRelations(plugin, pluginUUID);
|
||||
} catch (AvailableInAnotherContextException e) {
|
||||
runningPlugin = new RunningPluginImpl();
|
||||
runningPlugin.setHeader(new HeaderImpl(uuid));
|
||||
runningPlugin.setHeader(new HeaderImpl(pluginUUID));
|
||||
resourceRegistryPublisher.addToContext(contextUUID, runningPlugin);
|
||||
} catch (ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
@ -128,8 +133,16 @@ public class RestISPublisher extends ISPublisher {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void unpublishPlugins() {
|
||||
logger.info("The Plugin will be removed when the Eservice will be removed thanks to propagation contraints. Nothing to do");
|
||||
public void unpublishPlugins(boolean force) throws Exception {
|
||||
if(force) {
|
||||
List<RunningPlugin> runningPlugins = resourceRegistryClient.getRelatedResourcesFromReferenceResource(RunningPlugin.class, Uses.class, EService.class, this.eServiceUUID, Direction.IN, true);
|
||||
for(RunningPlugin runningPlugin : runningPlugins) {
|
||||
resourceRegistryPublisher.delete(runningPlugin);
|
||||
}
|
||||
}else {
|
||||
logger.info("The Plugin will be removed when the Eservice will be removed thanks to propagation contraints. Nothing to do");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue