fixing caching

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173966 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-05 16:52:43 +00:00
parent 6a557f5a03
commit fabf08829f
5 changed files with 47 additions and 19 deletions

View File

@ -44,6 +44,11 @@
<artifactId>common-smartgears</artifactId> <artifactId>common-smartgears</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId> <artifactId>common-authorization</artifactId>

View File

@ -6,6 +6,7 @@ package org.gcube.datatransfer.resolver.caches;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver; import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver;
import org.gcube.datatransfer.resolver.listeners.UriResolverStartupListener; import org.gcube.datatransfer.resolver.listeners.UriResolverStartupListener;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -37,8 +38,10 @@ public class LoadingCatalogueApplicationProfilesCache {
public String load(String vreName) public String load(String vreName)
throws Exception { throws Exception {
logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" loaded"); logger.info("Loading the cache for vreName: "+vreName);
return loadApplicationProfiles(vreName); String fullScope = loadFullScopeByApplicationProfile(vreName);
logger.info("Returning fullScope: "+fullScope+ " for the VRE name: "+vreName);
return fullScope;
} }
}; };
@ -57,12 +60,20 @@ public class LoadingCatalogueApplicationProfilesCache {
1, TimeUnit.HOURS).removalListener(removalListener). 1, TimeUnit.HOURS).removalListener(removalListener).
build(loader); build(loader);
//PRE-POPULATE CACHE try{
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true); //PRE-POPULATE CACHE
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope()); logger.info("Trying to pre-poluate catalogue resolver cache");
ScopeProvider.instance.set(UriResolverStartupListener.getContextScope());
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true);
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied "+catalogueApplicationProfiles); logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied");
logger.info("Pre-Loaded cache is: "+catalogueApplicationProfiles.toString()); logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
}catch(Exception e){
}finally{
}
} }
@ -83,7 +94,7 @@ public class LoadingCatalogueApplicationProfilesCache {
* @param vreName the vre name * @param vreName the vre name
* @return the string * @return the string
*/ */
public static String loadApplicationProfiles(String vreName){ public static String loadFullScopeByApplicationProfile(String vreName){
String fullScope = null; String fullScope = null;
try { try {

View File

@ -38,7 +38,7 @@ public class LoadingGisViewerApplicationURLCache {
@Override @Override
public String load(String scope) public String load(String scope)
throws Exception { throws Exception {
logger.info(LoadingGisViewerApplicationURLCache.class.getSimpleName() +" loaded"); logger.info("Loading the cache for scope: "+scope);
return loadGisViewerApplicationURL(scope); return loadGisViewerApplicationURL(scope);
} }
}; };
@ -81,6 +81,11 @@ public class LoadingGisViewerApplicationURLCache {
logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL"); logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL");
ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverStartupListener.getGisViewerProfile().getGenericResource(), UriResolverStartupListener.getGisViewerProfile().getAppId(), false); ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverStartupListener.getGisViewerProfile().getGenericResource(), UriResolverStartupListener.getGisViewerProfile().getAppId(), false);
if(reader.getApplicationProfile()==null){
logger.error("NO Appllication Profile "+UriResolverStartupListener.getGisViewerProfile().getAppId()+" found in the scope: "+scope+", returning null!");
return null;
}
String url = reader.getApplicationProfile().getUrl(); String url = reader.getApplicationProfile().getUrl();
logger.info("With scope "+scope+" loaded the GisViewer Application URL "+url); logger.info("With scope "+scope+" loaded the GisViewer Application URL "+url);
return url; return url;

View File

@ -20,6 +20,8 @@ import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache;
import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache; import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache;
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader; import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader;
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException; import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -60,25 +62,29 @@ public class UriResolverStartupListener implements ServletContextListener {
*/ */
@Override @Override
public void contextInitialized(ServletContextEvent event) { public void contextInitialized(ServletContextEvent event) {
try {
try {
contextScope = loadScopeFromEnvironment(); contextScope = loadScopeFromEnvironment();
ApplicationContext ctx = ContextProvider.get();
String rootScope = ctx.container().configuration().infrastructure();
logger.info("The ContextProvider returns the root scope: "+rootScope);
} }
catch (ServletException e) { catch (Exception e) {
// //
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
//init the caches
new LoadingGeonetworkInstanceCache(); new LoadingGeonetworkInstanceCache();
new LoadingGisViewerApplicationURLCache(); new LoadingGisViewerApplicationURLCache();
new LoadingCatalogueApplicationProfilesCache(); new LoadingCatalogueApplicationProfilesCache();
logger.info("Context initialized with: "); logger.info("Context initialized with: ");
logger.info("Scope: "+contextScope); logger.info("Scope: "+contextScope);
logger.info("GisViewerProfile: "+gisViewerProfile.getAppId() + " "+gisViewerProfile.getGenericResource()); logger.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]");
logger.info("GeoExplorerProfile: "+geoExplorerProfile. getAppId() + " "+geoExplorerProfile.getGenericResource()); logger.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]");
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -95,7 +95,7 @@ public class GisResolver {
try { try {
if(isGisLink){ if(isGisLink){
//ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
//ServerParameters geonetworkParams = getCachedServerParameters(scope); //ServerParameters geonetworkParams = getCachedServerParameters(scope);
GisLayerItem gisLayerItem = getGisLayerForLayerUUID(scope, gisUUID); GisLayerItem gisLayerItem = getGisLayerForLayerUUID(scope, gisUUID);
@ -157,11 +157,12 @@ public class GisResolver {
logger.info("Tentative of recovering gis viewer application hostname from cache for scope: "+scope); logger.info("Tentative of recovering gis viewer application hostname from cache for scope: "+scope);
String gisViewerAppHostname = LoadingGisViewerApplicationURLCache.getCache().get(scope); String gisViewerAppHostname = LoadingGisViewerApplicationURLCache.getCache().get(scope);
if(gisViewerAppHostname==null){ if(gisViewerAppHostname==null){
logger.info("Gis viewer application hostname is null, reading from application profile.."); // logger.info("Gis viewer application hostname is null, reading from application profile..");
String url = LoadingGisViewerApplicationURLCache.loadGisViewerApplicationURL(scope); // String url = LoadingGisViewerApplicationURLCache.loadGisViewerApplicationURL(scope);
LoadingGisViewerApplicationURLCache.getCache().put(scope, url); // LoadingGisViewerApplicationURLCache.getCache().put(scope, url);
logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url); // logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url);
return url; // return url;
throw new Exception("GisViewer Application not found in the scope: "+scope);
}else }else
logger.info("Cache for GisViewerApplication end point is not null using it"); logger.info("Cache for GisViewerApplication end point is not null using it");