From e85206c33b8604c73fae8fbb016146ad1f021da1 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Mon, 27 Dec 2021 13:52:13 +0100 Subject: [PATCH] feature completed and alpha tested --- .classpath | 6 +- .project | 10 +- .../com.gwtplugins.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.jdt.core.prefs | 2 + .settings/org.eclipse.wst.common.component | 36 +++- CHANGELOG.md | 4 + FUNDING.md | 26 +++ pom.xml | 6 +- .../client/ResourceManagementPortlet.java | 53 ++++- .../client/remote/ServiceProxy.java | 2 + .../client/remote/ServiceProxyAsync.java | 3 + .../client/utils/Commands.java | 2 + .../resourcemanagement/server/Gateway.java | 33 +++ .../server/ServiceProxyImpl.java | 202 +++++++++++++++++- 14 files changed, 362 insertions(+), 25 deletions(-) create mode 100644 FUNDING.md create mode 100644 src/main/java/org/gcube/portlets/admin/resourcemanagement/server/Gateway.java diff --git a/.classpath b/.classpath index d483cce..1e13fa7 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -41,5 +41,5 @@ - + diff --git a/.project b/.project index b7c8bf0..7c9ee95 100644 --- a/.project +++ b/.project @@ -40,11 +40,6 @@ - - org.eclipse.m2e.core.maven2Builder - - - com.gwtplugins.gdt.eclipse.core.webAppProjectValidator @@ -55,6 +50,11 @@ + + org.eclipse.m2e.core.maven2Builder + + + org.eclipse.m2e.core.maven2Nature diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index 41ad7dd..a173a9d 100644 --- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -lastWarOutDir=/Users/massi/Documents/workspace/resource-management/target/resource-management-6.7.0-SNAPSHOT +lastWarOutDir=/Users/massi/workspace/resource-management-portlet/target/resource-management-portlet-7.0.0-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index a5c7673..43c8195 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 9abfccb..3ef5d5d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,10 +1,34 @@ - + + + + + - - + + + + + + + + - - - + + + + uses + + + + + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b694d7..98c81f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v7.1.0-SNAPSHOT] - 2021-12-27 + +- Please add a resource to the VRE which indicates the gateway through it is accessible + ## [v7.0.0] - 2020-07-21 Ported to git diff --git a/FUNDING.md b/FUNDING.md new file mode 100644 index 0000000..6fa9eac --- /dev/null +++ b/FUNDING.md @@ -0,0 +1,26 @@ +# Acknowledgments + +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](https://cordis.europa.eu/project/id/004260) (grant no. 004260). +- the Seventh Framework Programme for research, technological development and demonstration + - [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488); + - [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019); + - [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465); + - [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644); + - [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754). +- the H2020 research and innovation programme + - [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024); + - [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119); + - [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142); + - [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182); + - [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680); + - [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610); + - [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001); + - [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194); + - [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914); + - [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091); + - [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650); + - [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409); + - [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042); \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5f7977a..6b79988 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.admin resource-management-portlet - 7.0.0 + 7.1.0-SNAPSHOT war gCube Resource Management Portlet @@ -104,7 +104,7 @@ org.gcube.portlets.admin rmp-common-library - [2.8.2-SNAPSHOT, 3.0.0-SNAPSHOT) + [2.8.4-SNAPSHOT, 3.0.0-SNAPSHOT) @@ -125,7 +125,7 @@ org.gcube.core common-scope-maps - provided + runtime org.gcube.resourcemanagement diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/ResourceManagementPortlet.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/ResourceManagementPortlet.java index 11b9ade..2c24bf6 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/ResourceManagementPortlet.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/ResourceManagementPortlet.java @@ -17,6 +17,8 @@ package org.gcube.portlets.admin.resourcemanagement.client; +import java.util.List; + import org.gcube.portlets.admin.ishealthmonitor.client.dialog.ISMonitor; import org.gcube.portlets.admin.resourcemanagement.client.forms.genericresources.DeployVirtualCollection; import org.gcube.portlets.admin.resourcemanagement.client.remote.ProxyRegistry; @@ -621,7 +623,7 @@ public class ResourceManagementPortlet implements EntryPoint { protected void onClick(final ComponentEvent be) { super.onClick(be); Dialog dlg = new Dialog(); - dlg.setHeading("About - Resource Management"); + dlg.setHeading("About - Infrastructure Monitor"); dlg.addText("
This software is part of the gCube Project.
" + "Site: http://www.gcube-system.org/" + "

