From a17e6756fe21bae9f68312ecb7355c9fc73aaa13 Mon Sep 17 00:00:00 2001 From: "fabio.sinibaldi" Date: Thu, 21 Mar 2019 16:25:40 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-publishing/gCat-Feeder-Suite@178651 82a268e6-3cf1-43bd-a215-b396298e98cf --- gCat-Feeder/pom.xml | 15 ++- .../gCatFeeder/service/GCatFeeder.java | 14 ++- .../service/GCatFeederLyfeCycleManager.java | 32 ++++- .../gCatFeeder/service/GCatFeederManager.java | 18 ++- .../gCatFeeder/service/ServiceConstants.java | 4 + .../impl/CatalogueControllersManagerImpl.java | 2 +- .../engine/impl/CollectorsManagerImpl.java | 2 +- .../service/engine/impl/FeederEngineImpl.java | 23 +++- .../engine/impl/PersistenceManagerImpl.java | 46 +++++++ .../service/model/ExecutionRequest.java | 34 ++++++ .../gCatFeeder/service/rest/Capabilities.java | 2 +- .../gCatFeeder/service/rest/Executions.java | 19 ++- .../gCatFeeder/service/BaseTest.java | 26 ++++ .../gCatFeeder/service/CapabilitiesTest.java | 33 ++++++ .../gCatFeeder/service/TestCommon.java | 10 ++ .../service/mockups/FakeCataloguePlugin.java | 71 +++++++++++ .../service/mockups/FakeCollectorPlugin.java | 112 ++++++++++++++++++ .../service/mockups/FakeCustomData.java | 22 ++++ ...hing.gCatFeeder.catalogues.CataloguePlugin | 1 + ...hing.gCatfeeder.collectors.CollectorPlugin | 1 + gCat-Feeder/src/test/resources/logback.xml | 16 +++ 21 files changed, 483 insertions(+), 20 deletions(-) create mode 100644 gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/PersistenceManagerImpl.java create mode 100644 gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/BaseTest.java create mode 100644 gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/CapabilitiesTest.java create mode 100644 gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/TestCommon.java create mode 100644 gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCataloguePlugin.java create mode 100644 gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCollectorPlugin.java create mode 100644 gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCustomData.java create mode 100644 gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin create mode 100644 gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin create mode 100644 gCat-Feeder/src/test/resources/logback.xml diff --git a/gCat-Feeder/pom.xml b/gCat-Feeder/pom.xml index c4c1685..d9427b7 100644 --- a/gCat-Feeder/pom.xml +++ b/gCat-Feeder/pom.xml @@ -62,7 +62,6 @@ javax.ws.rs javax.ws.rs-api - 2.0 @@ -72,6 +71,20 @@ jersey-container-servlet + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-simple + test + + + ch.qos.logback + logback-classic + 1.0.13 + test + + + \ No newline at end of file diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeeder.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeeder.java index 01620c8..d4cb714 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeeder.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeeder.java @@ -2,8 +2,15 @@ package org.gcube.data.publishing.gCatFeeder.service; import javax.ws.rs.ApplicationPath; +import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager; +import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager; +import org.gcube.data.publishing.gCatFeeder.service.engine.ExecutionManager; import org.gcube.data.publishing.gCatFeeder.service.engine.FeederEngine; +import org.gcube.data.publishing.gCatFeeder.service.engine.impl.CatalogueControllersManagerImpl; +import org.gcube.data.publishing.gCatFeeder.service.engine.impl.CollectorsManagerImpl; +import org.gcube.data.publishing.gCatFeeder.service.engine.impl.ExecutionManagerImpl; import org.gcube.data.publishing.gCatFeeder.service.engine.impl.FeederEngineImpl; +import org.gcube.data.publishing.gCatFeeder.service.rest.Capabilities; import org.gcube.data.publishing.gCatFeeder.service.rest.Executions; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; @@ -18,13 +25,14 @@ public class GCatFeeder extends ResourceConfig{ @Override protected void configure() { bind(FeederEngineImpl.class).to(FeederEngine.class); -// bind(ImporterImpl.class).to(Importer.class); -// bind(PerformanceManagerImpl.class).to(PerformanceManager.class); + bind(CatalogueControllersManagerImpl.class).to(CatalogueControllersManager.class); + bind(CollectorsManagerImpl.class).to(CollectorsManager.class); + bind(ExecutionManagerImpl.class).to(ExecutionManager.class); } }; register(binder); registerClasses(Executions.class); - + registerClasses(Capabilities.class); } } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederLyfeCycleManager.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederLyfeCycleManager.java index 50951f8..12da169 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederLyfeCycleManager.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederLyfeCycleManager.java @@ -1,7 +1,12 @@ package org.gcube.data.publishing.gCatFeeder.service; +import javax.inject.Inject; import javax.xml.bind.annotation.XmlRootElement; +import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager; +import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager; +import org.gcube.data.publishing.gCatFeeder.service.engine.ExecutionManager; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError; import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler; import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent.Start; import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent.Stop; @@ -9,17 +14,38 @@ import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent.Stop; @XmlRootElement(name = "gcatFeeder-lifecycle") public class GCatFeederLyfeCycleManager extends ApplicationLifecycleHandler{ + @Inject + ExecutionManager executions; + + @Inject + CollectorsManager collectors; + + @Inject + CatalogueControllersManager controllers; + + @Override public void onStart(Start e) { - // TODO Auto-generated method stub super.onStart(e); + + try { + collectors.initInScope(); + controllers.initInScope(); + } catch (InternalError ex) { + throw new RuntimeException("Initialization Error",ex); + } + + executions.load(); } @Override - public void onStop(Stop e) { - // TODO Auto-generated method stub + public void onStop(Stop e) { super.onStop(e); + + + + } } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederManager.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederManager.java index 77e57d7..2a9c593 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederManager.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/GCatFeederManager.java @@ -2,18 +2,32 @@ package org.gcube.data.publishing.gCatFeeder.service; import javax.inject.Inject; +import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager; +import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager; import org.gcube.data.publishing.gCatFeeder.service.engine.ExecutionManager; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError; import org.gcube.smartgears.ApplicationManager; public class GCatFeederManager implements ApplicationManager{ - @Inject ExecutionManager executions; + @Inject + CollectorsManager collectors; + + @Inject + CatalogueControllersManager controllers; + @Override public void onInit() { - executions.load(); + try { + collectors.init(); + controllers.init(); + } catch (InternalError e) { + throw new RuntimeException("Initialization Error",e); + } + } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java index 3942108..aa7327c 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java @@ -10,6 +10,10 @@ public class ServiceConstants { public static final String PATH="execution"; public static final String EXECUTION_ID_PARAMETER="executionId"; + + + public static final String COLLECTOR_ID_PARAMETER="collector"; + public static final String CATALOGUE_ID_PARAMETER="collector"; } public static interface Capabilities{ diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CatalogueControllersManagerImpl.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CatalogueControllersManagerImpl.java index 5d54bf8..0a5ac03 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CatalogueControllersManagerImpl.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CatalogueControllersManagerImpl.java @@ -23,7 +23,7 @@ public class CatalogueControllersManagerImpl implements CatalogueControllersMana private ServiceLoader cataloguePluginsLoader = null; - private ConcurrentHashMap availablePlugins=null; + private ConcurrentHashMap availablePlugins=new ConcurrentHashMap(); public CatalogueControllersManagerImpl() { diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CollectorsManagerImpl.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CollectorsManagerImpl.java index debdbdf..bbd2381 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CollectorsManagerImpl.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CollectorsManagerImpl.java @@ -26,7 +26,7 @@ public class CollectorsManagerImpl implements CollectorsManager { private ServiceLoader collectorPluginsLoader = null; - private ConcurrentHashMap availablePlugins=null; + private ConcurrentHashMap availablePlugins=new ConcurrentHashMap<>(); public CollectorsManagerImpl() { diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/FeederEngineImpl.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/FeederEngineImpl.java index 2bc546c..de19dab 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/FeederEngineImpl.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/FeederEngineImpl.java @@ -1,6 +1,7 @@ package org.gcube.data.publishing.gCatFeeder.service.engine.impl; import java.util.Collection; +import java.util.Set; import javax.inject.Inject; @@ -24,7 +25,7 @@ public class FeederEngineImpl implements FeederEngine { @Inject private ExecutionManager executions; @Inject - private CollectorsManager crawlers; + private CollectorsManager collectors; @Inject private CatalogueControllersManager catalogues; @Inject @@ -54,8 +55,24 @@ public class FeederEngineImpl implements FeederEngine { private void verifyRequest(ExecutionRequest request) throws InternalError,CollectorNotFound,DescriptorNotFound{ - // for each requested source check if available - // for each requested target check if available + + Set availableControllers=catalogues.getAvailableControllers(); + if(request.getToInvokeControllers().size()==1&&request.getToInvokeControllers().contains("ALL")) { + request.setToInvokeControllers(availableControllers); + } + for(String requestedCatalogue:request.getToInvokeControllers()) + if(!availableControllers.contains(requestedCatalogue)) + throw new DescriptorNotFound("Requested catalogue controller "+requestedCatalogue+" not found."); + + + Set availableCollectors=collectors.getAvailableCollectors(); + if(request.getToInvokeCollectors().size()==1&&request.getToInvokeCollectors().contains("ALL")) { + request.setToInvokeCollectors(availableControllers); + } + + for(String requestedCollector:request.getToInvokeCollectors()) + if(!availableCollectors.contains(requestedCollector)) + throw new DescriptorNotFound("Requested collector "+requestedCollector+" not found."); } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/PersistenceManagerImpl.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/PersistenceManagerImpl.java new file mode 100644 index 0000000..0a5d7bb --- /dev/null +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/PersistenceManagerImpl.java @@ -0,0 +1,46 @@ +package org.gcube.data.publishing.gCatFeeder.service.engine.impl; + +import java.util.Collection; + +import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager; +import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor; +import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter; +import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.ElementNotFound; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError; + +public class PersistenceManagerImpl implements PersistenceManager { + + @Override + public ExecutionDescriptor create(ExecutionRequest request) throws PersistenceError, InvalidRequest { + // TODO Auto-generated method stub + return null; + } + + @Override + public ExecutionDescriptor getById(String id) throws PersistenceError, ElementNotFound, InvalidRequest { + // TODO Auto-generated method stub + return null; + } + + @Override + public Collection get(ExecutionDescriptorFilter filter) + throws PersistenceError, InvalidRequest { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean update(ExecutionDescriptor toUpdate) throws PersistenceError, ElementNotFound { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean acquire(String id) throws PersistenceError, ElementNotFound { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/model/ExecutionRequest.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/model/ExecutionRequest.java index 62f5c79..b0697e9 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/model/ExecutionRequest.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/model/ExecutionRequest.java @@ -1,5 +1,39 @@ package org.gcube.data.publishing.gCatFeeder.service.model; +import java.util.HashSet; +import java.util.Set; + public class ExecutionRequest { + private Set toInvokeCollectors=new HashSet<>(); + private Set toInvokeControllers=new HashSet<>(); + + + public ExecutionRequest addCollectorId(String id) { + this.toInvokeCollectors.add(id); + return this; + } + + + public ExecutionRequest addControllerId(String id) { + this.toInvokeControllers.add(id); + return this; + } + + public Set getToInvokeCollectors() { + return toInvokeCollectors; + } + + public Set getToInvokeControllers() { + return toInvokeControllers; + } + + + public void setToInvokeCollectors(Set toInvokeCollectors) { + this.toInvokeCollectors = toInvokeCollectors; + } + + public void setToInvokeControllers(Set toInvokeControllers) { + this.toInvokeControllers = toInvokeControllers; + } } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Capabilities.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Capabilities.java index 8f92931..61bfeb1 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Capabilities.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Capabilities.java @@ -23,7 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @ManagedBy(GCatFeederManager.class) -@Path(ServiceConstants.Executions.PATH) +@Path(ServiceConstants.Capabilities.PATH) public class Capabilities { private static final Logger log= LoggerFactory.getLogger(Capabilities.class); diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java index 691f207..6224190 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java @@ -9,9 +9,11 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import org.gcube.data.publishing.gCatFeeder.service.GCatFeederManager; import org.gcube.data.publishing.gCatFeeder.service.ServiceConstants; @@ -39,11 +41,19 @@ public class Executions { @POST @Produces(MediaType.APPLICATION_JSON) - public ExecutionDescriptor submit() { - + public ExecutionDescriptor submit(@Context UriInfo info) { + try { ExecutionRequest request=new ExecutionRequest(); - return engine.submit(request); + for(String collector:info.getQueryParameters().get(ServiceConstants.Executions.COLLECTOR_ID_PARAMETER)) + request.addCollectorId(collector); + + for(String catalogue:info.getQueryParameters().get(ServiceConstants.Executions.CATALOGUE_ID_PARAMETER)) + request.addCollectorId(catalogue); + + log.trace("Submitting request {} ",request); + + return engine.submit(request); } catch (PersistenceError e) { log.warn("Unexpected Exception while talking to persistnce",e); throw new WebApplicationException("Invalid Request.", e,Response.Status.INTERNAL_SERVER_ERROR); @@ -53,8 +63,7 @@ public class Executions { }catch(Throwable t) { log.warn("Unexpected Exception ",t); throw new WebApplicationException("Unexpected Exception.", t,Response.Status.INTERNAL_SERVER_ERROR); - } - + } } diff --git a/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/BaseTest.java b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/BaseTest.java new file mode 100644 index 0000000..9791bf6 --- /dev/null +++ b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/BaseTest.java @@ -0,0 +1,26 @@ +package org.gcube.data.publishing.gCatFeeder.service; + +import java.io.IOException; +import java.sql.SQLException; + +import javax.ws.rs.core.Application; + +import org.glassfish.jersey.test.JerseyTest; +import org.junit.BeforeClass; + +public class BaseTest extends JerseyTest{ + + + @BeforeClass + public static void init() throws IOException, SQLException{ + + } + + + @Override + protected Application configure() { + + return new GCatFeeder(); + } + +} diff --git a/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/CapabilitiesTest.java b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/CapabilitiesTest.java new file mode 100644 index 0000000..60b53da --- /dev/null +++ b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/CapabilitiesTest.java @@ -0,0 +1,33 @@ +package org.gcube.data.publishing.gCatFeeder.service; + +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import org.junit.Test; + +public class CapabilitiesTest extends BaseTest { + + + @Test + public void getCollectors() { + WebTarget target= + target(ServiceConstants.Capabilities.PATH).path(ServiceConstants.Capabilities.COLLECTORS_PATH); + + System.out.println(target.getUri()); + Response resp=target.request().get(); + System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class)); + if(resp.getStatus()!=200) throw new RuntimeException("Capabilities interface error should never happen"); + } + + @Test + public void getControllers() { + WebTarget target= + target(ServiceConstants.Capabilities.PATH).path(ServiceConstants.Capabilities.CATALOGUES_PATH); + + System.out.println(target.getUri()); + Response resp=target.request().get(); + System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class)); + if(resp.getStatus()!=200) throw new RuntimeException("Capabilities interface error should never happen"); + } + +} diff --git a/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/TestCommon.java b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/TestCommon.java new file mode 100644 index 0000000..3a90704 --- /dev/null +++ b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/TestCommon.java @@ -0,0 +1,10 @@ +package org.gcube.data.publishing.gCatFeeder.service; + +public class TestCommon { + + public static final String FAKE_CATALOGUE_ID="FAKE_CATALOGUE"; + + public static final String FAKE_COLLECTOR_NAME="FAKE_COLLECTOR"; + + public static final String UNAVAILABLE_CATALOGUE="UNAVAILABLE_CATALOGUE"; +} diff --git a/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCataloguePlugin.java b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCataloguePlugin.java new file mode 100644 index 0000000..ec4b24a --- /dev/null +++ b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCataloguePlugin.java @@ -0,0 +1,71 @@ +package org.gcube.data.publishing.gCatFeeder.service.mockups; + +import org.gcube.data.publishing.gCatFeeder.catalogues.CatalogueController; +import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.CataloguePluginDescriptor; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.PublishReport; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.CatalogueInteractionException; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.ControllerInstantiationFault; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.PublicationException; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.WrongObjectFormatException; +import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData; +import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor; +import org.gcube.data.publishing.gCatFeeder.model.ControllerConfiguration; +import org.gcube.data.publishing.gCatFeeder.service.TestCommon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FakeCataloguePlugin implements CataloguePlugin { + + private static final Logger log= LoggerFactory.getLogger(FakeCataloguePlugin.class); + + + + private class FakeController implements CatalogueController{ + @Override + public PublishReport publishItem(CatalogueFormatData toPublish) + throws WrongObjectFormatException, CatalogueInteractionException, PublicationException { + try { + log.debug("Simulating publish wait.."); + Thread.sleep(400); + } catch (InterruptedException e) { + } + return new PublishReport(true, "FAKE CONTROLLER DOES NOT PUBLISH DATA"); + } + + @Override + public void configure(ControllerConfiguration config) { + + } + } + + + + @Override + public CataloguePluginDescriptor getDescriptor() { + return new CataloguePluginDescriptor(TestCommon.FAKE_CATALOGUE_ID); + } + + @Override + public CatalogueController instantiateController(CatalogueInstanceDescriptor desc) + throws ControllerInstantiationFault { + return new FakeController(); + } + + @Override + public void init() throws Exception { + log.debug("Simulating init..."); + try{ + Thread.sleep(400); + }catch(InterruptedException e) {} + } + + @Override + public void initInScope() throws Exception { + log.debug("Simulating init in scope..."); + try{ + Thread.sleep(400); + }catch(InterruptedException e) {} + } + +} diff --git a/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCollectorPlugin.java b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCollectorPlugin.java new file mode 100644 index 0000000..2ba0292 --- /dev/null +++ b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCollectorPlugin.java @@ -0,0 +1,112 @@ +package org.gcube.data.publishing.gCatFeeder.service.mockups; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData; +import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor; +import org.gcube.data.publishing.gCatFeeder.model.ControllerConfiguration; +import org.gcube.data.publishing.gCatFeeder.service.TestCommon; +import org.gcube.data.publishing.gCatfeeder.collectors.CatalogueRetriever; +import org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin; +import org.gcube.data.publishing.gCatfeeder.collectors.DataCollector; +import org.gcube.data.publishing.gCatfeeder.collectors.DataTransformer; +import org.gcube.data.publishing.gCatfeeder.collectors.model.PluginDescriptor; +import org.gcube.data.publishing.gCatfeeder.collectors.model.faults.CatalogueInstanceNotFound; +import org.gcube.data.publishing.gCatfeeder.collectors.model.faults.CatalogueNotSupportedException; +import org.gcube.data.publishing.gCatfeeder.collectors.model.faults.CollectorFault; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FakeCollectorPlugin implements CollectorPlugin { + private static final Logger log= LoggerFactory.getLogger(FakeCollectorPlugin.class); + + + + @Override + public PluginDescriptor getDescriptor() { + return new PluginDescriptor(TestCommon.FAKE_COLLECTOR_NAME); + } + + @Override + public CatalogueRetriever getRetrieverByCatalogueType(String catalogueType) throws CatalogueNotSupportedException { + switch(catalogueType) { + case TestCommon.UNAVAILABLE_CATALOGUE : + case TestCommon.FAKE_CATALOGUE_ID : return new CatalogueRetriever() { + @Override + public CatalogueInstanceDescriptor getInstance() throws CatalogueInstanceNotFound { + // TODO Auto-generated method stub + return null; + } + }; + default : throw new CatalogueNotSupportedException(catalogueType+" not supported by "+TestCommon.FAKE_COLLECTOR_NAME); + } + } + + @Override + public Set getSupportedCatalogueTypes() { + return new HashSet (Arrays.asList(new String[] { + TestCommon.FAKE_CATALOGUE_ID,TestCommon.UNAVAILABLE_CATALOGUE})); + } + + @Override + public DataTransformer getTransformerByCatalogueType( + String catalogueType) throws CatalogueNotSupportedException { + switch(catalogueType) { + case TestCommon.UNAVAILABLE_CATALOGUE : + case TestCommon.FAKE_CATALOGUE_ID : return new DataTransformer() { + + @Override + public Set transform(Collection collectedData) { + return new HashSet<>(collectedData); + } + + + }; + default : throw new CatalogueNotSupportedException(catalogueType+" not supported by "+TestCommon.FAKE_COLLECTOR_NAME); + } + } + + @Override + public DataCollector getCollector() { + return new DataCollector() { + @Override + public Set collect() throws CollectorFault { + HashSet toReturn=new HashSet<>(); + for(int i=0;i<1000;i++) + toReturn.add(new FakeCustomData()); + return toReturn; + } + }; + } + + @Override + public ControllerConfiguration getPublisherControllerConfiguration(String catalogueType) + throws CatalogueNotSupportedException { + switch(catalogueType) { + case TestCommon.UNAVAILABLE_CATALOGUE : + case TestCommon.FAKE_CATALOGUE_ID : return new ControllerConfiguration(); + default : throw new CatalogueNotSupportedException(catalogueType+" not supported by "+TestCommon.FAKE_COLLECTOR_NAME); + } + + } + + @Override + public void init() throws Exception { + log.debug("Simulating init..."); + try{ + Thread.sleep(400); + }catch(InterruptedException e) {} + } + + @Override + public void initInScope() throws Exception { + log.debug("Simulating init in scope..."); + try{ + Thread.sleep(400); + }catch(InterruptedException e) {} + } + +} diff --git a/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCustomData.java b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCustomData.java new file mode 100644 index 0000000..625ddec --- /dev/null +++ b/gCat-Feeder/src/test/java/org/gcube/data/publishing/gCatFeeder/service/mockups/FakeCustomData.java @@ -0,0 +1,22 @@ +package org.gcube.data.publishing.gCatFeeder.service.mockups; + +import java.util.concurrent.atomic.AtomicLong; + +import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData; +import org.gcube.data.publishing.gCatfeeder.collectors.model.CustomData; + +public class FakeCustomData implements CustomData, CatalogueFormatData{ + + private static final AtomicLong counter=new AtomicLong(0); + + + private long number=counter.incrementAndGet(); + + + + @Override + public String toCatalogueFormat() { + return "DATA "+number; + } + +} \ No newline at end of file diff --git a/gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin b/gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin new file mode 100644 index 0000000..7a3647f --- /dev/null +++ b/gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin @@ -0,0 +1 @@ +org.gcube.data.publishing.gCatFeeder.service.mockups.FakeCataloguePlugin \ No newline at end of file diff --git a/gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin b/gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin new file mode 100644 index 0000000..3a0454f --- /dev/null +++ b/gCat-Feeder/src/test/resources/META-INF/services/org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin @@ -0,0 +1 @@ +org.gcube.data.publishing.gCatFeeder.service.mockups.FakeCollectorPlugin \ No newline at end of file diff --git a/gCat-Feeder/src/test/resources/logback.xml b/gCat-Feeder/src/test/resources/logback.xml new file mode 100644 index 0000000..6ea2f23 --- /dev/null +++ b/gCat-Feeder/src/test/resources/logback.xml @@ -0,0 +1,16 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + \ No newline at end of file