/** as {@link Machines#findUniqueMachineLocation(Iterable)} */ public static Maybe<MachineLocation> findUniqueMachineLocation(Iterable<? extends Location> locations) { return Machines.findUniqueMachineLocation(locations); }
public static Maybe<String> findSubnetHostname(Iterable<? extends Location> ll) { Maybe<MachineLocation> l = findUniqueMachineLocation(ll); if (!l.isPresent()) { return Maybe.absent(); // throw new IllegalStateException("Cannot find hostname for among "+ll); } return Machines.getSubnetHostname(l.get()); }
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> findSubnetOrPublicHostname(Entity entity) { String hn = entity.getAttribute(Attributes.HOSTNAME); if (hn!=null) { // attributes already set, see if there was a SUBNET_HOSTNAME set // note we rely on (public) hostname being set _after_ subnet_hostname, // to prevent tiny possibility of races resulting in hostname being returned // becasue subnet is still being looked up -- see MachineLifecycleEffectorTasks Maybe<String> sn = findSubnetHostname(entity); if (sn.isPresent()) return sn; // short-circuit discovery if attributes have been set already return Maybe.of(hn); } Maybe<MachineLocation> l = findUniqueMachineLocation(entity.getLocations()); if (!l.isPresent()) return Maybe.absent(); InetAddress addr = l.get().getAddress(); if (addr==null) return Maybe.absent(); return Maybe.fromNullable(addr.getHostName()); }
public static Maybe<String> findSubnetOrPrivateIp(Entity entity) { // see comments in findSubnetOrPrivateHostname String hn = entity.getAttribute(Attributes.ADDRESS); if (hn!=null) { Maybe<String> sn = findSubnetIp(entity); if (sn.isPresent()) return sn; return Maybe.of(hn); } Maybe<MachineLocation> l = findUniqueMachineLocation(entity.getLocations()); if (!l.isPresent()) return Maybe.absent(); InetAddress addr = l.get().getAddress(); if (addr==null) return Maybe.absent(); return Maybe.fromNullable(addr.getHostAddress()); }
@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); } }
public static <T extends MachineLocation> Maybe<T> findUniqueMachineLocation(Iterable<? extends Location> locations, Class<T> clazz) { return findUniqueElement(locations, clazz); }
public static Maybe<String> findSubnetHostname(Entity entity) { String sh = entity.getAttribute(Attributes.SUBNET_HOSTNAME); if (sh!=null) return Maybe.of(sh); return findSubnetHostname(entity.getLocations()); }
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 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"); }
@Test public void testFindUniqueElementAbsentWhenItemsNull() throws Exception { assertTrue(Machines.findUniqueElement(null, SshMachineLocation.class).isAbsent()); }
/** returns URL, if it can be inferred; null otherwise */ protected String inferUrl(boolean requireManagementAccessible) { String domain = getDomainWithoutWildcard(); Integer port = checkNotNull(getPort(), "no port configured (the requested port may be in use)"); if (requireManagementAccessible) { HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, port); if (accessible!=null) { domain = accessible.getHostText(); port = accessible.getPort(); } } if (domain==null) domain = Machines.findSubnetHostname(this).orNull(); return inferUrl(domain, Optional.of(port)); }
/** as {@link Machines#findUniqueSshMachineLocation(Iterable)} */ public static Maybe<SshMachineLocation> findUniqueSshMachineLocation(Iterable<? extends Location> locations) { return Machines.findUniqueMachineLocation(locations, SshMachineLocation.class); }
Maybe<String> lh = Machines.getSubnetHostname(machine); Maybe<String> la = Machines.getSubnetIp(machine); if (lh.isPresent() && entity().sensors().get(Attributes.SUBNET_HOSTNAME) == null) { entity().sensors().set(Attributes.SUBNET_HOSTNAME, lh.get());
Maybe<SupportsPortForwarding> supportPortForwardingLoc = Machines.findUniqueElement(ll, SupportsPortForwarding.class); if (supportPortForwardingLoc.isPresent()) { Cidr source = entity.getConfig(MANAGEMENT_ACCESS_CIDR);
@Test public void testFindSubnetHostnameFromLocationWithoutPrivate() throws Exception { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class) .location(sshMachineWithoutPrivateSpec)); assertEquals(Machines.findSubnetHostname(entity).get(), publicAddr); }
public static Maybe<MachineLocation> findUniqueMachineLocation(Iterable<? extends Location> locations) { return findUniqueMachineLocation(locations, MachineLocation.class); }
HttpExecutorFactory httpExecutorFactory = null; Collection<? extends Location> locations = Locations.getLocationsCheckingAncestors(builder.entity.getLocations(), builder.entity); Maybe<MachineLocation> location = Machines.findUniqueElement(locations, MachineLocation.class); if (location.isPresent() && location.get().hasExtension(HttpExecutorFactory.class)) { httpExecutorFactory = location.get().getExtension(HttpExecutorFactory.class);
@Test public void testFindSubnetHostnameFromLocation() throws Exception { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class) .location(sshMachineSpec)); assertEquals(Machines.findSubnetHostname(entity).get(), privateAddr); }
/** * @deprecated since 0.9.0; see {@link #findUniqueMachineLocation(Iterable, Class)}, * e.g. {@code findUniqueMachineLocation(locations, SshMachineLocation.class)} */ @Deprecated public static Maybe<SshMachineLocation> findUniqueSshMachineLocation(Iterable<? extends Location> locations) { return findUniqueMachineLocation(locations, SshMachineLocation.class); }