@Override public ComputationSpec load(String url) throws Exception { //First resolve to a real host-port combo if it's Mesos DNS String specEndpoint = url; String specHost = specEndpoint.split("//")[1].split("/")[0]; if (specHost.endsWith(".")) { // Need to do a srv record resolution List<LookupResult> results = dnsResolver.dnsSrvLookup(specHost); if (!results.isEmpty()) { specHost = InetAddress.getByName(results.get(0).host()).getHostAddress() + ":" + results.get(0).port(); LOGGER.info("Setting spec host to: " + specHost); } else { throw new RuntimeException(String.format("Dns Srv Resolution for spec host failed: %s", specHost)); } specEndpoint = specEndpoint.split("//")[0] + "//" + specHost + "/" + specEndpoint.split("//")[1] .replaceFirst(".*\\./", ""); } HttpGet getRequest = new HttpGet(specEndpoint); HttpResponse response = httpClient.execute(getRequest); if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) { throw new Exception("Received: " + response.getStatusLine().getStatusCode() + " from spec url: " + url); } return mapper.readValue(EntityUtils.toByteArray(response.getEntity()), ComputationSpec.class); } }
public void updateDNS() { synchronized (sync) { if (shutdown) { return; } long ttl = TimeUnit.SECONDS.convert(period, periodUnit); try { List<LookupResult> lookupResults = srvResolver.resolve(srvRecord); List<HostAndPort> hosts = Lists.newArrayListWithCapacity(lookupResults.size()); for (LookupResult lookupResult : lookupResults) { hosts.add(HostAndPort.fromParts(lookupResult.host(), lookupResult.port())); ttl = Math.min(ttl, lookupResult.ttl()); } List<HostAndPort> newAddresses = Ordering.from(HostAndPortComparator.INSTANCE).sortedCopy(hosts); if (!newAddresses.equals(addresses)) { addresses = newAddresses; log.info("Connecting to " + newAddresses); List<AddressAndClient> addressAndClients = getAddressesAndClients(newAddresses); setPendingClient(addressAndClients); } } finally { long delay = clamp(MIN_DNS_WAIT_TIME, MAX_DNS_WAIT_TIME, ttl); refreshJob = this.executor.schedule(this::updateDNS, delay, TimeUnit.SECONDS); } } }
LookupResult result = results.get(0); builder.setHost(result.host()); builder.setPort(result.port());
LookupResult result = results.get(0); builder.setHost(result.host()); builder.setPort(result.port());