use of org.platformlayer.service.dns.model.DnsServer in project platformlayer by platformlayer.
the class DnsHelpers method buildDnsFile.
public ZoneFile buildDnsFile(DnsZone dnsZone) throws OpsException {
ZoneFile dnsFile = new ZoneFile(dnsZone.dnsName);
Iterable<DnsServer> dnsServers = platformLayer.listItems(DnsServer.class);
for (DnsServer dnsServer : dnsServers) {
switch(dnsServer.getState()) {
case DELETE_REQUESTED:
case DELETED:
log.info("Skipping server (deleted/deleting): " + dnsServer);
continue;
case ACTIVE:
// Good
break;
default:
log.warn("Dns server not yet active: " + dnsServer);
// failed = true;
continue;
}
List<EndpointInfo> dnsServerEndpoints = EndpointInfo.findEndpoints(dnsServer.getTags(), 53);
if (dnsServerEndpoints.isEmpty()) {
throw new OpsException("Cannot find endpoint for: " + dnsServer);
}
// Use the ID to produce a stable identifier
// TODO: What if we shutdown nameservers? Should we do something like consistent hashing instead?
// i.e. always create ns1 ... ns16, and then dynamically repoint them as we add/remove nameservers?
// Does this really help?
// String serverId = dnsServer"ns" + dnsServer.getId();
String dnsName = dnsServer.dnsName;
if (dnsName == null) {
throw new OpsException("DnsName not set on " + dnsServer);
}
// TODO: This might not be the right address in complex networks
for (EndpointInfo dnsServerEndpoint : dnsServerEndpoints) {
String address = dnsServerEndpoint.publicIp;
dnsFile.addNS(dnsZone.dnsName, address, dnsName);
}
}
Iterable<DnsRecord> dnsRecords = platformLayer.listItems(DnsRecord.class);
for (DnsRecord record : dnsRecords) {
switch(record.getState()) {
case DELETE_REQUESTED:
case DELETED:
log.info("Skipping record (deleted/deleting): " + record);
continue;
default:
break;
}
if (!isInZone(record, dnsZone)) {
continue;
}
dnsFile.addAddress(record.dnsName, record.address);
}
return dnsFile;
}
use of org.platformlayer.service.dns.model.DnsServer in project platformlayer by platformlayer.
the class DnsService method beforeCreateItem.
@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
if (item instanceof DnsServer) {
DnsServer model = (DnsServer) item;
model.dnsName = normalize(model.dnsName);
if (Strings.isNullOrEmpty(model.dnsName)) {
throw new IllegalArgumentException("dnsName must be specified");
}
}
if (item instanceof DnsRecord) {
DnsRecord model = (DnsRecord) item;
model.dnsName = normalize(model.dnsName);
if (Strings.isNullOrEmpty(model.dnsName)) {
throw new IllegalArgumentException("dnsName must be specified");
}
if (Strings.isNullOrEmpty(model.recordType)) {
model.recordType = "A";
}
if (model.recordType.equals("A")) {
// OK
} else {
throw new IllegalArgumentException("Record type not supported: " + model.recordType);
}
}
if (item instanceof DnsZone) {
DnsZone model = (DnsZone) item;
model.dnsName = normalize(model.dnsName);
if (Strings.isNullOrEmpty(model.dnsName)) {
model.dnsName = normalize(model.getId());
}
}
super.beforeCreateItem(item);
}
use of org.platformlayer.service.dns.model.DnsServer in project platformlayer by platformlayer.
the class DnsHelpers method uploadToAllDnsServers.
public void uploadToAllDnsServers(ZoneFile dnsFile) throws OpsException {
// TODO: Likely problems with concurrent creation of servers and domain entries??
boolean failed = false;
for (DnsServer dnsServer : platformLayer.listItems(DnsServer.class)) {
switch(dnsServer.state) {
case DELETE_REQUESTED:
case DELETED:
log.info("Skipping server (deleted/deleting): " + dnsServer);
continue;
case ACTIVE:
// Good
break;
default:
log.warn("Dns server not yet active: " + dnsServer);
failed = true;
continue;
}
// TODO: We could have a 'cluster key' that is used to tag the
// machines providing this service
Machine machine = instances.findMachine(dnsServer);
if (machine == null) {
log.warn("Dns server instance not found: " + dnsServer);
failed = true;
continue;
}
OpsTarget target = machine.getTarget(service.getSshKey());
try {
upload(target, dnsFile);
} catch (OpsException e) {
log.warn("Error updloading dns to server: " + dnsServer, e);
failed = true;
continue;
}
}
if (failed) {
throw new OpsException("Could not update all DNS servers in cluster").setRetry(TimeSpan.ONE_MINUTE);
}
}
Aggregations