Configurable Multiple handler management

This commit is contained in:
Fabio Sinibaldi 2022-04-29 15:31:17 +02:00
parent 8e6b1e0106
commit 0322042d73
6 changed files with 75 additions and 25 deletions

View File

@ -3,8 +3,10 @@ package org.gcube.application.cms.plugins;
import org.gcube.application.cms.plugins.Plugin;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import java.util.Map;
public interface PluginManagerInterface {
public Plugin getById(String pluginID) throws ConfigurationException;
public Map<String,Plugin> getByType(String type) throws ConfigurationException;
}

View File

@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.gcube.application.cms.plugins.IndexerPluginInterface;
import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.MaterializationPlugin;
import org.gcube.application.cms.plugins.faults.*;
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
import org.gcube.application.cms.plugins.reports.*;
@ -48,17 +49,23 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
@Override
protected EventExecutionReport onDeleteDocument(EventExecutionReport report) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
report = super.onDeleteDocument(report);
return deIndex(report,getIndexer(),getInternalIndexParams(report.getTheRequest()));
for(IndexerPluginInterface indexer : getIndexer(report.getTheRequest()))
report= deIndex(report,indexer,getInternalIndexParams(report.getTheRequest()));
return report;
}
@Override
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
theReport = super.onDeleteFileSet(theReport);
String phase = theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase();
Document parameters = null;
if(phase.equals(Phases.PENDING_APPROVAL))
return index(theReport,getIndexer(),getInternalIndexParams(theReport.getTheRequest()));
parameters =getInternalIndexParams(theReport.getTheRequest());
if(phase.equals(Phases.PUBLISHED))
return index(theReport,getIndexer(),getPublicIndexParams(theReport.getTheRequest()));
parameters = getPublicIndexParams(theReport.getTheRequest());
if(parameters!= null)
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
return theReport;
}
@ -69,11 +76,13 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
@Override
protected StepExecutionReport run() throws Exception {
// Materialize
theReport = materializeDocument(theReport,getMaterializer(),getMaterializationParameters(theReport.getTheRequest()));
for(MaterializationPlugin mat : getMaterializer(theReport.getTheRequest()))
theReport = materializeDocument(theReport,mat,getMaterializationParameters(theReport.getTheRequest()));
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
// Index
theReport = index(theReport,getIndexer(),
getInternalIndexParams(theReport.getTheRequest()));
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
theReport = index(theReport,indexer,getInternalIndexParams(theReport.getTheRequest()));
// setPhase
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
theReport.getToSetLifecycleInformation().setPhase(Phases.PENDING_APPROVAL);
@ -87,8 +96,8 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
@Override
protected StepExecutionReport run() throws Exception {
// Index
theReport = index(theReport,getIndexer(),
getPublicIndexParams(theReport.getTheRequest()));
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
// setPhase
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
theReport.getToSetLifecycleInformation().setPhase(Phases.PUBLISHED);

View File

@ -15,12 +15,17 @@ import org.gcube.application.geoportal.common.model.configuration.Configuration;
import org.gcube.application.geoportal.common.model.configuration.Index;
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.plugins.IndexerPluginDescriptor;
import org.gcube.application.geoportal.common.model.plugins.MaterializerPluginDescriptor;
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.utils.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Slf4j
public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements LifecycleManager {
@ -85,17 +90,18 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
setStep(new GuardedStepExecution(Steps.PUBLISH) {
@Override
protected StepExecutionReport run() throws Exception {
if(!theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE))
throw new StepException("Document is not in "+LifecycleInformation.CommonPhases.DRAFT_PHASE+" phase");
//Check Performed by Guarded Step Execution
// if(!theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE))
// throw new StepException("Document is not in "+LifecycleInformation.CommonPhases.DRAFT_PHASE+" phase");
// Materialize
theReport = materializeDocument(theReport, getMaterializer(),
getMaterializationParameters(theReport.getTheRequest()));
for(MaterializationPlugin mat : getMaterializer(theReport.getTheRequest()))
theReport = materializeDocument(theReport, mat, getMaterializationParameters(theReport.getTheRequest()));
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
// Index
theReport = index(theReport,getIndexer(),
getPublicIndexParams(theReport.getTheRequest()));
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
// setPhase
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
theReport.getToSetLifecycleInformation().setPhase("PUBLISHED");
@ -133,12 +139,14 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
JSONPathWrapper wrapper = new JSONPathWrapper(report.getTheRequest().getDocument().getTheDocument().toJson());
for (String s : wrapper.getMatchingPaths("..*[?(@." + RegisteredFileSet.PAYLOADS + ")]")){
log.info("Requesting dematerialization for {} ",s);
report = deMaterialize(report,getMaterializer(),new Document("fileSetPath",s));
for(MaterializationPlugin mat : getMaterializer(report.getTheRequest()))
report = deMaterialize(report,mat,new Document("fileSetPath",s));
if(!report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
break;
}
if(report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) {
report = deIndex(report,getIndexer(),getPublicIndexParams(report.getTheRequest()));
for(IndexerPluginInterface indexer : getIndexer(report.getTheRequest()))
report = deIndex(report,indexer,getPublicIndexParams(report.getTheRequest()));
}
return report;
}
@ -147,11 +155,13 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
// dematerialize selected
blockNonDraft(theReport);
deMaterialize(theReport,getMaterializer(),
theReport.getTheRequest().getCallParameters());
for(MaterializationPlugin mat : getMaterializer(theReport.getTheRequest()))
deMaterialize(theReport,mat,
theReport.getTheRequest().getCallParameters());
// de index
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
deIndex(theReport,getIndexer(),getPublicIndexParams(theReport.getTheRequest()));
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
deIndex(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
return theReport;
}
@ -162,12 +172,22 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
}
protected IndexerPluginInterface getIndexer() throws ConfigurationException {
return (IndexerPluginInterface) pluginManager.getById("SDI-Indexer-Plugin");
protected List<IndexerPluginInterface> getIndexer(BaseRequest request) throws ConfigurationException {
ArrayList<IndexerPluginInterface> toReturn=new ArrayList<>();
UseCaseDescriptor desc = request.getUseCaseDescriptor();
List<HandlerDeclaration> indexers = desc.getHandlersMapByType().get(IndexerPluginDescriptor.INDEXER);
for (HandlerDeclaration handlerDeclaration : indexers)
toReturn.add((IndexerPluginInterface) pluginManager.getById(handlerDeclaration.getId()));
return toReturn;
}
protected MaterializationPlugin getMaterializer() throws ConfigurationException {
return (MaterializationPlugin) pluginManager.getById("SDI-Default-Materializer");
protected List<MaterializationPlugin> getMaterializer(BaseRequest request) throws ConfigurationException {
ArrayList<MaterializationPlugin> toReturn=new ArrayList<>();
UseCaseDescriptor desc = request.getUseCaseDescriptor();
List<HandlerDeclaration> materializers = desc.getHandlersMapByType().get(MaterializerPluginDescriptor.MATERIALIZER);
for (HandlerDeclaration handlerDeclaration : materializers)
toReturn.add((MaterializationPlugin) pluginManager.getById(handlerDeclaration.getId()));
return toReturn;
}
protected <T extends DocumentHandlingReport> T deIndex(T report, IndexerPluginInterface indexer, Document parameters) throws InvalidPluginRequestException {

View File

@ -1,6 +1,12 @@
package org.gcube.application.cms.commons.model;
import org.junit.Test;
public class Serialization {
@Test
public void testSerializations(){
}
}

View File

@ -11,6 +11,7 @@ import org.gcube.application.geoportal.common.utils.ContextUtils;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class PluginManager extends AbstractScopedMap<PluginManager.PluginMap> implements PluginManagerInterface {
@ -128,4 +129,15 @@ public class PluginManager extends AbstractScopedMap<PluginManager.PluginMap> im
log.warn("Invalid report provided by {} ",p.getDescriptor().getId(),e);
}
}
@Override
public Map<String, Plugin> getByType(String type) throws ConfigurationException {
HashMap<String,Plugin> toReturn = new HashMap<>();
getObject().forEach((s, plugin) -> {
if (plugin!=null&&plugin.getDescriptor().getType().equals(type))
toReturn.put(s,plugin);
});
return toReturn;
}
}

View File

@ -133,6 +133,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
log.debug("Using user defined spatial reference " + reference);
GeoJsonObject object = Serialization.convert(reference.getGeoJson(), GeoJsonObject.class);
GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.fromGeoJSON(object.getBbox());