Feature #17265, provide oAuth2 service with capability to be deployed on
a multi instance clustermaster
parent
f6de43b5ef
commit
e3fba7691e
@ -0,0 +1,48 @@
|
||||
# gCube System - My VREs Portlet
|
||||
|
||||
|
||||
## Structure of the project
|
||||
|
||||
* The source code is present in the src folder.
|
||||
|
||||
## Built With
|
||||
|
||||
* [OpenJDK](https://openjdk.java.net/) - The JDK used
|
||||
* [Maven](https://maven.apache.org/) - Dependency Management
|
||||
|
||||
## Documentation
|
||||
|
||||
* Use of this service is described in the [Wiki](https://wiki.gcube-system.org/gcube/User%27s_Guide).
|
||||
|
||||
## Change log
|
||||
|
||||
See [Releases](https://code-repo.d4science.org/gCubeSystem/my-vres/releases).
|
||||
|
||||
## Authors
|
||||
|
||||
* **Massimiliano Assante** - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
|
||||
|
||||
## Maintainers
|
||||
|
||||
* **Massimiliano Assante** - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the EUPL V.1.1 License - see the [LICENSE.md](LICENSE.md) file for details.
|
||||
|
||||
|
||||
## About the gCube Framework
|
||||
This software is part of the [gCubeFramework](https://www.gcube-system.org/ "gCubeFramework"): an
|
||||
open-source software toolkit used for building and operating Hybrid Data
|
||||
Infrastructures enabling the dynamic deployment of Virtual Research Environments
|
||||
by favouring the realisation of reuse oriented policies.
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- DILIGENT (grant no. 004260);
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- D4Science (grant no. 212488), D4Science-II (grant no.239019), ENVRI (grant no. 283465), EUBrazilOpenBio (grant no. 288754), iMarine(grant no. 283644);
|
||||
- the H2020 research and innovation programme
|
||||
- BlueBRIDGE (grant no. 675680), EGIEngage (grant no. 654142), ENVRIplus (grant no. 654182), Parthenos (grant no. 654119), SoBigData (grant no. 654024),DESIRA (grant no. 818194), ARIADNEplus (grant no. 823914), RISIS2 (grant no. 824091), PerformFish (grant no. 727610), AGINFRAplus (grant no. 731001);
|
||||
|
@ -0,0 +1,107 @@
|
||||
package org.gcube.portlet.user.my_vres.server;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.resources.gcore.utils.Group;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.spy.memcached.MemcachedClient;
|
||||
|
||||
/**
|
||||
* @author Massimiliano Assante at ISTI-CNR
|
||||
*/
|
||||
public class DistributedCacheClient {
|
||||
|
||||
// Logger
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DistributedCacheClient.class);
|
||||
|
||||
private static final String MEMCACHED_RESOURCE_NAME = "Memcached";
|
||||
private static final String CATEGORY = "Database";
|
||||
|
||||
private MemcachedClient mClient;
|
||||
|
||||
/**
|
||||
* Singleton object
|
||||
*/
|
||||
private static DistributedCacheClient singleton = new DistributedCacheClient();
|
||||
|
||||
/**
|
||||
* Build the singleton instance
|
||||
*/
|
||||
private DistributedCacheClient(){
|
||||
List<InetSocketAddress> addrs = discoverHostOfServiceEndpoint();
|
||||
try {
|
||||
mClient = new MemcachedClient(addrs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the singleton instance
|
||||
*/
|
||||
public static DistributedCacheClient getInstance(){
|
||||
if (singleton == null) {
|
||||
singleton = new DistributedCacheClient();
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public MemcachedClient getMemcachedClient() {
|
||||
return mClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve endpoint resoruce from IS
|
||||
* @return List of InetSocketAddresses
|
||||
* @throws Exception
|
||||
*/
|
||||
private static List<InetSocketAddress> discoverHostOfServiceEndpoint(){
|
||||
|
||||
String currentScope = ScopeProvider.instance.get();
|
||||
String infrastructure = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||
ScopeProvider.instance.set(infrastructure);
|
||||
List<InetSocketAddress> toReturn = new ArrayList<InetSocketAddress>();
|
||||
try{
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Name/text() eq '"+ MEMCACHED_RESOURCE_NAME +"'");
|
||||
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'");
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> ses = client.submit(query);
|
||||
if (ses.isEmpty()) {
|
||||
logger.error("There is no Memcached cluster having name: " + MEMCACHED_RESOURCE_NAME + " and Category " + CATEGORY + " on root context in this infrastructure: ");
|
||||
return null;
|
||||
}
|
||||
for (ServiceEndpoint se : ses) {
|
||||
Group<AccessPoint> aps = se.profile().accessPoints();
|
||||
for (AccessPoint ap : aps.asCollection()) {
|
||||
String address = ap.address(); //e.g. socialnetworking-d-d4s.d4science.org:11211
|
||||
String[] splits = address.split(":");
|
||||
String hostname = splits[0];
|
||||
int port = Integer.parseInt(splits[1]);
|
||||
toReturn.add(new InetSocketAddress(hostname, port));
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch(Exception e){
|
||||
logger.error("Error while retrieving hosts for the Memcached cluster having name: " + MEMCACHED_RESOURCE_NAME + " and Category " + CATEGORY + " on root context");
|
||||
}finally{
|
||||
ScopeProvider.instance.set(currentScope);
|
||||
}
|
||||
ScopeProvider.instance.set(currentScope);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue