Machines { public static Maybe<String> findSubnetHostname(Iterable<? extends Location> ll) { Maybe<MachineLocation> l = findUniqueMachineLocation(ll); if (!l.isPresent()) { return Maybe.absent(); } return Machines.getSubnetHostname(l.get()); }  static Maybe<String> getSubnetHostname(Location where); static Maybe<String> getSubnetIp(Location where); @Nonnull @SuppressWarnings("unchecked") static Maybe<T> findUniqueElement(Iterable<?> items, Class<T> type); static Maybe<MachineLocation> findUniqueMachineLocation(Iterable<? extends Location> locations); static Maybe<T> findUniqueMachineLocation(Iterable<? extends Location> locations, Class<T> clazz); static Maybe<String> findSubnetHostname(Iterable<? extends Location> ll); static Maybe<String> findSubnetHostname(Entity entity); static Maybe<String> findSubnetOrPublicHostname(Entity entity); static Maybe<String> findSubnetOrPrivateIp(Entity entity); static Maybe<String> findSubnetIp(Entity entity); static Maybe<String> findSubnetIp(Iterable<? extends Location> ll); static boolean warnIfLocalhost(Collection<? extends Location> locations, String message);  }
@Test public void testFindSubnetHostnameFromAttribute() throws Exception { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class) .location(sshMachineSpec)); entity.sensors().set(Attributes.SUBNET_HOSTNAME, "myval"); assertEquals(Machines.findSubnetHostname(entity).get(), "myval"); }
@Test public void testFindSubnetHostnameFromLocation() throws Exception { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class) .location(sshMachineSpec)); assertEquals(Machines.findSubnetHostname(entity).get(), privateAddr); }
@Test public void testFindSubnetHostnameFromLocationWithoutPrivate() throws Exception { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class) .location(sshMachineWithoutPrivateSpec)); assertEquals(Machines.findSubnetHostname(entity).get(), publicAddr); }