From d96186d0e9786369d6e90b2be691b441a8c6ed44 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 10 Jun 2020 14:46:02 +0200 Subject: [PATCH] Bug fixing LoadingMapOfDetachedVRE --- .../caches/LoadingMapOfDetachedVRE.java | 90 +++++++++---------- .../caches/LoadingMapOfScopeCache.java | 9 +- .../init/UriResolverSmartGearManagerInit.java | 2 + ...etachedVREs.java => DetachedVREsTest.java} | 25 ++++-- .../GetAllInfrastructureScopesFromIS.java | 28 +++--- src/test/java/GisResolverTest.java | 2 +- 6 files changed, 81 insertions(+), 75 deletions(-) rename src/test/java/{DetachedVREs.java => DetachedVREsTest.java} (55%) diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java index d8ae311..6d6e71d 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java @@ -3,7 +3,7 @@ */ package org.gcube.datatransfer.resolver.caches; -import java.util.concurrent.ConcurrentMap; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -23,15 +23,16 @@ 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 8, 2020 + * Jun 10, 2020 */ public class LoadingMapOfDetachedVRE { - private static Logger logger = LoggerFactory.getLogger(LoadingMapOfDetachedVRE.class); + private static Logger LOG = LoggerFactory.getLogger(LoadingMapOfDetachedVRE.class); private static LoadingCache vreNameToVRE; static{ @@ -42,9 +43,14 @@ public class LoadingMapOfDetachedVRE { public VRE load(String vreName) throws Exception { - logger.info("Loading the cache for VRE name: {}",vreName); - VRE theVRE = loadFullScopeforScopeName(vreName); - logger.info("Returning {} with scope {} for the VRE name: {}", VRE.class.getSimpleName(), theVRE.getScope(), vreName); + 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; } @@ -55,20 +61,18 @@ public class LoadingMapOfDetachedVRE { @Override public void onRemoval(RemovalNotification arg0) { - logger.info("cache expired"); - //prePopulateCache(); - + LOG.info("cache expired"); } }; vreNameToVRE = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite( - 1, TimeUnit.DAYS).removalListener(removalListener). + 12, TimeUnit.HOURS).removalListener(removalListener). build(loader); //Populating the cache at init stage populateTheCache(); - logger.info("Pre-Loaded detached VRE Name to VRE Obj cache with: "+vreNameToVRE.asMap().size()+" item/s"); + LOG.info("Pre-Loaded detached VRE Name to VRE Obj cache with: "+vreNameToVRE.asMap().size()+" item/s"); } @@ -76,22 +80,23 @@ public class LoadingMapOfDetachedVRE { * Populate the cache. */ private static void populateTheCache(){ + try{ - //POPULATE THE CACHE READING THE RESOURCE "CATALOGUE-RESOLVER" - logger.info("Trying to pre-populate the detached VREs cache with mapping (VRE Name, VRE Obj)"); + //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()); DetachedREsClient detachedREsClient = new DetachedREsClient(); DetachedREs detachedREs = detachedREsClient.getDetachedREs(); int totalVREDimissed = 0; for (Gateway gateway : detachedREs.getGateways().values()) { - logger.trace("Gateway: " + gateway.getName()); + LOG.trace("Gateway: " + gateway.getName()); int vreDismissedPerGatew = 0; for (VO vo : gateway.getVos().values()) { - logger.trace("VO: " + vo.getName()); + LOG.trace("VO: " + vo.getName()); for (VRE vre : vo.getVres().values()) { - if(logger.isTraceEnabled()) { - logger.trace("VRE name: " + vre.getName() + + if(LOG.isTraceEnabled()) { + LOG.trace("VRE name: " + vre.getName() + " scope: "+vre.getScope() + " VRE catalogue url: " + vre.getCatalogUrl() + " VRE catalog Portlet URL: "+vre.getCatalogPortletURL()); @@ -99,28 +104,30 @@ public class LoadingMapOfDetachedVRE { try { if(vre.getScope()!=null && !vre.getScope().isEmpty()) { String vreName = vre.getScope().split("/")[3]; - vreNameToVRE.put(vreName, vre); + vreNameToVRE.asMap().put(vreName, vre); vreDismissedPerGatew++; } }catch (Exception e) { - logger.warn("Error on parsing the scope: "+vre.getScope()+ " skipping it"); + LOG.warn("Error on parsing the scope: "+vre.getScope()+ " skipping it"); } } } - logger.debug("\nVREs dismissed loaded and cached per " + gateway.getName() + " are: "+vreDismissedPerGatew); + LOG.debug("VREs dismissed loaded and cached per " + gateway.getName() + " are: "+vreDismissedPerGatew); totalVREDimissed+=vreDismissedPerGatew; } - logger.debug("\nTotal detached VREs are: "+totalVREDimissed); + LOG.debug("Total detached VREs are: "+totalVREDimissed); - logger.info("Cache populated with: "); - ConcurrentMap mapOfVreNames = vreNameToVRE.asMap(); + LOG.info("Cache populated with: "); + Map mapOfVreNames = vreNameToVRE.asMap(); for (String key : mapOfVreNames.keySet()) { VRE theDetachedVRE = mapOfVreNames.get(key); - logger.info("detached VRE with scope {}, catalogueURL {}, cataloguePortletURL {}", - theDetachedVRE.getScope(), theDetachedVRE.getCatalogUrl(), + LOG.info("VRE name {}, VRE obj with scope {}, catalogueURL {}, cataloguePortletURL {}", + key, + theDetachedVRE.getScope(), + theDetachedVRE.getCatalogUrl(), theDetachedVRE.getCatalogPortletURL()); } @@ -132,8 +139,9 @@ public class LoadingMapOfDetachedVRE { } + /** - * Gets the. + * Gets the VRE obj for input VRE name. * * @param vreName the vre name * @return the vre @@ -141,35 +149,25 @@ public class LoadingMapOfDetachedVRE { */ public static VRE get(String vreName) throws ExecutionException{ - boolean cacheNotLoaded = true; - final int MAX_ATTEMPTS = 3; - int retry = 1; - while (cacheNotLoaded) { - cacheNotLoaded = vreNameToVRE == null; - if(retry