.append(getName())
.append(
".placementPolicies.groupAssociations.size should be 1.")
.toString());
} else {
GroupAssociation a = policies.getGroupAssociations().get(0);
if (a.getType() == null) {
a.setType(GroupAssociationType.WEAK); // set to default
}
if (a.getReference() == null) {
valid = false;
failedMsgList
.add(new StringBuilder()
.append(getName())
.append(
".placementPolicies.groupAssociations[0].reference not set.")
.toString());
} else if (a.getReference().equals(getName())) {
valid = false;
failedMsgList
.add(new StringBuilder()
.append(getName())
.append(
".placementPolicies.groupAssociations[0] refers to itself.")
.toString());
} else if (!groups.containsKey(a.getReference())) {
valid = false;
failedMsgList
.add(new StringBuilder()
.append(getName())
.append(
".placementPolicies.groupAssociations[0] refers to invalid node group ")
.append(a.getReference()).append(".").toString());
} else {
/*
* This is normal case, do more checks.
*
* If STRICT is specified, the host number of the current node
* group should not be larger than the referenced one.
*/
if (a.getType() == GroupAssociationType.STRICT) {
/*
* For the referenced node group, we assume the max node number equals to
* instance number when instance per host is unspecified. For the reference
* node group, we assume the min node number is 1 when instance per host is
* unspecified. This rule follows the underlying placement algorithm.
*/
int hostNum = 1;
int refHostNum =
groups.get(a.getReference()).getInstanceNum();
if (calculateHostNum() != null) {
hostNum = calculateHostNum();
}
if (groups.get(a.getReference()).calculateHostNum() != null) {
refHostNum =
groups.get(a.getReference()).calculateHostNum();
}
if (hostNum > refHostNum) {
valid = false;
failedMsgList
.add(new StringBuilder()
.append(getName())
.append(
".placementPolicies.groupAssociations[0] requires "
+ "more hosts than the referenced node group ")
.append(a.getReference()).append(".").toString());
}
}
// current implementation only support sum(in/out degree) <= 1
PlacementPolicy refPolicies =
groups.get(a.getReference()).getPlacementPolicies();
if (refPolicies != null
&& refPolicies.getGroupAssociations() != null
&& !refPolicies.getGroupAssociations().isEmpty()) {
valid = false;
failedMsgList
.add(new StringBuilder()
.append(getName())
.append(
".placementPolicies.groupAssociations[0] refers to node group ")
.append(a.getReference())
.append(" which also has reference(s).")
.toString());
}
}
}