diff --git a/pom.xml b/pom.xml index a132624..7882f19 100644 --- a/pom.xml +++ b/pom.xml @@ -84,13 +84,13 @@ xercesImpl 2.9.1 - + org.gcube.information-system resource-registry-client - 1.3.0-SNAPSHOT + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) org.gcube.information-system diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java index e1ca147..aa8eabe 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java @@ -261,6 +261,9 @@ public class Callbacks { new AsyncCallback() { public void onSuccess(final CompleteResourceProfile result) { + + + Dialog dlg = new Dialog(); dlg.setLayout(new FitLayout()); dlg.setHeading("XML Resource Profile"); @@ -273,10 +276,13 @@ public class Callbacks { // This resource has already been opened if (TaskbarRegister.contains(result.getID())) { TaskbarRegister.getTaskbarItem(result.getID()).destroy(); + Commands.showPopup("Retrieve Resource Profile", "Refreshing profile for id: " + result.getID(), 3000); } MainPanel taskbarContainer = WidgetsRegistry.getPanel(UIIdentifiers.TASKBAR_PANEL); + + TaskbarItem tkItem = new TaskbarItem( StatusHandler.getStatus().getCurrentScope(), result.getType(), @@ -286,12 +292,16 @@ public class Callbacks { result.getTitle(), "resource-profile-taskbar-item", "profile-big-icon"); + /* tkItem.getRelatedWindow().setMainWidget( new ResourceProfilePanel( result.getType(), result.getXmlRepresentation(), result.getHtmlRepresentation()).getWidget()); - TaskbarRegister.registerTaskbarWidget(result.getID(), tkItem); + + */ + + //TaskbarRegister.registerTaskbarWidget(result.getID(), tkItem); } catch (Exception e) { GWT.log("During HTML conversion", e); } finally { @@ -312,6 +322,9 @@ public class Callbacks { public void onSuccess(final Tuple result) { + + + if (result.size() < 3) { MessageBox.alert("Invalid Report Received", "Don't know why :(", null); Commands.unmask(UIIdentifiers.GLOBAL_STATUS_BAR_ID); @@ -339,6 +352,8 @@ public class Callbacks { reportID, 3000); } MainPanel taskbarContainer = WidgetsRegistry.getPanel(UIIdentifiers.TASKBAR_PANEL); + + TaskbarItem tkItem = new TaskbarItem( StatusHandler.getStatus().getCurrentScope(), ResourceTypeDecorator.DeployReport, 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 745869a..20ef5da 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 @@ -196,6 +196,7 @@ public class Commands { } public static final void doGetResourceProfileByID(final Object caller, final String scope, final String resourceID) { + ProxyRegistry.getProxyInstance().getResourceByID( scope, null, // no type specified @@ -217,6 +218,8 @@ public class Commands { "Getting Profile details for " + FWSTranslate.getFWSNameFromLabel(resourceType) + ": " + resourceID, WidgetsRegistry.getPanel(UIIdentifiers.RESOURCE_DETAIL_GRID_PANEL).getContainer() ); + + ProxyRegistry.getProxyInstance().getResourceByID( scope, resourceType, @@ -237,6 +240,8 @@ public class Commands { return; } + GWT.log("TEST--- on handleGetDeploymentReport", null); + Dialog dlg = new Dialog(); dlg.setLayout(new FitLayout()); dlg.setHeading("XML Resource Profile"); @@ -290,6 +295,8 @@ public class Commands { return; } + + Dialog dlg = new Dialog(); dlg.setLayout(new FitLayout()); dlg.setHeading("XML Resource Profile"); @@ -559,9 +566,13 @@ public class Commands { public static void showPopup(final String title, final String text) { showPopup(title, text, Configuration.popupDelay); + + } public static void showPopup(final String title, final String text, final int delayMills) { + + InfoConfig cfg = new InfoConfig(title, text); cfg.display = delayMills; Info.display(cfg); diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/profile/ResourceProfilePanel.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/profile/ResourceProfilePanel.java index f3d2900..d375eb2 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/profile/ResourceProfilePanel.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/profile/ResourceProfilePanel.java @@ -27,7 +27,7 @@ import com.extjs.gxt.ui.client.widget.Html; import com.extjs.gxt.ui.client.widget.TabItem; import com.extjs.gxt.ui.client.widget.TabPanel; import com.extjs.gxt.ui.client.widget.treepanel.TreePanel; -import com.liferay.portal.kernel.json.JSON; +import com.google.gwt.core.client.GWT; /** * @author Daniele Strollo (ISTI-CNR) @@ -107,12 +107,13 @@ public class ResourceProfilePanel extends TabPanel { this.add(jsonProfilePanel); */ - + /**End new registry ***/ } public final Component getWidget() { + return this; } } diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/resourcetree/ResourcesTreePanel.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/resourcetree/ResourcesTreePanel.java index 446c85c..c7a4741 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/resourcetree/ResourcesTreePanel.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/views/resourcetree/ResourcesTreePanel.java @@ -180,10 +180,10 @@ public class ResourcesTreePanel { if (StatusHandler.getStatus().isLoadGHNatStartup()) { GWT.log(""+StatusHandler.getStatus().isLoadGHNatStartup()); -// Commands.doLoadResourceDetailsGrid(this, -// StatusHandler.getStatus().getCurrentScope(), -// "GHN"); -// + Commands.doLoadResourceDetailsGrid(this, + StatusHandler.getStatus().getCurrentScope(), + "GHN"); + //select the GHN for (ModelData md: store.getAllItems()) { if (md.get("node").toString().compareTo("GHN") == 0) diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarItem.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarItem.java index 51847c1..7bd7887 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarItem.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarItem.java @@ -67,7 +67,15 @@ public class TaskbarItem { this.detachButton = new TaskbarButton("btn" + id, type, title) { protected void onClick(final com.extjs.gxt.ui.client.event.ComponentEvent ce) { - relatedWidget.doMinimize(); + + + + + + GWT.log("open tab for id resources:"+resourceID.trim()); + Window.open( GWT.getModuleBaseURL().replace("resourcemanagementportlet/", "") +"resource/getResource?resId="+resourceID, "_blank", ""); + //TODO Delete a pop up with detail + //relatedWidget.doMinimize(); } }; this.detachButton.setStyleName("taskbar-button"); @@ -79,8 +87,10 @@ public class TaskbarItem { this.relatedWidget.setHeading(title); if (Configuration.openProfileOnLoad) { + this.activate(); } else { + this.relatedWidget.setIsMinimized(true); } @@ -105,19 +115,12 @@ public class TaskbarItem { closeAll.setIconStyle("closeall-icon"); mnu.add(closeAll); - - - - - - - - if (type != null && type == ResourceTypeDecorator.DeployReport) { MenuItem refresh = new MenuItem("Refresh") { @Override protected void onClick(final ComponentEvent be) { + super.onClick(be); ProxyRegistry.getProxyInstance().checkDeployStatus( getScope(), @@ -136,8 +139,7 @@ public class TaskbarItem { protected void onClick(final ComponentEvent be) { super.onClick(be); GWT.log("open tab for id resources:"+resourceID.trim()); - Window.open("resource/getResource?resId="+resourceID, "_blank", ""); - + Window.open( GWT.getModuleBaseURL().replace("resourcemanagementportlet/", "") +"resource/getResource?resId="+resourceID, "_blank", ""); } }; openNewTab.setIconStyle("openTab-icon"); @@ -158,6 +160,7 @@ public class TaskbarItem { @Override protected void onClick(final ComponentEvent be) { super.onClick(be); + Commands.doGetResourceProfileByID( this, getScope(), diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarWindow.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarWindow.java index e1c4a48..b1433e1 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarWindow.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/widgets/taskbar/TaskbarWindow.java @@ -24,6 +24,7 @@ import org.gcube.resourcemanagement.support.shared.util.Configuration; import com.extjs.gxt.ui.client.event.IconButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.Component; +import com.extjs.gxt.ui.client.widget.MessageBox; import com.extjs.gxt.ui.client.widget.Window; import com.extjs.gxt.ui.client.widget.button.ToolButton; import com.extjs.gxt.ui.client.widget.layout.FitLayout; @@ -63,6 +64,7 @@ public class TaskbarWindow extends Window { })); */ if (Configuration.openProfileOnLoad) { + this.show(); } } diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java index caf85fb..878acad 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java @@ -5,16 +5,19 @@ import java.util.HashMap; import java.util.List; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.scope.impl.ScopeBean; import org.gcube.informationsystem.model.entity.Resource; -import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClient; -import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClientFactory; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.informationsystem.types.TypeBinder.TypeDefinition; import org.gcube.portlets.admin.resourcemanagement.shared.resource.CacheList; import org.gcube.portlets.admin.resourcemanagement.shared.resource.UtilityResource; import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator; import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResourceProfile; - +/** + * + * @author pieve mail:alessandro.pieve@isti.cnr.it + * + */ public class RegistryClientRequester { private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); /** @@ -26,29 +29,31 @@ public class RegistryClientRequester { */ //list a resource with a sub category - public static final HashMap> getResourcesTree(final ScopeBean queryScope) throws Exception { - + public static final HashMap> getResourcesTree(String scope) throws Exception { + + + HashMap> retval = new HashMap>(); - ScopeProvider.instance.set(queryScope.toString()); + + ScopeProvider.instance.set(scope); try { List typeDefinitions = resourceRegistryClient.getSchema(Resource.class, true); for (TypeDefinition td : typeDefinitions) { - //da eliminare una volta modificato il decoratore - // if (td.getName().equals("EService")) - // retval.put("RunningInstance", UtilityResource.getSubResourcesTree(td.getName(),queryScope.toString())); + + if (td.getName().equals("EService")) + retval.put("RunningInstance", UtilityResource.getSubResourcesTreeQuery(td.getName(),scope)); if (td.getName().equals("Configuration")) - retval.put("GenericResource", UtilityResource.getSubResourcesTree(td.getName(),queryScope.toString())); - + retval.put("GenericResource", UtilityResource.getSubResourcesTreeQuery(td.getName(),scope)); + if (td.getName().equals("HostingNode")) + retval.put("GHN", UtilityResource.getSubResourcesTreeQuery(td.getName(),scope)); } - - } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } + return retval; } @@ -57,8 +62,12 @@ public class RegistryClientRequester { //list string (xml formatted) for table public static final List getResourcesByTypeSubType( String scope,String type,String subType) throws Exception { - CacheList.resourceid.clear(); + + + //CacheList.resourceid.clear(); + ScopeProvider.instance.set(scope); Listresource=new ArrayList(); + switch (type) { case "RunningInstance": System.out.println("---------------->RunningInstance "); @@ -66,7 +75,12 @@ public class RegistryClientRequester { break; case "GenericResource": System.out.println("---------------->GenericResource "); - resource=UtilityResource.CreateListConfiguration(scope,type,subType); + //resource=UtilityResource.CreateListConfiguration(scope,type,subType); + resource=UtilityResource.CreateListConfigurationQuery(scope,type,subType); + break; + case "GHN": + System.out.println("---------------->GHN "); + resource=UtilityResource.CreateListHostingNode(scope,type,subType); break; } @@ -80,7 +94,6 @@ public class RegistryClientRequester { public static CompleteResourceProfile getResourceByID( String xml2htmlMapping, String scope, String type, String resID) { - String representation=CacheList.resourceid.get(resID).getBody(); //get resource by id @@ -88,8 +101,9 @@ public class RegistryClientRequester { String xmlRepresentation="" + ""+resID+"" + ""+type+"" - + representation - + ""; + + ""+scope+"" + + representation + + ""; String htmlRepresentation=representation; ScopeProvider.instance.set(scope); return new CompleteResourceProfile(resID, ResourceTypeDecorator.valueOf(type),title,xmlRepresentation, htmlRepresentation); 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 449aa5e..4e0f630 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 @@ -297,17 +297,19 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro /**LISTA DI RISORSE*/ public final HashMap> getResourceTypeTree(final String scope) throws Exception { try { + + + ScopeBean gscope = new ScopeBean(scope); //Old Registry //HashMap> results = ISClientRequester.getResourcesTree(getCacheManager(this.getCurrentStatus()), gscope); //New Registry - HashMap> results = RegistryClientRequester.getResourcesTree(gscope); - /*TEST */ - for (String key : results.keySet()) { - System.out.println("***->"+key); - } + //before is not necessary + ScopeProvider.instance.set(scope); + HashMap> results = RegistryClientRequester.getResourcesTree(scope); + return results; @@ -344,10 +346,6 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro //New code List request=RegistryClientRequester.getResourcesByTypeSubType(scope, type,null); - - - - return request; } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e); @@ -447,12 +445,10 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro try { System.out.println("---------------->getResourcesBySubType type:"+type+ "- subtype:"+subType); //Old code - //List request=ISClientRequester.getResourcesByType(getCacheManager(this.getCurrentStatus()), new ScopeBean(scope), type, subtype); + //List request=ISClientRequester.getResourcesByType(getCacheManager(this.getCurrentStatus()), new ScopeBean(scope), type, subType); //New code List request=RegistryClientRequester.getResourcesByTypeSubType(scope, type,subType); - - return request; @@ -469,9 +465,8 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro System.out.println("---------------->getResourceByID scope:"+scope+" type:"+type+" resID:"+resID); System.out.println("---------------->getResourceByID this.getXML2HTMLMapping():"+this.getXML2HTMLMapping()); //OLD CODE - /* - CompleteResourceProfile profile = ISClientRequester.getResourceByID(this.getXML2HTMLMapping(), new ScopeBean(scope), type, resID); - */ + //CompleteResourceProfile profile = ISClientRequester.getResourceByID(this.getXML2HTMLMapping(), new ScopeBean(scope), type, resID); + //NEW CODE CompleteResourceProfile profile = RegistryClientRequester.getResourceByID(this.getXML2HTMLMapping(), scope, type, resID); diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServletResource.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServletResource.java index 3715e72..9c2aca7 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServletResource.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServletResource.java @@ -9,20 +9,17 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.gcube.portlets.admin.resourcemanagement.shared.resource.CacheList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + public class ServletResource extends HttpServlet { - private static final Logger log = LoggerFactory.getLogger(ServletResource.class); /** * */ private static final long serialVersionUID = 8877769357760713039L; - private String message; public void init() throws ServletException { // Do required initialization - log.debug("+++++++++++++Servlet Resource path"+this.getServletContext().getContextPath()); + } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/CacheList.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/CacheList.java index 4282204..305eb41 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/CacheList.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/CacheList.java @@ -11,5 +11,5 @@ public class CacheList { //use from //type-subtype, list di resource - public static Map> resourceTable = Collections.synchronizedMap(new HashMap()); + //public static Map> resourceTable = Collections.synchronizedMap(new HashMap()); } diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/GenericResourceObject.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/GenericResourceObject.java index 906d117..30249b7 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/GenericResourceObject.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/GenericResourceObject.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlRootElement; http:$$cloud.recas.ba.infn.it:8787$occi$compute$0805c2db-ae17-4418-9ecd-8e81552791d2@dded8184-c033-48af-8633-b1adcf3e3308 Node deployed to Provider dded8184-c033-48af-8633-b1adcf3e3308with serviceProfile3b6633b7-593a-4626-af19-61295fe23bc1 - * @author pieve + * @author pieve mail:alessandro.pieve@isti.cnr.it * */ @XmlRootElement(name = "Resource") diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/HostingNodeObject.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/HostingNodeObject.java new file mode 100644 index 0000000..cf38dfd --- /dev/null +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/HostingNodeObject.java @@ -0,0 +1,204 @@ +package org.gcube.portlets.admin.resourcemanagement.shared.resource; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + +a7597dbc-28a3-4ad5-ba6d-19e7a0a2d41d +GHN +upv.es +certified +niebla.i3m.upv.es:80 +17:07 +2017-03-28T10:10:33+02:00 +2832216 +17957 +17676 +0.87 +0.36 +0.39 +2.1.0-4.2.0-139932 +2.0.0-4.2.0-132475 +/gcube/devNext;/gcube + +*@author pieve mail:alessandro.pieve@isti.cnr.it +*/ +@XmlRootElement(name = "Resource") +public class HostingNodeObject { + + private String id; + private String type; + private String subType; + private String status; + private String name; + private String upTime; + private String lastUpdate; + private long localAvailableSpace; + private long virtualSize; + private long virtualAvailable; + private String loadLast1Min; + private String loadLast5Min; + private String loadLast15Min; + private String gcfVersion; + private String ghnVersion; + private String scopes; + + public HostingNodeObject(){} + + + public HostingNodeObject(String id, String type, String subType, + String status, String name, String upTime, String lastUpdate, + long localAvailableSpace, long virtualSize, + long virtualAvailable, String loadLast1Min, String loadLast5Min, + String loadLast15Min, String gcfVersion, String ghnVersion, + String scopes) { + super(); + this.id = id; + this.type = type; + this.subType = subType; + this.status = status; + this.name = name; + this.upTime = upTime; + this.lastUpdate = lastUpdate; + this.localAvailableSpace = localAvailableSpace; + this.virtualSize = virtualSize; + this.virtualAvailable = virtualAvailable; + this.loadLast1Min = loadLast1Min; + this.loadLast5Min = loadLast5Min; + this.loadLast15Min = loadLast15Min; + this.gcfVersion = gcfVersion; + this.ghnVersion = ghnVersion; + this.scopes = scopes; + } + + @XmlElement(name = "ID") + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + @XmlElement(name = "Type") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + @XmlElement(name = "SubType") + public String getSubType() { + return subType; + } + public void setSubType(String subType) { + this.subType = subType; + } + + @XmlElement(name = "Status") + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + @XmlElement(name = "Name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + @XmlElement(name = "Uptime") + public String getUpTime() { + return upTime; + } + public void setUpTime(String upTime) { + this.upTime = upTime; + } + + @XmlElement(name = "LastUpdate") + public String getLastUpdate() { + return lastUpdate; + } + public void setLastUpdate(String lastUpdate) { + this.lastUpdate = lastUpdate; + } + + @XmlElement(name = "LocalAvailableSpace") + public long getLocalAvailableSpace() { + return localAvailableSpace; + } + public void setLocalAvailableSpace(long localAvailableSpace) { + this.localAvailableSpace = localAvailableSpace; + } + + @XmlElement(name = "VirtualSize") + public long getVirtualSize() { + return virtualSize; + } + public void setVirtualSize(long virtualSize) { + this.virtualSize = virtualSize; + } + + @XmlElement(name = "VirtualAvailable") + public long getVirtualAvailable() { + return virtualAvailable; + } + public void setVirtualAvailable(long virtualAvailable) { + this.virtualAvailable = virtualAvailable; + } + + @XmlElement(name = "LoadLast1Min") + public String getLoadLast1Min() { + return loadLast1Min; + } + public void setLoadLast1Min(String loadLast1Min) { + this.loadLast1Min = loadLast1Min; + } + + @XmlElement(name = "LoadLast5Min") + public String getLoadLast5Min() { + return loadLast5Min; + } + public void setLoadLast5Min(String loadLast5Min) { + this.loadLast5Min = loadLast5Min; + } + + @XmlElement(name = "LoadLast15Min") + public String getLoadLast15Min() { + return loadLast15Min; + } + public void setLoadLast15Min(String loadLast15Min) { + this.loadLast15Min = loadLast15Min; + } + + @XmlElement(name = "gcf-version") + public String getGcfVersion() { + return gcfVersion; + } + public void setGcfVersion(String gcfVersion) { + this.gcfVersion = gcfVersion; + } + + @XmlElement(name = "ghn-version") + public String getGhnVersion() { + return ghnVersion; + } + public void setGhnVersion(String ghnVersion) { + this.ghnVersion = ghnVersion; + } + + + @XmlElement(name = "Scopes") + public String getScopes() { + return scopes; + } + public void setScopes(String scopes) { + this.scopes = scopes; + } + +} diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java index c9396c8..8d89c49 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java @@ -3,32 +3,45 @@ package org.gcube.portlets.admin.resourcemanagement.shared.resource; import java.io.StringWriter; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.model.ER; import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.entity.facet.AccessPointFacet; -import org.gcube.informationsystem.model.entity.facet.IdentifierFacet; +import org.gcube.informationsystem.model.entity.facet.MemoryFacet; import org.gcube.informationsystem.model.entity.facet.NetworkingFacet; import org.gcube.informationsystem.model.entity.facet.ServiceStateFacet; +import org.gcube.informationsystem.model.entity.facet.SimplePropertyFacet; import org.gcube.informationsystem.model.entity.facet.SoftwareFacet; +import org.gcube.informationsystem.model.entity.facet.StateFacet; import org.gcube.informationsystem.model.entity.resource.Configuration; import org.gcube.informationsystem.model.entity.resource.EService; +import org.gcube.informationsystem.model.entity.resource.HostingNode; import org.gcube.informationsystem.model.relation.ConsistsOf; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClient; -import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClientFactory; +import org.gcube.informationsystem.model.relation.consistsof.HasPersistentMemory; +import org.gcube.informationsystem.model.relation.consistsof.HasVolatileMemory; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; +import com.google.gwt.thirdparty.json.JSONArray; +import com.google.gwt.thirdparty.json.JSONObject; + + + +/** + * + * @author pieve mail:alessandro.pieve@isti.cnr.it + * + */ public class UtilityResource { - private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); - //UTILITY per Calcolare i sotto alberi public static ArrayList getSubResourcesTree(String entity, String scope) throws Exception{ ArrayList list = new ArrayList<>(); List resources = (List) resourceRegistryClient.getInstances(entity, true); @@ -38,7 +51,7 @@ public class UtilityResource { for (Facet f : facets) { switch (entity) { - /* + /* case "Software": if(f instanceof NetworkingFacet){ NetworkingFacet nf = (NetworkingFacet) f; @@ -70,14 +83,16 @@ public class UtilityResource { list.add(nf.getHostName()); } break; - + */ case "HostingNode": if(f instanceof NetworkingFacet){ NetworkingFacet nf = (NetworkingFacet) f; - list.add(nf.getDomainName()); + if (!list.contains(nf.getDomainName())){ + list.add(nf.getDomainName()); + } } break; - + /* case "Dataset": if(f instanceof NetworkingFacet){ NetworkingFacet nf = (NetworkingFacet) f; @@ -99,17 +114,11 @@ public class UtilityResource { */ case "Configuration": if(f instanceof SoftwareFacet){ - System.out.println("------------Configuration--SoftwareFacet-- identified by GenericResource"); + // System.out.println("------------Configuration--SoftwareFacet-- identified by GenericResource"); SoftwareFacet sf = (SoftwareFacet) f; if (!list.contains(sf.getGroup())){ list.add(sf.getGroup()); - System.out.println("------------sf.getGroup()"+sf.getGroup()); } - //creo mappa con tutta la struttura - //passo lo scope - UtilityResource.CreateCacheListConfiguration(scope); - - } break; /* @@ -155,28 +164,170 @@ public class UtilityResource { break; */ + } } } - - } - - return list; + } + + + + + + + + public static ArrayList getSubResourcesTreeQuery(String entity, String scope) throws Exception{ + + ArrayList list = new ArrayList<>(); + String field = null; + String identifiedFacet = null; + switch (entity) { + + case "HostingNode": + field="domainName"; + identifiedFacet="NetworkingFacet"; + break; + + case "Configuration": + field="group"; + identifiedFacet="SoftwareFacet"; + break; + + case "EService": //GcoreEndPoint + field="group"; + identifiedFacet="SoftwareFacet"; + break; + + } + String query="SELECT DISTINCT("+field+") AS "+field+" " + + "FROM (TRAVERSE outE('IsIdentifiedBy'),inV('"+identifiedFacet+"') FROM "+entity+")"; + + System.out.println("------------query----------->"+query); + String result=resourceRegistryClient.query(query, 1000, null); + JSONObject jsonObj = new JSONObject(result); + JSONArray jsonArray=jsonObj.getJSONArray("result"); + + for(int i=0;i < jsonArray.length();i++){ + list.add(jsonArray.getJSONObject(i).getString(field)); + } + return list; + } + + + /*** + * Create a list for configuration (aka GenericResourceObject) + * @param scope + * @param typeE + * @return + * @throws Exception + */ + public static List CreateListConfigurationQuery(String scope, + String typeC, String subTypeC) throws Exception { + + ScopeProvider.instance.set(scope); + + String query=null; + if (subTypeC==null){ + query="SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') " + + " FROM Configuration WHILE $depth<=0)"; + } + else{ + query="SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') " + + " FROM Configuration ) where group='"+subTypeC+"'"; + } + System.out.println("------------query list configuration----------->"+query); + + JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.setProperty(Marshaller.JAXB_FRAGMENT, true); + + Listresource=new ArrayList(); + String id=""; + //String type="EService"; + String type="GenericResource"; + String subType=""; + String name=""; + String description=""; + + String result=resourceRegistryClient.query(query, 1000, null); + JSONObject jsonObj = new JSONObject(result); + JSONArray jsonArray=jsonObj.getJSONArray("result"); + + for(int i=0;i < jsonArray.length();i++){ + //TODO + //id=jsonArray.getJSONObject(i).getString("header"); + //id="b981efde-18ea-4867-98e7-5d024fcfc0cb"+i; + JSONObject header=new JSONObject(jsonArray.getJSONObject(i).getString("header")); + id=(String) header.get("uuid"); + System.out.println("------------id----------->"+id); + + try{ + name=jsonArray.getJSONObject(i).getString("name"); + }catch(Exception e){ + name=""; + } + try{ + description=jsonArray.getJSONObject(i).getString("description"); + }catch(Exception e){ + description=""; + } + + + + GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,scope); + + + StringWriter sw = new StringWriter(); + m.marshal(temp,sw); + + UUID uuid =UUID.fromString(id); + // ER configurationRegistry=resourceRegistryClient.getInstance(Configuration.class, uuid); + // CacheList.resourceid.put(id, new ResourceObject(name, configurationRegistry.toString())); + + resource.add(sw.toString()); + + + } + + /* + List econfiguration = (List) resourceRegistryClient.getInstances(Configuration.NAME,false); + for (Configuration et : econfiguration) { + id=et.getHeader().getUUID().toString(); + List facets = et.getIdentificationFacets(); + for (Facet f : facets) { + if(f instanceof SoftwareFacet){ + SoftwareFacet sf = (SoftwareFacet) f; + name=sf.getName(); + subType=sf.getGroup(); + description= sf.getDescription(); + + } + } + CacheList.resourceid.put(id, new ResourceObject(name, et.toString())); + GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,scope); + + StringWriter sw = new StringWriter(); + m.marshal(temp,sw); + // filter to subtype + if (subTypeC!=null){ + if (subType.equals(subTypeC)){ + resource.add(sw.toString()); + } + } + else + resource.add(sw.toString()); } + */ + return resource; + + } - - - - - - - - /*** * Create a list for eservice (aka gcore endpoint) @@ -320,65 +471,130 @@ public class UtilityResource { } - - //NOT WORK it's too slow - private static void CreateCacheListConfiguration(String scope) throws Exception { - // TODO Auto-generated method stub + + /*** + * Create a list for hosting node (aka GHN) + * @param scope + * @param typeE + * @return + * @throws Exception + * @throws Exception + */ + public static List CreateListHostingNode(String scope, String typeC,String subTypeC) throws Exception { + ScopeProvider.instance.set(scope); - JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class); + JAXBContext context = JAXBContext.newInstance(HostingNodeObject.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, true); Listresource=new ArrayList(); String id=""; - //String type="EService"; - String type="GenericResource"; - String subType=""; - String name=""; - String description=""; - List econfiguration = (List) resourceRegistryClient.getInstances(Configuration.NAME,false); - for (Configuration et : econfiguration) { - id=et.getHeader().getUUID().toString(); - List facets = et.getIdentificationFacets(); + //String type="HostingNode"; + String type="GHN"; + String subType="";//-- + String status="";//--- + String name="";// + String upTime="-"; + String lastUpdate="-"; + long localAvailableSpace = 0; + long virtualSize=0; + long virtualAvailable=0; + String loadLast1Min="-"; + String loadLast5Min="-"; + String loadLast15Min="-"; + String gcfVersion=""; + String ghnVersion=""; + + List ehosting = (List) resourceRegistryClient.getInstances(HostingNode.NAME,false); + for (HostingNode eh : ehosting) { + id=eh.getHeader().getUUID().toString(); + lastUpdate=eh.getHeader().getLastUpdateTime().toString(); + List facets = eh.getIdentificationFacets(); for (Facet f : facets) { - if(f instanceof SoftwareFacet){ - SoftwareFacet sf = (SoftwareFacet) f; - - name=sf.getName(); - subType=sf.getGroup(); - description= sf.getDescription(); - + if(f instanceof NetworkingFacet){ + NetworkingFacet nf = (NetworkingFacet) f; + subType=nf.getDomainName(); + name=nf.getHostName(); } } - CacheList.resourceid.put(id, new ResourceObject(name, et.toString())); - - GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,scope); + CacheList.resourceid.put(id, new ResourceObject(name, eh.toString())); + List> consist = eh.getConsistsOf(); + for (ConsistsOf c : consist) { + //System.out.println("------------ConsistsOf--ConsistsOf-- c"+c.toString()); + if(c instanceof ConsistsOf){ + + if (c.getTarget() instanceof SimplePropertyFacet){ + SimplePropertyFacet sp = (SimplePropertyFacet) c.getTarget(); + try { + gcfVersion=sp.getAdditionalProperty("SmartGearsDistribution").toString(); + ghnVersion=sp.getAdditionalProperty("SmartGears").toString(); + } + catch(Exception e){ + gcfVersion=""; + ghnVersion=""; + } + } + //get disk space + if (c instanceof HasPersistentMemory){ + HasPersistentMemory hpm = (HasPersistentMemory) c; + try { + MemoryFacet mfh = (MemoryFacet) hpm.getTarget(); + localAvailableSpace=mfh.getSize()- mfh.getUsed(); + } + catch(Exception e){ + localAvailableSpace=0; + } + } + //get ram space + if (c instanceof HasVolatileMemory){ + HasVolatileMemory hvm = (HasVolatileMemory) c; + try { + if (hvm.getAdditionalProperty("memoryType").equals("RAM")){ + MemoryFacet mf = (MemoryFacet) hvm.getTarget(); + virtualAvailable=mf.getSize()-mf.getUsed(); + virtualSize=mf.getSize(); + } + } + catch(Exception e){ + virtualAvailable=0; + virtualSize=0; + } + } + //get status + if (c.getTarget() instanceof StateFacet){ + StateFacet st = (StateFacet) c.getTarget(); + try { + status=st.getValue(); + } + catch(Exception e){ + status=""; + } + } + } + } + HostingNodeObject temp =new HostingNodeObject( id, type, subType, + status, name, upTime, lastUpdate, + localAvailableSpace, virtualSize, + virtualAvailable, loadLast1Min, loadLast5Min, + loadLast15Min, gcfVersion, ghnVersion, + scope); StringWriter sw = new StringWriter(); m.marshal(temp,sw); - System.out.println("---------------->sw.toString "+sw.toString()); - - if (CacheList.resourceTable.containsKey(type+subType)){ - List listResource=CacheList.resourceTable.get(type+subType); - if (!listResource.contains(sw.toString())) - listResource.add(sw.toString()); - + // filter to subtype + if (subTypeC!=null){ + if (subType.equals(subTypeC)){ + resource.add(sw.toString()); + } } - else{ - ListlistResource=new ArrayList(); - listResource.add(sw.toString()); - CacheList.resourceTable.put(type+subType, listResource); - } - - - } - - + else + resource.add(sw.toString()); + + } + return resource; } - - }