modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
| 61 +++++++---
1 file changed, 47 insertions(+), 14 deletions(-)
New commits:
commit 791f8148611c4e6d830dd3cfdfe55b8d7489e86b
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jan 30 17:30:11 2013 -0500
[BZ 902406] i still think this doesn't work. but its close. we now merge unknown
resources and their children breadth first. however, i think we need children specified in
some resources when we don't. need to take a closer look and test
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
index 56a372e..aea8380 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
@@ -25,6 +25,7 @@ package org.rhq.core.pc.inventory;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
@@ -36,10 +37,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
@@ -1135,7 +1138,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
modifiedResourceIds.size()));
}
- mergeUnknownResources(unknownResourceIds);
+ mergeUnknownResources(unknownResourceIds, syncInfo);
mergeModifiedResources(modifiedResourceIds);
if (!partialInventory) {
purgeObsoleteResources(allServerSideUuids);
@@ -2836,7 +2839,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
return;
}
- private void mergeUnknownResources(Set<Integer> unknownResourceIds) {
+ private void mergeUnknownResources(Set<Integer> unknownResourceIds,
ResourceSyncInfo syncInfo) {
if (log.isDebugEnabled()) {
log.debug("Merging [" + unknownResourceIds.size()
+ "] unknown Resources and their descendants into local
inventory...");
@@ -2847,8 +2850,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
DiscoveryServerService dss =
configuration.getServerServices().getDiscoveryServerService();
Set<Resource> unknownResources = dss.getResources(unknownResourceIds,
false);
- Map<Integer, Set<Integer>> childrenIdsOfUnknownResources;
- childrenIdsOfUnknownResources = new HashMap<Integer,
Set<Integer>>(unknownResources.size());
+ Map<ResourceSyncInfo, Set<Integer>>
childrenIdsOfUnknownResources;
+ childrenIdsOfUnknownResources = new HashMap<ResourceSyncInfo,
Set<Integer>>(unknownResources.size());
Set<Integer> toBeIgnored = new HashSet<Integer>();
for (Resource unknownResource : unknownResources) {
@@ -2867,30 +2870,60 @@ public class InventoryManager extends AgentService implements
ContainerService,
}
// get all the children IDs of the unknown resources we just merged
- Set<Resource> unknownChildren =
unknownResource.getChildResources();
- Set<Integer> unknownChildrenIds = new
HashSet<Integer>(unknownChildren.size());
- for (Resource unknownChild : unknownChildren) {
- unknownChildrenIds.add(unknownChild.getId());
+ ResourceSyncInfo unknownResourceAndItsTree =
findResourceSyncInfoById(unknownResource.getId(), syncInfo);
+ if (unknownResourceAndItsTree != null) {
+ Collection<ResourceSyncInfo> unknownChildren =
unknownResourceAndItsTree.getChildSyncInfos();
+ Set<Integer> unknownChildrenIds = new
HashSet<Integer>(unknownChildren.size());
+ for (ResourceSyncInfo unknownChild : unknownChildren) {
+ unknownChildrenIds.add(unknownChild.getId());
+ }
+ childrenIdsOfUnknownResources.put(unknownResourceAndItsTree,
unknownChildrenIds);
+ } else {
+ log.error("Could not find the unknown resource in the sync info:
" + unknownResource);
}
- childrenIdsOfUnknownResources.put(unknownResource.getId(),
unknownChildrenIds);
- unknownChildren.clear(); // help GC
}
unknownResourceIds.removeAll(toBeIgnored);
// now, do it again recursively so we merge the children
- Set<Entry<Integer, Set<Integer>>> entrySet =
childrenIdsOfUnknownResources.entrySet();
- Iterator<Entry<Integer, Set<Integer>>> entrySetIterator =
entrySet.iterator();
+ Set<Entry<ResourceSyncInfo, Set<Integer>>> entrySet =
childrenIdsOfUnknownResources.entrySet();
+ Iterator<Entry<ResourceSyncInfo, Set<Integer>>>
entrySetIterator = entrySet.iterator();
while (entrySetIterator.hasNext()) {
- Entry<Integer, Set<Integer>> entry =
entrySetIterator.next();
+ Entry<ResourceSyncInfo, Set<Integer>> entry =
entrySetIterator.next();
+ ResourceSyncInfo unknownParent = entry.getKey();
Set<Integer> unknownChildrenIds = entry.getValue();
entrySetIterator.remove(); // help GC
- mergeUnknownResources(unknownChildrenIds);
+ mergeUnknownResources(unknownChildrenIds, unknownParent);
unknownChildrenIds.clear(); // help GC
}
}
return;
}
+ // this is potentially expensive - only use this if you know the ID you are looking
for is
+ // near the top of the provided tree of sync infos.
+ private ResourceSyncInfo findResourceSyncInfoById(int needle, ResourceSyncInfo
haystack) {
+ // use a Q so we do this breadth first
+ Queue<ResourceSyncInfo> q = new
ConcurrentLinkedQueue<ResourceSyncInfo>();
+ try {
+ q.offer(haystack);
+ while (!q.isEmpty()) {
+ ResourceSyncInfo node = q.poll();
+ if (node.getId() == needle) {
+ return node;
+ }
+ Collection<ResourceSyncInfo> children = node.getChildSyncInfos();
+ if (children != null) {
+ for (ResourceSyncInfo child : children) {
+ q.offer(child);
+ }
+ }
+ }
+ return null; // couldn't find it
+ } finally {
+ q.clear(); // help GC
+ }
+ }
+
// private void print(Resource resourceTreeNode, int level) {
// StringBuilder builder = new StringBuilder();
// for (int i = 0; i < level; i++) {
Show replies by date