fixing bug on catalogue resolver

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174046 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-07 14:12:14 +00:00
parent c8c531b681
commit e08a47c5d7
2 changed files with 26 additions and 25 deletions

View File

@ -3,7 +3,6 @@
*/ */
package org.gcube.datatransfer.resolver.caches; package org.gcube.datatransfer.resolver.caches;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
@ -52,29 +51,39 @@ public class LoadingCatalogueApplicationProfilesCache {
public void onRemoval(RemovalNotification<String, String> arg0) { public void onRemoval(RemovalNotification<String, String> arg0) {
logger.info("cache expired"); logger.info("cache expired");
//prePopulateCache();
} }
}; };
catalogueApplicationProfiles = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite( catalogueApplicationProfiles = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
1, TimeUnit.HOURS).removalListener(removalListener). 1, TimeUnit.DAYS).removalListener(removalListener).
build(loader); build(loader);
//Populating the cache at init stage
populateTheCache();
logger.info("Pre-Loaded CatalogueApplicationProfiles cache with: "+catalogueApplicationProfiles.asMap().size()+" item/s");
}
/**
* Populate the cache.
*/
private static void populateTheCache(){
try{ try{
//PRE-POPULATE CACHE //POPULATE THE CACHE READING THE RESOURCE "CATALOGUE-RESOLVER"
logger.info("Trying to pre-poluate catalogue resolver cache"); logger.info("Trying to pre-populate catalogue resolver cache");
ScopeProvider.instance.set(UriResolverStartupListener.getRootContextScope()); ScopeProvider.instance.set(UriResolverStartupListener.getRootContextScope());
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getRootContextScope(), true); ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getRootContextScope(), true);
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope()); catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
logger.info("Cache populated with: "+catalogueApplicationProfiles.asMap().toString());
logger.info("cache instancied"); //logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
}catch(Exception e){ }catch(Exception e){
}finally{ }finally{
} }
} }
/** /**
@ -96,19 +105,12 @@ public class LoadingCatalogueApplicationProfilesCache {
*/ */
public static String loadFullScopeByApplicationProfile(String vreName){ public static String loadFullScopeByApplicationProfile(String vreName){
String fullScope = null; //THIS CHECK SHOULD BE NOT NEEDED
try { String fullScope = catalogueApplicationProfiles.getIfPresent(vreName);
fullScope = catalogueApplicationProfiles.get(vreName);
}
catch (ExecutionException e) {
logger.warn("ExecutionException: ",e);
}
if(fullScope==null){ if(fullScope==null){
logger.debug("FullScope is null for VRE_NAME: "+vreName+" into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", reading profile again"); populateTheCache();
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getRootContextScope(), true); fullScope = catalogueApplicationProfiles.getIfPresent(vreName);
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
} }
return fullScope; return fullScope;

View File

@ -19,7 +19,6 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.gcube.datatransfer.resolver.util.HTTPCallsUtils; import org.gcube.datatransfer.resolver.util.HTTPCallsUtils;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -41,7 +40,7 @@ public class TestResolvers {
* Storage hub test. * Storage hub test.
* @throws Exception * @throws Exception
*/ */
@Test //@Test
public void storageHubTest() throws Exception{ public void storageHubTest() throws Exception{
String storageHubId = "2019b881-083b-444a-81be-8abee4b91020"; String storageHubId = "2019b881-083b-444a-81be-8abee4b91020";
@ -84,7 +83,7 @@ public class TestResolvers {
* Storage hub test. * Storage hub test.
* @throws Exception * @throws Exception
*/ */
@Test //@Test
public void storageIDTest() throws Exception{ public void storageIDTest() throws Exception{
String storageID = "clZ2YmxTYytETzVLaHkwMjM3TmVETTFMb256YVRMS3lHbWJQNStIS0N6Yz0"; String storageID = "clZ2YmxTYytETzVLaHkwMjM3TmVETTFMb256YVRMS3lHbWJQNStIS0N6Yz0";
@ -165,7 +164,7 @@ public class TestResolvers {
* Storage hub test. * Storage hub test.
* @throws Exception * @throws Exception
*/ */
@Test //@Test
public void catalogueResolverTest() throws Exception{ public void catalogueResolverTest() throws Exception{
String entityName = "sarda-sarda"; String entityName = "sarda-sarda";
@ -205,7 +204,7 @@ public class TestResolvers {
* Storage hub test. * Storage hub test.
* @throws Exception * @throws Exception
*/ */
@Test //@Test
public void catalogueResolverCreatePublicItemURLTest() throws Exception{ public void catalogueResolverCreatePublicItemURLTest() throws Exception{
String entityName = "sarda-sarda"; String entityName = "sarda-sarda";
@ -248,7 +247,7 @@ public class TestResolvers {
* Storage hub test. * Storage hub test.
* @throws Exception * @throws Exception
*/ */
@Test //@Test
public void catalogueResolverCreatePubrivatetemURLTest() throws Exception{ public void catalogueResolverCreatePubrivatetemURLTest() throws Exception{
String entityName = "dynamic_reporting"; String entityName = "dynamic_reporting";