diff --git a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java index ead17a3..f8195e9 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/UriResolver.java @@ -2,11 +2,14 @@ package org.gcube.datatransfer.resolver; import javax.ws.rs.Path; +import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; import org.gcube.datatransfer.resolver.requesthandler.TokenSetter; import org.gcube.datatransfer.resolver.services.CatalogueResolver; +import org.gcube.smartgears.annotations.ManagedBy; import org.glassfish.jersey.server.ResourceConfig; @Path("uri-resolver") +@ManagedBy(UriResolverSmartGearManagerInit.class) public class UriResolver extends ResourceConfig { public UriResolver() { 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 731872a..e38061e 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java @@ -7,7 +7,7 @@ package org.gcube.datatransfer.resolver.caches; import java.util.concurrent.TimeUnit; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader; -import org.gcube.datatransfer.resolver.init.UriResolverSmartGearInit; +import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,7 +80,7 @@ public class LoadingGeoExplorerApplicationURLCache { if (scope == null || scope.isEmpty()) logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL"); - ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverSmartGearInit.getGeoExplorerProfile().getGenericResource(), UriResolverSmartGearInit.getGeoExplorerProfile().getAppId(), false); + ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverSmartGearManagerInit.getGeoExplorerProfile().getGenericResource(), UriResolverSmartGearManagerInit.getGeoExplorerProfile().getAppId(), false); String url = reader.getApplicationProfile().getUrl(); logger.info("With scope "+scope+" loaded the GeoExplorer Application URL "+url); return url; 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 bbe093b..06ff8a6 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java @@ -7,7 +7,7 @@ package org.gcube.datatransfer.resolver.caches; import java.util.concurrent.TimeUnit; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader; -import org.gcube.datatransfer.resolver.init.UriResolverSmartGearInit; +import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,10 +80,10 @@ public class LoadingGisViewerApplicationURLCache { if (scope == null || scope.isEmpty()) logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL"); - ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverSmartGearInit.getGisViewerProfile().getGenericResource(), UriResolverSmartGearInit.getGisViewerProfile().getAppId(), false); + ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverSmartGearManagerInit.getGisViewerProfile().getGenericResource(), UriResolverSmartGearManagerInit.getGisViewerProfile().getAppId(), false); if(reader.getApplicationProfile()==null){ - logger.error("NO Appllication Profile "+UriResolverSmartGearInit.getGisViewerProfile().getAppId()+" found in the scope: "+scope+", returning null!"); + logger.error("NO Appllication Profile "+UriResolverSmartGearManagerInit.getGisViewerProfile().getAppId()+" found in the scope: "+scope+", returning null!"); return null; } String url = reader.getApplicationProfile().getUrl(); diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingVREsScopeCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingVREsScopeCache.java index 699a4ae..f641494 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingVREsScopeCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingVREsScopeCache.java @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureVREs; -import org.gcube.datatransfer.resolver.init.UriResolverSmartGearInit; +import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,9 +75,9 @@ public class LoadingVREsScopeCache { private static void populateTheCache(){ try{ //POPULATE THE CACHE READING THE RESOURCE "CATALOGUE-RESOLVER" - logger.info("Trying to pre-populate VRE Names to Scope cache"); - ScopeProvider.instance.set(UriResolverSmartGearInit.getRootContextScope()); - Map map = GetAllInfrastructureVREs.loadMapOFVreNameToScope(UriResolverSmartGearInit.getRootContextScope()); + logger.info("Trying to pre-populate the cache with mapping (VRE Name, VRE Full Scope)"); + ScopeProvider.instance.set(UriResolverSmartGearManagerInit.getRootContextScope()); + Map map = GetAllInfrastructureVREs.loadMapOFVreNameToScope(UriResolverSmartGearManagerInit.getRootContextScope()); vresNameToScope.asMap().putAll(map); logger.info("Cache populated with: "+vresNameToScope.asMap().toString()); //logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString()); diff --git a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearInit.java b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java similarity index 71% rename from src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearInit.java rename to src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java index 39ddce7..73d9663 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearInit.java +++ b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java @@ -26,14 +26,14 @@ import org.slf4j.LoggerFactory; /** - * The Class UriResolverSmartGearInit. + * The Class UriResolverSmartGearManagerInit. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * Nov 15, 2018 */ -public class UriResolverSmartGearInit implements ApplicationManager { +public class UriResolverSmartGearManagerInit implements ApplicationManager { - private static Logger logger = LoggerFactory.getLogger(UriResolverSmartGearInit.class); + private static Logger log = LoggerFactory.getLogger(UriResolverSmartGearManagerInit.class); public static final String GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES = "gisviewerappgenericresource.properties"; public static final String GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES = "geoexplorerappgenericresource.properties"; @@ -54,41 +54,44 @@ public class UriResolverSmartGearInit implements ApplicationManager { */ @Override public void onInit() { - + log.debug("init called"); try { + boolean initContextPerformed = false; + if(rootContextScope==null){ - logger.info("The RootContextScope is null, getting it from ScopeProvider"); + log.info("The RootContextScope is null, getting it from ScopeProvider"); String scope = ScopeProvider.instance.get(); ScopeBean theScopeBean = new ScopeBean(scope); - logger.info("The ScopeBean is: "+theScopeBean.toString()); + log.info("The ScopeBean is: "+theScopeBean.toString()); if(theScopeBean.is(Type.INFRASTRUCTURE)){ rootContextScope = theScopeBean.name(); rootContextScope = rootContextScope.startsWith("/")?rootContextScope:"/"+rootContextScope; - logger.info("The RootContextScope has value: "+rootContextScope); + log.info("The RootContextScope has value: "+rootContextScope); + //THE ROOT SCOPE has been initialized + initContextPerformed = true; } - }else{ + } - //THE ROOT SCOPE has been initialized + if(gisViewerProfile==null || geoExplorerProfile==null){ + gisViewerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); + geoExplorerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); + log.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]"); + log.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]"); + } + + if(gisViewerProfile!=null && geoExplorerProfile!=null & initContextPerformed){ + log.info("Pre-Loading caches... using RootContextScope: "+rootContextScope); - gisViewerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); - geoExplorerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); //init the caches new LoadingGeonetworkInstanceCache(); new LoadingGisViewerApplicationURLCache(); new LoadingVREsScopeCache(); - //new LoadingCatalogueApplicationProfilesCache(); - - logger.info("Context initialized with: "); - logger.info("Scope: "+rootContextScope); - logger.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]"); - logger.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]"); - } } catch (Exception e) { // - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); } } @@ -122,9 +125,9 @@ public class UriResolverSmartGearInit implements ApplicationManager { return new ApplicationProfilePropertyReader(new FileInputStream(new File(realPath))); } catch (PropertyFileNotFoundException | FileNotFoundException ex) { - logger.error("PropertyFileNotFoundException: "+contextPath, ex); + log.error("PropertyFileNotFoundException: "+contextPath, ex); }catch (IOException e) { - logger.error("Error on loading property from: "+contextPath, e); + log.error("Error on loading property from: "+contextPath, e); } return null; @@ -139,13 +142,13 @@ public class UriResolverSmartGearInit implements ApplicationManager { */ public static String loadScopeFromEnvironment() throws ServletException{ - logger.info("Reading Environment Variable "+ENV_SCOPE); + log.info("Reading Environment Variable "+ENV_SCOPE); String scopeFromEnv = System.getenv(ENV_SCOPE); if(scopeFromEnv == null || scopeFromEnv.isEmpty()) throw new ServletException(UriResolverServletContextListener.class.getName() +" cannot read scope from Environment Variable: "+ENV_SCOPE+", It is null or empty"); - logger.info("Read scope: "+scopeFromEnv+" from Environment Variable: "+ENV_SCOPE); + log.info("Read scope: "+scopeFromEnv+" from Environment Variable: "+ENV_SCOPE); return scopeFromEnv; } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java index 7509333..dba1be7 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java @@ -26,7 +26,6 @@ import javax.ws.rs.core.StreamingOutput; import org.apache.commons.io.IOUtils; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.datatransfer.resolver.SingleFileStreamingOutput; import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter; import org.gcube.datatransfer.resolver.gis.GeonetworkInstance; import org.gcube.datatransfer.resolver.gis.GeonetworkServiceInterface; @@ -40,6 +39,7 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.exceptions.InternalServerException; import org.gcube.datatransfer.resolver.util.GetResponseRecordFilter; import org.gcube.datatransfer.resolver.util.HTTPCallsUtils; +import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput; import org.gcube.datatransfer.resolver.util.HTTPCallsUtils.HttpResponse; import org.gcube.datatransfer.resolver.util.ScopeUtil; import org.gcube.spatial.data.geonetwork.configuration.Configuration; diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index 399e554..e091dfc 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -22,8 +22,8 @@ import org.gcube.contentmanagement.blobstorage.service.IClient; import org.gcube.contentmanager.storageclient.wrapper.AccessType; import org.gcube.contentmanager.storageclient.wrapper.MemoryType; import org.gcube.contentmanager.storageclient.wrapper.StorageClient; -import org.gcube.datatransfer.resolver.SingleFileStreamingOutput; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; +import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/gcube/datatransfer/resolver/SingleFileStreamingOutput.java b/src/main/java/org/gcube/datatransfer/resolver/util/SingleFileStreamingOutput.java similarity index 97% rename from src/main/java/org/gcube/datatransfer/resolver/SingleFileStreamingOutput.java rename to src/main/java/org/gcube/datatransfer/resolver/util/SingleFileStreamingOutput.java index eb4d92d..17cd094 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/SingleFileStreamingOutput.java +++ b/src/main/java/org/gcube/datatransfer/resolver/util/SingleFileStreamingOutput.java @@ -1,4 +1,4 @@ -package org.gcube.datatransfer.resolver; +package org.gcube.datatransfer.resolver.util; import java.io.IOException; import java.io.InputStream;