@EJB
private SubjectManagerLocal subjectManager;
public ResourceGroup createAutoClusterBackingGroup(Subject subject, ClusterKey clusterKey, boolean addResources) {
ResourceGroup autoClusterBackingGroup = null;
Query query = entityManager.createNamedQuery(ResourceGroup.QUERY_FIND_BY_CLUSTER_KEY);
query.setParameter("clusterKey", clusterKey.toString());
ResourceType resourceType = entityManager.find(ResourceType.class, ClusterKey.getResourceType(clusterKey));
ResourceGroup resourceGroup = entityManager.find(ResourceGroup.class, clusterKey.getClusterGroupId());
if (!authorizationManager.canViewGroup(subject, clusterKey.getClusterGroupId())) {
throw new PermissionException("You do not have permission to view child cluster groups of the group ["
+ resourceGroup.getName() + "]");
}
// [BZ 817604] In unusual circumstances this clusterKey may be stale. Ensure the cluster group
// is still a compat group before creating a backing group.
if (GroupCategory.COMPATIBLE != resourceGroup.getGroupCategory()) {
throw new IllegalStateException("The root group has changed. Please refresh your group before continuing.");
}
List<Resource> resources = null;
try {
autoClusterBackingGroup = (ResourceGroup) query.getSingleResult();
} catch (NoResultException nre) {
try {
resources = getAutoClusterResources(subject, clusterKey);
String name = null;
if (resources.isEmpty()) {
name = "Group of " + resourceType.getName();
} else {
for (Resource res : resources) {
if (name == null) {
name = res.getName();
} else {
if (!name.equals(res.getName())) {
name = "Group of " + resourceType.getName();
}
}
}
}
// Note, group names do not need to be unique for non-visible groups, like autocluster backing groups
autoClusterBackingGroup = new ResourceGroup(name, resourceType);
autoClusterBackingGroup.setClusterKey(clusterKey.toString());
autoClusterBackingGroup.setClusterResourceGroup(resourceGroup);
autoClusterBackingGroup.setVisible(false);
// You are allowed to cause the creation of an auto cluster backing group as long as you can