use of org.platformlayer.ops.dns.EndpointDnsRecord in project platformlayer by platformlayer.
the class PublicEndpoint method addChildren.
@Override
protected void addChildren() throws OpsException {
final OwnedEndpoint endpoint;
{
endpoint = addChild(OwnedEndpoint.class);
endpoint.publicPort = publicPort;
endpoint.publicPortCluster = publicPortCluster;
endpoint.backendPort = backendPort;
endpoint.parentItem = parentItem;
endpoint.transport = transport;
}
if (tagItem != null) {
Tagger tagger = injected(Tagger.class);
OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {
@Override
public TagChanges get() throws OpsException {
int maxAttempts = 5;
int attempt = 0;
PublicEndpointBase item = endpoint.getItem();
while (true) {
attempt++;
if (item == null) {
if (!OpsContext.isDelete()) {
throw new OpsException("Endpoint not created");
} else {
log.warn("No endpoint => no tagging to be done");
return null;
}
}
List<EndpointInfo> endpointInfos = EndpointInfo.findEndpoints(item.getTags(), publicPort);
if (!endpointInfos.isEmpty()) {
TagChanges tagChanges = new TagChanges();
for (EndpointInfo endpointInfo : endpointInfos) {
tagChanges.addTags.add(endpointInfo.toTag());
}
return tagChanges;
}
if (attempt != maxAttempts) {
log.info("Endpoint not yet found; sleeping and retrying");
TimeSpan.FIVE_SECONDS.doSafeSleep();
item = platformLayerClient.getItem(item.getKey());
continue;
} else {
throw new OpsException("Cannot find endpoint for port: " + publicPort);
}
}
}
};
tagger.platformLayerKey = tagItem;
tagger.tagChangesProvider = tagChanges;
addChild(tagger);
}
if (defaultBlocked) {
// Block on machine's firewall
log.warn("Not adding firewall block; relying on default block");
// addChild(IptablesFirewallEntry.build(FirewallRecord.buildBlockPort(protocol, backendPort)));
}
if (!Strings.isNullOrEmpty(dnsName)) {
EndpointDnsRecord dns = injected(EndpointDnsRecord.class);
dns.destinationPort = publicPort;
dns.endpointProvider = new Provider<PublicEndpointBase>() {
@Override
public PublicEndpointBase get() {
return endpoint.getItem();
}
};
dns.dnsName = dnsName;
addChild(dns);
}
}
Aggregations