@Override public void openFirewallPortRangeAsync(final EntityAndAttribute<String> publicIp, final PortRange portRange, final Protocol protocol, final Cidr accessingCidr) { DeferredExecutor<String> updater = new DeferredExecutor<String>("open-firewall", publicIp, Predicates.notNull(), new Runnable() { public void run() { portForwarder.openFirewallPortRange(publicIp.getEntity(), portRange, protocol, accessingCidr); }}); subscribe(publicIp.getEntity(), publicIp.getAttribute(), updater); updater.apply(publicIp.getEntity(), publicIp.getValue()); }
public static <T> Supplier<T> attributeSupplier(Entity entity, AttributeSensor<T> sensor) { return EntityAndAttribute.create(entity, sensor); }
@Override public void openStaticNatAsync(Entity serviceToOpen, EntityAndAttribute<String> whereToAdvertiseHostname) { // FIXME Do in deferred block; what do we wait for? String staticNat = portForwarder.openStaticNat(serviceToOpen); whereToAdvertiseHostname.setValue(staticNat); }
private static <T> void setAttributeIfChanged(EntityAndAttribute<T> entityAndAttribute, T val) { setAttributeIfChanged(entityAndAttribute.getEntity(), entityAndAttribute.getAttribute(), val); }
public void apply(Entity source, Object valueIgnored) { Location targetVm = Iterables.getOnlyElement(portSensor.getEntity().getLocations(), null); if (targetVm==null) { log.warn("Skipping port forward rule for "+portSensor.getEntity()+" because it does not have a location"); return; String ip = (String) publicIp.getValue(); if (ip == null) { log.warn("Skipping firewall rule for "+publicIp+" because it does not have an IP"); Integer privateServicePort = TypeCoercions.coerce(portSensor.getValue(), Integer.class); if (privateServicePort==null) { log.warn("Skipping port forward rule for "+publicIp+" because it does not advertise a port on "+portSensor); log.debug("Port forward details: "+portSensor.getEntity()+":"+portSensor.getAttribute().getName()+" = "+newFrontEndpoint); } else { newFrontEndpoint = portSensor.getEntity().getAttribute(Attributes.HOSTNAME)+":"+portSensor.getAttribute(); whereToAdvertiseEndpoint.setValue(newFrontEndpoint); } else if (oldMapping!=null) { whereToAdvertiseEndpoint.setValue(null);
public void run() { Entity entity = privatePort.getEntity(); Integer privatePortVal = privatePort.getValue(); MachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations()).get(); HostAndPort publicEndpoint = portForwarder.openPortForwarding(machine, privatePortVal, optionalPublicPort, protocol, accessingCidr); // TODO What publicIpId to use in portForwardManager.associate? Elsewhere, uses jcloudsMachine.getJcloudsId(). portForwarder.getPortForwardManager().associate(machine.getId(), publicEndpoint, machine, privatePortVal); whereToAdvertiseEndpoint.setValue(publicEndpoint.getHostText()+":"+publicEndpoint.getPort()); }}; }
subscribe(targetToUpdate.getEntity(), targetToMatch, mapper); subscribe(targetToUpdate.getEntity(), targetToUpdate.getAttribute(), mapper); subscribe(replacementSource.getEntity(), replacementSource.getAttribute(), mapper); String newval = mapper.apply(targetToUpdate.get()); if (newval != null) { setAttributeIfChanged(targetToUpdate, newval);
/** * Deletes the NAT rule for the given port. * * Expects caller to call {@link PortForwardManager#forgetPortMapping(String, int)} */ public void closePortForwarding(EntityAndAttribute<Integer> privatePort, int publicPort) { Entity entity = privatePort.getEntity(); Integer targetPort = privatePort.getValue(); MachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations()).get(); String targetIp = Iterables.getFirst(Iterables.concat(machine.getPrivateAddresses(), machine.getPublicAddresses()), null); if (targetIp == null) { throw new IllegalStateException("Failed to close port-forwarding for machine " + machine + " because its location has no target ip: " + machine); } HostAndPort targetSide = HostAndPort.fromParts(targetIp, targetPort); HostAndPort publicSide = HostAndPort.fromParts(subnetTier.getConfig(NETWORK_PUBLIC_IP), publicPort); closePortForwarding(targetSide, publicSide, Protocol.TCP); }
@Override public String apply(String sensorVal) { if (sensorVal==null) return null; String input = targetToUpdate.get(); String replacementText = replacementSource.get(); log.debug("sensor mapper transforming address in "+targetToUpdate+", with "+replacementText+" (old value is "+input+")"); String suffix = ""; if (optionalTargetPort.isPresent()) { Integer port = optionalTargetPort.get().get(); if (port==null) { log.warn("no map-from port available for sensor mapper replacing addresses in "+targetToUpdate+ targetValsToMatch.put(targetToMatch, targetToUpdate.getEntity().getAttribute(targetToMatch));
public void run() { portForwarder.openFirewallPortRange(publicIp.getEntity(), portRange, protocol, accessingCidr); }}); subscribe(publicIp.getEntity(), publicIp.getAttribute(), updater);
/** * {@inheritDoc} * * Returns the current value of the {@link #getAttribute() attribute} on the {@link #getEntity() entity}. * * @see #getValue() */ @Override public T get() { return getValue(); }
public static <T> EntityAndAttribute<T> create(Entity entity, AttributeSensor<T> attribute) { return new EntityAndAttribute<T>(entity, attribute); }
public static <T> Supplier<T> attributeSupplierWhenReady(EntityAndAttribute<T> tuple) { return attributeSupplierWhenReady(tuple.getEntity(), tuple.getAttribute()); }
public void run() { portForwarder.openFirewallPortRange(publicIp.getEntity(), portRange, protocol, accessingCidr); }}; }
@Override public void openFirewallPortAndAdvertise(EntityAndAttribute<String> publicIp, EntityAndAttribute<?> portSensor, Integer optionalPublicPort, Protocol protocol, Cidr accessingCidr, EntityAndAttribute<String> whereToAdvertiseEndpoint) { FirewallUpdater2 updater = new FirewallUpdater2(publicIp, portSensor, optionalPublicPort, protocol, accessingCidr, whereToAdvertiseEndpoint); subscriptions().subscribe(publicIp.getEntity(), publicIp.getAttribute(), updater); subscriptions().subscribe(portSensor.getEntity(), portSensor.getAttribute(), updater); updater.apply(publicIp.getEntity(), publicIp.getValue()); }
public static <T> void setAttributeIfChanged(EntityAndAttribute<T> entityAndAttribute, T val) { setAttributeIfChanged(entityAndAttribute.getEntity(), entityAndAttribute.getAttribute(), val); }
/** * @deprecated since 0.7.0; use {@link #create(Entity, AttributeSensor)}; this does not relate to {@link Supplier} */ @Deprecated public static <T> EntityAndAttribute<T> supplier(Entity entity, AttributeSensor<T> attribute) { return create(entity, attribute); }
@Override public void advertise(EntityAndAttribute<Integer> source, HostAndPort publicEndpoint) { String endpoint = publicEndpoint.getHostText() + ":" + publicEndpoint.getPort(); whereToAdvertiseEndpoint.setValue(endpoint); } };
@Override public void openFirewallPortRange(EntityAndAttribute<String> publicIp, int lowerBoundPort, int upperBoundPort, FirewallRule.Protocol protocol, Cidr accessingCidr) { SimpleFirewallUpdater updater = new SimpleFirewallUpdater(publicIp, lowerBoundPort, upperBoundPort, protocol, accessingCidr); subscriptions().subscribe(publicIp.getEntity(), publicIp.getAttribute(), updater); updater.apply(publicIp.getEntity(), publicIp.getValue()); }
subscribe(ImmutableMap.of("notifyOfInitialValue", Boolean.TRUE), source.getEntity(), source.getAttribute(), updater); subscribe(source.getEntity(), AbstractEntity.LOCATION_ADDED, updater);