Set<String> ids = Sets.newHashSet();
for (DnsRecordset recordset : records) {
DnsRecordsetData data = recordset.getData();
Recordset r = new Recordset();
String fqdn = recordset.getFqdn();
r.name = fqdn;
r.id = "" + data.getId();
if (ids.contains(r.id)) {
throw new IllegalStateException();
}
ids.add(r.id);
r.zone_id = "" + data.getZoneId();
r.weight = null;
r.ttl = null;
r.type = data.getType();
if (data.hasState()) {
r.deleted_at = Clock.toDate(data.getState().getDeletedAt());
}
if (DnsService.TYPE_SOA.equalsIgnoreCase(r.type)) {
hasSoa = true;
}
r.records = Lists.newArrayList();
for (DnsRecord dnsRecord : recordset.getRecords()) {
Record record = new Record();
DnsRecordData recordData = dnsRecord.getData();
record.value = recordData.getTarget();
if (recordData.hasWeight()) {
record.weight = recordData.getWeight();
}
if (recordData.hasPort()) {
record.port = recordData.getPort();
}
if (recordData.hasPriority()) {
record.priority = recordData.getPriority();
}
r.records.add(record);
}
recordsets.add(r);
}
if (createSoa && !hasSoa) {
Recordset r = new Recordset();
r.name = zoneName;
// primary hostmaster serial refresh retry expire default_ttl
String primary = "ns." + zoneName;
String hostmaster = "hostmaster@" + zoneName;