platform.addChildResource(server);
}
inventoryReport.addAddedRoot(platform);
// Merge this inventory report to get platform and servers in NEW state
MergeInventoryReportResults mergeResults = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
assert mergeResults != null;
assert checkIgnoredTypes(mergeResults) : "nothing should have been ignored: "
+ mergeResults.getIgnoredResourceTypes();
PlatformSyncInfo platformSyncInfo = mergeResults.getPlatformSyncInfo();
assert platformSyncInfo != null;
// Collect the resource ids generated for the platform and the servers
int platformId = platformSyncInfo.getPlatform().getId();
List<Integer> serverIds = new LinkedList<Integer>();
for (Integer serverId : platformSyncInfo.getTopLevelServerIds()) {
serverIds.add(serverId);
}
int[] arrayOfServerIds = ArrayUtils.unwrapCollection(serverIds);
// Now import platform and servers into inventory
discoveryBoss.importResources(subjectManager.getOverlord(), new int[] { platformId });
discoveryBoss.importResources(subjectManager.getOverlord(), arrayOfServerIds);
// make sure servers are committed into inventory now
List<Integer> serverTypeIdInList = new ArrayList<Integer>(1);
serverTypeIdInList.add(serverType.getId());
PageList<Resource> allServers = resourceManager.findResourceByIds(subjectManager.getOverlord(),
arrayOfServerIds, false, PageControl.getUnlimitedInstance());
for (Resource aServer : allServers) {
assert aServer.getInventoryStatus() == InventoryStatus.COMMITTED : "should be committed: " + aServer;
}
assert allServers.getTotalSize() == arrayOfServerIds.length : "all servers were not committed into inventory";
// now ignore the server type - this should uninventory all servers
resourceTypeManager.setResourceTypeIgnoreFlagAndUninventoryResources(subjectManager.getOverlord(),
serverType.getId(), true);
// make sure all servers were uninventoried
allServers = resourceManager.findResourceByIds(subjectManager.getOverlord(), arrayOfServerIds, false,
PageControl.getUnlimitedInstance());
for (Resource aServer : allServers) {
assert aServer.getInventoryStatus() != InventoryStatus.COMMITTED : "should not be committed: " + aServer;
}
// Merge the inventory report again to simulate another discovery - the servers should be ignored now
mergeResults = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
assert mergeResults != null;
platformSyncInfo = mergeResults.getPlatformSyncInfo();
assert platformSyncInfo != null;
assertNotNull(mergeResults.getIgnoredResourceTypes());
assert checkIgnoredTypes(mergeResults, 1) : "expected one ignored type";
assert mergeResults.getIgnoredResourceTypes().contains(new ResourceTypeFlyweight(serverType));
assertEquals(InventoryStatus.COMMITTED, platformSyncInfo.getPlatform().getInventoryStatus()); // notice platform is committed now
assertEquals(platformSyncInfo.getTopLevelServerIds().size(), 0); // notice there are no server children now
}