public String getPropertyName() { return delegate.getPropertyName(); } public boolean isAvailable() {
public boolean isAvailable() { String property = System.getProperty(getPropertyName()); return property!=null; } public boolean isNonEmpty() {
public String getValue() { return System.getProperty(getPropertyName()); } @Override
public boolean isNonEmpty() { String property = System.getProperty(getPropertyName()); return property!=null && !property.equals(""); } public String getValue() {
public static synchronized DatabaseReader getDatabaseReader() { if (databaseReader!=null) return databaseReader; try { File f = new File(MAXMIND_DB_PATH); databaseReader = new DatabaseReader.Builder(f).build(); } catch (IOException e) { lookupFailed = true; log.debug("MaxMind geo lookup unavailable; either download and unpack the latest "+ "binary from "+MAXMIND_DB_URL+" into "+MAXMIND_DB_PATH+", "+ "or specify a different HostGeoLookup implementation with the key "+ BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName()+" (error trying to read: "+e+")"); } return databaseReader; }
@Override public String toString() { return getPropertyName()+(isAvailable()?"="+getValue():"(unset)"); } }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { super.tearDown(); if (origGeoLookupImpl != null) { System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), origGeoLookupImpl); } else { System.clearProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName()); } HostGeoInfo.clearCachedLookup(); }
@Test(groups={"Integration"}) public void testIncludesAddressWithoutGeography() { System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), StubHostGeoLookup.class.getName()); geoDns.config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true); app.start(ImmutableList.of(locWithoutGeo)); target.sensors().set(Attributes.HOSTNAME, StubHostGeoLookup.HOMELESS_IP); LOG.info("geo-scaling test, using {}.{}; expect to be wired to {}", new Object[] {subDomain, primaryDomain, addrWithoutGeo}); assertTargetHostsEventually(geoDns, 1); }
@Test(groups={"Integration"}) public void testIgnoresAddressWithoutGeography() throws Exception { System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), StubHostGeoLookup.class.getName()); geoDns.config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, false); // false is default app.start(ImmutableList.of(locWithoutGeo)); target.sensors().set(Attributes.HOSTNAME, StubHostGeoLookup.HOMELESS_IP); LOG.info("geo-scaling test, using {}.{}; expect not to be wired to {}", new Object[] {subDomain, primaryDomain, addrWithoutGeo}); Asserts.succeedsContinually(MutableMap.of("timeout", 10*1000), new Runnable() { @Override public void run() { assertEquals(geoDns.getTargetHosts().size(), 0, "targets="+geoDns.getTargetHosts()); } }); }