public static Maybe<String> findSubnetIp(Iterable<? extends Location> ll) { // TODO Or if can't find MachineLocation, should we throw new IllegalStateException("Cannot find hostname for among "+ll); Maybe<MachineLocation> l = findUniqueMachineLocation(ll); return (l.isPresent()) ? Machines.getSubnetIp(l.get()) : Maybe.<String>absent(); }
public static Maybe<String> getSubnetHostname(Location where) { // TODO Should we look at HasNetworkAddresses? But that's not a hostname. String hostname = null; if (where instanceof HasSubnetHostname) { hostname = ((HasSubnetHostname) where).getSubnetHostname(); } if (hostname == null && where instanceof MachineLocation) { Maybe<String> subnetIp = getSubnetIp(where); if (subnetIp.isPresent()) { hostname = subnetIp.get(); } else { InetAddress addr = ((MachineLocation) where).getAddress(); if (addr != null) hostname = addr.getHostAddress(); } } log.debug("computed subnet hostname {} for {}", hostname, where); // TODO if Maybe.absent(message) appears, could/should use that // TODO If no machine available, should we throw new IllegalStateException("Cannot find hostname for "+where); return Maybe.fromNullable(hostname); }
@Test public void testSetPrivateIpToPublicIp() throws Exception { JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of()); assertEquals(publicAddresses, machine.getPublicAddresses()); assertEquals(machine.getPublicAddresses().size(), 1); String publicAddress = machine.getPublicAddresses().iterator().next(); assertEquals(machine.getPrivateAddress().get(), publicAddress); assertEquals(machine.getSubnetHostname(), machine.getHostname()); assertEquals(machine.getSubnetIp(), publicAddress); assertEquals(Machines.getSubnetHostname(machine).get(), machine.getHostname()); assertEquals(Machines.getSubnetIp(machine).get(), publicAddress); assertEquals(machine.getPrivateAddresses().size(), 1); assertEquals(machine.getPrivateAddresses().iterator().next(), publicAddress); } }
@Test public void testConfigurePrivateAddresses() throws Exception { SshMachineLocation host2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", Networking.getReachableLocalHost()) .configure(SshMachineLocation.PRIVATE_ADDRESSES, ImmutableList.of("1.2.3.4")) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); assertEquals(host2.getPrivateAddresses(), ImmutableSet.of("1.2.3.4")); assertEquals(Machines.getSubnetIp(host2).get(), "1.2.3.4"); assertEquals(Machines.getSubnetHostname(host2).get(), "1.2.3.4"); }
Maybe<String> la = Machines.getSubnetIp(machine); if (lh.isPresent() && entity().sensors().get(Attributes.SUBNET_HOSTNAME) == null) { entity().sensors().set(Attributes.SUBNET_HOSTNAME, lh.get());