nikolas.laskaris 2016-09-21 15:31:25 +00:00
parent 1c9c4041c7
commit 15d687462e
5 changed files with 961 additions and 870 deletions

View File

@ -74,8 +74,8 @@
<dependency> <dependency>
<groupId>org.gcube.resources</groupId> <groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId> <artifactId>registry-publisher</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> <!-- <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> -->
<!-- <version>[1.2.4-SNAPSHOT, 2.0.0-SNAPSHOT)</version> --> <version>[1.2.4-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<!-- changed from version 1.1.0-SNAPSHOT. If this change introduces problems, please revert --> <!-- changed from version 1.1.0-SNAPSHOT. If this change introduces problems, please revert -->
</dependency> </dependency>

View File

@ -5,8 +5,6 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import javax.servlet.http.HttpSession;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -17,81 +15,75 @@ public class SessionManager {
/** The logger. */ /** The logger. */
private static final Logger logger = LoggerFactory.getLogger(SessionManager.class); private static final Logger logger = LoggerFactory.getLogger(SessionManager.class);
// protected static Thread thread = new CleanSessionThread(); protected static Thread thread = new CleanSessionThread();
protected static SessionManager sessionManager = new SessionManager(); protected static SessionManager sessionManager = new SessionManager();
protected HashMap<String, ASLSession> sessions; protected HashMap<String, ASLSession> sessions;
protected SessionManager() { protected SessionManager() {
sessions = new HashMap<String, ASLSession>(); sessions = new HashMap<String, ASLSession>();
// thread.setDaemon(true); thread.setDaemon(true);
// thread.start(); thread.start();
} }
public static SessionManager getInstance() { public static SessionManager getInstance() {
return sessionManager; return sessionManager;
} }
public void setASLSession(HttpSession userSession, String username){
ASLSession aslSession = new ASLSession(userSession, username);
sessions.put(userSession.getId() + "_" + username, aslSession);
}
public ASLSession getASLSession(String externalSessionID, String username) public ASLSession getASLSession(String externalSessionID, String username)
{ {
ASLSession session = sessions.get(externalSessionID + "_" + username); ASLSession session = sessions.get(externalSessionID + "_" + username);
// if(session == null || !session.isValid() || !session.getUsername().equals(username)) if(session == null || !session.isValid() || !session.getUsername().equals(username))
// { {
// session = new ASLSession(externalSessionID, username); session = new ASLSession(externalSessionID, username);
// sessions.put(externalSessionID + "_" + username, session); sessions.put(externalSessionID + "_" + username, session);
// } }
// if (session.getScope()!=null) //covers first helper's invocation if (session.getScope()!=null) //covers first helper's invocation
// ScopeProvider.instance.set(session.getScopeName()); ScopeProvider.instance.set(session.getScopeName());
//
// if (session.getSecurityToken()!=null){ if (session.getSecurityToken()!=null){
// logger.debug("Setting SecurityTokenProvider to: "+session.getSecurityToken()+" in thread "+Thread.currentThread().getId()); logger.debug("Setting SecurityTokenProvider to: "+session.getSecurityToken()+" in thread "+Thread.currentThread().getId());
// SecurityTokenProvider.instance.set(session.getSecurityToken()); SecurityTokenProvider.instance.set(session.getSecurityToken());
// } }
return session; return session;
} }
// @Override @Override
// protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// thread.interrupt(); thread.interrupt();
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted");
// thread.join(); thread.join();
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was joint"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was joint");
// super.finalize(); super.finalize();
// } }
// protected static class CleanSessionThread extends Thread protected static class CleanSessionThread extends Thread
// { {
// public void run() public void run()
// { {
// while(true) while(true)
// { {
// try { try {
// Thread.sleep(300000); Thread.sleep(300000);
// } catch (InterruptedException e) { } catch (InterruptedException e) {
// logger.error("Exception:", e); logger.error("Exception:", e);
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted (in clean thread)"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted (in clean thread)");
// break; break;
// } }
// //TODO: cleanup invalid sessions: add locks... //TODO: cleanup invalid sessions: add locks...
// Set<String> keys = sessionManager.sessions.keySet(); Set<String> keys = sessionManager.sessions.keySet();
// Iterator<String> iter = keys.iterator(); Iterator<String> iter = keys.iterator();
// while(iter.hasNext()) while(iter.hasNext())
// { {
// String extSessionID = iter.next(); String extSessionID = iter.next();
// if(!sessionManager.sessions.get(extSessionID).isValid()) if(!sessionManager.sessions.get(extSessionID).isValid())
// { {
// sessionManager.sessions.remove(extSessionID); sessionManager.sessions.remove(extSessionID);
// } }
// } }
// } }
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was terminated"); logger.debug(new Date(System.currentTimeMillis()) + " clean thread was terminated");
// } }
//
// } }
} }

