git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-publishing/gCat-Feeder-Suite@178684 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f0f21c51cc
commit
711b099a2f
|
@ -1,5 +1,5 @@
|
|||
#Generated by Maven Integration for Eclipse
|
||||
#Tue Mar 19 16:04:16 CET 2019
|
||||
#Mon Mar 25 12:23:14 CET 2019
|
||||
version=1.0.0-SNAPSHOT
|
||||
groupId=org.gcube.data-publishing.gCat-Feeder
|
||||
m2e.projectName=ckan-controller-plugin
|
||||
|
|
|
@ -19,4 +19,16 @@ public class GCatPlugin implements CataloguePlugin {
|
|||
return new GCatController(desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initInScope() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#Generated by Maven Integration for Eclipse
|
||||
#Tue Mar 19 16:05:42 CET 2019
|
||||
#Mon Mar 25 12:23:24 CET 2019
|
||||
version=1.0.0-SNAPSHOT
|
||||
groupId=org.gcube.data-publishing.gCat-Feeder
|
||||
m2e.projectName=gCat-Controller
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -7,10 +7,14 @@ import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersM
|
|||
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.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Storage;
|
||||
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.engine.impl.InfrastructureUtilsImpl;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.StorageImpl;
|
||||
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;
|
||||
|
@ -29,6 +33,8 @@ public class GCatFeeder extends ResourceConfig{
|
|||
bind(CatalogueControllersManagerImpl.class).to(CatalogueControllersManager.class).in(Singleton.class);
|
||||
bind(CollectorsManagerImpl.class).to(CollectorsManager.class).in(Singleton.class);
|
||||
bind(ExecutionManagerImpl.class).to(ExecutionManager.class).in(Singleton.class);
|
||||
bind(InfrastructureUtilsImpl.class).to(Infrastructure.class);
|
||||
bind(StorageImpl.class).to(Storage.class);
|
||||
}
|
||||
};
|
||||
register(binder);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine;
|
||||
|
||||
public interface Infrastructure {
|
||||
|
||||
public String getCurrentToken();
|
||||
public String getCurrentContext();
|
||||
public String getCurrentContextName();
|
||||
public String getClientID(String token);
|
||||
public void setToken(String token);
|
||||
|
||||
//
|
||||
|
||||
public String encrypt(String toEncrypt);
|
||||
public String decrypt(String toDecrypt);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.reports.ExecutionReport;
|
||||
|
||||
public interface Storage {
|
||||
|
||||
|
||||
public String storeReport(ExecutionReport report) throws InternalError;
|
||||
}
|
|
@ -6,12 +6,13 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.CataloguePluginNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.ContextUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -24,6 +25,10 @@ public class CatalogueControllersManagerImpl implements CatalogueControllersMana
|
|||
|
||||
private ConcurrentHashMap<String,CataloguePlugin> availablePlugins=new ConcurrentHashMap<String, CataloguePlugin>();
|
||||
|
||||
@Inject
|
||||
private Infrastructure infrastructure;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void post() {
|
||||
//load plugins
|
||||
|
@ -66,7 +71,7 @@ public class CatalogueControllersManagerImpl implements CatalogueControllersMana
|
|||
|
||||
@Override
|
||||
public void initInScope() throws InternalError {
|
||||
log.trace("Initialization under scope {} ",ContextUtils.getCurrentScope());
|
||||
log.trace("Initialization under scope {} ",infrastructure.getCurrentContext());
|
||||
for(Entry<String,CataloguePlugin> entry:availablePlugins.entrySet()) {
|
||||
log.debug("Scope initialization for : {} ",entry.getKey());
|
||||
try {
|
||||
|
|
|
@ -7,10 +7,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.CataloguePluginNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.CollectorNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError;
|
||||
|
@ -29,6 +31,10 @@ public class CollectorsManagerImpl implements CollectorsManager {
|
|||
|
||||
private ConcurrentHashMap<String,CollectorPlugin> availablePlugins=new ConcurrentHashMap<>();
|
||||
|
||||
@Inject
|
||||
private Infrastructure infrastructure;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void post() {
|
||||
//load plugins
|
||||
|
@ -68,7 +74,7 @@ public class CollectorsManagerImpl implements CollectorsManager {
|
|||
|
||||
@Override
|
||||
public void initInScope() throws InternalError {
|
||||
log.trace("Initialization under scope {} ",ContextUtils.getCurrentScope());
|
||||
log.trace("Initialization under scope {} ",infrastructure.getCurrentContext());
|
||||
for(Entry<String,CollectorPlugin> entry:availablePlugins.entrySet()) {
|
||||
log.debug("Scope initialization for : {} ",entry.getKey());
|
||||
try {
|
||||
|
|
|
@ -5,8 +5,14 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
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.engine.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Storage;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -19,18 +25,55 @@ public class ExecutionManagerImpl implements ExecutionManager {
|
|||
|
||||
private boolean defaultConfiguration=true;
|
||||
|
||||
private PersistenceManager persistence;
|
||||
private CollectorsManager collectors;
|
||||
private CatalogueControllersManager catalogues;
|
||||
|
||||
private Infrastructure infrastructure;
|
||||
private Storage storage;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void post() {
|
||||
executor=new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<Runnable>());
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setPersistence(PersistenceManager p) {
|
||||
this.persistence=p;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setCollectorPluginManager(CollectorsManager c) {
|
||||
this.collectors=c;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setCataloguesPluginManager(CatalogueControllersManager c) {
|
||||
this.catalogues=c;
|
||||
}
|
||||
|
||||
|
||||
@Inject
|
||||
public void setInfastructureInterface(Infrastructure infra) {
|
||||
this.infrastructure=infra;
|
||||
}
|
||||
@Inject
|
||||
public void setStorage(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void submit(ExecutionDescriptor desc) {
|
||||
log.debug("Checking if {} is already in queue");
|
||||
ExecutionTask toSubmit=new ExecutionTask(desc);
|
||||
toSubmit.setCataloguesPluginManager(catalogues);
|
||||
toSubmit.setCollectorPluginManager(collectors);
|
||||
toSubmit.setInfastructureInterface(infrastructure);
|
||||
toSubmit.setPersistence(persistence);
|
||||
toSubmit.setStorage(storage);
|
||||
|
||||
if(!executor.getQueue().contains(toSubmit)) {
|
||||
log.trace("Inserting execution in queue {} ");
|
||||
executor.execute(toSubmit);
|
||||
|
|
|
@ -4,9 +4,6 @@ import java.io.Serializable;
|
|||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.data.publishing.gCatFeeder.catalogues.CatalogueController;
|
||||
import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin;
|
||||
import org.gcube.data.publishing.gCatFeeder.catalogues.model.PublishReport;
|
||||
|
@ -18,7 +15,9 @@ import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
|
|||
import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor;
|
||||
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.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Storage;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionStatus;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.CataloguePluginNotFound;
|
||||
|
@ -28,8 +27,6 @@ import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError
|
|||
import org.gcube.data.publishing.gCatFeeder.service.model.reports.CatalogueReport;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.reports.CollectorReport;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.reports.ExecutionReport;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.CommonUtils;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.ContextUtils;
|
||||
import org.gcube.data.publishing.gCatfeeder.collectors.CatalogueRetriever;
|
||||
import org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin;
|
||||
import org.gcube.data.publishing.gCatfeeder.collectors.DataCollector;
|
||||
|
@ -49,6 +46,10 @@ public class ExecutionTask implements Runnable {
|
|||
private CollectorsManager collectors;
|
||||
private CatalogueControllersManager catalogues;
|
||||
|
||||
private Infrastructure infrastructure;
|
||||
|
||||
private Storage storage;
|
||||
|
||||
public ExecutionTask(ExecutionDescriptor desc) {
|
||||
super();
|
||||
this.request=desc;
|
||||
|
@ -86,80 +87,93 @@ public class ExecutionTask implements Runnable {
|
|||
}
|
||||
|
||||
|
||||
@Inject
|
||||
public void setPersistence(PersistenceManager p) {
|
||||
this.persistence=p;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setCollectorPluginManager(CollectorsManager c) {
|
||||
this.collectors=c;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setCataloguesPluginManager(CatalogueControllersManager c) {
|
||||
this.catalogues=c;
|
||||
}
|
||||
|
||||
|
||||
public void setInfastructureInterface(Infrastructure infra) {
|
||||
this.infrastructure=infra;
|
||||
}
|
||||
|
||||
public void setStorage(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// try {
|
||||
// log.debug("Starting to handle {} ",request);
|
||||
//
|
||||
// log.debug("Setting caller token..");
|
||||
// String actualToken=CommonUtils.decryptString(request.getCallerEncryptedToken());
|
||||
// SecurityTokenProvider.instance.set(actualToken);
|
||||
//
|
||||
// // try to lock request (FINISH ON FAIL)
|
||||
// if(persistence.acquire(request.getId())) {
|
||||
// try {
|
||||
//
|
||||
//
|
||||
// log.info("Acquired : {} ",request);
|
||||
//
|
||||
// ExecutionReport report=new ExecutionReport();
|
||||
// report.getGenericInformations().setStartTime(Instant.now());
|
||||
// report.setStartingScope(ContextUtils.getCurrentScopeName());
|
||||
//
|
||||
// // -- ON SUCCESS reload request
|
||||
// request =persistence.getById(request.getId());
|
||||
//
|
||||
// // For ALL COLLECTORS IN REQUEST
|
||||
// for(String collectorId : request.getCollectors()) {
|
||||
// CollectorReport collectorReport=handleCollector(collectorId);
|
||||
// report.getCollectorReports().add(collectorReport);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // FINALIZE
|
||||
//
|
||||
// report.getGenericInformations().setEndTime(Instant.now());
|
||||
//
|
||||
// String reportUrl=storeReport(report);
|
||||
// log.info("Stored report at {} ",reportUrl);
|
||||
// request.setReportUrl(reportUrl);
|
||||
// request.setStatus(ExecutionStatus.SUCCESS);
|
||||
// persistence.update(request);
|
||||
// }catch(PersistenceError | InvalidRequest e) {
|
||||
// log.error("Unexpected exception while dealing with persistence ",e);
|
||||
// }catch(Throwable t) {
|
||||
// log.error("Unexpected generic exception.",t);
|
||||
// request.setStatus(ExecutionStatus.FAILED);
|
||||
// persistence.update(request);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// }else {
|
||||
// log.debug("Request [{}] is already being managed.",request);
|
||||
// }
|
||||
// }catch(Throwable t) {
|
||||
// log.error("THREAD CANNOT HANDLE REQUESTS!!!. ",t);
|
||||
// }
|
||||
try {
|
||||
log.debug("Starting to handle {} ",request);
|
||||
|
||||
log.debug("Setting caller token..");
|
||||
String actualToken=infrastructure.decrypt(request.getCallerEncryptedToken());
|
||||
infrastructure.setToken(actualToken);
|
||||
|
||||
// try to lock request (FINISH ON FAIL)
|
||||
if(persistence.acquire(request.getId())) {
|
||||
try {
|
||||
|
||||
|
||||
log.info("Acquired : {} ",request);
|
||||
|
||||
ExecutionReport report=new ExecutionReport();
|
||||
report.getGenericInformations().setStartTime(Instant.now());
|
||||
report.setStartingScope(infrastructure.getCurrentContextName());
|
||||
|
||||
// -- ON SUCCESS reload request
|
||||
request =persistence.getById(request.getId());
|
||||
|
||||
// For ALL COLLECTORS IN REQUEST
|
||||
for(String collectorId : request.getCollectors()) {
|
||||
CollectorReport collectorReport=handleCollector(collectorId);
|
||||
report.getCollectorReports().add(collectorReport);
|
||||
|
||||
}
|
||||
|
||||
// FINALIZE
|
||||
|
||||
report.getGenericInformations().setEndTime(Instant.now());
|
||||
|
||||
String reportUrl=storage.storeReport(report);
|
||||
log.info("Stored report at {} ",reportUrl);
|
||||
request.setReportUrl(reportUrl);
|
||||
request.setStatus(ExecutionStatus.SUCCESS);
|
||||
persistence.update(request);
|
||||
}catch(PersistenceError | InvalidRequest e) {
|
||||
log.error("Unexpected exception while dealing with persistence ",e);
|
||||
}catch(Throwable t) {
|
||||
log.error("Unexpected generic exception.",t);
|
||||
request.setStatus(ExecutionStatus.FAILED);
|
||||
persistence.update(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else {
|
||||
log.debug("Request [{}] is already being managed.",request);
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
log.error("THREAD CANNOT HANDLE REQUESTS!!!. ",t);
|
||||
request.setStatus(ExecutionStatus.FAILED);
|
||||
try {
|
||||
persistence.update(request);
|
||||
} catch (Throwable e) {
|
||||
log.error("Unable to update execution Descriptor {} ",request,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private CatalogueReport handleCatalogueController(String cataloguePluginId,CollectorPlugin collectorPlugin,Set<Serializable> collectedData) {
|
||||
CatalogueReport catalogueReport=new CatalogueReport();
|
||||
catalogueReport.getGenericInformations().setStartTime(Instant.now());
|
||||
|
@ -177,12 +191,12 @@ public class ExecutionTask implements Runnable {
|
|||
log.debug("Transforming Collected Data");
|
||||
DataTransformer transformer=collectorPlugin.getTransformerByCatalogueType(cataloguePluginId);
|
||||
Set<CatalogueFormatData> transformed=transformer.transform(collectedData);
|
||||
log.trace("Going to publish {} items to {} ",transformed.size(),instanceDescriptor.getUrl());
|
||||
log.trace("Going to publish {} items to {} ",transformed.size(),instanceDescriptor);
|
||||
|
||||
// ** PUBLISH VIA CONTROLLER
|
||||
for(CatalogueFormatData item : transformed) {
|
||||
try {
|
||||
PublishReport itemReport=controller.publishItem(item);
|
||||
catalogueReport.getPublishedRecords().add(controller.publishItem(item));
|
||||
}catch(WrongObjectFormatException e) {
|
||||
catalogueReport.getPublishedRecords().add(new PublishReport(false,"Wrong format : "+e.getMessage()));
|
||||
} catch (CatalogueInteractionException e) {
|
||||
|
@ -223,8 +237,8 @@ public class ExecutionTask implements Runnable {
|
|||
catalogueReport.getGenericInformations().setEndTime(Instant.now());
|
||||
return catalogueReport;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private CollectorReport handleCollector(String collectorId) {
|
||||
CollectorReport collectorReport=new CollectorReport();
|
||||
collectorReport.getGenericInformations().setStartTime(Instant.now());
|
||||
|
@ -243,7 +257,7 @@ public class ExecutionTask implements Runnable {
|
|||
// * FOR ALL CATALOGUES IN REQUEST
|
||||
for(String cataloguePluginId:request.getCatalogues()) {
|
||||
CatalogueReport catalogueReport=handleCatalogueController(cataloguePluginId,collectorPlugin,collectedData);
|
||||
|
||||
|
||||
collectorReport.getPublisherReports().add(catalogueReport);
|
||||
}
|
||||
|
||||
|
@ -258,14 +272,12 @@ public class ExecutionTask implements Runnable {
|
|||
collectorReport.getGenericInformations().setSuccess(false);
|
||||
collectorReport.getGenericInformations().setGenericMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
collectorReport.getGenericInformations().setEndTime(Instant.now());
|
||||
return collectorReport;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static final String storeReport(ExecutionReport report) {
|
||||
throw new RuntimeException("Implement me");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine.impl;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.CommonUtils;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.ContextUtils;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.TokenUtils;
|
||||
|
||||
public class InfrastructureUtilsImpl implements Infrastructure {
|
||||
|
||||
@Override
|
||||
public String getCurrentToken() {
|
||||
return TokenUtils.getCurrentToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentContext() {
|
||||
return ContextUtils.getCurrentScope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientID(String token){
|
||||
try{
|
||||
return TokenUtils.getClientId(token);
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException("Unable to get client id from "+token);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToken(String token) {
|
||||
TokenUtils.setToken(token);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCurrentContextName() {
|
||||
return ContextUtils.getCurrentScopeName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String decrypt(String toDecrypt) {
|
||||
return CommonUtils.decryptString(toDecrypt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String toEncrypt) {
|
||||
return CommonUtils.encryptString(toEncrypt);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine.impl;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Storage;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.reports.ExecutionReport;
|
||||
|
||||
public class StorageImpl implements Storage{
|
||||
|
||||
@Override
|
||||
public String storeReport(ExecutionReport report) throws InternalError {
|
||||
throw new RuntimeException("Implment THIS");
|
||||
}
|
||||
|
||||
}
|
|
@ -89,6 +89,12 @@ public class ExecutionDescriptor {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExecutionDescriptor [id=" + id + ", collectors=" + collectors + ", catalogues=" + catalogues
|
||||
+ ", callerEncryptedToken=" + callerEncryptedToken + ", callerIdentity=" + callerIdentity
|
||||
+ ", callerContext=" + callerContext + ", status=" + status + ", reportUrl=" + reportUrl + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,13 +11,16 @@ import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersM
|
|||
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.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Storage;
|
||||
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.model.fault.InternalError;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.mockups.InfrastructureMockup;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.mockups.PersistenceManagerMock;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.mockups.StorageMockup;
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.Before;
|
||||
|
@ -73,6 +76,8 @@ public class BaseTest extends JerseyTest{
|
|||
bind(CollectorsManagerImpl.class).to(CollectorsManager.class).in(Singleton.class);
|
||||
bind(ExecutionManagerImpl.class).to(ExecutionManager.class).in(Singleton.class);
|
||||
bind(PersistenceManagerMock.class).to(PersistenceManager.class).in(Singleton.class);
|
||||
bind(InfrastructureMockup.class).to(Infrastructure.class);
|
||||
bind(StorageMockup.class).to(Storage.class);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -47,7 +47,10 @@ public class ExecutionsTest extends BaseTest {
|
|||
switch(pollResult.getStatus()) {
|
||||
case FAILED:
|
||||
case STOPPED : throw new RuntimeException("Unexpected execution status "+pollResult.getStatus());
|
||||
case SUCCESS : end=true; break;
|
||||
case SUCCESS : {
|
||||
System.out.println(pollResult);
|
||||
end=true; break;
|
||||
}
|
||||
default : try {
|
||||
Thread.sleep(400);} catch (InterruptedException e) {}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
|
|||
public class FakeCollectorPlugin implements CollectorPlugin<FakeCustomData> {
|
||||
private static final Logger log= LoggerFactory.getLogger(FakeCollectorPlugin.class);
|
||||
|
||||
|
||||
private static final int NUM_ITEMS=10;
|
||||
|
||||
@Override
|
||||
public PluginDescriptor getDescriptor() {
|
||||
|
@ -75,7 +75,7 @@ public class FakeCollectorPlugin implements CollectorPlugin<FakeCustomData> {
|
|||
@Override
|
||||
public Set<FakeCustomData> collect() throws CollectorFault {
|
||||
HashSet<FakeCustomData> toReturn=new HashSet<>();
|
||||
for(int i=0;i<1000;i++)
|
||||
for(int i=0;i<NUM_ITEMS;i++)
|
||||
toReturn.add(new FakeCustomData());
|
||||
return toReturn;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.mockups;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Infrastructure;
|
||||
|
||||
public class InfrastructureMockup implements Infrastructure {
|
||||
|
||||
@Override
|
||||
public String getCurrentToken() {
|
||||
return "FAKE_TOKEN";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentContext() {
|
||||
return "FAKE_CONTEXT";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentContextName() {
|
||||
return "FAKE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientID(String token){
|
||||
return "FAKE_ID";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToken(String token) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String decrypt(String toDecrypt) {
|
||||
return toDecrypt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String toEncrypt) {
|
||||
return toEncrypt;
|
||||
}
|
||||
}
|
|
@ -5,9 +5,9 @@ import java.util.Collections;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.enterprise.inject.Default;
|
||||
import javax.inject.Singleton;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Infrastructure;
|
||||
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;
|
||||
|
@ -20,6 +20,10 @@ import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError
|
|||
|
||||
public class PersistenceManagerMock implements PersistenceManager {
|
||||
|
||||
@Inject
|
||||
private Infrastructure infrastructure;
|
||||
|
||||
|
||||
@Override
|
||||
public ExecutionDescriptor create(ExecutionRequest request) throws PersistenceError, InvalidRequest {
|
||||
return getEquivalent(request);
|
||||
|
@ -61,9 +65,9 @@ public class PersistenceManagerMock implements PersistenceManager {
|
|||
|
||||
private ExecutionDescriptor getEquivalent(ExecutionRequest req) {
|
||||
ExecutionDescriptor toReturn=new ExecutionDescriptor();
|
||||
toReturn.setCallerContext("TEST");
|
||||
toReturn.setCallerIdentity("TESTER");
|
||||
toReturn.setCallerEncryptedToken("TEST");
|
||||
toReturn.setCallerContext(infrastructure.getCurrentContextName());
|
||||
toReturn.setCallerIdentity(infrastructure.getClientID(infrastructure.getCurrentToken()));
|
||||
toReturn.setCallerEncryptedToken(infrastructure.encrypt("TEST"));
|
||||
|
||||
toReturn.setCatalogues(req.getToInvokeControllers());
|
||||
toReturn.setCollectors(req.getToInvokeCollectors());
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.mockups;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Storage;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.reports.ExecutionReport;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class StorageMockup implements Storage {
|
||||
|
||||
private static ObjectMapper mapper=new ObjectMapper();
|
||||
|
||||
|
||||
@Override
|
||||
public String storeReport(ExecutionReport report) throws InternalError {
|
||||
try {
|
||||
File f=File.createTempFile("report", ".json");
|
||||
String serialized=mapper.writeValueAsString(report);
|
||||
|
||||
Files.write(Paths.get(f.getAbsolutePath()), serialized.getBytes());
|
||||
|
||||
return f.getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
throw new InternalError("Unable to rite report : ",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#Generated by Maven Integration for Eclipse
|
||||
#Tue Mar 19 16:04:13 CET 2019
|
||||
#Mon Mar 25 12:23:24 CET 2019
|
||||
version=1.0.0-SNAPSHOT
|
||||
groupId=org.gcube.data-publishing.gCat-Feeder
|
||||
m2e.projectName=test-commons
|
||||
|
|
Loading…
Reference in New Issue