// setup simple test structures
Subject subject = SessionTestHelper.createNewSubject(em, "subject-ClusterManagerBeanTest");
Role role = SessionTestHelper.createNewRoleForSubject(em, subject, "role-ClusterManagerBeanTest",
Permission.MANAGE_INVENTORY);
ResourceGroup clusterGroup = SessionTestHelper.createNewCompatibleGroupForRole(em, role,
"clusterGroup-ClusterManagerBeanTest");
// setup two test resource trees to make into a resource cluster. Two compatible root nodes
// with the exact same child hierarchy
List<Resource> treeA = ResourceTreeHelper.createTree(em,
"A=d1c1,d1c2; d1c1=d2c1,d2c2; d2c1=d3c1,d3c2; d2c2=d3c3,d3c4");
List<Resource> treeB = ResourceTreeHelper.createTree(em,
"B=d1c1,d1c2; d1c1=d2c1,d2c2; d2c1=d3c1,d3c2; d2c2=d3c3,d3c4");
// test simple implicit resources
Resource nodeA = ResourceTreeHelper.findNode(treeA, "A");
Resource nodeB = ResourceTreeHelper.findNode(treeB, "B");
resourceGroupManager.addResourcesToGroup(subject, clusterGroup.getId(), new int[] { nodeA.getId(),
nodeB.getId() });
PageList<Resource> AChildren = resourceManager.findChildResources(subject, nodeA.getId(), PageControl
.getUnlimitedInstance());
assert !AChildren.isEmpty() : "Expected Children for Node A";
int AChildResourceTypeId = AChildren.get(0).getResourceType().getId();
String AChildResourceKey = AChildren.get(0).getResourceKey();
ClusterKey clusterKey = new ClusterKey(clusterGroup.getId(), AChildResourceTypeId, AChildResourceKey);
assert clusterKey.getClusterGroupId() == clusterGroup.getId();
assert clusterKey.getDepth() == 1;
assert AChildResourceKey.equals(clusterKey.getHierarchy().get(0).getResourceKey());
assert AChildResourceTypeId == clusterKey.getHierarchy().get(0).getResourceTypeId();
assert AChildResourceTypeId == ClusterKey.getResourceType(clusterKey);
assert ClusterKey.valueOf(clusterKey.toString()) != null;
List<Resource> resources = clusterManager.getAutoClusterResources(subject, clusterKey);
assert resources.size() == 2;
assert resources.get(0).getId() != resources.get(1).getId();
assert resources.get(0).getParentResource().getId() != resources.get(1).getParentResource().getId();
assert resources.get(0).getParentResource().getId() == nodeA.getId()
|| resources.get(0).getParentResource().getId() == nodeB.getId();
assert resources.get(1).getParentResource().getId() == nodeA.getId()
|| resources.get(1).getParentResource().getId() == nodeB.getId();
assertNull(clusterManager.getAutoClusterBackingGroup(subject, clusterKey));
ResourceGroup backingGroup = clusterManager.createAutoClusterBackingGroup(subject, clusterKey, true);
assertNotNull(backingGroup);
assertEquals(backingGroup.getClusterKey(), clusterKey.toString());
assertEquals(backingGroup.getClusterResourceGroup(), clusterGroup);
//Set<Resource> backingGroupResources = backingGroup.getExplicitResources();
// explicitResources for backingGroup is lazy, so we need to hit resourceManager for the answer
List<Resource> backingGroupResources = resourceManager.findExplicitResourcesByResourceGroup(subject,
backingGroup, PageControl.getUnlimitedInstance());
assertEquals(backingGroupResources.size(), resources.size());