View File

@ -26,12 +26,12 @@ import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.application.framework.core.util.CacheEntryConstants; import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString; import org.gcube.application.framework.core.util.QueryString;
import org.gcube.application.framework.core.util.SessionConstants; import org.gcube.application.framework.core.util.SessionConstants;
//import org.gcube.common.resources.gcore.Resources; import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
//import org.gcube.informationsystem.publisher.ScopedPublisher; import org.gcube.informationsystem.publisher.ScopedPublisher;
//import org.gcube.informationsystem.publisher.stubs.registry.faults.PublisherException; import org.gcube.informationsystem.publisher.stubs.registry.faults.PublisherException;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -62,7 +62,7 @@ public class GenericResource implements GenericResourceInfoI {
// protected static ISPublisher publisher = null; // protected static ISPublisher publisher = null;
// protected static ISClient client = null; // protected static ISClient client = null;
// protected static ScopedPublisher scopedPublisher = null; protected static ScopedPublisher scopedPublisher = null;
protected static RegistryPublisher publisher = null; protected static RegistryPublisher publisher = null;
protected static DiscoveryClient<org.gcube.common.resources.gcore.GenericResource> client = null; protected static DiscoveryClient<org.gcube.common.resources.gcore.GenericResource> client = null;
@ -82,7 +82,7 @@ public class GenericResource implements GenericResourceInfoI {
session = SessionManager.getInstance().getASLSession(extrenalSessionID, username); session = SessionManager.getInstance().getASLSession(extrenalSessionID, username);
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); scopedPublisher = RegistryPublisherFactory.scopedPublisher();
publisher = RegistryPublisherFactory.create(); publisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
@ -109,7 +109,7 @@ public class GenericResource implements GenericResourceInfoI {
this.session = session; this.session = session;
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); scopedPublisher = RegistryPublisherFactory.scopedPublisher();
publisher = RegistryPublisherFactory.create(); publisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
@ -316,8 +316,7 @@ public class GenericResource implements GenericResourceInfoI {
//maybe should change the visibility (into public) of addScope() within the Resource class of common-gcore-resources package in order to use it here. //maybe should change the visibility (into public) of addScope() within the Resource class of common-gcore-resources package in order to use it here.
List<String> scopes=new ArrayList<String>(); List<String> scopes=new ArrayList<String>();
scopes.add(session.getScope()); scopes.add(session.getScope());
org.gcube.common.resources.gcore.GenericResource res = scopedPublisher.create(gCubeRes, scopes);
org.gcube.common.resources.gcore.GenericResource res = publisher.create(gCubeRes, scopes);
logger.info("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString()); logger.info("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString());
// 1-oct-2013 -- adding generic resource to cache // 1-oct-2013 -- adding generic resource to cache
@ -576,7 +575,7 @@ public class GenericResource implements GenericResourceInfoI {
// //TODO // //TODO
// CachesManager.getInstance().getGenericResourceCache().get(queryString).setTimeToLive(0); // CachesManager.getInstance().getGenericResourceCache().get(queryString).setTimeToLive(0);
// } // }
} catch (Exception e) { } catch (PublisherException e) {
logger.error("Exception:", e); logger.error("Exception:", e);
throw new RemoteException(); throw new RemoteException();
} }

