fix Bug #19192 RStudio Wrapper portlet does not support double queries

This commit is contained in:
Massimiliano Assante 2020-05-06 11:17:13 +02:00
parent 2350a32705
commit b99319c450
1 changed files with 50 additions and 44 deletions

View File

@ -169,39 +169,44 @@ public class RStudioServiceImpl extends RemoteServiceServlet implements RStudioS
* @param token * @param token
* @return * @return
*/ */
private String getRStudioGCoreEndpoint(PortalContext pContext, long userId, GCubeUser curUser, String scope, String token) { private String getRStudioGCoreEndpoint(PortalContext pContext, long userId, GCubeUser curUser, String context, String token) {
String toReturn = ""; String toReturn = "";
UserManager um = new LiferayUserManager(); UserManager um = new LiferayUserManager();
_log.debug("Checking if user " + curUser.getFullname() + " has already an RStudio Instance set ... "); _log.debug("Checking if user " + curUser.getFullname() + " has already an RStudio Instance set ... ");
String hostedOnSet = null; String hostedOnSet = null;
try { try {
//check if an RStudio instance was previously set (RETRO-COMPATIBILY) Map<String, String> userRStudioInstances = getUserRStudioInstances(um, curUser);
if (um.readCustomAttr(userId, RSTUDIO_URL) != null && um.readCustomAttr(userId, RSTUDIO_URL).toString().compareTo("") != 0) { hostedOnSet = userRStudioInstances.get(context);
_log.debug("User had already an RStudio Instance set, upgrading to new version "); _log.info("**** Checking if the user instance " + hostedOnSet+" exists in the VO for this VRE: " + context);
hostedOnSet = (String) um.readCustomAttr(userId, RSTUDIO_URL);
writeRStudioInstanceInScope(um, curUser, scope, hostedOnSet);
um.saveCustomAttr(userId, RSTUDIO_URL, ""); //reset the old value to blank so that from now on it will read from the new field
}
hostedOnSet = getUserRStudioInstances(um,curUser).get(scope);
_log.info("**** Checking if the user instance " + hostedOnSet+" exists in the VO for this VRE: " + scope);
//if the instance exists and is still available in the given context //if the instance exists and is still available in the given context
List<GCoreEndpoint> gCoreResources = getRStudioGCoreEndpoints(scope); List<GCoreEndpoint> gCoreResources = getRStudioGCoreEndpoints(context);
if (hostedOnSet != null && checkRStudioGCoreInstanceExistence(curUser, hostedOnSet, gCoreResources) ) { if (hostedOnSet != null && checkRStudioGCoreInstanceExistence(curUser, hostedOnSet, gCoreResources) ) {
toReturn = getRConnectorURL(hostedOnSet, token); toReturn = getRConnectorURL(hostedOnSet, token);
_log.info("User " + curUser.getFullname() + " has RStudio Instance set and is valid, returning rConnector URL " + toReturn); _log.info("User " + curUser.getFullname() + " has RStudio Instance set and is valid, returning rConnector URL " + toReturn);
} }
else {//need to find the RStudio else {//need to find the RStudio
//check first if there is an instance allocated on another scope
_log.info("User " + curUser.getFullname() + " DOES NOT have RStudio Instance set for this context "+context + " check if she as an instance assigned on another context");
if (! userRStudioInstances.isEmpty()) {
String theFirstInstance = userRStudioInstances.values().iterator().next();
toReturn = getRConnectorURL(theFirstInstance, token);
_log.info("Found instance: "+ theFirstInstance);
writeRStudioInstanceInScope(um, curUser, context, theFirstInstance);
_log.debug("User " + curUser.getFullname() + " RStudio gCore Instance set reused = " + theFirstInstance + " for new context " + context);
}
else { //no instance allocated on another scope
_log.info("User " + curUser.getFullname() + " DOES NOT have RStudio Instance set or the instance previous set no longer exists, calculating allocation ... "); _log.info("User " + curUser.getFullname() + " DOES NOT have RStudio Instance set or the instance previous set no longer exists, calculating allocation ... ");
HashMap<String, Integer> rStudioDistributionMap = new HashMap<>(); HashMap<String, Integer> rStudioDistributionMap = new HashMap<>();
for (GCoreEndpoint res : gCoreResources) { for (GCoreEndpoint res : gCoreResources) {
String hostedOn = extractGCoreEndpointHostAndPort(res); String hostedOn = extractGCoreEndpointHostAndPort(res);
rStudioDistributionMap.put(hostedOn, 0); rStudioDistributionMap.put(hostedOn, 0);
} }
List<GCubeUser> vreUsers = um.listUsersByGroup(pContext.getCurrentGroupId(getThreadLocalRequest()), false); List<GCubeUser> vreUsers = um.listUsersByGroup(pContext.getCurrentGroupId(getThreadLocalRequest()), false);
_log.debug("VRE " + scope + " has totalUsers = " + vreUsers.size()); _log.debug("VRE " + context + " has totalUsers = " + vreUsers.size());
for (GCubeUser gCubeUser : vreUsers) { for (GCubeUser gCubeUser : vreUsers) {
if (getUserRStudioInstances(um,gCubeUser).get(scope) != null) { if (getUserRStudioInstances(um,gCubeUser).get(context) != null) {
String hostedOn = getUserRStudioInstances(um,gCubeUser).get(scope); String hostedOn = getUserRStudioInstances(um,gCubeUser).get(context);
if (rStudioDistributionMap.containsKey(hostedOn)) { if (rStudioDistributionMap.containsKey(hostedOn)) {
int noToSet = rStudioDistributionMap.get(hostedOn)+1; int noToSet = rStudioDistributionMap.get(hostedOn)+1;
rStudioDistributionMap.put(hostedOn, noToSet); rStudioDistributionMap.put(hostedOn, noToSet);
@ -226,9 +231,10 @@ public class RStudioServiceImpl extends RemoteServiceServlet implements RStudioS
} }
i++; i++;
} }
writeRStudioInstanceInScope(um, curUser, scope, host2Select); writeRStudioInstanceInScope(um, curUser, context, host2Select);
_log.debug("User " + curUser.getFullname() + " RStudio gCore Instance set calculated = " + host2Select + " for context " + scope); _log.debug("User " + curUser.getFullname() + " RStudio gCore Instance set calculated = " + host2Select + " for context " + context);
toReturn = getRConnectorURL(host2Select, token); toReturn = getRConnectorURL(host2Select, token);
}
_log.debug("User " + curUser.getFullname() + " has RStudio gCore Instance set, returning rConnector URL " + toReturn); _log.debug("User " + curUser.getFullname() + " has RStudio gCore Instance set, returning rConnector URL " + toReturn);
} }