[Incident #16671] Fixing Catalogue Resolver in case of working with INFRASTRUCTURE and VO scope
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@179444 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5d4549115a
commit
f266f6ea96
|
@ -4,6 +4,9 @@
|
|||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<dependent-module archiveName="ckan-util-library-2.9.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library-TRUNK/ckan-util-library-TRUNK">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<property name="context-root" value="uri-resolver"/>
|
||||
<property name="java-output-path" value="/uri-resolver/target/classes"/>
|
||||
</wb-module>
|
||||
|
|
|
@ -146,5 +146,7 @@
|
|||
</Change>
|
||||
<Change>[Task #16471] Tested Catalogue Resolver backward compatibility
|
||||
</Change>
|
||||
<Change>[Incident #16671] Fixing Catalogue Resolver in case of working with INFRASTRUCTURE and VO scope
|
||||
</Change>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
20
pom.xml
20
pom.xml
|
@ -1,4 +1,5 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
@ -92,6 +93,13 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- //TO BE ADDED THE VERSION 18.0
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
|
@ -128,11 +136,11 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.sun.jersey</groupId> -->
|
||||
<!-- <artifactId>jersey-server</artifactId> -->
|
||||
<!-- <version>1.19.4</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.sun.jersey</groupId> -->
|
||||
<!-- <artifactId>jersey-server</artifactId> -->
|
||||
<!-- <version>1.19.4</version> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<!-- weld -->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datatransfer.resolver.caches;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
|
||||
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
|
||||
|
||||
/**
|
||||
* The Class LoadingMapOfScopeCache.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* May 13, 2019
|
||||
*/
|
||||
public class LoadingMapOfScopeCache {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(LoadingMapOfScopeCache.class);
|
||||
private static LoadingCache<String, ScopeBean> scopeNamesToFullScopes;
|
||||
|
||||
static{
|
||||
|
||||
CacheLoader<String, ScopeBean> loader = new CacheLoader<String, ScopeBean>(){
|
||||
|
||||
@Override
|
||||
public ScopeBean load(String scopeName)
|
||||
throws Exception {
|
||||
|
||||
logger.info("Loading the cache for scope: {}",scopeName);
|
||||
ScopeBean fullScope = loadFullScopeforScopeName(scopeName);
|
||||
logger.info("Returning {} for the Scope name: {}",ScopeBean.class.getSimpleName(), scopeName);
|
||||
return fullScope;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
RemovalListener<String, ScopeBean> removalListener = new RemovalListener<String, ScopeBean>() {
|
||||
|
||||
@Override
|
||||
public void onRemoval(RemovalNotification<String, ScopeBean> arg0) {
|
||||
|
||||
logger.info("cache expired");
|
||||
//prePopulateCache();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
scopeNamesToFullScopes = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite(
|
||||
1, TimeUnit.DAYS).removalListener(removalListener).
|
||||
build(loader);
|
||||
|
||||
|
||||
//Populating the cache at init stage
|
||||
populateTheCache();
|
||||
logger.info("Pre-Loaded VRE to Scope cache with: "+scopeNamesToFullScopes.asMap().size()+" item/s");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populate the cache.
|
||||
*/
|
||||
private static void populateTheCache(){
|
||||
try{
|
||||
//POPULATE THE CACHE READING THE RESOURCE "CATALOGUE-RESOLVER"
|
||||
logger.info("Trying to pre-populate the cache with mapping (Scope Name, Full Scope)");
|
||||
ScopeProvider.instance.set(UriResolverSmartGearManagerInit.getRootContextScope());
|
||||
Map<String, String> map = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(UriResolverSmartGearManagerInit.getRootContextScope());
|
||||
|
||||
for (String scopeName : map.keySet()) {
|
||||
scopeNamesToFullScopes.asMap().put(scopeName, new ScopeBean(map.get(scopeName)));
|
||||
}
|
||||
|
||||
logger.info("Cache populated with: "+scopeNamesToFullScopes.asMap().toString());
|
||||
//logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
|
||||
|
||||
// if(UriResolverSmartGearManagerInit.getRootContextScope().compareTo("/gcube")==0){
|
||||
// logger.warn("HARD-CABLING PARTHENOS_Registry scope to resolve PARTHENOS_REGISTRY Links in dev environment");
|
||||
// scopeNamesToFullScopes.asMap().put("PARTHENOS_Registry", "/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry");
|
||||
// }
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
//SILENT
|
||||
}finally{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param scopeName the scope name
|
||||
* @return the scope bean
|
||||
* @throws ExecutionException the execution exception
|
||||
*/
|
||||
public static ScopeBean get(String scopeName) throws ExecutionException{
|
||||
|
||||
return scopeNamesToFullScopes.get(scopeName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load full scopefor scope name.
|
||||
*
|
||||
* @param scopeName the scope name
|
||||
* @return the scope bean
|
||||
*/
|
||||
protected static ScopeBean loadFullScopeforScopeName(String scopeName){
|
||||
|
||||
//THIS CHECK SHOULD BE NOT NEEDED
|
||||
ScopeBean fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);
|
||||
|
||||
if(fullScope==null){
|
||||
populateTheCache();
|
||||
fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);
|
||||
}
|
||||
|
||||
return fullScope;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the cache.
|
||||
*
|
||||
* @return the cache
|
||||
*/
|
||||
public LoadingCache<String, ScopeBean> getCache(){
|
||||
return scopeNamesToFullScopes;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datatransfer.resolver.caches;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
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.UriResolverSmartGearManagerInit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class LoadingVREsScopeCache.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Nov 8, 2018
|
||||
*/
|
||||
public class LoadingVREsScopeCache {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(LoadingVREsScopeCache.class);
|
||||
private static LoadingCache<String, String> vresNameToScope;
|
||||
|
||||
static{
|
||||
|
||||
CacheLoader<String, String> loader = new CacheLoader<String, String>(){
|
||||
|
||||
@Override
|
||||
public String load(String vreName)
|
||||
throws Exception {
|
||||
|
||||
logger.info("Loading the cache for vreName: "+vreName);
|
||||
String fullScope = loadFullScopeforVreName(vreName);
|
||||
logger.info("Returning fullScope: "+fullScope+ " for the VRE name: "+vreName);
|
||||
return fullScope;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
|
||||
|
||||
@Override
|
||||
public void onRemoval(RemovalNotification<String, String> arg0) {
|
||||
|
||||
logger.info("cache expired");
|
||||
//prePopulateCache();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
vresNameToScope = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite(
|
||||
1, TimeUnit.DAYS).removalListener(removalListener).
|
||||
build(loader);
|
||||
|
||||
|
||||
//Populating the cache at init stage
|
||||
populateTheCache();
|
||||
logger.info("Pre-Loaded VRE to Scope cache with: "+vresNameToScope.asMap().size()+" item/s");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populate the cache.
|
||||
*/
|
||||
private static void populateTheCache(){
|
||||
try{
|
||||
//POPULATE THE CACHE READING THE RESOURCE "CATALOGUE-RESOLVER"
|
||||
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());
|
||||
|
||||
if(UriResolverSmartGearManagerInit.getRootContextScope().compareTo("/gcube")==0){
|
||||
logger.warn("HARD-CABLING PARTHENOS_Registry scope to resolve PARTHENOS_REGISTRY Links in dev environment");
|
||||
vresNameToScope.asMap().put("PARTHENOS_Registry", "/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry");
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
|
||||
}finally{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param vreName the vre name
|
||||
* @return the string
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
public static String get(String vreName) throws ExecutionException{
|
||||
|
||||
return vresNameToScope.get(vreName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load application profiles.
|
||||
*
|
||||
* @param vreName the vre name
|
||||
* @return the string
|
||||
*/
|
||||
protected static String loadFullScopeforVreName(String vreName){
|
||||
|
||||
//THIS CHECK SHOULD BE NOT NEEDED
|
||||
String fullScope = vresNameToScope.getIfPresent(vreName);
|
||||
|
||||
if(fullScope==null){
|
||||
populateTheCache();
|
||||
fullScope = vresNameToScope.getIfPresent(vreName);
|
||||
}
|
||||
|
||||
return fullScope;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
|
@ -23,54 +25,60 @@ import org.xml.sax.InputSource;
|
|||
|
||||
|
||||
/**
|
||||
* The Class GetAllInfrastructureVREs.
|
||||
* The Class GetAllInfrastructureScopes.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Nov 8, 2018
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Nov 8, 2018
|
||||
* May 16, 2019
|
||||
*/
|
||||
public class GetAllInfrastructureVREs {
|
||||
public class GetAllInfrastructureScopes {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureVREs.class);
|
||||
public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureScopes.class);
|
||||
|
||||
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
|
||||
|
||||
|
||||
/**
|
||||
* Load map of vre name to scope.
|
||||
* Load map of scope name to full scope.
|
||||
*
|
||||
* @param rootScope the root scope
|
||||
* @return the map of binding between (VRE_NAME, FULL_SCOPE_OF_VRE_NAME)
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static Map<String, String> loadMapOFVreNameToScope(String rootScope) throws Exception{
|
||||
public static Map<String, String> loadMapOfScopeNameToFullScope(String rootScope) throws Exception{
|
||||
|
||||
String originalScope = ScopeProvider.instance.get();
|
||||
|
||||
try{
|
||||
|
||||
ScopeBean scopeBean = null;
|
||||
Map<String, String> scopeNameToFullScopeMap = new HashMap<String,String>();
|
||||
ScopeProvider.instance.set(rootScope);
|
||||
String secondaryType = "INFRASTRUCTURE";
|
||||
String secondaryType = Type.INFRASTRUCTURE.name();
|
||||
scopeBean = new ScopeBean(rootScope);
|
||||
logger.info("Added the couple ({},{}) as {} (NAME, FULL SCOPE) into map", scopeBean.name(), rootScope, secondaryType);
|
||||
scopeNameToFullScopeMap.put(scopeBean.name(), rootScope);
|
||||
List<String> listVOScopes = getListOfVOScopes(secondaryType);
|
||||
Map<String, String> vreNameFullScope = new HashMap<String,String>();
|
||||
logger.info("Searching for secondaryType="+secondaryType +" scope/s found is/are: " +listVOScopes);
|
||||
logger.info("Searching for secondaryType={} the scope/s found is/are: " +secondaryType, listVOScopes);
|
||||
|
||||
secondaryType = "VRE";
|
||||
//int noVOTypeCount = 0;
|
||||
for (String voScope : listVOScopes) {
|
||||
int count = voScope.length() - voScope.replace("/", "").length();
|
||||
//int count = voScope.length() - voScope.replace("/", "").length();
|
||||
scopeBean = new ScopeBean(voScope);
|
||||
//IS A VO
|
||||
if(count==2){
|
||||
logger.info(voScope +" is a VO...");
|
||||
//if(count==2){
|
||||
if(scopeBean.is(Type.VO)){
|
||||
secondaryType = Type.VO.name();
|
||||
logger.info("{} is a {}...",voScope,secondaryType);
|
||||
ScopeProvider.instance.set(voScope);
|
||||
scopeBean = new ScopeBean(voScope);
|
||||
logger.info("Added the couple ({},{}) as {} (NAME, FULL SCOPE) into map", scopeBean.name(), voScope, secondaryType);
|
||||
scopeNameToFullScopeMap.put(scopeBean.name(), voScope);
|
||||
secondaryType = Type.VRE.name();
|
||||
List<String> listVREs = getListOfResourcesForSecondaryType(secondaryType);
|
||||
logger.debug("VREs found for VO "+voScope+ " is/are "+listVREs.size()+ ": "+listVREs);
|
||||
for (String vreName : listVREs) {
|
||||
String vreScope = String.format("%s/%s", voScope,vreName);
|
||||
vreNameFullScope.put(vreName, vreScope);
|
||||
scopeNameToFullScopeMap.put(vreName, vreScope);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
@ -84,8 +92,8 @@ public class GetAllInfrastructureVREs {
|
|||
System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
|
||||
}*/
|
||||
|
||||
logger.info("Total VRE is: "+vreNameFullScope.size());
|
||||
return vreNameFullScope;
|
||||
logger.info("Total VRE is: "+scopeNameToFullScopeMap.size());
|
||||
return scopeNameToFullScopeMap;
|
||||
|
||||
}catch(Exception e ){
|
||||
throw new Exception("Error on loading the map of VRE nameto scope: ", e);
|
|
@ -17,7 +17,7 @@ import org.gcube.common.scope.impl.ScopeBean;
|
|||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
||||
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfilePropertyReader;
|
||||
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
|
@ -93,7 +93,7 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
|
|||
//init the caches
|
||||
new LoadingGeonetworkInstanceCache();
|
||||
new LoadingGisViewerApplicationURLCache();
|
||||
new LoadingVREsScopeCache();
|
||||
new LoadingMapOfScopeCache();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -225,4 +225,8 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
|
|||
|
||||
return rootContextScope;
|
||||
}
|
||||
|
||||
public static void setRootContextScope(String rootContextScope) {
|
||||
UriResolverSmartGearManagerInit.rootContextScope = rootContextScope;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ import javax.ws.rs.WebApplicationException;
|
|||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -62,18 +63,18 @@ public class AnalyticsGetResolver {
|
|||
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
String fullScope = "";
|
||||
ScopeBean fullScopeBean = null;
|
||||
|
||||
//CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
||||
try{
|
||||
fullScope = LoadingVREsScopeCache.get(vreName);
|
||||
fullScopeBean = LoadingMapOfScopeCache.get(vreName);
|
||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
||||
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
|
||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
|
||||
}
|
||||
ApplicationProfileReader reader = null;
|
||||
try{
|
||||
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
|
||||
reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
|
||||
}catch(Exception e){
|
||||
logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, e);
|
||||
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+ANALYTICS_EXECUTOR_PORTLET_NAME+". Please contact the support", this.getClass(), helpURI);
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* EASTER EGG - TO BE REMOVED
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
*/
|
||||
@Path("cr7huevos")
|
||||
public class CR7Huevos {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class);
|
||||
|
||||
@GET
|
||||
@Produces({MediaType.TEXT_HTML})
|
||||
@Path("")
|
||||
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
|
||||
|
||||
String indexFile = "/WEB-INF/jsp/cr7huevos.jsp";
|
||||
|
||||
try{
|
||||
logger.info("Easter EGG called :-) - TO BE REMOVE");
|
||||
String realPath = req.getServletContext().getRealPath(indexFile);
|
||||
return new FileInputStream(new File(realPath));
|
||||
}catch (Exception e) {
|
||||
|
||||
if(!(e instanceof WebApplicationException)){
|
||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Index.jsp not found. Please, contact the support!";
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
||||
}
|
||||
//ALREADY MANAGED AS WebApplicationException
|
||||
logger.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -16,13 +16,15 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
||||
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
|
||||
import org.gcube.datatransfer.resolver.catalogue.ItemCatalogueURLs;
|
||||
import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureVREs;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.gcube.datatransfer.resolver.util.Util;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -122,11 +124,11 @@ public class CatalogueResolver {
|
|||
String serverUrl = Util.getServerURL(req);
|
||||
|
||||
final String vreName = scope.substring(scope.lastIndexOf("/")+1, scope.length());
|
||||
String fullScope = null;
|
||||
ScopeBean fullScope = null;
|
||||
|
||||
//CHECK IF THE vreName has a valid scope, so it is a valid VRE
|
||||
try {
|
||||
fullScope = LoadingVREsScopeCache.get(vreName);
|
||||
fullScope = LoadingMapOfScopeCache.get(vreName);
|
||||
}catch(ExecutionException e){
|
||||
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
|
||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
|
||||
|
@ -158,29 +160,37 @@ public class CatalogueResolver {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the item catalogue url.
|
||||
* Gets the item catalogue UR ls.
|
||||
*
|
||||
* @param req the req
|
||||
* @param vreName the vre name
|
||||
* @param scopeName the scope name
|
||||
* @param entityContext the entity context
|
||||
* @param entityName the entity name
|
||||
* @return the item catalogue url
|
||||
* @return the item catalogue UR ls
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String vreName, String entityContext, String entityName) throws Exception{
|
||||
protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String scopeName, String entityContext, String entityName) throws Exception{
|
||||
|
||||
try {
|
||||
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
|
||||
String fullScope = "";
|
||||
ScopeBean scopeBean = null;
|
||||
try{
|
||||
fullScope = LoadingVREsScopeCache.get(vreName);
|
||||
scopeBean = LoadingMapOfScopeCache.get(scopeName);
|
||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
||||
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
|
||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name '"+vreName+"'. Is it registered as VRE in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI);
|
||||
logger.error("Error on getting the fullscope from cache for scopeName "+scopeName, e);
|
||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the scope name '"+scopeName+"'. Is it registered as a valid Scope in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI);
|
||||
}
|
||||
|
||||
String fullScope = scopeBean.toString();
|
||||
logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());
|
||||
|
||||
if(scopeBean.is(Type.VO)) {
|
||||
logger.info("It is a {} scope", Type.VO);
|
||||
logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO, Type.INFRASTRUCTURE);
|
||||
fullScope = fullScope.substring(0, fullScope.indexOf("/"));
|
||||
logger.info("Overriden the input scope {} with {} type: {}", fullScope, Type.INFRASTRUCTURE, fullScope);
|
||||
}
|
||||
logger.info("Read fullScope: "+fullScope + " for VRE_NAME: "+vreName +" from cache created by: "+GetAllInfrastructureVREs.class.getSimpleName());
|
||||
|
||||
ScopeProvider.instance.set(fullScope);
|
||||
GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
||||
|
|
|
@ -14,8 +14,9 @@ import javax.ws.rs.WebApplicationException;
|
|||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -61,14 +62,15 @@ public class KnimeGetResolver {
|
|||
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
String fullScope = "";
|
||||
ScopeBean scopeBean = null;
|
||||
try{
|
||||
fullScope = LoadingVREsScopeCache.get(vreName);
|
||||
scopeBean = LoadingMapOfScopeCache.get(vreName);
|
||||
}catch(ExecutionException | InvalidCacheLoadException e){
|
||||
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
|
||||
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
|
||||
}
|
||||
ApplicationProfileReader reader = null;
|
||||
String fullScope = scopeBean.toString();
|
||||
try{
|
||||
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
|
||||
}catch(Exception e){
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
|
||||
|
||||
|
||||
/**
|
||||
* The Class CatalogueResolverTest.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Dec 7, 2016
|
||||
* May 13, 2019
|
||||
*/
|
||||
public class CatalogueResolverTest {
|
||||
|
||||
|
@ -18,19 +21,14 @@ public class CatalogueResolverTest {
|
|||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
// jsonRequest = "{" +
|
||||
// "\"gcube_scope\" : \"/gcube\"," +
|
||||
// "\"entity_context\" : \"dataset\"," +
|
||||
// "\"entity_name\" : \"sarda-sarda\"" +
|
||||
// "}";
|
||||
// //String test = "{" +
|
||||
// // "\"gcube_scope\" : \"/gcube\"," +
|
||||
// // "\"entity_context\" : \"dataset\"," +
|
||||
// // "\"entity_name\" : \"sarda-sarda\"," +
|
||||
// // "\"query\" : {\"key1\" : \"value1\", \"key2\":\"value2\"}" +
|
||||
//
|
||||
//
|
||||
// // "}";
|
||||
try {
|
||||
|
||||
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
|
||||
//ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
|
||||
GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
||||
System.out.println(ckanCatalogueReference.toString());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,18 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
||||
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
|
||||
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
|
@ -32,9 +38,9 @@ import org.xml.sax.InputSource;
|
|||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Nov 8, 2018
|
||||
*/
|
||||
public class GetAllInfrastructureVREs {
|
||||
public class GetAllInfrastructureScopesFromIS {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureVREs.class);
|
||||
public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureScopesFromIS.class);
|
||||
|
||||
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
|
||||
|
||||
|
@ -45,47 +51,81 @@ public class GetAllInfrastructureVREs {
|
|||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
// //TODO TOKEN TO ROOT SCOPE
|
||||
// String rootScope = "/gcube";
|
||||
// //String rootScope = "/d4science.research-infrastructures.eu";
|
||||
// ScopeProvider.instance.set(rootScope);
|
||||
//
|
||||
// String secondaryType = "INFRASTRUCTURE";
|
||||
// List<String> listVOScopes = getListOfVOScopes("INFRASTRUCTURE");
|
||||
//
|
||||
// System.out.println("Searching for secondaryType="+secondaryType +" scope/s found is/are: " +listVOScopes);
|
||||
//
|
||||
// Map<String, String> vreNameFullScope = new HashMap<String,String>();
|
||||
//
|
||||
// secondaryType = "VRE";
|
||||
// int noVOTypeCount = 0;
|
||||
// for (String voScope : listVOScopes) {
|
||||
// int count = voScope.length() - voScope.replace("/", "").length();
|
||||
// //IS A VO
|
||||
// if(count==2){
|
||||
// logger.info(voScope +" is a VO...");
|
||||
// ScopeProvider.instance.set(voScope);
|
||||
// List<String> listVREs = getListOfResourcesForSecondaryType(secondaryType);
|
||||
// System.out.println("VREs found for VO "+voScope+ " is/are "+listVREs.size()+ ": "+listVREs);
|
||||
// for (String vreName : listVREs) {
|
||||
// String vreScope = String.format("%s/%s", voScope,vreName);
|
||||
// vreNameFullScope.put(vreName, vreScope);
|
||||
// }
|
||||
//
|
||||
// }else{
|
||||
// noVOTypeCount++;
|
||||
// System.out.println(voScope +" is not a VO, skipping it");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// System.out.println("Total VO is: "+(listVOScopes.size()+noVOTypeCount));
|
||||
// for (String vreName : vreNameFullScope.keySet()) {
|
||||
// System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
|
||||
// }
|
||||
//
|
||||
// System.out.println("Total VRE is: "+vreNameFullScope.size());
|
||||
|
||||
|
||||
//TODO TOKEN TO ROOT SCOPE
|
||||
String rootScope = "/gcube";
|
||||
//String rootScope = "/d4science.research-infrastructures.eu";
|
||||
ScopeProvider.instance.set(rootScope);
|
||||
UriResolverSmartGearManagerInit.setRootContextScope(rootScope);
|
||||
LoadingMapOfScopeCache cache = new LoadingMapOfScopeCache();
|
||||
|
||||
String secondaryType = "INFRASTRUCTURE";
|
||||
List<String> listVOScopes = getListOfVOScopes("INFRASTRUCTURE");
|
||||
|
||||
System.out.println("Searching for secondaryType="+secondaryType +" scope/s found is/are: " +listVOScopes);
|
||||
|
||||
Map<String, String> vreNameFullScope = new HashMap<String,String>();
|
||||
|
||||
secondaryType = "VRE";
|
||||
int noVOTypeCount = 0;
|
||||
for (String voScope : listVOScopes) {
|
||||
int count = voScope.length() - voScope.replace("/", "").length();
|
||||
//IS A VO
|
||||
if(count==2){
|
||||
logger.info(voScope +" is a VO...");
|
||||
ScopeProvider.instance.set(voScope);
|
||||
List<String> listVREs = getListOfResourcesForSecondaryType(secondaryType);
|
||||
System.out.println("VREs found for VO "+voScope+ " is/are "+listVREs.size()+ ": "+listVREs);
|
||||
for (String vreName : listVREs) {
|
||||
String vreScope = String.format("%s/%s", voScope,vreName);
|
||||
vreNameFullScope.put(vreName, vreScope);
|
||||
}
|
||||
|
||||
}else{
|
||||
noVOTypeCount++;
|
||||
System.out.println(voScope +" is not a VO, skipping it");
|
||||
int i = 0;
|
||||
for (String string : cache.getCache().asMap().keySet()) {
|
||||
try {
|
||||
System.out.println(++i+") Scope Name: "+string + " to full scope: "+LoadingMapOfScopeCache.get(string));
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String scopeName = "devsec";
|
||||
ScopeBean scopeBean = LoadingMapOfScopeCache.get(scopeName);
|
||||
String fullScope = scopeBean.toString();
|
||||
logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());
|
||||
|
||||
System.out.println("Total VO is: "+(listVOScopes.size()+noVOTypeCount));
|
||||
for (String vreName : vreNameFullScope.keySet()) {
|
||||
System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
|
||||
if(scopeBean.is(Type.VO)) {
|
||||
logger.info("It is a {} scope", Type.VO);
|
||||
logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO, Type.INFRASTRUCTURE);
|
||||
fullScope = fullScope.substring(0, fullScope.indexOf("/"));
|
||||
logger.info("Overriden the input scope {} with {} type: {}", fullScope, Type.INFRASTRUCTURE, fullScope);
|
||||
}
|
||||
|
||||
System.out.println("Total VRE is: "+vreNameFullScope.size());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue