Plugin Management
This commit is contained in:
parent
aa58648d64
commit
3d4ef046ac
|
@ -19,4 +19,6 @@ public interface LifecycleManager extends InitializablePlugin{
|
||||||
public Configuration getCurrentConfiguration() throws ConfigurationException;
|
public Configuration getCurrentConfiguration() throws ConfigurationException;
|
||||||
|
|
||||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException;
|
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException;
|
||||||
|
|
||||||
|
public void setPluginManager(PluginManagerInterface manager);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.gcube.application.cms.plugins;
|
||||||
|
|
||||||
|
import org.gcube.application.cms.plugins.Plugin;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
|
||||||
|
public interface PluginManagerInterface {
|
||||||
|
|
||||||
|
public Plugin getById(String pluginID) throws ConfigurationException;
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.application.cms.concessioni.plugins;
|
package org.gcube.application.cms.concessioni.plugins;
|
||||||
|
|
||||||
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.BsonDocument;
|
import org.bson.BsonDocument;
|
||||||
import org.bson.BsonString;
|
import org.bson.BsonString;
|
||||||
|
@ -9,6 +10,7 @@ import org.gcube.application.cms.concessioni.sdi.SDIManager;
|
||||||
import org.gcube.application.cms.concessioni.sdi.faults.SDIInteractionException;
|
import org.gcube.application.cms.concessioni.sdi.faults.SDIInteractionException;
|
||||||
import org.gcube.application.cms.plugins.InitializablePlugin;
|
import org.gcube.application.cms.plugins.InitializablePlugin;
|
||||||
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
||||||
|
import org.gcube.application.cms.plugins.PluginManagerInterface;
|
||||||
import org.gcube.application.cms.plugins.faults.EventException;
|
import org.gcube.application.cms.plugins.faults.EventException;
|
||||||
import org.gcube.application.cms.plugins.reports.*;
|
import org.gcube.application.cms.plugins.reports.*;
|
||||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||||
|
@ -42,6 +44,9 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
||||||
DESCRIPTOR.setVersion(new ComparableVersion("1.0.0"));
|
DESCRIPTOR.setVersion(new ComparableVersion("1.0.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
PluginManagerInterface pluginManager;
|
||||||
|
|
||||||
// TODO DISCOVER
|
// TODO DISCOVER
|
||||||
MaterializationPlugin plugin = new SDIMaterializerPlugin();
|
MaterializationPlugin plugin = new SDIMaterializerPlugin();
|
||||||
|
|
||||||
|
@ -49,21 +54,8 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
||||||
public InitializationReport initInContext() throws InitializationException {
|
public InitializationReport initInContext() throws InitializationException {
|
||||||
InitializationReport report = new InitializationReport();
|
InitializationReport report = new InitializationReport();
|
||||||
try{
|
try{
|
||||||
InitializationReport matPluginReport = plugin.initInContext();
|
|
||||||
switch(matPluginReport.getStatus()){
|
|
||||||
case OK: {
|
|
||||||
report.setStatus(Report.Status.OK);
|
report.setStatus(Report.Status.OK);
|
||||||
report.putMessage("Initialized "+plugin.getDescriptor().getId()+" in current context");
|
} catch (Throwable e) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
default :{
|
|
||||||
report.setStatus(Report.Status.WARNING);
|
|
||||||
report.putMessage("Unable to initialize "+plugin.getDescriptor().getId());
|
|
||||||
matPluginReport.getMessages().forEach(s ->
|
|
||||||
report.putMessage(plugin.getDescriptor().getId()+" : "+s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (InitializationException e) {
|
|
||||||
log.error("Unable to initialize plugins in {} ",ContextUtils.getCurrentScope(),e);
|
log.error("Unable to initialize plugins in {} ",ContextUtils.getCurrentScope(),e);
|
||||||
report.setStatus(Report.Status.WARNING);
|
report.setStatus(Report.Status.WARNING);
|
||||||
report.putMessage("Unable to initialize plugins in "+ ContextUtils.getCurrentScope()+" : "+e.getMessage());
|
report.putMessage("Unable to initialize plugins in "+ ContextUtils.getCurrentScope()+" : "+e.getMessage());
|
||||||
|
@ -75,21 +67,10 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
||||||
public InitializationReport init() throws InitializationException {
|
public InitializationReport init() throws InitializationException {
|
||||||
InitializationReport report = new InitializationReport();
|
InitializationReport report = new InitializationReport();
|
||||||
try{
|
try{
|
||||||
InitializationReport matPluginReport = plugin.init();
|
|
||||||
switch(matPluginReport.getStatus()){
|
|
||||||
case OK: {
|
|
||||||
report.setStatus(Report.Status.OK);
|
report.setStatus(Report.Status.OK);
|
||||||
report.putMessage("Initialized "+plugin.getDescriptor().getId());
|
plugin= (MaterializationPlugin) pluginManager.getById("SDI-Default-Materializer");
|
||||||
break;
|
if(plugin == null ) throw new InitializationException("SDI-Default-Materializer not found");
|
||||||
}
|
} catch (Throwable e) {
|
||||||
default :{
|
|
||||||
report.setStatus(Report.Status.WARNING);
|
|
||||||
report.putMessage("Unable to initialize "+plugin.getDescriptor().getId());
|
|
||||||
matPluginReport.getMessages().forEach(s ->
|
|
||||||
report.putMessage(plugin.getDescriptor().getId()+" : "+s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (InitializationException e) {
|
|
||||||
log.error("Unable to initialize plugins ",e);
|
log.error("Unable to initialize plugins ",e);
|
||||||
report.setStatus(Report.Status.WARNING);
|
report.setStatus(Report.Status.WARNING);
|
||||||
report.putMessage("Unable to initialize plugins : "+e.getMessage());
|
report.putMessage("Unable to initialize plugins : "+e.getMessage());
|
||||||
|
@ -214,6 +195,8 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Configuration getCurrentConfiguration() throws ConfigurationException {
|
public Configuration getCurrentConfiguration() throws ConfigurationException {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.gcube.application.cms.concessioni.plugins;
|
package org.gcube.application.cms.concessioni.plugins;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Synchronized;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.concessioni.sdi.SDIManager;
|
import org.gcube.application.cms.concessioni.sdi.SDIManager;
|
||||||
|
@ -24,7 +26,9 @@ import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
|
||||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||||
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SDIMaterializerPlugin implements MaterializationPlugin {
|
public class SDIMaterializerPlugin implements MaterializationPlugin {
|
||||||
|
@ -35,14 +39,23 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
|
||||||
private String documentPath;
|
private String documentPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDIManager sdiManager;
|
Map<String,SDIManager> sdiManagerMap=null;
|
||||||
|
|
||||||
|
|
||||||
|
private SDIManager getSDIManager(){
|
||||||
|
return sdiManagerMap.get(ContextUtils.getCurrentScope());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Synchronized
|
||||||
public InitializationReport initInContext() throws InitializationException {
|
public InitializationReport initInContext() throws InitializationException {
|
||||||
InitializationReport report = new InitializationReport();
|
InitializationReport report = new InitializationReport();
|
||||||
try{
|
try{
|
||||||
log.info("Initializing in "+ ContextUtils.getCurrentScope());
|
if(getSDIManager()==null) {
|
||||||
sdiManager=new SDIManager();
|
String context = ContextUtils.getCurrentScope();
|
||||||
|
log.info("Initializing in " + context);
|
||||||
|
sdiManagerMap.put(context,new SDIManager());
|
||||||
|
}
|
||||||
report.setStatus(Report.Status.OK);
|
report.setStatus(Report.Status.OK);
|
||||||
report.putMessage("Initialized SDI Manager");
|
report.putMessage("Initialized SDI Manager");
|
||||||
} catch (SDIInteractionException e) {
|
} catch (SDIInteractionException e) {
|
||||||
|
@ -52,8 +65,10 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Synchronized
|
||||||
public InitializationReport init() throws InitializationException {
|
public InitializationReport init() throws InitializationException {
|
||||||
InitializationReport report = new InitializationReport();
|
InitializationReport report = new InitializationReport();
|
||||||
|
sdiManagerMap=new HashMap<>();
|
||||||
report.setStatus(Report.Status.OK);
|
report.setStatus(Report.Status.OK);
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +131,7 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
|
||||||
requestArguments.putIfAbsent("layerTitle",fs.getString(requestArguments.getString("titleField")));
|
requestArguments.putIfAbsent("layerTitle",fs.getString(requestArguments.getString("titleField")));
|
||||||
else requestArguments.putIfAbsent("layerTitle",fs.getUUID());
|
else requestArguments.putIfAbsent("layerTitle",fs.getUUID());
|
||||||
|
|
||||||
RegisteredFileSet obtained = sdiManager.materializeLayer(fs,requestArguments);
|
RegisteredFileSet obtained = getSDIManager().materializeLayer(fs,requestArguments);
|
||||||
log.debug("Obtained {} ",obtained);
|
log.debug("Obtained {} ",obtained);
|
||||||
documentNavigator.setElement("$..[?(@.uuid == "+fs.getUUID()+")]",obtained);
|
documentNavigator.setElement("$..[?(@.uuid == "+fs.getUUID()+")]",obtained);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package org.gcube.application.geoportal.service.engine.providers;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.gcube.application.cms.plugins.InitializablePlugin;
|
import org.gcube.application.cms.plugins.InitializablePlugin;
|
||||||
|
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||||
import org.gcube.application.cms.plugins.Plugin;
|
import org.gcube.application.cms.plugins.Plugin;
|
||||||
|
import org.gcube.application.cms.plugins.PluginManagerInterface;
|
||||||
import org.gcube.application.cms.plugins.faults.InitializationException;
|
import org.gcube.application.cms.plugins.faults.InitializationException;
|
||||||
import org.gcube.application.cms.plugins.faults.ShutDownException;
|
import org.gcube.application.cms.plugins.faults.ShutDownException;
|
||||||
import org.gcube.application.cms.plugins.reports.InitializationReport;
|
import org.gcube.application.cms.plugins.reports.InitializationReport;
|
||||||
|
@ -15,9 +17,10 @@ import org.reflections.util.FilterBuilder;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PluginManager extends AbstractScopedMap<Map<String, Plugin>>{
|
public class PluginManager extends AbstractScopedMap<Map<String, Plugin>> implements PluginManagerInterface {
|
||||||
|
|
||||||
Map<String,Plugin> implementations=new HashMap<>();
|
Map<String,Plugin> implementations=new HashMap<>();
|
||||||
|
|
||||||
|
@ -37,6 +40,9 @@ public class PluginManager extends AbstractScopedMap<Map<String, Plugin>>{
|
||||||
Plugin plugin = pluginClass.newInstance();
|
Plugin plugin = pluginClass.newInstance();
|
||||||
log.debug("Loading {} descriptiorn : ", plugin, plugin.getDescriptor());
|
log.debug("Loading {} descriptiorn : ", plugin, plugin.getDescriptor());
|
||||||
implementations.put(plugin.getDescriptor().getId(), plugin);
|
implementations.put(plugin.getDescriptor().getId(), plugin);
|
||||||
|
|
||||||
|
if(plugin instanceof LifecycleManager)
|
||||||
|
((LifecycleManager)plugin).setPluginManager(this);
|
||||||
}catch (Throwable t){
|
}catch (Throwable t){
|
||||||
log.warn("Unable to instantiate Plugin "+pluginClass,t);
|
log.warn("Unable to instantiate Plugin "+pluginClass,t);
|
||||||
}
|
}
|
||||||
|
@ -52,8 +58,7 @@ public class PluginManager extends AbstractScopedMap<Map<String, Plugin>>{
|
||||||
log.info("INIT Plugin {}",id);
|
log.info("INIT Plugin {}",id);
|
||||||
try {
|
try {
|
||||||
InitializablePlugin ip=(InitializablePlugin) p;
|
InitializablePlugin ip=(InitializablePlugin) p;
|
||||||
InitializationReport rep=ip.init();
|
logReport(ip,ip.init());
|
||||||
log.info("INIT REPORT : {}",rep);
|
|
||||||
}catch (InitializationException e){
|
}catch (InitializationException e){
|
||||||
log.error("Failed to initialize "+id,e);
|
log.error("Failed to initialize "+id,e);
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
|
@ -72,8 +77,7 @@ public class PluginManager extends AbstractScopedMap<Map<String, Plugin>>{
|
||||||
log.info("INIT Plugin {} in context {} ",id, ContextUtils.getCurrentScope());
|
log.info("INIT Plugin {} in context {} ",id, ContextUtils.getCurrentScope());
|
||||||
try {
|
try {
|
||||||
InitializablePlugin ip=(InitializablePlugin) p;
|
InitializablePlugin ip=(InitializablePlugin) p;
|
||||||
InitializationReport rep=ip.initInContext();
|
logReport(ip,ip.initInContext());
|
||||||
log.info("INIT REPORT : {}",rep);
|
|
||||||
}catch (InitializationException e){
|
}catch (InitializationException e){
|
||||||
log.error("Failed to initialize "+id,e);
|
log.error("Failed to initialize "+id,e);
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
|
@ -106,4 +110,25 @@ public class PluginManager extends AbstractScopedMap<Map<String, Plugin>>{
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plugin getById(String pluginID) throws ConfigurationException {
|
||||||
|
return getObject().get(pluginID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final void logReport(Plugin p, InitializationReport report){
|
||||||
|
switch(report.getStatus()){
|
||||||
|
case ERROR: {
|
||||||
|
log.error("Plugin [{}] STATUS : {}, INFO {} ",p.getDescriptor().getId(),report.getStatus(),report.getMessages());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WARNING: {
|
||||||
|
log.warn("Plugin [{}] STATUS : {}, INFO {} ",p.getDescriptor().getId(),report.getStatus(),report.getMessages());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default :{
|
||||||
|
log.info("Plugin [{}] STATUS : {}, INFO {} ",p.getDescriptor().getId(),report.getStatus(),report.getMessages());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue