added possibility to look doe service endpoint RConnector resource in the scope

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/rstudio-wrapper-portlet@131414 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-09-15 15:36:41 +00:00
parent c183b09563
commit f09a529630
7 changed files with 77 additions and 11 deletions

View File

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/rstudio-wrapper-portlet-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/rstudio-wrapper-portlet-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/rstudio-wrapper-portlet-1.0.0-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<classpathentry kind="src" output="target/rstudio-wrapper-portlet-1.1.0-SNAPSHOT/WEB-INF/classes" path="target/generated-sources/gwt">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/rstudio-wrapper-portlet-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/rstudio-wrapper-portlet-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -56,5 +56,5 @@
</classpathentry>
<classpathentry kind="lib" path="/Users/massi/portal/externals/GWT/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/Users/massi/portal/externals/GWT/gwt-2.7.0/validation-api-1.0.0.GA.jar" sourcepath="/Users/massi/portal/externals/GWT/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/rstudio-wrapper-portlet-1.0.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/rstudio-wrapper-portlet-1.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -49,5 +49,6 @@
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>com.google.gwt.eclipse.core.gwtNature</nature>
<nature>com.liferay.ide.core.liferayNature</nature>
</natures>
</projectDescription>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="rstudio-wrapper-portlet">
<wb-module deploy-name="rstudio-wrapper-portlet-portlet">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>

View File

@ -2,8 +2,8 @@
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.jaxrs" version="2.0"/>
<installed facet="liferay.portlet" version="6.0"/>
<installed facet="liferay.portlet" version="6.2"/>
</faceted-project>

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>rstudio-wrapper-portlet</artifactId>
<packaging>war</packaging>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>RStudio Wrapper Portlet</name>
<properties>
@ -70,6 +70,11 @@
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>

View File

@ -7,13 +7,21 @@ import java.util.List;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
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.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.rstudio_wrapper_portlet.client.RStudioService;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import static org.gcube.data.analysis.rconnector.client.Constants.rConnector;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@ -24,6 +32,8 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class RStudioServiceImpl extends RemoteServiceServlet implements RStudioService {
private static final Logger _log = LoggerFactory.getLogger(RStudioServiceImpl.class);
private static final String SERVICE_EP_NAME = "RConnector";
private static final String CATEGORY = "DataAnalysis";
/**
* the current ASLSession
* @return the session
@ -51,13 +61,55 @@ public class RStudioServiceImpl extends RemoteServiceServlet implements RStudioS
String toReturn = "";
String token = getASLSession().getSecurityToken();
try {
_log.debug("calling rConnector with token = "+token);
toReturn = rConnector().build().connect().toURL().toExternalForm();
} catch (MalformedURLException e) {
String scope = getASLSession().getScope();
_log.debug("calling rConnector with scope = " + scope + " and token = "+token );
List<ServiceEndpoint> resources = getRStudioServiceEndpoints(scope);
if (resources.size() > 1) {
_log.error("Too many Service Endpoints having name " + SERVICE_EP_NAME +" in this scope: " + scope);
throw new TooManyRStudioResourcesException("There exist more than 1 Runtime Resource in this scope having name "
+ SERVICE_EP_NAME + " and Category " + CATEGORY + ". Only one allowed per scope.");
}
else if (resources.size() == 0){
_log.warn("There is no Service Endpoint having name " + SERVICE_EP_NAME +" and Category " + CATEGORY + " in this scope. Returning default instance");
toReturn = rConnector().build().connect().toURL().toExternalForm();
} else {
ServiceEndpoint res = resources.get(0);
String hostedOn = res.profile().runtime().hostedOn();
String[] splits = hostedOn.split(":");
String host = splits[0];
int port = 80;
try {
port = Integer.parseInt(splits[1]);
} catch (Exception e) {
_log.warn("Could not find an integer after :, using default port 80");
}
toReturn = rConnector().at(host, port).build().connect().toURL().toExternalForm();
}
} catch (Exception e) {
e.printStackTrace();
}
_log.debug("returning URL from rConnector = "+toReturn);
return toReturn;
}
/**
*
* @return the
* @throws Exception
*/
private List<ServiceEndpoint> getRStudioServiceEndpoints(String scope) throws Exception {
_log.debug("getRStudioServiceEndpoints on scope="+scope );
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '"+ SERVICE_EP_NAME +"'");
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> toReturn = client.submit(query);
ScopeProvider.instance.set(currScope);
return toReturn;
}
}

View File

@ -0,0 +1,8 @@
package org.gcube.portlets.user.rstudio_wrapper_portlet.server;
@SuppressWarnings("serial")
public class TooManyRStudioResourcesException extends Exception {
public TooManyRStudioResourcesException(String message) {
super(message);
}
}