@Override public String toString() { return getPropertyName()+(isAvailable()?"="+getValue():"(unset)"); } }
public BasicDelegatingSystemProperty(String name) { delegate = new StringSystemProperty(name); } public String getPropertyName() {
@Override public String toString() { return delegate.toString(); } }
public String getPropertyName() { return delegate.getPropertyName(); } public boolean isAvailable() {
public double getValue() { return Double.parseDouble(delegate.getValue()); } }
public boolean isAvailable() { return delegate.isAvailable(); } @Override
public boolean isAvailable() { String property = System.getProperty(getPropertyName()); return property!=null; } public boolean isNonEmpty() {
public int getValue() { return Integer.parseInt(delegate.getValue()); } }
public String getValue() { return System.getProperty(getPropertyName()); } @Override
private static HostGeoLookup findHostGeoLookupImpl() throws InstantiationException, IllegalAccessException, ClassNotFoundException { String type = BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getValue(); if (type==null) { type = BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL_LEGACY.getValue(); if (type!=null && !warnedLegacy) { warnedLegacy = true; log.warn("Using deprecated host-geo-lookup property "+BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL_LEGACY+"; " + "set "+BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL+" instead"); } } /* utrace seems more accurate than geobytes, and it gives a report of how many tokens are left; * but maxmind if it's installed locally is even better (does not require remote lookup), * so use it if available */ if (type==null) { if (MaxMind2HostGeoLookup.getDatabaseReader()!=null) return new MaxMind2HostGeoLookup(); log.debug("Using Utrace remote for geo lookup because MaxMind2 is not available"); return new UtraceHostGeoLookup(); } if (type.isEmpty()) return null; return (HostGeoLookup) new ClassLoaderUtils(HostGeoInfo.class).loadClass(type).newInstance(); }
public boolean isNonEmpty() { String property = System.getProperty(getPropertyName()); return property!=null && !property.equals(""); } public String getValue() {
/** returns an IP address for localhost, * paying attention to system property * {@link BrooklynServiceAttributes#LOCALHOST_IP_ADDRESS} * if set to prevent default selection when needed, * otherwise finding the first bindable/reachable NIC from a system lookup which usually * prefers IPv4 then non-loopback devices (but use the system property if if needed) */ public static InetAddress getLocalhostInetAddress() { return TypeCoercions.coerce(JavaGroovyEquivalents.elvis(BrooklynServiceAttributes.LOCALHOST_IP_ADDRESS.getValue(), Networking.getLocalHost(true, false, true, true, 500)), InetAddress.class); } }
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; }
super.setUp(); origGeoLookupImpl = BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getValue(); HostGeoInfo.clearCachedLookup();
@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()); } }); }