use of org.platformlayer.core.model.PublicEndpointBase in project platformlayer by platformlayer.
the class OwnedEndpoint method buildItemTemplate.
@Override
protected PublicEndpointBase buildItemTemplate() throws OpsException {
InstanceBase instance = OpsContext.get().getInstance(InstanceBase.class);
PlatformLayerKey instanceKey = instance.getKey();
PublicEndpointBase publicEndpoint = platformLayerCloudHelpers.createPublicEndpoint(instance, parentItem);
// publicEndpoint.network = network;
publicEndpoint.publicPort = publicPort;
publicEndpoint.publicPortCluster = publicPortCluster;
publicEndpoint.backendPort = backendPort;
publicEndpoint.instance = instanceKey;
publicEndpoint.key = PlatformLayerKey.fromId(instance.getId() + "_" + publicPort);
if (transport != null) {
publicEndpoint.transport = transport.toString();
}
// publicEndpoint.getTags().add(OpsSystem.get().createParentTag(instance));
Tag uniqueTag = UniqueTag.build(instance, String.valueOf(publicPort));
publicEndpoint.getTags().add(uniqueTag);
return publicEndpoint;
}
use of org.platformlayer.core.model.PublicEndpointBase in project platformlayer by platformlayer.
the class PlatformLayerCloudHelpers method createPublicEndpoint.
public PublicEndpointBase createPublicEndpoint(InstanceBase instance, PlatformLayerKey parent) throws OpsException {
MachineProvider cloudController = getCloud(instance.cloud);
PublicEndpointBase endpoint = cloudController.buildEndpointTemplate();
if (parent != null) {
endpoint.getTags().add(Tag.buildParentTag(parent));
}
return endpoint;
// throw new UnsupportedOperationException();
}
use of org.platformlayer.core.model.PublicEndpointBase 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.core.model.PublicEndpointBase 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