4953: Uri Resolver: remove jumps of scope from Readers (for Generic and Runtime resource)

Task-Url: https://support.d4science.org/issues/4953

Application Profile Reader updated in order to read Resource by root scope

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@131178 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-09-07 13:54:30 +00:00
parent e082f323c7
commit 2fdd25e714
4 changed files with 47 additions and 27 deletions

View File

@ -11,6 +11,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox; import org.gcube.resources.discovery.client.queries.impl.QueryBox;
@ -73,17 +74,21 @@ public class ApplicationProfileReader {
ApplicationProfile appProf = new ApplicationProfile(); ApplicationProfile appProf = new ApplicationProfile();
String queryString = GcubeQuery.getGcubeGenericQueryString(secondaryType, appId); String queryString = GcubeQuery.getGcubeGenericQueryString(secondaryType, appId);
String originalScope = null;
logger.info("Trying to fetch ApplicationProfile in the scope: "+scope+", SecondaryType: " + secondaryType + ", AppId: " + appId);
try { try {
originalScope = ScopeProvider.instance.get();
String infra = ScopeUtil.getInfrastructureNameFromScope(scope);
ScopeProvider.instance.set(infra);
logger.info("Trying to fetch ApplicationProfile in the infra scope: "+infra+", SecondaryType: " + secondaryType + ", AppId: " + appId);
Query q = new QueryBox(queryString); Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client(); DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q); List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0) if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the scope: "+scope); throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the infra scope: "+infra);
else { else {
String elem = appProfile.get(0); String elem = appProfile.get(0);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@ -168,6 +173,14 @@ public class ApplicationProfileReader {
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e); logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
return null; return null;
}finally{
if(originalScope!=null && !originalScope.isEmpty()){
ScopeProvider.instance.set(originalScope);
logger.info("scope provider setted to orginal scope: "+originalScope);
}else{
ScopeProvider.instance.reset();
logger.info("scope provider reset");
}
} }
} }

View File

@ -17,27 +17,27 @@ public class ScopeUtil {
public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class); public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class);
// public static String getInfrastructureNameFromScope(String scope) throws Exception{ public static String getInfrastructureNameFromScope(String scope) throws Exception{
//
// if(scope==null || scope.isEmpty()){ if(scope==null || scope.isEmpty()){
// throw new Exception("Scope is null or empty"); throw new Exception("Scope is null or empty");
// } }
//
// if(!scope.startsWith(SCOPE_SEPARATOR)){ if(!scope.startsWith(SCOPE_SEPARATOR)){
// logger.warn("Input scope: "+scope+" not have / is a really scope?"); logger.warn("Input scope: "+scope+" not have / is a really scope?");
// scope = SCOPE_SEPARATOR+scope; scope = SCOPE_SEPARATOR+scope;
// logger.warn("Tentative as scope: "+scope); logger.warn("Tentative as scope: "+scope);
// } }
//
// String[] splitScope = scope.split(SCOPE_SEPARATOR); String[] splitScope = scope.split(SCOPE_SEPARATOR);
//
// String rootScope = SCOPE_SEPARATOR + splitScope[1]; String rootScope = SCOPE_SEPARATOR + splitScope[1];
//
// if(rootScope.length()<2){ if(rootScope.length()<2){
// throw new Exception("Infrastructure name not found in "+scope); throw new Exception("Infrastructure name not found in "+scope);
// } }
//
// return rootScope; return rootScope;
//
// } }
} }

View File

@ -34,7 +34,7 @@ public class GeoRuntimeReader {
public static enum GEO_SERVICE{GEOSERVER, GEONETWORK}; public static enum GEO_SERVICE{GEOSERVER, GEONETWORK};
public static final Logger logger = LoggerFactory.getLogger(GisResolver.class); public static final Logger logger = LoggerFactory.getLogger(GeoRuntimeReader.class);
private ServerParameters getParameters(String scope, GEO_SERVICE geoservice) throws Exception private ServerParameters getParameters(String scope, GEO_SERVICE geoservice) throws Exception
{ {
@ -54,6 +54,8 @@ public class GeoRuntimeReader {
SimpleQuery query = queryFor(ServiceEndpoint.class); SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'"); query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
logger.info("GeoRuntimeReader, using scope: "+scope + ", to get resource: "+resourceName);
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class); DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> r = client.submit(query); List<ServiceEndpoint> r = client.submit(query);

View File

@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE; import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE;
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel; import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel;
@ -202,7 +203,7 @@ public class GisResolver extends HttpServlet{
logger.info("SCOPE is: " + scope); logger.info("SCOPE is: " + scope);
try { try {
ScopeProvider.instance.set(scope);
ServerParameters geonetworkParams = getCachedServerParameters(scope); ServerParameters geonetworkParams = getCachedServerParameters(scope);
String wmsRequest = getLayerWmsRequest(scope, gisUUID, geonetworkParams); String wmsRequest = getLayerWmsRequest(scope, gisUUID, geonetworkParams);
logger.info("wms url is: " + wmsRequest); logger.info("wms url is: " + wmsRequest);
@ -233,6 +234,9 @@ public class GisResolver extends HttpServlet{
String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!"; String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!";
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error); sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
return; return;
}finally{
logger.error("Resetting scope");
ScopeProvider.instance.reset();
} }
} }
@ -367,6 +371,7 @@ public class GisResolver extends HttpServlet{
String scope = "/gcube/devsec/devVRE"; String scope = "/gcube/devsec/devVRE";
String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8"; String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
try { try {
ScopeProvider.instance.set(scope);
ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope); ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams); String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams);
logger.info("Final url is: " + wmsRequest); logger.info("Final url is: " + wmsRequest);