git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@82220 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e4fc536d0a
commit
702ea6bfbb
12
pom.xml
12
pom.xml
|
@ -32,13 +32,11 @@
|
||||||
<artifactId>accesslogger</artifactId>
|
<artifactId>accesslogger</artifactId>
|
||||||
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.informationsystem</groupId>
|
<groupId>org.gcube.informationsystem</groupId>
|
||||||
<artifactId>iscache</artifactId>
|
<artifactId>iscache</artifactId>
|
||||||
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.dvos</groupId>
|
<groupId>org.gcube.dvos</groupId>
|
||||||
<artifactId>voms-admin-stubs</artifactId>
|
<artifactId>voms-admin-stubs</artifactId>
|
||||||
|
@ -64,6 +62,16 @@
|
||||||
<artifactId>ghn-core-runtime</artifactId>
|
<artifactId>ghn-core-runtime</artifactId>
|
||||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.personalisation</groupId>
|
||||||
|
<artifactId>profileadministration-client-library</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.personalisation</groupId>
|
||||||
|
<artifactId>userprofileaccess-client-library</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<!--
|
<!--
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.application.framework.core.cache;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.cache.factories.GenericResourceCacheEntryFactory;
|
import org.gcube.application.framework.core.cache.factories.GenericResourceCacheEntryFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import net.sf.ehcache.CacheManager;
|
import net.sf.ehcache.CacheManager;
|
||||||
import net.sf.ehcache.Ehcache;
|
import net.sf.ehcache.Ehcache;
|
||||||
|
@ -29,11 +31,16 @@ public class CachesManager {
|
||||||
|
|
||||||
protected HashMap<String, Ehcache> caches;
|
protected HashMap<String, Ehcache> caches;
|
||||||
|
|
||||||
|
/** The logger. */
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(CachesManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor
|
* The constructor
|
||||||
*/
|
*/
|
||||||
protected CachesManager() {
|
protected CachesManager() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
manager = CacheManager.create(CachesManager.class.getResource("/ehcache.xml"));
|
manager = CacheManager.create(CachesManager.class.getResource("/ehcache.xml"));
|
||||||
|
|
||||||
caches = new HashMap<String, Ehcache>();
|
caches = new HashMap<String, Ehcache>();
|
||||||
|
@ -67,11 +74,11 @@ public class CachesManager {
|
||||||
|
|
||||||
public Ehcache getEhcache (String cacheName, CacheEntryFactory cacheFactory) {
|
public Ehcache getEhcache (String cacheName, CacheEntryFactory cacheFactory) {
|
||||||
if (caches.get(cacheName) == null) {
|
if (caches.get(cacheName) == null) {
|
||||||
|
logger.debug("Didn't find any previous cache for "+cacheName+". Creating a new and returning that.");
|
||||||
Ehcache newCache = manager.getEhcache(cacheName);
|
Ehcache newCache = manager.getEhcache(cacheName);
|
||||||
newCache = new SelfPopulatingCache(newCache, cacheFactory);
|
newCache = new SelfPopulatingCache(newCache, cacheFactory);
|
||||||
caches.put(cacheName, newCache);
|
caches.put(cacheName, newCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
return caches.get(cacheName);
|
return caches.get(cacheName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,75 +1,79 @@
|
||||||
//package org.gcube.application.framework.core.cache;
|
package org.gcube.application.framework.core.cache;
|
||||||
//
|
|
||||||
//import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
////import org.gcube.common.core.scope.GCUBEScope;
|
//import org.gcube.common.core.scope.GCUBEScope;
|
||||||
////import org.gcube.common.core.utils.logging.GCUBELog;
|
//import org.gcube.common.core.utils.logging.GCUBELog;
|
||||||
////import org.gcube.informationsystem.cache.ISCache;
|
//import org.gcube.informationsystem.cache.ISCache;
|
||||||
////import org.gcube.informationsystem.cache.ISCacheManager;
|
//import org.gcube.informationsystem.cache.ISCacheManager;
|
||||||
//import net.sf.ehcache.Cache;
|
import net.sf.ehcache.Cache;
|
||||||
//import net.sf.ehcache.CacheManager;
|
import net.sf.ehcache.CacheManager;
|
||||||
//
|
|
||||||
//import org.gcube.resources.discovery.icclient.ICClient;
|
import org.gcube.informationsystem.cache.ISCache;
|
||||||
//import org.slf4j.Logger;
|
import org.gcube.informationsystem.cache.ISCacheManager;
|
||||||
//import org.slf4j.LoggerFactory;
|
import org.gcube.resources.discovery.icclient.ICClient;
|
||||||
//
|
import org.slf4j.Logger;
|
||||||
//
|
import org.slf4j.LoggerFactory;
|
||||||
///**
|
|
||||||
// * This class manages the running harvester threads.
|
|
||||||
// *
|
/**
|
||||||
// * @author Valia Tsagkalidou (KNUA)
|
* This class manages the running harvester threads.
|
||||||
// *
|
*
|
||||||
// */
|
* @author Valia Tsagkalidou (KNUA)
|
||||||
//
|
*
|
||||||
//public class RIsManager {
|
*/
|
||||||
//
|
|
||||||
//
|
public class RIsManager {
|
||||||
// /**
|
|
||||||
// * Defines the manager's instance
|
|
||||||
// */
|
/**
|
||||||
// private static RIsManager instance = null;
|
* Defines the manager's instance
|
||||||
//
|
*/
|
||||||
// /**
|
private static RIsManager instance = null;
|
||||||
// * keeps the ISCache per scope
|
|
||||||
// */
|
/**
|
||||||
//
|
* keeps the ISCache per scope
|
||||||
//// protected HashMap<String, ISCache> isCaches;
|
*/
|
||||||
//
|
|
||||||
// protected HashMap<String, Cache> caches; //(scope,iccache) pairs
|
// protected HashMap<String, ISCache> isCaches;
|
||||||
//
|
|
||||||
// /** Object logger. */
|
protected HashMap<String, Cache> caches; //(scope,iccache) pairs
|
||||||
//
|
|
||||||
// protected static final Logger logger = LoggerFactory.getLogger(RIsManager.class);
|
/** Object logger. */
|
||||||
//
|
|
||||||
// /**
|
protected static final Logger logger = LoggerFactory.getLogger(RIsManager.class);
|
||||||
// * Initializes RIsManager
|
|
||||||
// */
|
/**
|
||||||
// private RIsManager() {
|
* Initializes RIsManager
|
||||||
// caches = new HashMap<String, Cache>();
|
*/
|
||||||
// }
|
private RIsManager() {
|
||||||
//
|
caches = new HashMap<String, Cache>();
|
||||||
// /**
|
}
|
||||||
// * Retrieves the singleton
|
|
||||||
// * @return the only instance of RIsManager
|
/**
|
||||||
// */
|
* Retrieves the singleton
|
||||||
// synchronized public static RIsManager getInstance() {
|
* @return the only instance of RIsManager
|
||||||
// if (instance == null)
|
*/
|
||||||
// instance = new RIsManager();
|
synchronized public static RIsManager getInstance() {
|
||||||
// return instance;
|
if (instance == null)
|
||||||
// }
|
instance = new RIsManager();
|
||||||
//
|
return instance;
|
||||||
// /**
|
}
|
||||||
// * @param scope the GGUBEScope for which the RIs are requested
|
|
||||||
// * @return the ISCache for this specific scope
|
|
||||||
// */
|
// TODO: UNCOMMENT AND FIX THIS FUNCTION TO COMPLY WITH THE FeatherWeight Stack
|
||||||
|
/**
|
||||||
|
* @param scope the GGUBEScope for which the RIs are requested
|
||||||
|
* @return the ISCache for this specific scope
|
||||||
|
*/
|
||||||
// public synchronized Cache getISCache(String scope)
|
// public synchronized Cache getISCache(String scope)
|
||||||
// {
|
// {
|
||||||
// Cache info = caches.get(scope);
|
// ISCache info = caches.get(scope);
|
||||||
// if(info == null)
|
// if(info == null)
|
||||||
// {
|
// {
|
||||||
// // If the ISCache in not already created, then it creates a new instance and adds it to the HashMap
|
// // If the ISCache in not already created, then it creates a new instance and adds it to the HashMap
|
||||||
// try {
|
// try {
|
||||||
// CacheManager. //addManager(scope);
|
// CacheManager.addManager(scope);
|
||||||
// info = CacheManager.getCacheManager(scope). .getManager(scope).getCache();
|
// info = ISCacheManager.getCacheManager(scope).getManager(scope).getCache();
|
||||||
// caches.put(scope, info);
|
// caches.put(scope, info);
|
||||||
// try {
|
// try {
|
||||||
// Thread.sleep(5000);
|
// Thread.sleep(5000);
|
||||||
|
@ -82,5 +86,5 @@
|
||||||
// }
|
// }
|
||||||
// return info;
|
// return info;
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
||||||
{ //Retrieving generic resources based on their ID
|
{ //Retrieving generic resources based on their ID
|
||||||
query.addCondition("$resource/ID eq '"+querySt.get(CacheEntryConstants.id)+"'");
|
query.addCondition("$resource/ID eq '"+querySt.get(CacheEntryConstants.id)+"'");
|
||||||
// query.addAtomicConditions(new AtomicCondition("/ID", querySt.get(CacheEntryConstants.id)));
|
// query.addAtomicConditions(new AtomicCondition("/ID", querySt.get(CacheEntryConstants.id)));
|
||||||
|
|
||||||
}
|
}
|
||||||
// else if(querySt.containsKey(CacheEntryConstants.name) && querySt.get(CacheEntryConstants.name).equals(SessionConstants.ScenarioSchemaInfo))
|
// else if(querySt.containsKey(CacheEntryConstants.name) && querySt.get(CacheEntryConstants.name).equals(SessionConstants.ScenarioSchemaInfo))
|
||||||
// { //Retrieving the generic resource that represents the static search configuration
|
// { //Retrieving the generic resource that represents the static search configuration
|
||||||
|
@ -85,7 +84,7 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
||||||
else if(querySt.containsKey(CacheEntryConstants.name))
|
else if(querySt.containsKey(CacheEntryConstants.name))
|
||||||
{ //Retrieving generic resources based on their name
|
{ //Retrieving generic resources based on their name
|
||||||
query.addCondition("$resource/Profile/Name eq '"+querySt.get(CacheEntryConstants.name)+"'");
|
query.addCondition("$resource/Profile/Name eq '"+querySt.get(CacheEntryConstants.name)+"'");
|
||||||
// query.addAtomicConditions(new AtomicCondition("/Profile/Name", querySt.get(CacheEntryConstants.name)));
|
// query.addCondition("$resource/Profile/Body/VRE eq '"+querySt.get(CacheEntryConstants.vre)+"'");
|
||||||
}
|
}
|
||||||
else if(querySt.containsKey(CacheEntryConstants.vreResource))
|
else if(querySt.containsKey(CacheEntryConstants.vreResource))
|
||||||
{
|
{
|
||||||
|
@ -120,8 +119,6 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
||||||
for (GenericResource resource : results) {
|
for (GenericResource resource : results) {
|
||||||
ScopeGroup<String> scopes = resource.scopes();
|
ScopeGroup<String> scopes = resource.scopes();
|
||||||
logger.info("Number of scopes for ScenarioSchemaInfo: " + scopes.size());
|
logger.info("Number of scopes for ScenarioSchemaInfo: " + scopes.size());
|
||||||
String [] sc = (String[]) scopes.toArray();
|
|
||||||
logger.info(sc.toString());
|
|
||||||
if(scopes.contains(scope))
|
if(scopes.contains(scope))
|
||||||
newResult.add(resource);
|
newResult.add(resource);
|
||||||
}
|
}
|
||||||
|
@ -141,12 +138,36 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
||||||
results = newResult;
|
results = newResult;
|
||||||
}
|
}
|
||||||
logger.debug("size of results: " + results.size());
|
logger.debug("size of results: " + results.size());
|
||||||
|
|
||||||
|
logger.debug("Printing filtered results contents: ");
|
||||||
|
for(GenericResource genRes : results){
|
||||||
|
logger.debug("genRes.id():"+genRes.id());
|
||||||
|
logger.debug("genRes.profile().body():"+genRes.profile().body());
|
||||||
|
for(String s : genRes.scopes())
|
||||||
|
logger.debug("scope:"+s);
|
||||||
|
logger.debug("genRes.profile().bodyAsString():"+genRes.profile().bodyAsString());
|
||||||
|
logger.debug("genRes.profile().description():"+genRes.profile().description());
|
||||||
|
logger.debug("genRes.profile().name():"+genRes.profile().name());
|
||||||
|
logger.debug("genRes.profile().type():"+genRes.profile().type());
|
||||||
|
}
|
||||||
|
|
||||||
List<ISGenericResource> res = new ArrayList<ISGenericResource>();
|
List<ISGenericResource> res = new ArrayList<ISGenericResource>();
|
||||||
for(GenericResource resource : results)
|
for(GenericResource resource : results)
|
||||||
{
|
{
|
||||||
ISGenericResource genResource = new ISGenericResource(resource.id(), resource.profile().name(),resource.profile().description(),resource.profile().body().toString(),resource.profile().type());
|
ISGenericResource genResource = new ISGenericResource(resource.id(), resource.profile().name(),resource.profile().description(),resource.profile().bodyAsString(),resource.profile().type());
|
||||||
res.add(genResource);
|
res.add(genResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug("Printing res contents: ");
|
||||||
|
for(ISGenericResource gr : res){
|
||||||
|
logger.debug("gr.getBody():"+gr.getBody());
|
||||||
|
logger.debug("gr.getDescription():"+gr.getDescription());
|
||||||
|
logger.debug("gr.getId():"+gr.getId());
|
||||||
|
logger.debug("gr.getName():"+gr.getName());
|
||||||
|
logger.debug("gr.getSecondaryType():"+gr.getSecondaryType());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("",e);
|
logger.error("",e);
|
||||||
|
|
|
@ -167,7 +167,18 @@ public class GenericResource implements GenericResourceInfoI {
|
||||||
List<String> scopes=new ArrayList<String>();
|
List<String> scopes=new ArrayList<String>();
|
||||||
scopes.add(session.getScope());
|
scopes.add(session.getScope());
|
||||||
Resource res = scopedPublisher.create(gCubeRes, scopes);
|
Resource res = scopedPublisher.create(gCubeRes, scopes);
|
||||||
logger.trace("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString());
|
logger.info("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString());
|
||||||
|
|
||||||
|
//NIK-- 1/oct/2013 -- adding generic resource to cache
|
||||||
|
logger.info("Adding it also in cache...");
|
||||||
|
List<ISGenericResource> genRes = new ArrayList<ISGenericResource>();
|
||||||
|
genRes.add(genericResource);
|
||||||
|
QueryString query1 = new QueryString();
|
||||||
|
query1.addParameter(CacheEntryConstants.id, genericResource.getId());
|
||||||
|
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||||
|
CachesManager.getInstance().getGenericResourceCache().put(new net.sf.ehcache.Element(query1, genRes));
|
||||||
|
logger.info("...added in cache");
|
||||||
|
|
||||||
return res.id();
|
return res.id();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
|
@ -209,29 +220,32 @@ public class GenericResource implements GenericResourceInfoI {
|
||||||
scopes.add(scope);
|
scopes.add(scope);
|
||||||
// Resource res = scopedPublisher.update(gCubeRes, scopes);
|
// Resource res = scopedPublisher.update(gCubeRes, scopes);
|
||||||
Resource res = publisher.update(gCubeRes); //alternative of the above, if we don't want to define a scope -- better use scopedPublisher
|
Resource res = publisher.update(gCubeRes); //alternative of the above, if we don't want to define a scope -- better use scopedPublisher
|
||||||
logger.info("Updated generic resource ! New ID: "+res.id());
|
logger.info("Updated generic resource on IS ! New ID: "+res.id());
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Exception during update of generic resource:", e);
|
logger.error("Exception during update of generic resource:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QueryString query1 = new QueryString();
|
||||||
|
query1.addParameter(CacheEntryConstants.name, genericResource.getName().trim());
|
||||||
|
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||||
|
if(CachesManager.getInstance().getGenericResourceCache().isElementInMemory(query1) || CachesManager.getInstance().getGenericResourceCache().isElementOnDisk(query1))
|
||||||
|
{
|
||||||
|
logger.info("Replacing generic resource in cache...");
|
||||||
|
CachesManager.getInstance().getGenericResourceCache().get(query1).setTimeToLive(0);
|
||||||
|
CachesManager.getInstance().getGenericResourceCache().remove(query1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.info("The generic resource to replace in cache was not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
query1.clear();
|
||||||
List<ISGenericResource> genRes = new ArrayList<ISGenericResource>();
|
List<ISGenericResource> genRes = new ArrayList<ISGenericResource>();
|
||||||
genRes.add(genericResource);
|
genRes.add(genericResource);
|
||||||
QueryString query1 = new QueryString();
|
|
||||||
query1.addParameter(CacheEntryConstants.id, genericResource.getId());
|
query1.addParameter(CacheEntryConstants.id, genericResource.getId());
|
||||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||||
CachesManager.getInstance().getGenericResourceCache().put(new net.sf.ehcache.Element(query1, genRes));
|
CachesManager.getInstance().getGenericResourceCache().put(new net.sf.ehcache.Element(query1, genRes));
|
||||||
|
|
||||||
query1.clear();
|
|
||||||
query1.put(CacheEntryConstants.name, genericResource.getName().trim());
|
|
||||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
|
||||||
if(CachesManager.getInstance().getGenericResourceCache().isElementInMemory(query1) || CachesManager.getInstance().getGenericResourceCache().isElementOnDisk(query1))
|
|
||||||
{
|
|
||||||
//CachesManager.getInstance().getGenericResourceCache().get(query1).setTimeToLive(-1);
|
|
||||||
CachesManager.getInstance().getGenericResourceCache().remove(query1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logger.info("The generic resource was not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
|
|
Loading…
Reference in New Issue