The gCube/gCore software is licensed as Free Open Source software " + @@ -630,10 +632,7 @@ public class ResourceManagementPortlet implements EntryPoint { "\"as is\" and no expressed or " + "implied warranty is given for its use, quality or fitness for a " + "particular case.

" + - "" + - "

Issues can be submitted here.

" + - "

Notice: specify this Component:
Repository Path: /org/gcube/portlets/admin/resource-management

" + - "
This software was built over the gCube Featherweight Stack (FWS) and Google Webtool Kit (GWT) technologies.
" + + "

Issues can be submitted here.

" + "
"); dlg.setClosable(true); @@ -715,7 +714,7 @@ public class ResourceManagementPortlet implements EntryPoint { statusbar.add(new FillToolItem()); statusbar.add(new Label("Current Context:  ")); - Text scopeInfo = new Text(Messages.NO_SCOPE_SELECTED); + final Text scopeInfo = new Text(Messages.NO_SCOPE_SELECTED); scopeInfo.setWidth(350); statusbar.add(scopeInfo); WidgetsRegistry.registerWidget(UIIdentifiers.STATUS_SCOPE_INFO_ID, scopeInfo); @@ -732,6 +731,48 @@ public class ResourceManagementPortlet implements EntryPoint { copy2Clipboard.setText("Copy"); copy2Clipboard.setStyleAttribute("margin-top", "-12px"); statusbar.add(copy2Clipboard); + + + Button locateVREButton = new Button() { + @Override + protected void onClick(final ComponentEvent ce) { + String currentContext = StatusHandler.getStatus().getCurrentScope(); + String[] splits = currentContext.split("/"); + if (splits.length < 4) { //check if the context is a VRE (4 splits) + Window.alert("Locate function only applicable to VRE contexts"); + } else { + ProxyRegistry.getProxyInstance().getGatewayURLsGivenVREContext(currentContext, new AsyncCallback>() { + public void onSuccess(List result) { + Dialog dlg = new Dialog(); + dlg.setHeading("VRE is available on:"); + String markup = "

    "; + for (String gatewayURL : result) { + markup += "
  • "+gatewayURL+"
  • "; + } + markup += "

