if (nodeGroup.getInstancePerHost() != null) {
// assume this value is already validated
int requiredHostNum = instanceNum / nodeGroup.getInstancePerHost();
if (nodeGroup.getGroupRacks() != null) {
GroupRacks groupRacks =
new Gson().fromJson(nodeGroup.getGroupRacks(),
GroupRacks.class);
GroupRacksType rackType = groupRacks.getType();
List<RackInfo> racksInfo = rackInfoMgr.getRackInfos();
Set<String> specifiedRacks =
new HashSet<String>(Arrays.asList(groupRacks.getRacks()));
List<String> IntersecRacks = new ArrayList<String>();
Integer IntersecHostNum = 0;
Integer maxIntersecHostNum = 0;
for (RackInfo rackInfo : racksInfo) {
if (specifiedRacks.isEmpty() || specifiedRacks.size() == 0
|| specifiedRacks.contains(rackInfo.getName())) {
IntersecHostNum += rackInfo.getHosts().size();
IntersecRacks.add(rackInfo.getName());
if (rackInfo.getHosts().size() > maxIntersecHostNum) {
maxIntersecHostNum = rackInfo.getHosts().size();
}
}
}
if (rackType.equals(GroupRacksType.ROUNDROBIN)
&& IntersecHostNum < requiredHostNum) {
throw ClusterConfigException.LACK_PHYSICAL_HOSTS(
requiredHostNum, nodeGroup.getName(), IntersecHostNum);
} else if (rackType.equals(GroupRacksType.SAMERACK)
&& requiredHostNum > maxIntersecHostNum) {
throw ClusterConfigException.LACK_PHYSICAL_HOSTS(
requiredHostNum, nodeGroup.getName(), maxIntersecHostNum);
}
if (specifiedRacks.isEmpty()) {
groupRacks.setRacks(new String[0]);
} else {
groupRacks.setRacks(IntersecRacks
.toArray(new String[IntersecRacks.size()]));
}
nodeGroup.setGroupRacks((new Gson()).toJson(groupRacks));
clusterEntityMgr.update(nodeGroup);
}