private static <T> void setAttributeIfChanged(EntityAndAttribute<T> entityAndAttribute, T val) { setAttributeIfChanged(entityAndAttribute.getEntity(), entityAndAttribute.getAttribute(), val); }
public static <T> Supplier<T> attributeSupplierWhenReady(EntityAndAttribute<T> tuple) { return attributeSupplierWhenReady(tuple.getEntity(), tuple.getAttribute()); }
public static <T> void setAttributeIfChanged(EntityAndAttribute<T> entityAndAttribute, T val) { setAttributeIfChanged(entityAndAttribute.getEntity(), entityAndAttribute.getAttribute(), val); }
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); } } } }
@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 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()); }
if (privatePortVal == null) { if (log.isDebugEnabled()) log.debug("Private port null for entity {}; not opening or advertising mapped port", entity, source.getAttribute().getName()); return; log.debug("Set target sensor, advertising mapping of {}->{} ({})", new Object[] {entity, source.getAttribute().getName(), publicEndpoint});
subscribe(ImmutableMap.of("notifyOfInitialValue", Boolean.TRUE), source.getEntity(), source.getAttribute(), updater); subscribe(source.getEntity(), AbstractEntity.LOCATION_ADDED, updater);
@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()); }
log.debug("Port forward details: "+portSensor.getEntity()+":"+portSensor.getAttribute().getName()+" = "+newFrontEndpoint); } else { newFrontEndpoint = portSensor.getEntity().getAttribute(Attributes.HOSTNAME)+":"+portSensor.getAttribute();
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); } } } }
subscribe(targetToUpdate.getEntity(), targetToMatch, mapper); subscribe(targetToUpdate.getEntity(), targetToUpdate.getAttribute(), mapper); subscribe(replacementSource.getEntity(), replacementSource.getAttribute(), mapper);
@Override public void advertise(EntityAndAttribute<Integer> source, HostAndPort publicEndpoint) { String sourceSensor = source.getAttribute().getName(); Entity entity = source.getEntity(); AttributeSensor<String> mappedSensor = Sensors.newStringSensor("mapped." + sourceSensor); AttributeSensor<String> mappedEndpointSensor = Sensors.newStringSensor("mapped.endpoint." + sourceSensor); AttributeSensor<Integer> mappedPortSensor = Sensors.newIntegerSensor("mapped.portPart." + sourceSensor); String endpoint = publicEndpoint.getHostText() + ":" + publicEndpoint.getPort(); entity.sensors().set(mappedSensor, endpoint); entity.sensors().set(mappedEndpointSensor, endpoint); entity.sensors().set(mappedPortSensor, publicEndpoint.getPort()); } };