/** * {@inheritDoc} * * Returns the current value of the {@link #getAttribute() attribute} on the {@link #getEntity() entity}. * * @see #getValue() */ @Override public T get() { return getValue(); }
public void apply(Entity source, Object valueIgnored) { if (isSubnetEnabled()) { String ip = (String) publicIp.getValue(); if (ip == null) { log.warn("Skipping firewall rule for "+publicIp.getEntity()+"->"+publicIp.getAttribute()+" (ports "+lowerBoundPort+"-"+upperBoundPort+") because it does not have an IP"); return; } String ipId = retrievePublicIpId(ip); if (ipId == null) { log.error("Skipping firewall rule for "+ip+" because reverse-lookup of ip-id failed"); return; } boolean success = systemOpenFirewall(ipId, cidr, lowerBoundPort, upperBoundPort, protocol); if (success) { log.debug("Firewall opened: "+ip+":"+lowerBoundPort+"-"+upperBoundPort); } } } }
/** * 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 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()); }
@Override public void run() { Entity entity = source.getEntity(); Integer privatePortVal = source.getValue(); if (privatePortVal == null) { if (log.isDebugEnabled())
@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()); }
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);
public void apply(final Entity source, final Object valueIgnored) { T val = (T) attribute.getValue(); if (!readiness.apply(val)) { log.warn("Skipping {} for {} because attribute {} not ready", new Object[]{description, attribute.getEntity(), attribute.getAttribute()}); return; } final Task<Void> task = TaskBuilder.<Void>builder().displayName(description).body(runnable).build(); DynamicTasks.queueIfPossible(task).orSubmitAsync(source).asTask(); if (blockUntilEnded) { final String originalBlock = Tasks.setBlockingDetails(description); try { task.blockUntilEnded(); } finally { Tasks.setBlockingDetails(originalBlock); } } } }
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()); }}; }
@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()); }