From 29e1949301852bd622b41a430302de565f19aca9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 18 Jun 2020 15:48:47 +0200 Subject: [PATCH] merged (again) with #18967 --- CHANGELOG.md | 7 + pom.xml | 8 +- .../LoadingGNPublicLayerIDsInstanceCache.java | 2 +- ...LoadingGeoExplorerApplicationURLCache.java | 2 +- .../LoadingGeonetworkInstanceCache.java | 2 +- .../LoadingGisViewerApplicationURLCache.java | 2 +- .../caches/LoadingMapOfDetachedVRE.java | 208 ++++++++++++++++++ .../caches/LoadingMapOfScopeCache.java | 11 +- .../init/UriResolverSmartGearManagerInit.java | 33 ++- .../resolver/services/CatalogueResolver.java | 60 ++++- src/test/java/CatalogueNameExtractor.java | 1 - src/test/java/CatalogueResolverTest.java | 35 ++- src/test/java/DetachedVREsTest.java | 46 ++++ .../GetAllInfrastructureScopesFromIS.java | 28 +-- src/test/java/GisResolverTest.java | 1 - 15 files changed, 403 insertions(+), 43 deletions(-) create mode 100644 src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java create mode 100644 src/test/java/DetachedVREsTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6464bcb..f238888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2-4-0] [r4-24-0]- 2020-06-18 + +**New Features** + +[#18967] Extend the URIResolver behaviour to deal with Catalogue items belonging to Dismissed VREs + + ## [v2-3-2] [r4-23-0]- 2020-05-18 [#19288] Release the URI-Resolver to integrate the patched Uri-Resolver-Manager diff --git a/pom.xml b/pom.xml index fea6c8a..cb7c240 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.3.2 + 2.4.0-SNAPSHOT war The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications. @@ -85,6 +85,12 @@ [0.0.1,1.0.0-SNAPSHOT) + + org.gcube.infrastructure.detachedres + detachedres-library + [1.0.0,2.0.0-SNAPSHOT) + + org.gcube.common diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGNPublicLayerIDsInstanceCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGNPublicLayerIDsInstanceCache.java index d2e0e75..79a811a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGNPublicLayerIDsInstanceCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGNPublicLayerIDsInstanceCache.java @@ -53,7 +53,7 @@ public class LoadingGNPublicLayerIDsInstanceCache { RemovalListener> removalListener = new RemovalListener>() { public void onRemoval(RemovalNotification> removal) { - logger.info("cache expired"); + logger.debug("cache expired"); } }; diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java index 764945e..3fff14a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java @@ -46,7 +46,7 @@ public class LoadingGeoExplorerApplicationURLCache { RemovalListener removalListener = new RemovalListener() { public void onRemoval(RemovalNotification removal) { - logger.info("cache expired"); + logger.debug("cache expired"); } }; diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java index 01d0d57..d13449d 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java @@ -48,7 +48,7 @@ public class LoadingGeonetworkInstanceCache { RemovalListener removalListener = new RemovalListener() { public void onRemoval(RemovalNotification removal) { - logger.info("cache expired"); + logger.debug("cache expired"); } }; diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java index 7aa15b9..6e5b134 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java @@ -46,7 +46,7 @@ public class LoadingGisViewerApplicationURLCache { RemovalListener removalListener = new RemovalListener() { public void onRemoval(RemovalNotification removal) { - logger.info("cache expired"); + logger.debug("cache expired"); } }; diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java new file mode 100644 index 0000000..5c1a1e3 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java @@ -0,0 +1,208 @@ +/** + * + */ +package org.gcube.datatransfer.resolver.caches; + +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; +import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; + + +/** + * The Class LoadingMapOfDetachedVRE. + * + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) + * Jun 10, 2020 + */ +public class LoadingMapOfDetachedVRE { + + private static Logger LOG = LoggerFactory.getLogger(LoadingMapOfDetachedVRE.class); + private static LoadingCache vreNameToVRE; + + static{ + + CacheLoader loader = new CacheLoader(){ + + @Override + public VRE load(String vreName) + throws Exception { + + LOG.info("Loading the cache for VRE name: {}",vreName); + VRE theVRE = loadVREObjForVREName(vreName); + if(theVRE!=null) + LOG.info("Returning {} with scope {} for the VRE name: {}", VRE.class.getSimpleName(), theVRE.getScope(), vreName); + else { + LOG.info("No VRE obj for VRE name {}",vreName); + } + + return theVRE; + } + + }; + + RemovalListener removalListener = new RemovalListener() { + + @Override + public void onRemoval(RemovalNotification arg0) { + + LOG.debug("cache expired"); + } + }; + + vreNameToVRE = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite( + 12, TimeUnit.HOURS).removalListener(removalListener). + build(loader); + + + //Populating the cache at init stage + populateTheCache(); + LOG.info("Pre-Loaded detached VRE Name to VRE Obj cache with: "+vreNameToVRE.asMap().size()+" item/s"); + } + + + /** + * Populate the cache. + */ + private static void populateTheCache(){ + + String authorizationToken = null; + + try{ + //Populating the cache by using the detachedres-library + LOG.info("Trying to pre-populate the detached VREs cache with mapping (VRE Name, VRE Obj)"); + ScopeProvider.instance.set(UriResolverSmartGearManagerInit.getRootContextScope()); + + authorizationToken = SecurityTokenProvider.instance.get(); + + if(authorizationToken==null) { + LOG.info("No token found into {} to instance the {}, so reading it from SG configurations", + SecurityTokenProvider.class.getSimpleName(), DetachedREsClient.class.getSimpleName()); + + authorizationToken = UriResolverSmartGearManagerInit.getRootTokenFromSGConfiguration(); + if(authorizationToken!=null) + SecurityTokenProvider.instance.set(authorizationToken); + } + + DetachedREsClient detachedREsClient = new DetachedREsClient(); + DetachedREs detachedREs = detachedREsClient.getDetachedREs(); + + int totalVREDimissed = 0; + for (Gateway gateway : detachedREs.getGateways().values()) { + LOG.trace("Gateway: " + gateway.getName()); + int vreDismissedPerGatew = 0; + for (VO vo : gateway.getVos().values()) { + LOG.trace("VO: " + vo.getName()); + for (VRE vre : vo.getVres().values()) { + if(LOG.isTraceEnabled()) { + LOG.trace("VRE name: " + vre.getName() + + " scope: "+vre.getScope() + + " VRE catalogue url: " + vre.getCatalogUrl() + + " VRE catalog Portlet URL: "+vre.getCatalogPortletURL()); + } + try { + if(vre.getScope()!=null && !vre.getScope().isEmpty()) { + String vreName = vre.getScope().split("/")[3]; + vreNameToVRE.asMap().put(vreName, vre); + vreDismissedPerGatew++; + } + }catch (Exception e) { + LOG.warn("Error on parsing the scope: "+vre.getScope()+ " skipping it"); + + } + } + } + + LOG.debug("VREs dismissed loaded and cached per " + gateway.getName() + " are: "+vreDismissedPerGatew); + totalVREDimissed+=vreDismissedPerGatew; + } + + LOG.debug("Total detached VREs are: "+totalVREDimissed); + + LOG.info("Cache populated with: "); + Map mapOfVreNames = vreNameToVRE.asMap(); + for (String key : mapOfVreNames.keySet()) { + VRE theDetachedVRE = mapOfVreNames.get(key); + LOG.info("VRE name {}, VRE obj with scope {}, catalogueURL {}, cataloguePortletURL {}", + key, + theDetachedVRE.getScope(), + theDetachedVRE.getCatalogUrl(), + theDetachedVRE.getCatalogPortletURL()); + } + + }catch(Exception e){ + //SILENT + }finally{ + if(authorizationToken!=null) { + LOG.info("resetting security token provider"); + SecurityTokenProvider.instance.reset(); + } + + } + } + + + + /** + * Gets the VRE obj for input VRE name. + * + * @param vreName the vre name + * @return the vre + * @throws ExecutionException the execution exception + */ + public static VRE get(String vreName) throws ExecutionException{ + + try { + return vreNameToVRE.get(vreName); + }catch (Exception e) { + LOG.info("Error on getting VRE obj for vreName {}. Is the key {} not found in the cache?", vreName, vreName); + throw e; + } + } + + /** + * Load VRE obj for VRE name. + * + * @param vreName the vre name + * @return the vre + */ + protected static VRE loadVREObjForVREName(String vreName){ + + VRE theVRE = vreNameToVRE.getIfPresent(vreName); + + //THIS CHECK SHOULD NOT BE NEEDED + if(theVRE==null){ + populateTheCache(); + theVRE = vreNameToVRE.getIfPresent(vreName); + } + + return theVRE; + } + + + /** + * Gets the cache. + * + * @return the cache + */ + public LoadingCache getCache(){ + return vreNameToVRE; + } + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfScopeCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfScopeCache.java index 13b50c9..dde32a6 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfScopeCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfScopeCache.java @@ -54,7 +54,7 @@ public class LoadingMapOfScopeCache { @Override public void onRemoval(RemovalNotification arg0) { - logger.info("cache expired"); + logger.debug("cache expired"); //prePopulateCache(); } @@ -86,13 +86,6 @@ public class LoadingMapOfScopeCache { } logger.info("Cache populated with: "+scopeNamesToFullScopes.asMap().toString()); - //logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString()); - -// if(UriResolverSmartGearManagerInit.getRootContextScope().compareTo("/gcube")==0){ -// logger.warn("HARD-CABLING PARTHENOS_Registry scope to resolve PARTHENOS_REGISTRY Links in dev environment"); -// scopeNamesToFullScopes.asMap().put("PARTHENOS_Registry", "/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry"); -// } - }catch(Exception e){ //SILENT @@ -123,9 +116,9 @@ public class LoadingMapOfScopeCache { */ protected static ScopeBean loadFullScopeforScopeName(String scopeName){ - //THIS CHECK SHOULD BE NOT NEEDED ScopeBean fullScope = scopeNamesToFullScopes.getIfPresent(scopeName); + //THIS CHECK SHOULD NOT BE NEEDED if(fullScope==null){ populateTheCache(); fullScope = scopeNamesToFullScopes.getIfPresent(scopeName); diff --git a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java index ef36cca..3d2c751 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java +++ b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java @@ -8,6 +8,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; +import java.util.Set; import javax.servlet.ServletContext; import javax.servlet.ServletException; @@ -17,10 +18,13 @@ import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache; import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache; +import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE; import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache; import org.gcube.datatransfer.resolver.gis.property.ApplicationProfilePropertyReader; import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException; import org.gcube.smartgears.ApplicationManager; +import org.gcube.smartgears.ContextProvider; +import org.gcube.smartgears.context.application.ApplicationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,11 +93,12 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager { //JUST ONCE AND TO BE SURE WITH THE ROOT SCOPE INITIALIZED if(initRootContextPerformed && gisViewerProfile!=null && geoExplorerProfile!=null){ log.info("Pre-Loading caches... using rootContextScope: "+rootContextScope); - + //init the caches new LoadingGeonetworkInstanceCache(); new LoadingGisViewerApplicationURLCache(); new LoadingMapOfScopeCache(); + new LoadingMapOfDetachedVRE(); } } catch (Exception e) { @@ -229,4 +234,30 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager { public static void setRootContextScope(String rootContextScope) { UriResolverSmartGearManagerInit.rootContextScope = rootContextScope; } + + + /** + * Gets the root token from SG configurations. + * + * @return the root token from SG configurations + */ + public static String getRootTokenFromSGConfiguration() { + + try { + ApplicationContext ctx = ContextProvider.get(); + Set tokens = ctx.configuration().startTokens(); + for (String token : tokens) { + //I'm using the first token, + //it should be a token of root because of URI-Resolver works at root level + log.info("Token read from SG configuration is {}-MASKED-TOKEN",token.substring(0,10)); + return token; + } + log.warn("Token not found by reading the SG configurations!!! Returning null"); + return null; + } catch (Exception e) { + log.error("Error on reading the start tokens from SG configuration",e); + return null; + } + + } } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java index c8a652d..18d24eb 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -1,6 +1,9 @@ package org.gcube.datatransfer.resolver.services; +import java.net.URI; import java.net.URL; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ExecutionException; import javax.servlet.http.HttpServletRequest; @@ -20,15 +23,18 @@ import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET; import org.gcube.datatransfer.resolver.ConstantsResolver; +import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE; import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache; import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest; import org.gcube.datatransfer.resolver.catalogue.ItemCatalogueURLs; import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes; +import org.gcube.datatransfer.resolver.catalogue.resource.CatalogueStaticConfigurations; import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader; import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference; import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.util.Util; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE; import org.gcube.smartgears.utils.InnerMethodName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,6 +55,7 @@ public class CatalogueResolver { private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class); private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver"; + private static enum SCOPE_STATUS {ACTIVE, DETACHED} /** * Resolve catalogue. @@ -184,11 +191,29 @@ public class CatalogueResolver { try { String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue(); ScopeBean scopeBean = null; + SCOPE_STATUS scopeStatus = SCOPE_STATUS.ACTIVE; + VRE vreDetached = null; try{ scopeBean = LoadingMapOfScopeCache.get(scopeName); }catch(ExecutionException | InvalidCacheLoadException e){ - logger.error("Error on getting the fullscope from cache for scopeName "+scopeName, e); - throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the scope name '"+scopeName+"'. Is it registered as a valid Scope in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI); + logger.error("Error on getting the fullscope from cache for scopeName {}. Tryng to load it from DetachedRE",scopeName); + + boolean isScopeDetached = false; + try { + vreDetached = LoadingMapOfDetachedVRE.get(scopeName); + scopeBean = new ScopeBean(vreDetached.getScope()); + scopeStatus = SCOPE_STATUS.DETACHED; + logger.info("I loaded a valid VRE obj for scope name {}", scopeName); + isScopeDetached = true; + }catch (Exception e1) { + logger.warn("I was not able to load a detached VRE for vreName {}. Going to error for wrong scope",scopeName); + } + + //If is not a cas of scope detached, going to error for wrong scope + if(!isScopeDetached) { + logger.error("Error on getting the fullscope from cache for scopeName "+scopeName, e); + throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the scope name '"+scopeName+"'. Is it registered as a valid Scope in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI); + } } String fullScope = scopeBean.toString(); @@ -203,8 +228,37 @@ public class CatalogueResolver { } ScopeProvider.instance.set(fullScope); - GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints(); + GatewayCKANCatalogueReference ckanCatalogueReference = null; + logger.info("Managing scope status: {}",scopeStatus); + + switch (scopeStatus) { + case DETACHED: + + String privatePortletURL = vreDetached.getCatalogPortletURL(); + //The private portlet URL + Map mapAccessURLToCatalogue = new HashMap(3); + mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE,privatePortletURL); + + //Building the gateway catalogue public URL from private VRE Portlet URL + URI toURL = new URI(privatePortletURL); + String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost(); + //It returns the string "catalogue" + CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations(); + //Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g catalogue-bb) + String relativeURLWithCatalogueName = staticConf.buildRelativeURLToPublicCatalogueGateway(vreDetached.getCatalogUrl()); + String toGatewayPortletURL = String.format("%s/%s", publicURL, relativeURLWithCatalogueName); + mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY,toGatewayPortletURL); + + ckanCatalogueReference = new GatewayCKANCatalogueReference(fullScope, vreDetached.getCatalogUrl(), mapAccessURLToCatalogue); + break; + case ACTIVE: + default: + + ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints(); + break; + } + logger.info("For scope "+fullScope+" loaded end points: "+ckanCatalogueReference); //IS THE PRODUCT PLUBLIC OR PRIVATE? diff --git a/src/test/java/CatalogueNameExtractor.java b/src/test/java/CatalogueNameExtractor.java index e4460ee..5af2460 100644 --- a/src/test/java/CatalogueNameExtractor.java +++ b/src/test/java/CatalogueNameExtractor.java @@ -1,5 +1,4 @@ import org.gcube.datatransfer.resolver.catalogue.resource.CatalogueStaticConfigurations; -import org.junit.Test; public class CatalogueNameExtractor { diff --git a/src/test/java/CatalogueResolverTest.java b/src/test/java/CatalogueResolverTest.java index 123b132..2d4128c 100644 --- a/src/test/java/CatalogueResolverTest.java +++ b/src/test/java/CatalogueResolverTest.java @@ -1,6 +1,8 @@ -import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader; import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference; +import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; +import org.gcube.datatransfer.resolver.services.CatalogueResolver; /** @@ -12,18 +14,33 @@ import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueRe */ public class CatalogueResolverTest { + private static String entityName = "using_e-infrastructures_for_biodiversity_conservation"; + private static String entityContext = "ctlg"; + private static String vreName = "BlueBridgeProject"; + + private String rootContextScope = "/gcube"; + private String authorizationToken = ""; + + //@Before + public void init() { - /** - * The main method. - * - * @param args - * the arguments - */ - public static void main(String[] args) { + UriResolverSmartGearManagerInit.setRootContextScope(rootContextScope); + } + + + //@Test + public void testCatalogueResolver() { + SecurityTokenProvider.instance.set(authorizationToken); + CatalogueResolver catalogRes = new CatalogueResolver(); + catalogRes.resolveCatalogue(null, entityName, vreName, entityContext); + + } + + //@Test + public void testCatalogueLoadEndPoints() { try { - ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"); //ScopeProvider.instance.set("/d4science.research-infrastructures.eu"); GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints(); System.out.println(ckanCatalogueReference.toString()); diff --git a/src/test/java/DetachedVREsTest.java b/src/test/java/DetachedVREsTest.java new file mode 100644 index 0000000..61723ec --- /dev/null +++ b/src/test/java/DetachedVREsTest.java @@ -0,0 +1,46 @@ +import java.util.concurrent.ExecutionException; + +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DetachedVREsTest { + + public static Logger LOG = LoggerFactory.getLogger(DetachedVREsTest.class); + + public static String TOKEN = ""; + + public static String detachedVREName = "BlueBridgeProject"; + + public static String rootScope = "/gcube"; + + + //@Before + public void initCache() { + + } + /** + * Storage hub test. + * + * @throws Exception the exception + */ + //@Test + public void testCacheOfDetachedVREs() throws Exception{ + + try { + ScopeProvider.instance.set(rootScope); + SecurityTokenProvider.instance.set(TOKEN); + //LoadingMapOfDetachedVRE cache = new LoadingMapOfDetachedVRE(); + VRE theDetachedVRE = LoadingMapOfDetachedVRE.get(detachedVREName); + LOG.info("Detached VRE found {}", theDetachedVRE); + }catch (ExecutionException e) { + LOG.info("The Detached VRE for name {} not found",detachedVREName); + }catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/test/java/GetAllInfrastructureScopesFromIS.java b/src/test/java/GetAllInfrastructureScopesFromIS.java index 5c75910..285df15 100644 --- a/src/test/java/GetAllInfrastructureScopesFromIS.java +++ b/src/test/java/GetAllInfrastructureScopesFromIS.java @@ -3,7 +3,6 @@ import static org.gcube.resources.discovery.icclient.ICFactory.client; import java.io.StringReader; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -18,6 +17,7 @@ import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -38,12 +38,12 @@ public class GetAllInfrastructureScopesFromIS { protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()"; + /** - * The main method. - * - * @param args the arguments + * Test loading map of scope. */ - public static void main(String[] args) { + @Test + public void testLoadingMapOfScope() { try { @@ -53,16 +53,16 @@ public class GetAllInfrastructureScopesFromIS { UriResolverSmartGearManagerInit.setRootContextScope(rootScope); LoadingMapOfScopeCache cache = new LoadingMapOfScopeCache(); - int i = 0; - for (String string : cache.getCache().asMap().keySet()) { - try { - System.out.println(++i+") Scope Name: "+string + " to full scope: "+LoadingMapOfScopeCache.get(string)); - } catch (ExecutionException e) { - e.printStackTrace(); - } - } +// int i = 0; +// for (String string : cache.getCache().asMap().keySet()) { +// try { +// System.out.println(++i+") Scope Name: "+string + " to full scope: "+LoadingMapOfScopeCache.get(string)); +// } catch (ExecutionException e) { +// e.printStackTrace(); +// } +// } - String scopeName = "devsec"; + String scopeName = "abc"; ScopeBean scopeBean = LoadingMapOfScopeCache.get(scopeName); String fullScope = scopeBean.toString(); logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName()); diff --git a/src/test/java/GisResolverTest.java b/src/test/java/GisResolverTest.java index c42100d..39e8c46 100644 --- a/src/test/java/GisResolverTest.java +++ b/src/test/java/GisResolverTest.java @@ -1,6 +1,5 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem; -import org.gcube.datatransfer.resolver.gis.entity.ServerParameters; import org.gcube.datatransfer.resolver.services.GisResolver; /**