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>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<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.TimeUnit;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver;
import org.gcube.datatransfer.resolver.listeners.UriResolverStartupListener;
import org.slf4j.Logger;
@ -37,8 +38,10 @@ public class LoadingCatalogueApplicationProfilesCache {
public String load(String vreName)
throws Exception {
logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" loaded");
return loadApplicationProfiles(vreName);
logger.info("Loading the cache for vreName: "+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).
build(loader);
try{
//PRE-POPULATE CACHE
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("Pre-Loaded cache is: "+catalogueApplicationProfiles.toString());
logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied");
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
* @return the string
*/
public static String loadApplicationProfiles(String vreName){
public static String loadFullScopeByApplicationProfile(String vreName){
String fullScope = null;
try {

View File

@ -38,7 +38,7 @@ public class LoadingGisViewerApplicationURLCache {
@Override
public String load(String scope)
throws Exception {
logger.info(LoadingGisViewerApplicationURLCache.class.getSimpleName() +" loaded");
logger.info("Loading the cache for scope: "+scope);
return loadGisViewerApplicationURL(scope);
}
};
@ -81,6 +81,11 @@ public class LoadingGisViewerApplicationURLCache {
logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL");
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();
logger.info("With scope "+scope+" loaded the GisViewer Application URL "+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.gis.property.ApplicationProfileGenericResourceReader;
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.LoggerFactory;
@ -60,25 +62,29 @@ public class UriResolverStartupListener implements ServletContextListener {
*/
@Override
public void contextInitialized(ServletContextEvent event) {
try {
try {
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);
}
gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
//init the caches
new LoadingGeonetworkInstanceCache();
new LoadingGisViewerApplicationURLCache();
new LoadingCatalogueApplicationProfilesCache();
logger.info("Context initialized with: ");
logger.info("Scope: "+contextScope);
logger.info("GisViewerProfile: "+gisViewerProfile.getAppId() + " "+gisViewerProfile.getGenericResource());
logger.info("GeoExplorerProfile: "+geoExplorerProfile. getAppId() + " "+geoExplorerProfile.getGenericResource());
logger.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]");
logger.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]");
}
/* (non-Javadoc)

View File

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