private LookupResult toLookupResult(final HealthInfoInstance instance) { return LookupResult.create(instance.Node.Address, (int)instance.Service.Port, NODE_PRIORITY, NODE_WEIGHT, LOOKUP_TTL_SEC); }
public static LookupResult create(String host, int port, int priority, int weight, long ttl) { return new LookupResult(host, port, priority, weight, ttl); }
@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); } } }
if (results != null && !results.isEmpty()) { LookupResult result = results.get(0); builder.setHost(result.host()); builder.setPort(result.port()); if (result.host().endsWith(".consul.")) { Record[] newResults = new Lookup(result.host(), Type.A, DClass.IN).run(); if (newResults != null && newResults.length > 0) { builder.setHost(newResults[0].rdataToString()); } else { throw new IllegalArgumentException("Unable to resolve auth service host " + authServiceHost + " -> " + result.host() + " -> ???");
if (results != null && !results.isEmpty()) { LookupResult result = results.get(0); builder.setHost(result.host()); builder.setPort(result.port()); if (result.host().endsWith(".consul.")) { Record[] newResults = new Lookup(result.host(), Type.A, DClass.IN).run(); if (newResults != null && newResults.length > 0) { builder.setHost(newResults[0].rdataToString()); } else { throw new IllegalArgumentException("Unable to resolve audit service host " + auditServiceHost + " -> " + result.host() + " -> ???");
private static List<LookupResult> toLookupResults(Record[] queryResult) { ImmutableList.Builder<LookupResult> builder = ImmutableList.builder(); if (queryResult != null) { for (Record record: queryResult) { if (record instanceof SRVRecord) { SRVRecord srvRecord = (SRVRecord) record; builder.add(LookupResult.create(srvRecord.getTarget().toString(), srvRecord.getPort(), srvRecord.getPriority(), srvRecord.getWeight(), srvRecord.getTTL())); } } } return builder.build(); } }
public static LookupResult create(String host, int port, int priority, int weight, long ttl) { return new LookupResult(host, port, priority, weight, ttl); }
private static List<LookupResult> toLookupResults(Record[] queryResult) { ImmutableList.Builder<LookupResult> builder = ImmutableList.builder(); if (queryResult != null) { for (Record record: queryResult) { if (record instanceof SRVRecord) { SRVRecord srvRecord = (SRVRecord) record; builder.add(LookupResult.create(srvRecord.getTarget().toString(), srvRecord.getPort(), srvRecord.getPriority(), srvRecord.getWeight(), srvRecord.getTTL())); } } } return builder.build(); } }