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

View File

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