modules/core/dbutils/pom.xml | 2
modules/core/dbutils/src/main/scripts/dbsetup/inventory-schema.xml | 6
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml | 14
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java | 12
modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java | 13
modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java | 24
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/AutoGroupTopView.java | 106 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java | 7
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTopView.java | 17
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java | 58 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTopView.java | 27
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java | 83 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java | 378 ++++++----
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java | 10
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java | 22
15 files changed, 542 insertions(+), 237 deletions(-)
New commits:
commit 4632def4a92d6edfaffe118e07abd5135eb84c70
Merge: 67570cc... ab9648b...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Sep 27 15:00:56 2010 -0400
Merge branch 'master' into master-jay
Conflicts:
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
diff --cc modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
index d701852,aa854f8..f54ffd2
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
@@@ -54,12 -56,13 +55,14 @@@ import org.rhq.enterprise.gui.coregui.c
import org.rhq.enterprise.gui.coregui.client.ViewPath;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
+ import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**
* @author Greg Hinkle
+ * @author Ian Springer
*/
-public class ResourceGroupTreeView extends VLayout implements BookmarkableView {
+public class ResourceGroupTreeView extends LocatableVLayout implements BookmarkableView {
private TreeGrid treeGrid;
@@@ -73,8 -76,7 +76,9 @@@
private Map<Integer, ResourceType> typeMap;
private ResourceGroup selectedGroup;
- public ResourceGroupTreeView() {
+ public ResourceGroupTreeView(String locatorId) {
+ super(locatorId);
++
setWidth(250);
setHeight100();
}
@@@ -152,35 -154,33 +156,33 @@@
ResourceGroup group = result.get(0);
ResourceGroupTreeView.this.selectedGroup = group;
- if (GroupCategory.MIXED == group.getGroupCategory()) {
+ GroupCategory groupCategory = group.getGroupCategory();
+ switch (groupCategory) {
- case MIXED:
++ case MIXED:
+ ResourceGroupTreeView.this.rootResourceGroup = group;
+ ResourceGroupTreeView.this.rootGroupId = rootResourceGroup.getId();
+ TreeNode fakeRoot = new TreeNode("fakeRootNode");
+ TreeNode rootNode = new TreeNode(rootResourceGroup.getName());
+ rootNode.setID(String.valueOf(rootResourceGroup.getId())); //getClusterKey().toString());
+ fakeRoot.setChildren(new TreeNode[] { rootNode });
+ Tree tree = new Tree();
+ tree.setRoot(fakeRoot);
+ treeGrid.setData(tree);
+ treeGrid.markForRedraw();
- } else {
++ break;
++ case COMPATIBLE:
+ if (group.getClusterResourceGroup() == null) {
++ // This is a straight up compatible group.
ResourceGroupTreeView.this.rootResourceGroup = group;
- // This is a straight up group
- loadGroup(groupId);
- ResourceGroupTreeView.this.rootGroupId = rootResourceGroup.getId();
- TreeNode fakeRoot = new TreeNode("fakeRootNode");
- TreeNode rootNode = new TreeNode(rootResourceGroup.getName());
- rootNode.setID(String.valueOf(rootResourceGroup.getId())); //getClusterKey().toString());
- fakeRoot.setChildren(new TreeNode[] { rootNode });
- Tree tree = new Tree();
- tree.setRoot(fakeRoot);
- treeGrid.setData(tree);
- treeGrid.markForRedraw();
- break;
- case COMPATIBLE:
- if (group.getClusterResourceGroup() == null) {
- // This is a straight up compatible group.
- ResourceGroupTreeView.this.rootResourceGroup = group;
- } else {
- // This is a cluster group beneath a real recursive compatible group.
- ResourceGroupTreeView.this.rootResourceGroup = group.getClusterResourceGroup();
- }
- loadGroup(ResourceGroupTreeView.this.rootResourceGroup.getId());
- break;
+ } else {
- // Someone select a cluster group beneath a real recursive compatible group
-
- ResourceGroup rootGroup = group.getClusterResourceGroup();
- ResourceGroupTreeView.this.rootResourceGroup = rootGroup;
-
- loadGroup(rootGroup.getId());
++ // This is a cluster group beneath a real recursive compatible group.
++ ResourceGroupTreeView.this.rootResourceGroup = group.getClusterResourceGroup();
+ }
++ loadGroup(ResourceGroupTreeView.this.rootResourceGroup.getId());
++ break;
}
-
}
});
-
}
private void loadGroup(int groupId) {
@@@ -277,44 -268,79 +270,77 @@@
treeGrid.markForRedraw();
}
- public void loadTree(TreeNode parent, ClusterFlyweight parentNode, ClusterKey parentKey) {
- if (!parentNode.getChildren().isEmpty()) {
-
- // TODO Introduce type groups (Do we still like this model for recursive compatibles?)
-
- ArrayList<TreeNode> childNodes = new ArrayList<TreeNode>();
-
- HashMap<Integer, TreeNode> typeNodes = new HashMap<Integer, TreeNode>();
-
- for (ClusterFlyweight child : parentNode.getChildren()) {
- TreeNode node = new TreeNode(child.getName());
-
+ public void loadTree(TreeNode parentNode, ClusterFlyweight parentClusterGroup, ClusterKey parentKey) {
+ if (!parentClusterGroup.getChildren().isEmpty()) {
+ // First pass - group the children by type.
+ Map<ResourceType, List<ClusterFlyweight>> childrenByType = new HashMap<ResourceType, List<ClusterFlyweight>>();
+ for (ClusterFlyweight child : parentClusterGroup.getChildren()) {
ClusterKeyFlyweight keyFlyweight = child.getClusterKey();
- ClusterKey key = new ClusterKey(parentKey, keyFlyweight.getResourceTypeId(), keyFlyweight
- .getResourceKey());
ResourceType type = this.typeMap.get(keyFlyweight.getResourceTypeId());
+ List<ClusterFlyweight> children = childrenByType.get(type);
+ if (children == null) {
+ children = new ArrayList<ClusterFlyweight>();
+ childrenByType.put(type, children);
+ }
+ children.add(child);
+ }
- String icon = "types/" + type.getCategory().getDisplayName() + "_up_16.png";
-
- node.setIcon(icon);
+ // Second pass - process each of the sets of like-typed children created in the first pass.
+ List<TreeNode> childNodes = new ArrayList<TreeNode>();
+ for (ResourceType type : childrenByType.keySet()) {
+ List<ClusterFlyweight> children = childrenByType.get(type);
+ List<TreeNode> nodesByType = new ArrayList<TreeNode>();
+ for (ClusterFlyweight child : children) {
+ TreeNode node = createClusterGroupNode(parentKey, type, child);
+ nodesByType.add(node);
+
+ if (!child.getChildren().isEmpty()) {
+ // Recurse.
- ClusterKey key = (ClusterKey)node.getAttributeAsObject("key");
++ ClusterKey key = (ClusterKey) node.getAttributeAsObject("key");
+ loadTree(node, child, key);
+ }
+ }
- node.setID(key.getKey());
- node.setAttribute("key", key);
- node.setAttribute("resourceType", type);
- childNodes.add(node);
+ // TODO (ips): Insert subcategory nodes.
- if (child.getChildren().isEmpty()) {
- node.setIsFolder(false);
+ if (type.isSingleton()) {
+ // If it's a singleton type, just insert the cluster group node as is.
+ childNodes.addAll(nodesByType);
- }
- else {
+ } else {
- node.setIsFolder(true);
- loadTree(node, child, key);
+ // Otherwise insert an autoTypeGroup folder node to group all cluster groups of this type.
+ TreeNode autoTypeGroupNode = createAutoTypeGroupNode(type, nodesByType);
+ childNodes.add(autoTypeGroupNode);
}
}
- parent.setChildren(childNodes.toArray(new TreeNode[childNodes.size()]));
+ parentNode.setChildren(childNodes.toArray(new TreeNode[childNodes.size()]));
}
}
+ private TreeNode createClusterGroupNode(ClusterKey parentKey, ResourceType type, ClusterFlyweight child) {
+ TreeNode node = new TreeNode(child.getName());
+
+ ClusterKeyFlyweight keyFlyweight = child.getClusterKey();
- ClusterKey key = new ClusterKey(parentKey, keyFlyweight.getResourceTypeId(), keyFlyweight
- .getResourceKey());
++ ClusterKey key = new ClusterKey(parentKey, keyFlyweight.getResourceTypeId(), keyFlyweight.getResourceKey());
+ String id = key.getKey();
+ node.setID(id);
+ node.setAttribute("key", key);
+ node.setAttribute("resourceType", type);
+ node.setIsFolder(!child.getChildren().isEmpty());
+
+ String icon = "types/" + type.getCategory().getDisplayName() + "_up_16.png";
+ node.setIcon(icon);
+ return node;
+ }
+
+ private TreeNode createAutoTypeGroupNode(ResourceType type, List<TreeNode> memberNodes) {
+ String name = StringUtility.pluralize(type.getName());
+ TreeNode autoTypeGroupNode = new TreeNode(name);
+ autoTypeGroupNode.setIsFolder(true);
+ autoTypeGroupNode.setChildren(memberNodes.toArray(new TreeNode[memberNodes.size()]));
+ return autoTypeGroupNode;
+ }
+
public void renderView(ViewPath viewPath) {
currentViewId = viewPath.getCurrent();
int groupId = Integer.parseInt(currentViewId.getPath());
commit 67570cc0877700278ddac9588700699dd9b99129
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Sep 27 14:26:21 2010 -0400
Initial support for Group-Backed AutoGroups
- A lot of work to integrate autogroup nodes into the resource tree view
such that the group renders in the tabbed view while maintaining a
resource tree (not a group tree).
- Tried to pare down code in resourceTreeView to only what is necessary.
- Some more work pending: breadcrumb issues, context menu not yet there,
direct url (saved url) does not always expand tree.
- minor, prevent adding "s" to singulars ending in "s" in pluralization code.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
index f5c14c5..00a27f0 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
@@ -51,7 +51,6 @@ import org.rhq.enterprise.gui.coregui.client.alert.AlertsView;
import org.rhq.enterprise.gui.coregui.client.bundle.BundleTopView;
import org.rhq.enterprise.gui.coregui.client.dashboard.DashboardsView;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.AutoGroupTopView;
import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.ResourceGroupTopView;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.InventoryView;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceTopView;
@@ -292,8 +291,6 @@ public class CoreGUI implements EntryPoint, ValueChangeHandler<String> {
canvas = new ResourceTopView("Resource");
} else if (breadcrumbName.equals("ResourceGroup")) {
canvas = new ResourceGroupTopView("Group");
- } else if (breadcrumbName.equals("AutoGroup")) {
- canvas = new AutoGroupTopView("AutoGroup");
} else if (breadcrumbName.equals("Dashboard")) {
canvas = new DashboardsView("Dashboard");
} else if (breadcrumbName.equals("Bundles")) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
index e00ecbe..e5bfc72 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
@@ -60,7 +60,7 @@ import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTyp
* @author Ian Springer
*/
public class ResourceGroupDetailView extends AbstractTwoLevelTabSetView<ResourceGroupComposite, ResourceGroupTitleBar> {
- public static final String AUTO_GROUP_VIEW_PATH = "AutoGroup";
+ public static final String AUTO_GROUP_VIEW_PATH = "Resource/AutoGroup";
public static final String GROUP_VIEW_PATH = "ResourceGroup";
private Integer groupId;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTopView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTopView.java
index ec96874..01b72dd 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTopView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTopView.java
@@ -22,6 +22,7 @@ import com.smartgwt.client.widgets.Canvas;
import org.rhq.enterprise.gui.coregui.client.BookmarkableView;
import org.rhq.enterprise.gui.coregui.client.ViewPath;
+import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.ResourceGroupDetailView;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
/**
@@ -32,7 +33,7 @@ public class ResourceTopView extends LocatableHLayout implements BookmarkableVie
private Canvas contentCanvas;
private ResourceTreeView treeView;
private ResourceDetailView detailView = new ResourceDetailView(extendLocatorId("Detail"));
-
+ private ResourceGroupDetailView autoGroupDetailView;
public ResourceTopView(String locatorId) {
super(locatorId);
@@ -49,7 +50,6 @@ public class ResourceTopView extends LocatableHLayout implements BookmarkableVie
setContent(detailView);
}
-
public void setContent(Canvas newContent) {
for (Canvas child : this.contentCanvas.getChildren()) {
child.destroy();
@@ -58,10 +58,27 @@ public class ResourceTopView extends LocatableHLayout implements BookmarkableVie
this.contentCanvas.markForRedraw();
}
-
public void renderView(ViewPath viewPath) {
- this.treeView.renderView(viewPath);
- this.detailView.renderView(viewPath);
+ if ("AutoGroup".equals(viewPath.getCurrent().getPath())) {
+ if (null == autoGroupDetailView) {
+ this.autoGroupDetailView = new ResourceGroupDetailView(this.extendLocatorId("AutoGroupDetail"),
+ ResourceGroupDetailView.AUTO_GROUP_VIEW_PATH);
+ this.setContent(this.autoGroupDetailView);
+ this.detailView = null;
+ }
+ this.treeView.renderView(viewPath);
+ this.autoGroupDetailView.renderView(viewPath.next());
+ } else {
+ // Resource
+ if (null == detailView) {
+ this.detailView = new ResourceDetailView(extendLocatorId("Detail"));
+ this.setContent(this.detailView);
+ this.autoGroupDetailView = null;
+ }
+ this.treeView.renderView(viewPath);
+ this.detailView.renderView(viewPath);
+ }
+
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
index 07995df..3ad6835 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
@@ -287,13 +287,9 @@ public class ResourceTreeDatasource extends DataSource {
String id = idOf(resource);
setID(id);
- setAttribute(Attributes.ID, id);
String parentId = parentIdOf(resource);
setParentID(parentId);
- setAttribute(Attributes.PARENT_ID, parentId);
-
- // setAttribute("parentKey", parentId);
ResourceType type = resource.getResourceType();
String name = StringUtility.pluralize(type.getName());
@@ -326,12 +322,21 @@ public class ResourceTreeDatasource extends DataSource {
* Given a Resource, generate a unique ID for the AGNode.
*
* @param resource requires resourceType field be set. requires parentResource field be set (null for no parent)
- * @return The name string or null if the R
+ * @return The name string or null if the parentResource is null.
*/
public static String idOf(Resource resource) {
Resource parentResource = resource.getParentResource();
- return (parentResource != null) ? "autogroup_" + resource.getResourceType().getId() + "_"
- + parentResource.getId() : null;
+ return idOf(parentResource, resource.getResourceType());
+ }
+
+ /**
+ * Given a Resource, generate a unique ID for the AGNode.
+ *
+ * @param resource requires resourceType field be set. requires parentResource field be set (null for no parent)
+ * @return The name string or null if the parentResource is null;
+ */
+ public static String idOf(Resource parentResource, ResourceType resourceType) {
+ return (parentResource != null) ? "autogroup_" + resourceType.getId() + "_" + parentResource.getId() : null;
}
// parent node is either a subcategory node or a resouce node
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
index b20cfb3..2c7a973 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
@@ -24,7 +24,9 @@ package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail;
import java.util.ArrayList;
import java.util.EnumSet;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -74,10 +76,11 @@ import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGroupGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceTypeGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceSelectListener;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceTreeDatasource.AutoGroupTreeNode;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceTreeDatasource.ResourceTreeNode;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.operation.create.OperationCreateWizard;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.factory.ResourceFactoryCreateWizard;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
-import org.rhq.enterprise.gui.coregui.client.util.TreeUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
@@ -86,18 +89,18 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
*/
public class ResourceTreeView extends LocatableVLayout {
- private int selectedResourceId;
-
- private Resource rootResource;
-
private TreeGrid treeGrid;
+ private String selectedNodeId;
private Menu contextMenu;
+ private Resource rootResource;
+
private ViewId currentViewId;
private List<ResourceSelectListener> selectListeners = new ArrayList<ResourceSelectListener>();
- private boolean initialSelect = false;
+ // Maps autogroup/type backing group ids to the corresponding autogroup/type nodes.
+ Map<Integer, AutoGroupTreeNode> autoGroupNodeMap = new HashMap<Integer, AutoGroupTreeNode>();
public ResourceTreeView(String locatorId) {
super(locatorId);
@@ -133,20 +136,25 @@ public class ResourceTreeView extends LocatableVLayout {
treeGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
public void onSelectionChanged(SelectionEvent selectionEvent) {
if (!selectionEvent.isRightButtonDown() && selectionEvent.getState()) {
- ListGridRecord selectedNode = treeGrid.getSelectedRecord();
- if (selectedNode instanceof ResourceTreeDatasource.ResourceTreeNode) {
- System.out.println("Resource Node selected in tree: " + selectedNode);
- ResourceTreeDatasource.ResourceTreeNode resourceNode = (ResourceTreeDatasource.ResourceTreeNode) selectedNode;
+ ListGridRecord selectedRecord = treeGrid.getSelectedRecord();
+ if (selectedRecord instanceof ResourceTreeNode) {
+ System.out.println("AutoGroup Node selected in tree: " + selectedRecord);
+
+ ResourceTreeNode resourceNode = (ResourceTreeNode) selectedRecord;
+ selectedNodeId = resourceNode.getID();
String viewPath = "Resource/" + resourceNode.getResource().getId();
String currentViewPath = History.getToken();
if (!currentViewPath.startsWith(viewPath)) {
CoreGUI.goToView(viewPath);
}
- } else if (selectedNode instanceof ResourceTreeDatasource.AutoGroupTreeNode) {
- System.out.println("AutoGroup Node selected in tree: " + selectedNode);
- handleSelectedAutoGroupNode((ResourceTreeDatasource.AutoGroupTreeNode) selectedNode);
+ } else if (selectedRecord instanceof AutoGroupTreeNode) {
+ System.out.println("AutoGroup Node selected in tree: " + selectedRecord);
+
+ AutoGroupTreeNode agNode = (AutoGroupTreeNode) selectedRecord;
+ selectedNodeId = agNode.getID();
+ handleSelectedAutoGroupNode(agNode);
} else {
- System.out.println("Unhandled Node selected in tree: " + selectedNode);
+ System.out.println("Unhandled Node selected in tree: " + selectedRecord);
}
}
}
@@ -160,31 +168,29 @@ public class ResourceTreeView extends LocatableVLayout {
event.getNode();
event.cancel();
- if (event.getNode() instanceof ResourceTreeDatasource.AutoGroupTreeNode) {
- showContextMenu((ResourceTreeDatasource.AutoGroupTreeNode) event.getNode());
- } else if (event.getNode() instanceof ResourceTreeDatasource.ResourceTreeNode) {
- showContextMenu((ResourceTreeDatasource.ResourceTreeNode) event.getNode());
+ if (event.getNode() instanceof AutoGroupTreeNode) {
+ showContextMenu((AutoGroupTreeNode) event.getNode());
+ } else if (event.getNode() instanceof ResourceTreeNode) {
+ showContextMenu((ResourceTreeNode) event.getNode());
}
}
});
treeGrid.addDataArrivedHandler(new DataArrivedHandler() {
public void onDataArrived(DataArrivedEvent dataArrivedEvent) {
- if (!initialSelect) {
- updateBreadcrumbs();
- }
+ updateSelection();
}
});
}
- private void handleSelectedAutoGroupNode(final ResourceTreeDatasource.AutoGroupTreeNode agNode) {
+ private void handleSelectedAutoGroupNode(final AutoGroupTreeNode agNode) {
final ResourceGroupGWTServiceAsync resourceGroupService = GWTServiceLookup.getResourceGroupService();
// get the children tree nodes and build a child resourceId array
TreeNode[] children = treeGrid.getTree().getChildren(agNode);
final int[] childIds = new int[children.length];
for (int i = 0, size = children.length; (i < size); ++i) {
- childIds[i] = ((ResourceTreeDatasource.ResourceTreeNode) children[i]).getResource().getId();
+ childIds[i] = ((ResourceTreeNode) children[i]).getResource().getId();
}
// get the backing group if it exists, otherwise create the group
@@ -214,12 +220,21 @@ public class ResourceTreeView extends LocatableVLayout {
}
public void onSuccess(ResourceGroup result) {
+ // store a map entry from backingGroupId to AGTreeNode so we can easily
+ // get back to this node given the id of the backing group (from the viewpath)
+ autoGroupNodeMap.put(result.getId(), agNode);
renderAutoGroup(result);
}
});
} else {
- // backing group found, make sure the members are correct
+ // backing group found
final ResourceGroup backingGroup = result.get(0);
+
+ // store a map entry from backingGroupId to AGTreeNode so we can easily
+ // get back to this node given the id of the backing group (from the viewpath)
+ autoGroupNodeMap.put(backingGroup.getId(), agNode);
+
+ // make sure the members are correct before rendering
resourceGroupService.setAssignedResources(backingGroup.getId(), childIds, false,
new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
@@ -238,24 +253,28 @@ public class ResourceTreeView extends LocatableVLayout {
}
private void renderAutoGroup(ResourceGroup backingGroup) {
- String viewPath = "AutoGroup/" + backingGroup.getId();
+ String viewPath = "Resource/AutoGroup/" + backingGroup.getId();
String currentViewPath = History.getToken();
if (!currentViewPath.startsWith(viewPath)) {
CoreGUI.goToView(viewPath);
}
}
- private void updateBreadcrumbs() {
- TreeNode selectedNode = treeGrid.getTree().findById(
- ResourceTreeDatasource.ResourceTreeNode.idOf(selectedResourceId));
- // System.out.println("Trying to preopen: " + selectedNode);
- if (selectedNode != null) {
+ private void updateSelection() {
+
+ TreeNode selectedNode = null;
+ if (treeGrid != null && treeGrid.getTree() != null
+ && (selectedNode = treeGrid.getTree().findById(selectedNodeId)) != null) {
+
TreeNode[] parents = treeGrid.getTree().getParents(selectedNode);
treeGrid.getTree().openFolders(parents);
treeGrid.getTree().openFolder(selectedNode);
- treeGrid.selectRecord(selectedNode);
- initialSelect = true;
+ if (!selectedNode.equals(treeGrid.getSelectedRecord())) {
+ treeGrid.deselectAllRecords();
+ treeGrid.selectRecord(selectedNode);
+ }
+
treeGrid.markForRedraw();
// Update breadcrumbs
@@ -271,12 +290,12 @@ public class ResourceTreeView extends LocatableVLayout {
}
}
- private void showContextMenu(ResourceTreeDatasource.AutoGroupTreeNode node) {
+ private void showContextMenu(AutoGroupTreeNode node) {
contextMenu.setItems(new MenuItem(node.getName()));
contextMenu.showContextMenu();
}
- private void showContextMenu(final ResourceTreeDatasource.ResourceTreeNode node) {
+ private void showContextMenu(final ResourceTreeNode node) {
ResourceType type = node.getResource().getResourceType();
ResourceTypeRepository.Cache.getInstance().getResourceTypes(
type.getId(),
@@ -358,9 +377,11 @@ public class ResourceTreeView extends LocatableVLayout {
MenuItem operationItem = new MenuItem(operationDefinition.getDisplayName());
operationItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
+ int resourceId = ((ResourceTreeNode) treeGrid.getTree().findById(selectedNodeId)).getResource()
+ .getId();
ResourceCriteria criteria = new ResourceCriteria();
- criteria.addFilterId(selectedResourceId);
+ criteria.addFilterId(resourceId);
GWTServiceLookup.getResourceService().findResourcesByCriteria(criteria,
new AsyncCallback<PageList<Resource>>() {
@@ -467,11 +488,12 @@ public class ResourceTreeView extends LocatableVLayout {
addToDBItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent menuItemClickEvent) {
+ int resourceId = ((ResourceTreeNode) treeGrid.getTree().findById(selectedNodeId))
+ .getResource().getId();
DashboardPortlet p = new DashboardPortlet(def.getDisplayName() + " Chart",
GraphPortlet.KEY, 250);
- p.getConfiguration().put(
- new PropertySimple(GraphPortlet.CFG_RESOURCE_ID, selectedResourceId));
+ p.getConfiguration().put(new PropertySimple(GraphPortlet.CFG_RESOURCE_ID, resourceId));
p.getConfiguration().put(
new PropertySimple(GraphPortlet.CFG_DEFINITION_ID, def.getId()));
@@ -506,8 +528,8 @@ public class ResourceTreeView extends LocatableVLayout {
Resource getResource(int resourceId) {
if (this.treeGrid != null && this.treeGrid.getTree() != null) {
- ResourceTreeDatasource.ResourceTreeNode treeNode = (ResourceTreeDatasource.ResourceTreeNode) this.treeGrid
- .getTree().findById(ResourceTreeDatasource.ResourceTreeNode.idOf(resourceId));
+ ResourceTreeNode treeNode = (ResourceTreeNode) this.treeGrid.getTree().findById(
+ ResourceTreeNode.idOf(resourceId));
if (treeNode != null) {
return treeNode.getResource();
}
@@ -520,150 +542,129 @@ public class ResourceTreeView extends LocatableVLayout {
}
public void setSelectedResource(final int selectedResourceId) {
- this.selectedResourceId = selectedResourceId;
- TreeNode node;
- final String resourceNodeId = ResourceTreeDatasource.ResourceTreeNode.idOf(selectedResourceId);
- if (treeGrid != null && treeGrid.getTree() != null
- && (node = treeGrid.getTree().findById(resourceNodeId)) != null) {
+ selectedNodeId = ResourceTreeNode.idOf(selectedResourceId);
+ if (treeGrid != null && treeGrid.getTree() != null && (treeGrid.getTree().findById(selectedNodeId)) != null) {
// This is the case where the tree was previously loaded and we get fired to look at a different
- // node in the same tree and just have to switch the selection
-
- TreeNode[] parents = treeGrid.getTree().getParents(node);
- treeGrid.getTree().openFolders(parents);
- treeGrid.getTree().openFolder(node);
-
- if (!node.equals(treeGrid.getSelectedRecord())) {
- treeGrid.deselectAllRecords();
- treeGrid.selectRecord(node);
- }
+ // node in the same tree and just have to switch the selection
+ updateSelection();
- TreeUtility.printTree(treeGrid.getTree());
-
- updateBreadcrumbs();
} else {
-
// This is for cases where we have to load the tree fresh including down to the currently visible node
+ loadTree(selectedResourceId);
+ }
- final ResourceGWTServiceAsync resourceService = GWTServiceLookup.getResourceService();
- // This is an expensive call, but loads all nodes that are visible in the tree given a selected resource
- resourceService.getResourceLineageAndSiblings(selectedResourceId, new AsyncCallback<List<Resource>>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError("Failed to lookup platform for tree", caught);
- }
-
- public void onSuccess(List<Resource> result) {
- Resource root = result.get(0);
+ }
- if (!root.equals(ResourceTreeView.this.rootResource)) {
+ private void loadTree(final int selectedResourceId) {
+ selectedNodeId = ResourceTreeNode.idOf(selectedResourceId);
- if (treeGrid != null) {
- treeGrid.destroy();
- }
- buildTree();
+ final ResourceGWTServiceAsync resourceService = GWTServiceLookup.getResourceService();
+ // This is an expensive call, but loads all nodes that are visible in the tree given a selected resource
+ resourceService.getResourceLineageAndSiblings(selectedResourceId, new AsyncCallback<List<Resource>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to lookup platform for tree", caught);
+ }
- setRootResource(root);
+ public void onSuccess(List<Resource> result) {
+ Resource root = result.get(0);
- ResourceTreeDatasource dataSource = new ResourceTreeDatasource(result);
- treeGrid.setDataSource(dataSource);
- // GH: couldn't get initial data to mix with the datasource... so i put the initial data in
- // the first datasource request
- // treeGrid.setInitialData(selectedLineage);
+ if (!root.equals(ResourceTreeView.this.rootResource)) {
- addMember(treeGrid);
+ if (treeGrid != null) {
+ treeGrid.destroy();
+ }
+ buildTree();
- treeGrid.fetchData(treeGrid.getCriteria(), new DSCallback() {
- public void execute(DSResponse response, Object rawData, DSRequest request) {
- System.out.println("Done fetching data for tree.");
- updateBreadcrumbs();
- }
- });
+ setRootResource(root);
- TreeUtility.printTree(treeGrid.getTree());
+ // seed datasource with initial resource list
+ ResourceTreeDatasource dataSource = new ResourceTreeDatasource(result);
+ treeGrid.setDataSource(dataSource);
- TreeNode selectedNode = treeGrid.getTree().findById(resourceNodeId);
- // System.out.println("Trying to preopen: " + selectedNode);
- if (selectedNode != null) {
- // System.out.println("Preopen node!!!");
- TreeNode[] parents = treeGrid.getTree().getParents(selectedNode);
- treeGrid.getTree().openFolders(parents);
- treeGrid.getTree().openFolder(selectedNode);
+ addMember(treeGrid);
- for (TreeNode p : parents) {
- System.out.println("open? " + treeGrid.getTree().isOpen(p) + " node: " + p.getName());
- }
+ treeGrid.fetchData(treeGrid.getCriteria(), new DSCallback() {
+ public void execute(DSResponse response, Object rawData, DSRequest request) {
+ System.out.println("Done fetching data for tree.");
+ updateSelection();
+ }
+ });
- updateBreadcrumbs();
+ updateSelection();
- treeGrid.selectRecord(selectedNode);
- initialSelect = true;
- treeGrid.markForRedraw();
- }
+ } else {
+ ResourceTypeRepository.Cache.getInstance().loadResourceTypes(
+ result,
+ EnumSet.of(ResourceTypeRepository.MetadataType.operations,
+ ResourceTypeRepository.MetadataType.children,
+ ResourceTypeRepository.MetadataType.subCategory),
+ new ResourceTypeRepository.ResourceTypeLoadedCallback() {
+ public void onResourceTypeLoaded(List<Resource> result) {
+ treeGrid.getTree().linkNodes(ResourceTreeDatasource.buildNodes(result));
+
+ TreeNode selectedNode = treeGrid.getTree().findById(selectedNodeId);
+ if (selectedNode != null) {
+ updateSelection();
+
+ } else {
+ CoreGUI.getMessageCenter().notify(
+ new Message("Failed to select Resource [" + selectedResourceId + "] in tree.",
+ Message.Severity.Warning));
+ }
- } else {
+ }
+ });
- initialSelect = false;
- ResourceTypeRepository.Cache.getInstance().loadResourceTypes(
- result,
- EnumSet.of(ResourceTypeRepository.MetadataType.operations,
- ResourceTypeRepository.MetadataType.children,
- ResourceTypeRepository.MetadataType.subCategory),
- new ResourceTypeRepository.ResourceTypeLoadedCallback() {
- public void onResourceTypeLoaded(List<Resource> result) {
- treeGrid.getTree().linkNodes(ResourceTreeDatasource.buildNodes(result));
-
- //TreeUtility.printTree(treeGrid.getTree());
-
- TreeNode selectedNode = treeGrid.getTree().findById(resourceNodeId);
- if (selectedNode != null) {
- treeGrid.deselectAllRecords();
- treeGrid.selectRecord(selectedNode);
-
- TreeNode[] parents = treeGrid.getTree().getParents(selectedNode);
- treeGrid.getTree().openFolders(parents);
- treeGrid.getTree().openFolder(selectedNode);
-
- /*
- todo deleteme
- // Update breadcrumbs
- viewId.getBreadcrumbs().clear();
- for (int i = parents.length - 1; i >= 0; i--) {
- TreeNode n = parents[i];
- adjustBreadcrumb(n, viewId);
- }
- adjustBreadcrumb(selectedNode, viewId);
- CoreGUI.refreshBreadCrumbTrail();*/
+ }
+ }
+ });
+ }
- } else {
- CoreGUI.getMessageCenter().notify(
- new Message("Failed to select Resource [" + selectedResourceId
- + "] in tree.", Message.Severity.Warning));
- }
+ public void setSelectedAutoGroup(final Integer selectedAutoGroupId) {
- }
- });
+ AutoGroupTreeNode selectedNode = autoGroupNodeMap.get(selectedAutoGroupId);
+ if (treeGrid != null && treeGrid.getTree() != null && selectedNode != null) {
+ // This is the case where the tree was previously loaded and we get fired to look at a different
+ // node in the same tree and just have to switch the selection
- }
+ this.selectedNodeId = selectedNode.getID();
+ updateSelection();
- TreeNode selectedNode = treeGrid.getTree().findById(resourceNodeId);
- // System.out.println("Trying to preopen: " + selectedNode);
- if (selectedNode != null) {
- TreeNode[] parents = treeGrid.getTree().getParents(selectedNode);
+ } else {
+ // This is for cases where we have to load the tree fresh including down to the currently visible node
- // todo update viewPath's breadcrumbs
- }
+ final ResourceGroupGWTServiceAsync resourceGroupService = GWTServiceLookup.getResourceGroupService();
+ ResourceGroupCriteria criteria = new ResourceGroupCriteria();
+ criteria.addFilterId(selectedAutoGroupId);
+ criteria.addFilterVisible(false);
+ criteria.fetchResourceType(true);
+ resourceGroupService.findResourceGroupsByCriteria(criteria, new AsyncCallback<PageList<ResourceGroup>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to fetch autogroup backing group", caught);
+ }
- // CoreGUI.addBreadCrumb(new Place(String.valueOf(result.getId()), result.getName()));
+ public void onSuccess(PageList<ResourceGroup> result) {
+ ResourceGroup backingGroup = result.get(0);
+ // load the tree up to the autogroup's parent resource
+ loadTree(backingGroup.getAutoGroupParentResource().getId());
+
+ // get the node ID and use it to add a map entry, then call this again to finish up...
+ selectedNodeId = AutoGroupTreeNode.idOf(backingGroup.getAutoGroupParentResource(), backingGroup
+ .getResourceType());
+ AutoGroupTreeNode agNode = (AutoGroupTreeNode) treeGrid.getTree().findById(selectedNodeId);
+ autoGroupNodeMap.put(backingGroup.getId(), agNode);
+ updateSelection();
}
});
}
}
private void adjustBreadcrumb(TreeNode node, ViewId viewId) {
- if (node instanceof ResourceTreeDatasource.ResourceTreeNode) {
+ if (node instanceof ResourceTreeNode) {
- Resource nr = ((ResourceTreeDatasource.ResourceTreeNode) node).getResource();
+ Resource nr = ((ResourceTreeNode) node).getResource();
String display = node.getName() + " <span class=\"subtitle\">" + nr.getResourceType().getName() + "</span>";
String icon = "types/" + nr.getResourceType().getCategory().getDisplayName() + "_up_16.png";
@@ -687,7 +688,7 @@ public class ResourceTreeView extends LocatableVLayout {
c.addFilterParentResourceId(lineage.get(0).getId());
resourceService.findResourcesByCriteria(CoreGUI.getSessionSubject(), c, new AsyncCallback<PageList<Resource>>() {
public void onFailure(Throwable caught) {
- SC.say("SHit");
+ SC.say("NotGood");
}
public void onSuccess(PageList<Resource> result) {
@@ -708,7 +709,14 @@ public class ResourceTreeView extends LocatableVLayout {
public void renderView(ViewPath viewPath) {
currentViewId = viewPath.getCurrent();
- Integer resourceId = Integer.parseInt(currentViewId.getPath());
- setSelectedResource(resourceId);
+ String currentViewIdPath = currentViewId.getPath();
+ if ("AutoGroup".equals(currentViewIdPath)) {
+ ViewId nextViewId = viewPath.getNext();
+ Integer autoGroupId = Integer.parseInt(nextViewId.getPath());
+ setSelectedAutoGroup(autoGroupId);
+ } else {
+ Integer resourceId = Integer.parseInt(currentViewId.getPath());
+ setSelectedResource(resourceId);
+ }
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
index 00a2cf1..14ce7e6 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
@@ -21,17 +21,21 @@ package org.rhq.enterprise.gui.coregui.client.util;
/**
* A collection of utility methods for working with Strings.
+ *
+ * TODO: I18N. The logic here may need to be pluggable for different localizations.
*
* @author Ian Springer
*/
public class StringUtility {
public static String pluralize(String singularNoun) {
String pluralNoun;
- if (singularNoun.endsWith("y") && !singularNoun.endsWith("ay") && !singularNoun.endsWith("ey") &&
- !singularNoun.endsWith("oy")) {
+ if (singularNoun.endsWith("y") && !singularNoun.endsWith("ay") && !singularNoun.endsWith("ey")
+ && !singularNoun.endsWith("oy")) {
pluralNoun = singularNoun.substring(0, singularNoun.length() - 1) + "ies";
- } else {
+ } else if (!singularNoun.endsWith("s")) {
pluralNoun = singularNoun + "s";
+ } else {
+ pluralNoun = singularNoun;
}
return pluralNoun;
}
commit 746f2b2b63bf1aef017a1bfba7410002dbb008c6
Merge: a0461ff... 34d531b...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri Sep 24 16:18:36 2010 -0400
Merge branch 'master' into master-jay
commit a0461ff51bd1cf36283b504083b9eece378254d8
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri Sep 24 16:15:30 2010 -0400
Initial cut at adding autogroup support. autogroups will now have
backing groups.
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index 11ba639..02aa606 100644
--- a/modules/core/dbutils/pom.xml
+++ b/modules/core/dbutils/pom.xml
@@ -22,7 +22,7 @@
<properties>
<scm.module.path>modules/core/dbutils/</scm.module.path>
- <db.schema.version>2.95</db.schema.version>
+ <db.schema.version>2.96</db.schema.version>
</properties>
<dependencies>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/inventory-schema.xml b/modules/core/dbutils/src/main/scripts/dbsetup/inventory-schema.xml
index bf83991..6246880 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/inventory-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/inventory-schema.xml
@@ -168,11 +168,13 @@
<column name="CATEGORY" type="VARCHAR2" size="20" required="true"/>
+ <!-- These two only set if this is a backing group for a resource auto-cluster -->
<column name="CLUSTER_KEY" type="VARCHAR2" size="4000" required="false"/>
-
- <!-- These two only set if this is a backing group for a resource cluster -->
<column name="CLUSTER_RESOURCE_GROUP_ID" type="INTEGER" references="RHQ_RESOURCE_GROUP"/>
+ <!-- This only set if this is a backing group for a resource auto-group -->
+ <column name="AUTO_GROUP_PARENT_RESOURCE_ID" type="INTEGER" references="RHQ_RESOURCE"/>
+
<column name="VISIBLE" type="BOOLEAN"/>
<index name="RHQ_RES_GROUP_NAME" unique="false">
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index ddb1974..f0940ab 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -3215,6 +3215,20 @@
<schema-alterColumn table="RHQ_RESOURCE" column="VERSION" columnType="VARCHAR2" precision="100" />
</schemaSpec>
+ <schemaSpec version="2.96">
+ <!-- Support autogroup backing groups -->
+ <schema-addColumn table="RHQ_RESOURCE_GROUP" column="AUTO_GROUP_PARENT_RESOURCE_ID" columnType="INTEGER" />
+ <schema-directSQL>
+ <statement desc="Creating RHQ_RESOURCE_GROUP foreign key relation to RHQ_RESOURCE for autogroup backing groups">
+ ALTER TABLE RHQ_RESOURCE_GROUP
+ ADD CONSTRAINT RHQ_RG_AG_PARENT_ID_FK
+ FOREIGN KEY (AUTO_GROUP_PARENT_RESOURCE_ID)
+ REFERENCES RHQ_RESOURCE (ID)
+ </statement>
+ </schema-directSQL>
+
+ </schemaSpec>
+
</dbupgrade>
</target>
</project>
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java
index 6f5c259..2278c7f 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java
@@ -42,13 +42,14 @@ public class ResourceGroupCriteria extends TaggedCriteria {
private static final long serialVersionUID = 1L;
private Integer filterId;
- private Integer filterDownMemberCount; // required overrides
private String filterName;
private Boolean filterRecursive;
private Integer filterResourceTypeId; // requires overrides
private String filterResourceTypeName; // requires overrides
+ private Integer filterAutoGroupParentResourceId; // requires overrides
private String filterPluginName; // requires overrides
private GroupCategory filterGroupCategory;
+ private Integer filterDownMemberCount; // required overrides
private List<Integer> filterExplicitResourceIds; // requires overrides
private List<Integer> filterImplicitResourceIds; // requires overrides
private ResourceCategory filterExplicitResourceCategory; // requires overrides
@@ -71,6 +72,9 @@ public class ResourceGroupCriteria extends TaggedCriteria {
public ResourceGroupCriteria() {
filterOverrides.put("resourceTypeId", "resourceType.id = ?");
+ filterOverrides.put("resourceTypeName", "resourceType.name like ?");
+ filterOverrides.put("autoGroupParentResourceId", "autoGroupParentResource.id = ?");
+ filterOverrides.put("pluginName", "resourceType.plugin like ?");
filterOverrides.put("downMemberCount", "" //
+ "id IN ( SELECT implicitGroup.id " //
+ " FROM Resource res " //
@@ -78,8 +82,6 @@ public class ResourceGroupCriteria extends TaggedCriteria {
+ " WHERE res.currentAvailability.availabilityType = 0 " //
+ " GROUP BY implicitGroup.id " //
+ " HAVING COUNT(res) >= ? )");
- filterOverrides.put("resourceTypeName", "resourceType.name like ?");
- filterOverrides.put("pluginName", "resourceType.plugin like ?");
filterOverrides.put("explicitResourceIds", "" //
+ "id IN ( SELECT explicitGroup.id " //
+ " FROM Resource res " //
@@ -146,6 +148,10 @@ public class ResourceGroupCriteria extends TaggedCriteria {
this.filterResourceTypeName = filterResourceTypeName;
}
+ public void addFilterAutoGroupParentResourceId(Integer filterAutoGroupParentResourceId) {
+ this.filterAutoGroupParentResourceId = filterAutoGroupParentResourceId;
+ }
+
public void addFilterPluginName(String filterPluginName) {
this.filterPluginName = filterPluginName;
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
index 9355e30..6726bbb 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
@@ -1031,6 +1031,11 @@ public class Resource implements Comparable<Resource>, Serializable {
@ManyToMany(mappedBy = "resources", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
private Set<Tag> tags;
+ // When a resource is removed any referring autgroup backing groups should also be removed
+ // bulk delete
+ @OneToMany(mappedBy = "autoGroupParentResource", fetch = FetchType.LAZY)
+ private List<ResourceGroup> autoGroupBackingGroups = null;
+
public Resource() {
}
@@ -1629,6 +1634,14 @@ public class Resource implements Comparable<Resource>, Serializable {
}
}
+ public List<ResourceGroup> getAutoGroupBackingGroups() {
+ return autoGroupBackingGroups;
+ }
+
+ public void setAutoGroupBackingGroups(List<ResourceGroup> autoGroupBackingGroups) {
+ this.autoGroupBackingGroups = autoGroupBackingGroups;
+ }
+
public int compareTo(Resource that) {
return this.name.compareTo(that.getName());
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
index d9ca343..46d6bcb 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
@@ -183,8 +183,7 @@ import org.rhq.core.domain.tagging.Tag;
+ " AND res.id NOT IN ( SELECT explicitRes.id " //
+ " FROM ResourceGroup rg " //
+ " JOIN rg.explicitResources explicitRes " //
- + " WHERE rg.id = :groupId ) ")
-})
+ + " WHERE rg.id = :groupId ) ") })
@SequenceGenerator(name = "id", sequenceName = "RHQ_RESOURCE_GROUP_ID_SEQ")
@Table(name = "RHQ_RESOURCE_GROUP")
@XmlAccessorType(XmlAccessType.FIELD)
@@ -441,13 +440,18 @@ public class ResourceGroup extends Group {
@ManyToOne
private ResourceGroup clusterResourceGroup = null;
- // When false hide this group from the UI. For example, for a Resource Cluster backing group.
- private boolean visible = true;
-
- // When a compatible group is removed any referring backing groups should also be removed
+ // When a compatible group is removed any referring autocluster backing groups should also be removed
@OneToMany(mappedBy = "clusterResourceGroup")
private List<ResourceGroup> clusterBackingGroups = null;
+ // The parent resource for which this is an auto-group backing group
+ @JoinColumn(name = "AUTO_GROUP_PARENT_RESOURCE_ID", referencedColumnName = "ID", nullable = true)
+ @ManyToOne
+ private Resource autoGroupParentResource = null;
+
+ // When false hide this group from the UI. For example, for an autocluster or autogroup backing group.
+ private boolean visible = true;
+
// bulk delete @OneToMany(mappedBy = "resource", cascade = { CascadeType.ALL })
@OneToMany(mappedBy = "resourceGroup", cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
private Set<AlertDefinition> alertDefinitions = new LinkedHashSet<AlertDefinition>();
@@ -624,6 +628,14 @@ public class ResourceGroup extends Group {
this.clusterResourceGroup = clusterResourceGroup;
}
+ public Resource getAutoGroupParentResource() {
+ return autoGroupParentResource;
+ }
+
+ public void setAutoGroupParentResource(Resource autoGroupParentResource) {
+ this.autoGroupParentResource = autoGroupParentResource;
+ }
+
public boolean isVisible() {
return visible;
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
index 00a27f0..f5c14c5 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
@@ -51,6 +51,7 @@ import org.rhq.enterprise.gui.coregui.client.alert.AlertsView;
import org.rhq.enterprise.gui.coregui.client.bundle.BundleTopView;
import org.rhq.enterprise.gui.coregui.client.dashboard.DashboardsView;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.AutoGroupTopView;
import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.ResourceGroupTopView;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.InventoryView;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceTopView;
@@ -291,6 +292,8 @@ public class CoreGUI implements EntryPoint, ValueChangeHandler<String> {
canvas = new ResourceTopView("Resource");
} else if (breadcrumbName.equals("ResourceGroup")) {
canvas = new ResourceGroupTopView("Group");
+ } else if (breadcrumbName.equals("AutoGroup")) {
+ canvas = new AutoGroupTopView("AutoGroup");
} else if (breadcrumbName.equals("Dashboard")) {
canvas = new DashboardsView("Dashboard");
} else if (breadcrumbName.equals("Bundles")) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/AutoGroupTopView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/AutoGroupTopView.java
new file mode 100644
index 0000000..384444f
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/AutoGroupTopView.java
@@ -0,0 +1,106 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.inventory.groups.detail;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.widgets.Canvas;
+
+import org.rhq.core.domain.criteria.ResourceGroupCriteria;
+import org.rhq.core.domain.resource.group.ResourceGroup;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.gui.coregui.client.BookmarkableView;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.ViewPath;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceTreeView;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
+
+/**
+ * @author Greg Hinkle
+ */
+public class AutoGroupTopView extends LocatableHLayout implements BookmarkableView {
+
+ private Canvas contentCanvas;
+ private Integer parentResourceId;
+ private ResourceTreeView treeView;
+ private ResourceGroupDetailView detailView;
+
+ public AutoGroupTopView(String locatorId) {
+ super(locatorId);
+ }
+
+ @Override
+ protected void onInit() {
+ super.onInit();
+
+ setWidth100();
+ setHeight100();
+
+ treeView = new ResourceTreeView(getLocatorId());
+ detailView = new ResourceGroupDetailView(extendLocatorId("Detail"),
+ ResourceGroupDetailView.AUTO_GROUP_VIEW_PATH);
+ addMember(treeView);
+
+ contentCanvas = new Canvas();
+ addMember(contentCanvas);
+
+ setContent(detailView);
+ }
+
+ public void setContent(Canvas newContent) {
+ for (Canvas child : this.contentCanvas.getChildren()) {
+ child.destroy();
+ }
+ this.contentCanvas.addChild(newContent);
+ this.contentCanvas.markForRedraw();
+ }
+
+ public void renderView(final ViewPath viewPath) {
+ // we need the backing group parent resource id to render the LHS resource tree. Once it's rendered leave
+ // it displayed but don't muck with it. A LHS user selection will drive a view change.
+ if (null == this.parentResourceId) {
+ final int backingGroupId = Integer.valueOf(viewPath.getCurrent().getPath());
+ ResourceGroupCriteria criteria = new ResourceGroupCriteria();
+ criteria.addFilterId(backingGroupId);
+ criteria.addFilterVisible(false);
+ GWTServiceLookup.getResourceGroupService().findResourceGroupsByCriteria(criteria,
+ new AsyncCallback<PageList<ResourceGroup>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to fetch autogroup backing group", caught);
+ }
+
+ public void onSuccess(PageList<ResourceGroup> result) {
+ if (result.isEmpty()) {
+ CoreGUI.getErrorHandler().handleError(
+ "Failed to find autogroup backing group: " + backingGroupId);
+ } else {
+ String parentResourceId = String
+ .valueOf(result.get(0).getAutoGroupParentResource().getId());
+ treeView.renderView(new ViewPath(parentResourceId));
+ }
+ }
+ });
+ }
+ detailView.renderView(viewPath);
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
index f273c40..e00ecbe 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
@@ -60,7 +60,8 @@ import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTyp
* @author Ian Springer
*/
public class ResourceGroupDetailView extends AbstractTwoLevelTabSetView<ResourceGroupComposite, ResourceGroupTitleBar> {
- private static final String BASE_VIEW_PATH = "ResourceGroup";
+ public static final String AUTO_GROUP_VIEW_PATH = "AutoGroup";
+ public static final String GROUP_VIEW_PATH = "ResourceGroup";
private Integer groupId;
private ResourceGroupComposite groupComposite;
@@ -97,8 +98,8 @@ public class ResourceGroupDetailView extends AbstractTwoLevelTabSetView<Resource
private String currentTab;
private String currentSubTab;
- public ResourceGroupDetailView(String locatorId) {
- super(locatorId, BASE_VIEW_PATH);
+ public ResourceGroupDetailView(String locatorId, String baseViewPath) {
+ super(locatorId, baseViewPath);
this.hide();
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTopView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTopView.java
index ac0281c..3e87e03 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTopView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTopView.java
@@ -41,7 +41,6 @@ public class ResourceGroupTopView extends LocatableHLayout implements Bookmarkab
super(locatorId);
}
-
@Override
protected void onInit() {
super.onInit();
@@ -49,20 +48,16 @@ public class ResourceGroupTopView extends LocatableHLayout implements Bookmarkab
setWidth100();
setHeight100();
- treeView = new ResourceGroupTreeView();
+ treeView = new ResourceGroupTreeView(getLocatorId());
+ detailView = new ResourceGroupDetailView(extendLocatorId("Detail"), ResourceGroupDetailView.GROUP_VIEW_PATH);
addMember(treeView);
contentCanvas = new Canvas();
addMember(contentCanvas);
- detailView = new ResourceGroupDetailView(extendLocatorId("Detail"));
-
- // treeView.addResourceSelectListener(detailView);
-
setContent(detailView);
}
-
public void setContent(Canvas newContent) {
for (Canvas child : this.contentCanvas.getChildren()) {
child.destroy();
@@ -71,10 +66,8 @@ public class ResourceGroupTopView extends LocatableHLayout implements Bookmarkab
this.contentCanvas.markForRedraw();
}
-
- public void renderView(ViewPath viewPath) {
- this.treeView.renderView(viewPath);
- this.detailView.renderView(viewPath);
+ public void renderView(final ViewPath viewPath) {
+ treeView.renderView(viewPath);
+ detailView.renderView(viewPath);
}
-
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
index acaca4a..d701852 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
@@ -34,7 +34,6 @@ import com.smartgwt.client.data.Record;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler;
import com.smartgwt.client.widgets.grid.events.SelectionEvent;
-import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeNode;
@@ -55,11 +54,12 @@ import org.rhq.enterprise.gui.coregui.client.ViewId;
import org.rhq.enterprise.gui.coregui.client.ViewPath;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**
* @author Greg Hinkle
*/
-public class ResourceGroupTreeView extends VLayout implements BookmarkableView {
+public class ResourceGroupTreeView extends LocatableVLayout implements BookmarkableView {
private TreeGrid treeGrid;
@@ -73,7 +73,8 @@ public class ResourceGroupTreeView extends VLayout implements BookmarkableView {
private Map<Integer, ResourceType> typeMap;
private ResourceGroup selectedGroup;
- public ResourceGroupTreeView() {
+ public ResourceGroupTreeView(String locatorId) {
+ super(locatorId);
setWidth(250);
setHeight100();
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
index ca3f8e6..07995df 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
@@ -169,9 +169,7 @@ public class ResourceTreeDatasource extends DataSource {
ResourceTypeRepository.Cache.getInstance().loadResourceTypes(
result,
- EnumSet.of(
- ResourceTypeRepository.MetadataType.operations,
- ResourceTypeRepository.MetadataType.children,
+ EnumSet.of(ResourceTypeRepository.MetadataType.operations, ResourceTypeRepository.MetadataType.children,
ResourceTypeRepository.MetadataType.subCategory),
new ResourceTypeRepository.ResourceTypeLoadedCallback() {
public void onResourceTypeLoaded(List<Resource> result) {
@@ -204,7 +202,7 @@ public class ResourceTreeDatasource extends DataSource {
List<TreeNode> updatedNodes = new ArrayList<TreeNode>();
// Maps category node IDs to the corresponding category nodes.
Map<String, SubCategoryTreeNode> subcategoryNodes = new HashMap<String, SubCategoryTreeNode>();
- // Maps type node IDs to the corresponding type nodes.
+ // Maps autogroup/type node IDs to the corresponding autogroup/type nodes.
Map<String, AutoGroupTreeNode> autogroupNodes = new HashMap<String, AutoGroupTreeNode>();
for (ResourceTreeNode resourceNode : resourceNodes) {
@@ -222,7 +220,8 @@ public class ResourceTreeDatasource extends DataSource {
do {
String subcategoryNodeId = SubCategoryTreeNode.idOf(subcategory, parentResource);
if (!subcategoryNodes.containsKey(subcategoryNodeId)) {
- SubCategoryTreeNode subcategoryNode = new SubCategoryTreeNode(subcategory, parentResource);
+ SubCategoryTreeNode subcategoryNode = new SubCategoryTreeNode(subcategory,
+ parentResource);
subcategoryNodes.put(subcategoryNode.getID(), subcategoryNode);
System.out.println("Adding " + subcategoryNode + " to tree...");
updatedNodes.add(subcategoryNode);
@@ -253,9 +252,8 @@ public class ResourceTreeDatasource extends DataSource {
setAttribute(Attributes.ID, id);
ResourceSubCategory parentCategory = category.getParentSubCategory();
- String parentId = (parentCategory != null) ?
- SubCategoryTreeNode.idOf(parentCategory, parentResource) :
- ResourceTreeNode.idOf(parentResource);
+ String parentId = (parentCategory != null) ? SubCategoryTreeNode.idOf(parentCategory, parentResource)
+ : ResourceTreeNode.idOf(parentResource);
setParentID(parentId);
setAttribute(Attributes.PARENT_ID, parentId);
@@ -276,7 +274,17 @@ public class ResourceTreeDatasource extends DataSource {
* The folder node for a Resource autogroup.
*/
public static class AutoGroupTreeNode extends EnhancedTreeNode {
+
+ private Resource parentResource;
+ private ResourceType resourceType;
+
+ /**
+ * @param resource requires resourceType field be set. requires parentResource field be set (null for no parent)
+ */
private AutoGroupTreeNode(Resource resource) {
+ this.parentResource = resource.getParentResource();
+ this.resourceType = resource.getResourceType();
+
String id = idOf(resource);
setID(id);
setAttribute(Attributes.ID, id);
@@ -295,20 +303,44 @@ public class ResourceTreeDatasource extends DataSource {
setAttribute(Attributes.DESCRIPTION, type.getDescription());
}
+ public Resource getParentResource() {
+ return parentResource;
+ }
+
+ public ResourceType getResourceType() {
+ return resourceType;
+ }
+
+ /**
+ * Generates a backing group name based on the resource type name and parent resource name. It may not be unique
+ * so should not be used to query for the group (use rtId and parentResId). The name may be displayed to the
+ * user.
+ *
+ * @return The name of the backing group.
+ */
+ public String getBackingGroupName() {
+ return this.getParentResource().getName() + " ( " + this.getResourceType().getName() + " )";
+ }
+
+ /**
+ * Given a Resource, generate a unique ID for the AGNode.
+ *
+ * @param resource requires resourceType field be set. requires parentResource field be set (null for no parent)
+ * @return The name string or null if the R
+ */
public static String idOf(Resource resource) {
Resource parentResource = resource.getParentResource();
- return (parentResource != null) ?
- "autogroup" + resource.getResourceType().getId() + "_" + parentResource.getId() :
- null;
+ return (parentResource != null) ? "autogroup_" + resource.getResourceType().getId() + "_"
+ + parentResource.getId() : null;
}
+ // parent node is either a subcategory node or a resouce node
public static String parentIdOf(Resource resource) {
ResourceType type = resource.getResourceType();
ResourceSubCategory parentCategory = type.getSubCategory();
- return (parentCategory != null) ?
- SubCategoryTreeNode.idOf(parentCategory, resource.getParentResource()) :
- ResourceTreeNode.idOf(resource.getParentResource());
- }
+ return (parentCategory != null) ? SubCategoryTreeNode.idOf(parentCategory, resource.getParentResource())
+ : ResourceTreeNode.idOf(resource.getParentResource());
+ }
}
public static class ResourceTreeNode extends EnhancedTreeNode {
@@ -324,11 +356,9 @@ public class ResourceTreeDatasource extends DataSource {
Resource parentResource = resource.getParentResource();
String parentId;
if (parentResource != null) {
- parentId = resource.getResourceType().isSingleton() ?
- AutoGroupTreeNode.parentIdOf(resource) :
- AutoGroupTreeNode.idOf(resource);
- }
- else {
+ parentId = resource.getResourceType().isSingleton() ? AutoGroupTreeNode.parentIdOf(resource)
+ : AutoGroupTreeNode.idOf(resource);
+ } else {
parentId = null;
}
setParentID(parentId);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
index a03acaf..b20cfb3 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
@@ -52,6 +52,7 @@ import com.smartgwt.client.widgets.tree.events.NodeContextClickHandler;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.criteria.ResourceCriteria;
+import org.rhq.core.domain.criteria.ResourceGroupCriteria;
import org.rhq.core.domain.criteria.ResourceTypeCriteria;
import org.rhq.core.domain.dashboard.Dashboard;
import org.rhq.core.domain.dashboard.DashboardPortlet;
@@ -60,6 +61,7 @@ import org.rhq.core.domain.operation.OperationDefinition;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.domain.resource.group.ResourceGroup;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.Breadcrumb;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
@@ -69,6 +71,7 @@ import org.rhq.enterprise.gui.coregui.client.components.configuration.Configurat
import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.resource.graph.GraphPortlet;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
+import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGroupGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceTypeGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceSelectListener;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.operation.create.OperationCreateWizard;
@@ -131,15 +134,19 @@ public class ResourceTreeView extends LocatableVLayout {
public void onSelectionChanged(SelectionEvent selectionEvent) {
if (!selectionEvent.isRightButtonDown() && selectionEvent.getState()) {
ListGridRecord selectedNode = treeGrid.getSelectedRecord();
- System.out.println("Node selected in tree: " + selectedNode);
if (selectedNode instanceof ResourceTreeDatasource.ResourceTreeNode) {
- ResourceTreeDatasource.ResourceTreeNode resourceNode =
- (ResourceTreeDatasource.ResourceTreeNode) selectedNode;
+ System.out.println("Resource Node selected in tree: " + selectedNode);
+ ResourceTreeDatasource.ResourceTreeNode resourceNode = (ResourceTreeDatasource.ResourceTreeNode) selectedNode;
String viewPath = "Resource/" + resourceNode.getResource().getId();
String currentViewPath = History.getToken();
if (!currentViewPath.startsWith(viewPath)) {
CoreGUI.goToView(viewPath);
}
+ } else if (selectedNode instanceof ResourceTreeDatasource.AutoGroupTreeNode) {
+ System.out.println("AutoGroup Node selected in tree: " + selectedNode);
+ handleSelectedAutoGroupNode((ResourceTreeDatasource.AutoGroupTreeNode) selectedNode);
+ } else {
+ System.out.println("Unhandled Node selected in tree: " + selectedNode);
}
}
}
@@ -170,9 +177,77 @@ public class ResourceTreeView extends LocatableVLayout {
});
}
+ private void handleSelectedAutoGroupNode(final ResourceTreeDatasource.AutoGroupTreeNode agNode) {
+ final ResourceGroupGWTServiceAsync resourceGroupService = GWTServiceLookup.getResourceGroupService();
+
+ // get the children tree nodes and build a child resourceId array
+ TreeNode[] children = treeGrid.getTree().getChildren(agNode);
+ final int[] childIds = new int[children.length];
+ for (int i = 0, size = children.length; (i < size); ++i) {
+ childIds[i] = ((ResourceTreeDatasource.ResourceTreeNode) children[i]).getResource().getId();
+ }
+
+ // get the backing group if it exists, otherwise create the group
+ ResourceGroupCriteria criteria = new ResourceGroupCriteria();
+ criteria.addFilterResourceTypeId(agNode.getResourceType().getId());
+ criteria.addFilterAutoGroupParentResourceId(agNode.getParentResource().getId());
+ criteria.addFilterVisible(false);
+ resourceGroupService.findResourceGroupsByCriteria(criteria, new AsyncCallback<PageList<ResourceGroup>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to fetch autogroup backing group", caught);
+ }
+
+ public void onSuccess(PageList<ResourceGroup> result) {
+ if (result.isEmpty()) {
+ // Not found, create new backing group
+ // the backing group name is a display name using a unique parentResource-resourceType combo
+ final String backingGroupName = agNode.getBackingGroupName();
+ ResourceGroup backingGroup = new ResourceGroup(backingGroupName);
+ backingGroup.setAutoGroupParentResource(agNode.getParentResource());
+ backingGroup.setResourceType(agNode.getResourceType());
+ backingGroup.setVisible(false);
+ backingGroup.setRecursive(false);
+ resourceGroupService.createResourceGroup(backingGroup, childIds,
+ new AsyncCallback<ResourceGroup>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to create resource autogroup", caught);
+ }
+
+ public void onSuccess(ResourceGroup result) {
+ renderAutoGroup(result);
+ }
+ });
+ } else {
+ // backing group found, make sure the members are correct
+ final ResourceGroup backingGroup = result.get(0);
+ resourceGroupService.setAssignedResources(backingGroup.getId(), childIds, false,
+ new AsyncCallback<Void>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ "Failed to set assigned members for autogroup backing group", caught);
+ }
+
+ public void onSuccess(Void result) {
+ renderAutoGroup(backingGroup);
+ }
+ });
+ }
+ }
+ });
+
+ }
+
+ private void renderAutoGroup(ResourceGroup backingGroup) {
+ String viewPath = "AutoGroup/" + backingGroup.getId();
+ String currentViewPath = History.getToken();
+ if (!currentViewPath.startsWith(viewPath)) {
+ CoreGUI.goToView(viewPath);
+ }
+ }
private void updateBreadcrumbs() {
- TreeNode selectedNode = treeGrid.getTree().findById(ResourceTreeDatasource.ResourceTreeNode.idOf(selectedResourceId));
+ TreeNode selectedNode = treeGrid.getTree().findById(
+ ResourceTreeDatasource.ResourceTreeNode.idOf(selectedResourceId));
// System.out.println("Trying to preopen: " + selectedNode);
if (selectedNode != null) {
TreeNode[] parents = treeGrid.getTree().getParents(selectedNode);
@@ -205,9 +280,7 @@ public class ResourceTreeView extends LocatableVLayout {
ResourceType type = node.getResource().getResourceType();
ResourceTypeRepository.Cache.getInstance().getResourceTypes(
type.getId(),
- EnumSet.of(
- ResourceTypeRepository.MetadataType.operations,
- ResourceTypeRepository.MetadataType.children,
+ EnumSet.of(ResourceTypeRepository.MetadataType.operations, ResourceTypeRepository.MetadataType.children,
ResourceTypeRepository.MetadataType.subCategory,
ResourceTypeRepository.MetadataType.pluginConfigurationDefinition,
ResourceTypeRepository.MetadataType.resourceConfigurationDefinition),
@@ -509,8 +582,7 @@ public class ResourceTreeView extends LocatableVLayout {
TreeUtility.printTree(treeGrid.getTree());
- TreeNode selectedNode =
- treeGrid.getTree().findById(resourceNodeId);
+ TreeNode selectedNode = treeGrid.getTree().findById(resourceNodeId);
// System.out.println("Trying to preopen: " + selectedNode);
if (selectedNode != null) {
// System.out.println("Preopen node!!!");
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
index c9b4420..0528b06 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
@@ -146,6 +146,8 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage
@EJB
private ResourceManagerLocal resourceManager; // ourself, for xactional semantic consistency
@EJB
+ private ResourceGroupManagerLocal resourceGroupManager;
+ @EJB
private ResourceTypeManagerLocal typeManager;
@EJB
@IgnoreDependency
@@ -397,6 +399,26 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage
log.debug("Overlord is asynchronously deleting resource [" + attachedResource + "]");
}
+ // one more thing, delete any autogroup backing groups
+ List<ResourceGroup> backingGroups = attachedResource.getAutoGroupBackingGroups();
+ if (!backingGroups.isEmpty()) {
+ int size = backingGroups.size();
+ int[] backingGroupIds = new int[size];
+ for (int i = 0; (i < size); ++i) {
+ backingGroupIds[i] = backingGroups.get(i).getId();
+ }
+ try {
+ resourceGroupManager.deleteResourceGroups(user, backingGroupIds);
+ } catch (Throwable t) {
+ if (log.isDebugEnabled()) {
+ log.error("Bulk delete error for autogroup backing group deletion for " + backingGroupIds, t);
+ } else {
+ log.error("Bulk delete error for autogroup backing group deletion for " + backingGroupIds + ": "
+ + t.getMessage());
+ }
+ }
+ }
+
// now we can purge the resource, let cascading do the rest
entityManager.remove(attachedResource);