Bug fixing Incident #17506
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-task-executor-widget@181658 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0b54724c90
commit
0ef0723f69
|
@ -4,6 +4,8 @@
|
|||
date="${buildDate}">
|
||||
<Change>[Task #17349] Migrate ws-task-executor components to SHUB
|
||||
</Change>
|
||||
<Change>[Incident #17506] Bug fixing
|
||||
</Change>
|
||||
</Changeset>
|
||||
<Changeset
|
||||
component="org.gcube.portlets-widgets.ws-task-executor-widget.0-1-0"
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -97,10 +97,16 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3-0-0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- PORTAL MANAGER -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.wstaskexecutor.server;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
|
@ -24,6 +25,7 @@ import org.gcube.common.workspacetaskexecutor.shared.exception.WorkspaceFolderLo
|
|||
import org.gcube.common.workspacetaskexecutor.util.EncrypterUtil;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.client.rpc.WsTaskExecutorWidgetService;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.server.util.PortalContextUtil;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.server.util.RuntimeResourceReader;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScope;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScopeType;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.shared.SelectableOperator;
|
||||
|
@ -100,8 +102,6 @@ public class WsTaskExecutorWidgetServiceImpl extends RemoteServiceServlet implem
|
|||
GCubeUser user = PortalContextUtil.getUserLogged(this.getThreadLocalRequest());
|
||||
String scope = PortalContextUtil.getCurrentScope(this.getThreadLocalRequest());
|
||||
logger.debug("Found user "+user+ ", scope: "+scope+" into PortalContext, using them...");
|
||||
//String userToken = PortalContextUtil.getTokenFor(scope, user.getUsername());
|
||||
//SecurityTokenProvider.instance.set(userToken);
|
||||
ScopeProvider.instance.set(scope);
|
||||
logger.info("Using user "+user.getUsername()+ "and scope: "+scope+" to intancing the "+WorkspaceDataMinerTaskExecutor.class.getSimpleName());
|
||||
WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
|
||||
|
@ -116,27 +116,29 @@ public class WsTaskExecutorWidgetServiceImpl extends RemoteServiceServlet implem
|
|||
public List<GcubeScope> getListOfScopesForLoggedUser()
|
||||
throws Exception {
|
||||
|
||||
logger.debug("getListOfVREsForLoggedUser...: ");
|
||||
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
||||
long userId = user.getUserId();
|
||||
|
||||
// Instanciate the manager
|
||||
GroupManager groupManager = new LiferayGroupManager();
|
||||
logger.debug("getListOfScopesForLoggedUser called");
|
||||
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
|
||||
|
||||
if (!isWithinPortal()){
|
||||
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
|
||||
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
|
||||
// listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO));
|
||||
// listOfScopes.add(new GcubeScope("devsec", "/gcube/devsec", GcubeScopeType.VO));
|
||||
// listOfScopes.add(new GcubeScope("gcube", "/gcube", GcubeScopeType.ROOT));
|
||||
listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext/devNext", GcubeScopeType.VRE));
|
||||
Collections.sort(listOfScopes);
|
||||
return listOfScopes;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId);
|
||||
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
|
||||
long userId = user.getUserId();
|
||||
// Instanciate the manager
|
||||
GroupManager groupManager = new LiferayGroupManager();
|
||||
|
||||
//FILTERING THE VREs FOR GATEWAY
|
||||
long theGroupId = PortalContext.getConfiguration().getCurrentGroupId(this.getThreadLocalRequest());
|
||||
logger.info("Searching for userId {} and grouId {}", userId, theGroupId);
|
||||
Set<GCubeGroup> listOfGroups = groupManager.listGroupsByUserAndSiteGroupId(userId, theGroupId);
|
||||
logger.info("Found {} GcubeGroups", listOfGroups.size());
|
||||
|
||||
for (GCubeGroup gCubeGroup : listOfGroups) {
|
||||
GcubeScopeType scopeType=null;
|
||||
if(groupManager.isVRE(gCubeGroup.getGroupId())){
|
||||
|
@ -167,11 +169,21 @@ public class WsTaskExecutorWidgetServiceImpl extends RemoteServiceServlet implem
|
|||
logger.error("Error occurred server-side getting VRE folders: ", e);
|
||||
throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
|
||||
}
|
||||
|
||||
String scope = PortalContextUtil.getCurrentScope(this.getThreadLocalRequest());
|
||||
List<GcubeScope> dmScopes = new ArrayList<GcubeScope>(listOfScopes.size());
|
||||
//GETTING THE ENDPOINTS WHERE THE DM IS DEPLOYED
|
||||
for (GcubeScope gcubeScope : listOfScopes) {
|
||||
boolean exists = RuntimeResourceReader.serviceEndpointExists(scope, "DataMiner", "DataAnalysis");
|
||||
if(exists)
|
||||
dmScopes.add(gcubeScope);
|
||||
}
|
||||
|
||||
Collections.sort(listOfScopes);
|
||||
logger.info("Returning list of VREs: "+listOfScopes);
|
||||
return listOfScopes;
|
||||
Collections.sort(dmScopes);
|
||||
logger.info("Returning list of DM VREs where the User is registered: "+dmScopes);
|
||||
return dmScopes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.wstaskexecutor.server.util;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
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.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class RuntimeResourceReader.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Sep 13, 2019
|
||||
*/
|
||||
public class RuntimeResourceReader {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(RuntimeResourceReader.class);
|
||||
|
||||
/**
|
||||
* Gets the parameters.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param resourceName the resource name
|
||||
* @param resourceCategory the resource category
|
||||
* @return the parameters
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static ServerParameters getParameters(String scope, String resourceName, String resourceCategory) throws Exception
|
||||
{
|
||||
|
||||
ServerParameters parameters = new ServerParameters();
|
||||
String originalScope = null;
|
||||
try{
|
||||
|
||||
ServiceEndpoint se = getServiceEndpoint(scope, resourceName, resourceCategory);
|
||||
if(se.profile()==null)
|
||||
throw new Exception("IS profile is null for resource: "+resourceName);
|
||||
|
||||
Group<AccessPoint> accessPoints = se.profile().accessPoints();
|
||||
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found");
|
||||
|
||||
AccessPoint ap = accessPoints.iterator().next();
|
||||
parameters.setUrl(ap.address());
|
||||
parameters.setUser(ap.username()); //username
|
||||
|
||||
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
parameters.setPassword(decryptedPassword); //password
|
||||
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("Sorry, an error occurred on reading parameters in Runtime Resources",e);
|
||||
}finally{
|
||||
if(originalScope!=null && !originalScope.isEmpty()){
|
||||
ScopeProvider.instance.set(originalScope);
|
||||
logger.info("scope provider setted to orginal scope: "+originalScope);
|
||||
}else{
|
||||
ScopeProvider.instance.reset();
|
||||
logger.info("scope provider reset");
|
||||
}
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Service endpoint exists.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param resourceName the resource name
|
||||
* @param resourceCategory the resource category
|
||||
* @return true, if successful
|
||||
*/
|
||||
public static boolean serviceEndpointExists(String scope, String resourceName, String resourceCategory) {
|
||||
|
||||
ServiceEndpoint sEp = getServiceEndpoint(scope, resourceName, resourceCategory);
|
||||
return sEp!=null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the service endpoint.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param resourceName the resource name
|
||||
* @param resourceCategory the resource category
|
||||
* @return the service endpoint found. Otherwise null.
|
||||
*/
|
||||
public static ServiceEndpoint getServiceEndpoint(String scope, String resourceName, String resourceCategory) {
|
||||
|
||||
String originalScope = null;
|
||||
List<ServiceEndpoint> listEndPoints = null;
|
||||
try{
|
||||
|
||||
originalScope = ScopeProvider.instance.get();
|
||||
logger.info("Setting scope: {}", scope);
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'");
|
||||
|
||||
if(resourceCategory!=null && !resourceCategory.isEmpty()) {
|
||||
query.addCondition("$resource/Profile/Category/string() eq '"+resourceCategory+"'");
|
||||
}
|
||||
|
||||
logger.info("Searching the RR with Profile/Name '{}' and Profile/Category '{}'", resourceName, resourceCategory);
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
listEndPoints = client.submit(query);
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("Unexpeted error occurred on searching the EndPoint: ",e);
|
||||
|
||||
}finally{
|
||||
if(originalScope!=null && !originalScope.isEmpty()){
|
||||
ScopeProvider.instance.set(originalScope);
|
||||
logger.info("scope provider setted to orginal scope: "+originalScope);
|
||||
}else{
|
||||
ScopeProvider.instance.reset();
|
||||
logger.info("scope provider reset");
|
||||
}
|
||||
}
|
||||
|
||||
if (listEndPoints == null || listEndPoints.isEmpty()) {
|
||||
logger.info("No RR found with Profile/Name '{}' and Profile/Category '{}'"+ " in the scope "+scope , resourceName, resourceCategory);
|
||||
return null;
|
||||
}
|
||||
|
||||
ServiceEndpoint sEp = listEndPoints.get(0); //Returning the first EndPoint. I'm assuming that only one instance exists for input RR
|
||||
logger.info("{} found in the scope {}",ServiceEndpoint.class.getSimpleName(),scope);
|
||||
return sEp;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package org.gcube.portlets.widgets.wstaskexecutor.server.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* The Class ServerParameters.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 16, 2017
|
||||
*/
|
||||
public class ServerParameters implements Serializable{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -507665481374175091L;
|
||||
protected String url;
|
||||
protected String user;
|
||||
protected String password;
|
||||
|
||||
/**
|
||||
* Instantiates a new server parameters.
|
||||
*/
|
||||
public ServerParameters(){}
|
||||
|
||||
/**
|
||||
* Instantiates a new server parameters.
|
||||
*
|
||||
* @param url the url
|
||||
* @param user the user
|
||||
* @param password the password
|
||||
*/
|
||||
public ServerParameters(String url, String user, String password) {
|
||||
this.url = url;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the url.
|
||||
*
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the url.
|
||||
*
|
||||
* @param url the url to set
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user.
|
||||
*
|
||||
* @return the user
|
||||
*/
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user.
|
||||
*
|
||||
* @param user the user to set
|
||||
*/
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the password.
|
||||
*
|
||||
* @return the password
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password.
|
||||
*
|
||||
* @param password the password to set
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ServerParameters [url=");
|
||||
builder.append(url);
|
||||
builder.append(", user=");
|
||||
builder.append(user);
|
||||
builder.append(", password=");
|
||||
builder.append(password);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -115,8 +115,8 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
|
|||
|
||||
if(o==null)
|
||||
return -1;
|
||||
|
||||
return this.getScopeName().compareTo(o.getScopeName());
|
||||
|
||||
return this.getScopeTitle().compareToIgnoreCase(o.getScopeTitle());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package org.gcube.portlets.widgets.wstaskexecutor.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.server.WsTaskExecutorWidgetServiceImpl;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.server.util.RuntimeResourceReader;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScope;
|
||||
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScopeType;
|
||||
|
||||
/**
|
||||
* The Class CheckDMScopes.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Sep 13, 2019
|
||||
*/
|
||||
public class CheckDMScopes {
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
List<GcubeScope> listOfScopes = new ArrayList<GcubeScope>();
|
||||
//WsTaskExecutorWidgetServiceImpl sImpl = new WsTaskExecutorWidgetServiceImpl();
|
||||
listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE));
|
||||
listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE));
|
||||
|
||||
for (GcubeScope gcubeScope : listOfScopes) {
|
||||
boolean exists = RuntimeResourceReader.serviceEndpointExists(gcubeScope.getScopeName(), "DataMiner", "DataAnalysis");
|
||||
System.out.println("Is the DataMiner deployed in the scope: "+gcubeScope.getScopeName()+"? "+exists);
|
||||
}
|
||||
|
||||
|
||||
WsTaskExecutorWidgetServiceImpl wsImpl = new WsTaskExecutorWidgetServiceImpl();
|
||||
List<GcubeScope> listScopes = wsImpl.getListOfScopesForLoggedUser();
|
||||
|
||||
for (GcubeScope gcubeScope : listScopes) {
|
||||
System.out.println(gcubeScope.getScopeTitle());
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
for(int i=0; i<listScopes.size(); i++) {
|
||||
System.out.println(listScopes.get(i).getScopeTitle());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue