/* Convert to the baseclass */
rrs.add(crr);
}
ResourceRecordSet leafNode = new ResourceRecordSet();
leafNode.setType(type);
leafNode.setTTL(ttl);
leafNode.setResourceRecords(rrs);
/* Set a nominal weight so that we can set an identifier */
leafNode.setWeight(1L);
leafNode.setSetIdentifier("leafnode");
leafNode.setName(name);
List<String> healthchecksRemaining = new ArrayList<String>(healthcheckIds);
if (healthchecksRemaining.size() > 0) {
leafNode.setHealthCheckId(healthchecksRemaining.remove(0));
}
rrsList.add(leafNode);
if (healthchecksRemaining.isEmpty()) {
return rrsList;
}
/*
* If more than one health-check is associated with the answer set, we
* can use a chain of ALIAS records, each dependent on a different
* health-check to form a logical AND of the health-checks.
*/
ResourceRecordSet entryNode = leafNode;
while (!healthchecksRemaining.isEmpty()) {
ResourceRecordSet alias = new ResourceRecordSet();
AliasTarget aliasTarget = new AliasTarget();
String checksum = checksumResourceRecordSetData(entryNode);
/* The alias will be the new entry node, inherit its properties */
alias.setName(entryNode.getName());
alias.setType(entryNode.getType());
alias.setWeight(entryNode.getWeight());
/* Consume a health-check */
alias.setHealthCheckId(healthchecksRemaining.remove(0));
/* Rename the previous entry node */
String targetName = checksum + "." + entryNode.getName();
entryNode.setName(targetName);
aliasTarget.setDNSName(targetName);
aliasTarget.setEvaluateTargetHealth(true);
aliasTarget.setHostedZoneId(hostedZoneId);
/* Associate the alias and the alias target */
alias.setSetIdentifier("Alias to " + checksum);
alias.setAliasTarget(aliasTarget);
/* Add the alias and make it the new entry node */
rrsList.add(alias);
entryNode = alias;
}