From 18a451138fba291c86a5f0edc8d27afac7437df9 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Tue, 17 Sep 2019 17:55:53 +0200 Subject: [PATCH] my-vres --- distro/changelog.xml | 4 ++++ .../my_vres/server/DistributedCacheClient.java | 6 +++--- .../user/my_vres/server/MyVREsServiceImpl.java | 15 ++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index e10679c..5658a6f 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + It provides part of the gcube oAuth2 service with capability to be deployed on a multi instance cluster, it no longer posts the temporary code to the oAuth service, it places it in the memcahced cluster. + Ported to GWT 2.8.1 diff --git a/src/main/java/org/gcube/portlet/user/my_vres/server/DistributedCacheClient.java b/src/main/java/org/gcube/portlet/user/my_vres/server/DistributedCacheClient.java index 6dbd14c..5395778 100644 --- a/src/main/java/org/gcube/portlet/user/my_vres/server/DistributedCacheClient.java +++ b/src/main/java/org/gcube/portlet/user/my_vres/server/DistributedCacheClient.java @@ -3,7 +3,6 @@ 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; @@ -17,6 +16,7 @@ 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.KetamaConnectionFactory; import net.spy.memcached.MemcachedClient; /** @@ -43,8 +43,8 @@ public class DistributedCacheClient { private DistributedCacheClient(){ List addrs = discoverHostOfServiceEndpoint(); try { - mClient = new MemcachedClient(addrs); - } catch (IOException e) { + mClient = new MemcachedClient(new KetamaConnectionFactory(), addrs); + } catch (Exception e) { e.printStackTrace(); } } diff --git a/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java b/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java index 7294c49..0995f4a 100644 --- a/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java +++ b/src/main/java/org/gcube/portlet/user/my_vres/server/MyVREsServiceImpl.java @@ -36,6 +36,7 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.service.UserLocalServiceUtil; import net.spy.memcached.MemcachedClient; +import net.spy.memcached.internal.OperationFuture; /** * The server side implementation of the RPC service. @@ -45,9 +46,7 @@ import net.spy.memcached.MemcachedClient; public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsService { private static final Logger _log = LoggerFactory.getLogger(MyVREsServiceImpl.class); - /** - * - */ + public static final String CACHED_VOS = "CACHED_VRES"; /** * needed when querying for authorised services in authentication @@ -96,7 +95,6 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer LinkedHashMap> toReturn = new LinkedHashMap>(); - List currentSiteVGroups = gm.getVirtualGroups(ManagementUtils.getSiteGroupIdFromServletRequest(getThreadLocalRequest().getServerName())); for (VirtualGroup vg : currentSiteVGroups) { String gName = vg.getName(); @@ -349,6 +347,7 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer */ @SuppressWarnings("unchecked") private boolean authorizeApplication(String infrastructureName, String qToken, String tempCode, String clientId, String redirectURL) { + OperationFuture writeOp = null; try { //instance the client if first time if (entries == null) @@ -361,12 +360,14 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer object.put("redirect_uri", redirectURL); object.put("client_id", clientId); String JSONData = object.toJSONString(); - entries.set(tempCode, CACHE_SECONDS_EXPIRATION, JSONData); + writeOp = entries.set(tempCode, CACHE_SECONDS_EXPIRATION, JSONData); + + } catch (Exception e) { e.printStackTrace(); - return false; + return writeOp.getStatus().isSuccess(); } - return true; + return writeOp.getStatus().isSuccess(); }