use of org.platformlayer.dns.model.DnsRecord in project platformlayer by platformlayer.
the class NginxFrontendDns method buildItemTemplate.
@Override
protected DnsRecord buildItemTemplate() throws OpsException {
// TODO: Idempotency etc
// Machine machine = OpsContext.get().getInstance(Machine.class);
NginxService nginxService = OpsContext.get().getInstance(NginxService.class);
NginxFrontend nginxFrontend = OpsContext.get().getInstance(NginxFrontend.class);
Machine machine = instanceHelpers.getMachine(nginxService);
String address = machine.getNetworkPoint().getBestAddress(NetworkPoint.forPublicInternet());
DnsRecord record = new DnsRecord();
record.setDnsName(nginxFrontend.hostname);
record.getAddress().add(address);
Tag parentTag = Tag.buildParentTag(nginxFrontend.getKey());
record.getTags().add(parentTag);
Tag uniqueTag = UniqueTag.build(nginxService, nginxFrontend);
record.getTags().add(uniqueTag);
record.key = PlatformLayerKey.fromId(nginxFrontend.hostname);
return record;
}
use of org.platformlayer.dns.model.DnsRecord 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.dns.model.DnsRecord in project platformlayer by platformlayer.
the class EndpointDnsRecord method handler.
@Handler
public void handler() throws OpsException {
PublicEndpointBase endpoint = endpointProvider.get();
if (OpsContext.isConfigure()) {
// Create a DNS record
Tag parentTag = Tag.buildParentTag(endpoint.getKey());
List<EndpointInfo> endpoints = EndpointInfo.findEndpoints(endpoint.getTags(), destinationPort);
if (endpoints.isEmpty()) {
throw new OpsException("Cannot find endpoint for port: " + destinationPort);
}
DnsRecord record = new DnsRecord();
record.setDnsName(dnsName);
for (EndpointInfo endpointInfo : endpoints) {
record.getAddress().add(endpointInfo.publicIp);
}
record.getTags().add(parentTag);
record.setKey(PlatformLayerKey.fromId(dnsName));
try {
platformLayerClient.putItemByTag((ItemBase) record, parentTag);
} catch (PlatformLayerClientException e) {
throw new OpsException("Error registering persistent instance", e);
}
}
}
use of org.platformlayer.dns.model.DnsRecord 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);
}
Aggregations