use of org.platformlayer.ops.tagger.Tagger in project platformlayer by platformlayer.
the class OpenstackPublicEndpointController method addChildren.
// @Inject
// ImageFactory imageFactory;
//
@Override
protected void addChildren() throws OpsException {
final OpenstackPublicEndpoint model = OpsContext.get().getInstance(OpenstackPublicEndpoint.class);
OpenstackInstance instance = client.getItem(model.instance, OpenstackInstance.class);
CloudInstanceMapper instanceMapper;
{
instanceMapper = injected(CloudInstanceMapper.class);
instanceMapper.instance = instance;
addChild(instanceMapper);
}
final EnsureFirewallIngress ingress;
{
ingress = injected(EnsureFirewallIngress.class);
ingress.model = model;
instanceMapper.addChild(ingress);
}
{
OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {
@Override
public TagChanges get() {
TagChanges tagChanges = new TagChanges();
String address = ingress.getPublicAddress();
if (Strings.isNullOrEmpty(address)) {
throw new IllegalStateException();
}
EndpointInfo endpoint = new EndpointInfo(address, model.publicPort);
tagChanges.addTags.add(endpoint.toTag());
return tagChanges;
}
};
Tagger tagger = injected(Tagger.class);
tagger.platformLayerKey = model.getKey();
tagger.tagChangesProvider = tagChanges;
instanceMapper.addChild(tagger);
Tagger tagInstance = injected(Tagger.class);
tagInstance.platformLayerKey = null;
tagInstance.platformLayerKey = model.instance;
tagInstance.tagChangesProvider = tagChanges;
instanceMapper.addChild(tagInstance);
}
}
use of org.platformlayer.ops.tagger.Tagger in project platformlayer by platformlayer.
the class PersistentInstanceMapper method addChildren.
@Override
protected void addChildren() throws OpsException {
final PersistentInstance model = OpsContext.get().getInstance(PersistentInstance.class);
{
// Add tag with instance id to persistent instance (very helpful for DNS service!)
Tagger tagger = injected(Tagger.class);
tagger.platformLayerKey = model.getKey();
tagger.tagChangesProvider = new OpsProvider<TagChanges>() {
@Override
public TagChanges get() throws OpsException {
Machine machine = OpsContext.get().getInstance(Machine.class);
if (machine == null) {
if (OpsContext.isDelete()) {
return null;
}
throw new OpsException("No machine in scope");
}
TagChanges changeTags = new TagChanges();
changeTags.addTags.add(Tag.INSTANCE_KEY.build(machine.getKey()));
platformLayer.changeTags(model.getKey(), changeTags, null);
return changeTags;
}
};
addChild(tagger);
}
}
use of org.platformlayer.ops.tagger.Tagger in project platformlayer by platformlayer.
the class GoogleCloudPublicEndpointController method addChildren.
@Override
protected void addChildren() throws OpsException {
final GoogleCloudPublicEndpoint model = OpsContext.get().getInstance(GoogleCloudPublicEndpoint.class);
GoogleCloudInstance instance = client.getItem(model.instance, GoogleCloudInstance.class);
CloudInstanceMapper instanceMapper;
{
instanceMapper = injected(CloudInstanceMapper.class);
instanceMapper.instance = instance;
addChild(instanceMapper);
}
final EnsureFirewallIngress ingress;
{
ingress = injected(EnsureFirewallIngress.class);
ingress.model = model;
instanceMapper.addChild(ingress);
}
{
OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {
@Override
public TagChanges get() {
TagChanges tagChanges = new TagChanges();
String address = ingress.getPublicAddress();
if (Strings.isNullOrEmpty(address)) {
throw new IllegalStateException();
}
EndpointInfo endpoint = new EndpointInfo(address, model.publicPort);
tagChanges.addTags.add(endpoint.toTag());
return tagChanges;
}
};
Tagger tagger = injected(Tagger.class);
tagger.platformLayerKey = model.getKey();
tagger.tagChangesProvider = tagChanges;
instanceMapper.addChild(tagger);
Tagger tagInstance = injected(Tagger.class);
tagInstance.platformLayerKey = null;
tagInstance.platformLayerKey = model.instance;
tagInstance.tagChangesProvider = tagChanges;
instanceMapper.addChild(tagInstance);
}
}
use of org.platformlayer.ops.tagger.Tagger 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);
}
}
use of org.platformlayer.ops.tagger.Tagger in project platformlayer by platformlayer.
the class DirectPublicPorts method addChildren.
@Override
protected void addChildren() throws OpsException {
final CloudInstanceMapper cloudHost;
{
cloudHost = injected(CloudInstanceMapper.class);
cloudHost.createInstance = false;
cloudHost.instance = backendItem;
addChild(cloudHost);
}
final SocketAddressPoolAssignment assignPublicAddress;
{
assignPublicAddress = cloudHost.addChild(SocketAddressPoolAssignment.class);
assignPublicAddress.holder = backendItem.getKey();
if (Objects.equal(transport, Transport.Ipv6)) {
assignPublicAddress.poolProvider = new OpsProvider<ResourcePool<InetSocketAddress>>() {
@Override
public ResourcePool<InetSocketAddress> get() throws OpsException {
final ResourcePool<AddressModel> pool = directCloudHelpers.getAddressPool6().get();
return new AssignPortToAddressPool(pool, publicPort);
}
};
} else {
List<Integer> publicPortCluster = this.publicPortCluster;
if (publicPortCluster == null) {
publicPortCluster = Lists.newArrayList();
publicPortCluster.add(publicPort);
}
if (!publicPortCluster.contains(publicPort)) {
throw new OpsException("Port set specified, but public port not in the set");
}
assignPublicAddress.poolProvider = directCloudHelpers.getPublicAddressPool4(publicPort, publicPortCluster);
}
}
if (Objects.equal(transport, Transport.Ipv6)) {
// TODO: Do we need separate frontend / backend ports really?
if (this.publicPort != this.backendPort) {
throw new UnsupportedOperationException();
}
} else {
for (Protocol protocol : Protocol.TcpAndUdp()) {
IptablesForwardPort forward = injected(IptablesForwardPort.class);
forward.publicAddress = assignPublicAddress;
forward.ruleKey = protocol.name() + "-" + uuid;
forward.protocol = protocol;
forward.privateAddress = new OpsProvider<String>() {
@Override
public String get() throws OpsException {
// Refresh item to pick up new tags
backendItem = platformLayerClient.getItem(backendItem.getKey(), DirectInstance.class);
PlatformLayerCloudMachine instanceMachine = (PlatformLayerCloudMachine) instanceHelpers.getMachine(backendItem);
DirectInstance instance = (DirectInstance) instanceMachine.getInstance();
List<InetAddress> addresses = Tag.NETWORK_ADDRESS.find(instance);
InetAddress address = InetAddressChooser.preferIpv4().choose(addresses);
if (address == null) {
throw new IllegalStateException();
}
if (InetAddressUtils.isIpv6(address)) {
// We can't NAT IPV4 -> IPV6 (I think)
throw new IllegalStateException();
}
return address.getHostAddress();
}
};
forward.privatePort = backendPort;
cloudHost.addChild(forward);
}
}
{
OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {
@Override
public TagChanges get() {
TagChanges tagChanges = new TagChanges();
InetSocketAddress socketAddress = assignPublicAddress.get();
if (socketAddress == null) {
return null;
}
if (socketAddress.getPort() != publicPort) {
throw new IllegalStateException();
}
EndpointInfo endpoint = new EndpointInfo(socketAddress);
tagChanges.addTags.add(endpoint.toTag());
return tagChanges;
}
};
for (ItemBase tagItem : tagItems) {
Tagger tagger = addChild(Tagger.class);
tagger.platformLayerKey = tagItem.getKey();
tagger.tagChangesProvider = tagChanges;
}
}
}
Aggregations