Added SmartGear Init implementing the ApplicationManager

Performed a refactor

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174162 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-15 14:35:54 +00:00
parent 0e571e0963
commit 25dd2e78b1
8 changed files with 41 additions and 35 deletions

View File

@ -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() {

View File

@ -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;

View File

@ -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();

View File

@ -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<String, String> 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<String, String> 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());

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
package org.gcube.datatransfer.resolver;
package org.gcube.datatransfer.resolver.util;
import java.io.IOException;
import java.io.InputStream;