View File

@ -20,7 +20,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
//import org.gcube.informationsystem.publisher.ScopedPublisher; import org.gcube.informationsystem.publisher.ScopedPublisher;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -32,8 +32,8 @@ public class RuntimeResource {
private static final Logger logger = LoggerFactory.getLogger(RuntimeResource.class); private static final Logger logger = LoggerFactory.getLogger(RuntimeResource.class);
// protected static ScopedPublisher scopedPublisher = null; protected static ScopedPublisher scopedPublisher = null;
protected static RegistryPublisher registryPublisher = null; // protected static RegistryPublisher registryPublisher = null;
protected static DiscoveryClient<ServiceEndpoint> client = null; protected static DiscoveryClient<ServiceEndpoint> client = null;
/** /**
@ -47,9 +47,8 @@ public class RuntimeResource {
session = SessionManager.getInstance().getASLSession(extrenalSessionID, username); session = SessionManager.getInstance().getASLSession(extrenalSessionID, username);
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
scopedPublisher = RegistryPublisherFactory.scopedPublisher();
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); // registryPublisher = RegistryPublisherFactory.create();
registryPublisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
} }
@ -71,8 +70,8 @@ public class RuntimeResource {
this.session = session; this.session = session;
try { try {
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
// scopedPublisher = RegistryPublisherFactory.scopedPublisher(); scopedPublisher = RegistryPublisherFactory.scopedPublisher();
registryPublisher = RegistryPublisherFactory.create(); // registryPublisher = RegistryPublisherFactory.create();
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
} }
@ -96,8 +95,8 @@ public class RuntimeResource {
public String createRuntimeResource(ServiceEndpoint runtimeResource) throws RegistryNotFoundException { public String createRuntimeResource(ServiceEndpoint runtimeResource) throws RegistryNotFoundException {
List<String> scopes = new ArrayList<String>(); List<String> scopes = new ArrayList<String>();
scopes.add(session.getScope()); scopes.add(session.getScope());
// ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes); ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes);
ServiceEndpoint se = registryPublisher.create(runtimeResource); // ServiceEndpoint se = registryPublisher.create(runtimeResource);
logger.debug("Created Runtime Resource with id: "+se.id()+" on scope: "+scopes.toString()); logger.debug("Created Runtime Resource with id: "+se.id()+" on scope: "+scopes.toString());
return se.id(); return se.id();
} }
@ -110,8 +109,8 @@ public class RuntimeResource {
*/ */
public String updateRuntimeResource(ServiceEndpoint runtimeResource) throws RemoteException { public String updateRuntimeResource(ServiceEndpoint runtimeResource) throws RemoteException {
try { try {
// ServiceEndpoint se = scopedPublisher.update(runtimeResource); ServiceEndpoint se = scopedPublisher.update(runtimeResource);
ServiceEndpoint se = registryPublisher.update(runtimeResource); // ServiceEndpoint se = registryPublisher.update(runtimeResource);
logger.debug("Updated Runtime Resource with id: "+runtimeResource.id()+"\tNew id : "+se.id()); logger.debug("Updated Runtime Resource with id: "+runtimeResource.id()+"\tNew id : "+se.id());
return se.id(); return se.id();
} catch (Exception e) { } catch (Exception e) {
@ -130,8 +129,8 @@ public class RuntimeResource {
try { try {
List<String> scopes=new ArrayList<String>(); List<String> scopes=new ArrayList<String>();
scopes.add(session.getScope()); scopes.add(session.getScope());
// ServiceEndpoint se = scopedPublisher.remove(runtimeResource,scopes); ServiceEndpoint se = scopedPublisher.remove(runtimeResource,scopes);
ServiceEndpoint se = registryPublisher.remove(runtimeResource); // ServiceEndpoint se = registryPublisher.remove(runtimeResource);
logger.debug("Deleted Runtime Resource with id: "+runtimeResource.id()); logger.debug("Deleted Runtime Resource with id: "+runtimeResource.id());
return se.id(); return se.id();
} catch (Exception e) { } catch (Exception e) {