"; + dlg.addText(markup); + dlg.setClosable(true); + dlg.setModal(true); + dlg.setHideOnButtonClick(true); + dlg.show(); + } + + public void onFailure(Throwable caught) { + Window.alert("An error occurred: " + caught.getMessage()); + } + }); + } + + } + }; + + locateVREButton.setIconStyle("pluginVM-icon"); + locateVREButton.setToolTip("Shows in which D4Science Gateway the VRE is available"); + locateVREButton.setText("Locate"); + locateVREButton.setStyleAttribute("margin-top", "-12px"); + statusbar.add(locateVREButton); + + statusbar.add(new Label("  Resources No.: ")); Status loadedResources = new Status(); loadedResources.setWidth(35); diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java index 09f7482..fc41cc8 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java @@ -48,6 +48,8 @@ public interface ServiceProxy extends RemoteService { void initScopes(boolean doClean); void setSuperUser(boolean superUser); + + List getGatewayURLsGivenVREContext(String vreContext); /** * This way the servlet stores the scope in the session. diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxyAsync.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxyAsync.java index e6e70ea..db8501e 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxyAsync.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxyAsync.java @@ -60,6 +60,9 @@ public interface ServiceProxyAsync { void getGenericResourceDescriptor(String scope, String resID, AsyncCallback callback); + + void getGatewayURLsGivenVREContext(String vreContext, AsyncCallback> callback); + /** * @see ServiceProxy#getAvailableScopes() */ diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Commands.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Commands.java index 937ea22..ea47b5b 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Commands.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Commands.java @@ -195,6 +195,7 @@ public class Commands { } public static final void doGetResourceProfileByID(final Object caller, final String scope, final String resourceID) { + GWT.log("Commands.java doGetResourceProfileByID"); ProxyRegistry.getProxyInstance().getResourceByID( scope, null, // no type specified @@ -203,6 +204,7 @@ public class Commands { } public static final void doGetResourceProfile(final Object caller, final String scope, String resourceType, final String resourceID) { + GWT.log("doGetResourceProfile =" + resourceType); /** * Patch (i know do not tell me about it) */ diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/Gateway.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/Gateway.java new file mode 100644 index 0000000..08ed85e --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/Gateway.java @@ -0,0 +1,33 @@ +package org.gcube.portlets.admin.resourcemanagement.server; + +import java.util.ArrayList; + +import com.liferay.portal.model.Group; + +public class Gateway { + private Group site; + private ArrayList vres; + public Gateway(Group site, ArrayList vres) { + super(); + this.site = site; + this.vres = vres; + } + public Group getSite() { + return site; + } + public void setSite(Group site) { + this.site = site; + } + public ArrayList getVres() { + return vres; + } + public void setVres(ArrayList vres) { + this.vres = vres; + } + @Override + public String toString() { + return "Gateway [site=" + site + ", vres=" + vres + "]"; + } + + +} diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java index a8abb04..d72aeb2 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java @@ -23,6 +23,7 @@ import java.io.StringReader; import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Vector; @@ -62,11 +63,22 @@ import org.gcube.resourcemanagement.support.shared.util.Assertion; import org.gcube.resourcemanagement.support.shared.util.Configuration; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.impl.QueryTemplate; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.VirtualGroup; import org.gcube.vremanagement.resourcemanager.client.RMReportingLibrary; import org.w3c.dom.Node; import org.xml.sax.InputSource; import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.model.Group; +import com.liferay.portal.model.LayoutSet; +import com.liferay.portal.service.GroupLocalServiceUtil; +import com.liferay.portal.service.VirtualHostLocalServiceUtil; +import com.liferay.portal.util.PortalUtil; /** * @author Daniele Strollo @@ -440,8 +452,8 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro public final CompleteResourceProfile getResourceByID(final String scope, final String type, final String resID) { try { CompleteResourceProfile profile = ISClientRequester.getResourceByID(this.getXML2HTMLMapping(), new ScopeBean(scope), type, resID); - System.out.println("****\n\n\n CompleteResourceProfile getResourceByID(final String scope, final String type, final String resID) *****"); System.out.println("****CompleteResourceProfile getResourceByID("+scope+","+type+","+resID+") *****\n\n"); + System.out.println("Resource found XML:"+profile.getXmlRepresentation()); return profile; } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e); @@ -536,6 +548,194 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro ServerConsole.info(LOG_PREFIX, "FAILED ATTEMPT SUPER USER MODE FROM IP: " + ipAddressCaller); return matched; } + /** + * return the list of URLS for a given VRE Context + */ + @Override + public List getGatewayURLsGivenVREContext(String vreContext) { + + List theGateways= getGateways(new LiferayGroupManager()); + List gatewayURLs = new ArrayList<>(); + for (Gateway gateway : theGateways) { + LayoutSet layoutSet = null; + if (gateway.getSite().hasPublicLayouts()) + layoutSet = gateway.getSite().getPublicLayoutSet(); + else + layoutSet = gateway.getSite().getPrivateLayoutSet(); + final long companyId = PortalUtil.getDefaultCompanyId(); + long layoutSetId = layoutSet.getLayoutSetId(); + String vHost = ""; + try { + vHost = VirtualHostLocalServiceUtil.getVirtualHost(companyId, layoutSetId).getHostname(); + } catch (PortalException | SystemException e) { + e.printStackTrace(); + } + String theURL = "https://"+vHost+"/"; + gatewayURLs.add(theURL); + } + return gatewayURLs; + } + + + private List getGateways(GroupManager groupsManager) { + List toReturn = new ArrayList<>(); + try{ + List candidateGateways = GroupLocalServiceUtil.getGroups(org.gcube.vomanagement.usermanagement.util.ManagementUtils.getCompany().getCompanyId(), 0, true); + // real gateways have no children as well + for (Group group : candidateGateways) { + List children = group.getChildren(true); + if(children == null || children.isEmpty()) + if(! (group.getFriendlyURL().equals("/guest") || group.getFriendlyURL().equals("/global") )) {// skipping these sites + ArrayList theVRENames = new ArrayList<>(); + LinkedHashMap> sites = getPortalSitesMappedToVRE(group.getGroupId(), groupsManager); + for (VRECategory cat : sites.keySet()) { + for (VRE vre : sites.get(cat)) { + theVRENames.add(vre.getName()); + } + } + toReturn.add(new Gateway(group, theVRENames)); + ServerConsole.debug("Gateway " + group.getName() + " has " + theVRENames.size() + " VREs"); + } + } + } catch(Exception e){ + ServerConsole.error("Failed to retrieve the list of gateways", e); + return null; + } + return toReturn; + } + + /** + * + * @return the Virtual groups with their VREs in the order estabilished in + * the LR Control Panel + */ + private LinkedHashMap> getPortalSitesMappedToVRE(long currentSiteGroupId, GroupManager groupsManager) throws Exception { + + LinkedHashMap> toReturn = new LinkedHashMap>(); + + List currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId); + + for (VirtualGroup vg : currentSiteVGroups) { + ArrayList toCreate = new ArrayList(); + VRECategory cat = new VRECategory(1L, vg.getName(), vg.getDescription()); + toReturn.put(cat, toCreate); + } + + GCubeGroup rootGroupVO = groupsManager.getRootVO(); + + try { + ServerConsole.debug("root: " + rootGroupVO.getGroupName()); + } catch (NullPointerException e) { + ServerConsole.warn( + "Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle"); + return toReturn; + } + + // for each root sub organizations (VO) + for (GCubeGroup vOrg : rootGroupVO.getChildren()) { + for (GCubeGroup vreSite : vOrg.getChildren()) { + long vreID = vreSite.getGroupId(); + String vreName = vreSite.getGroupName(); + String vreDescription = vreSite.getDescription(); + List vreGroups = groupsManager.getVirtualGroups(vreID); + for (VirtualGroup vreGroup : vreGroups) { + for (VRECategory vre : toReturn.keySet()) { + if (vre.getName().compareTo(vreGroup.getName()) == 0) { + ArrayList toUpdate = toReturn.get(vre); + VRE toAdd = new VRE(vreName, vreDescription, vreID, "", ""); + toUpdate.add(toAdd); + } + } + } + } + } + return toReturn; + } + + + private class VRECategory { + private long categoryID; + private String name; + private String description; + + public VRECategory(long categoryID, String name, String description) { + super(); + this.categoryID = categoryID; + this.name = name; + this.description = description; + } + + @SuppressWarnings("unused") + public long getCategoryID() { + return categoryID; + } + + @SuppressWarnings("unused") + public String getDescription() { + return description; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return "VRECategory [categoryID=" + categoryID + ", name=" + name + ", description=" + description + "]"; + } + + } + private class VRE implements Comparable { + private String name; + private String description; + private long id; + private String url; + private String scope; + + public VRE(String name, String description, long id, String url, String scope) { + super(); + this.name = name; + this.description = description; + this.id = id; + this.url = url; + this.scope = scope; + } + + @SuppressWarnings("unused") + public String getDescription() { + return description; + } + + @SuppressWarnings("unused") + public long getId() { + return id; + } + + public String getName() { + return name; + } + + @SuppressWarnings("unused") + public String getScope() { + return scope; + } + + @SuppressWarnings("unused") + public String getUrl() { + return url; + } + + @Override + public String toString() { + return "VRE [name=" + name + ", description=" + description + ", id=" + id + ", url=" + url + ", scope=" + + scope + "]"; + } + + @Override + public int compareTo(VRE vre) { + return this.getName().compareTo(vre.getName()); + } + } }