use of org.xbill.DNS.TextParseException in project fabric8 by fabric8io.
the class KubernetesHelper method lookupServiceInDns.
/**
* Looks up the service in DNS.
* If this is a headless service, this call returns the endpoint IPs from DNS.
* If this is a non-headless service, this call returns the service IP only.
* <p/>
* See https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services.md#headless-services
*/
public static Set<String> lookupServiceInDns(String serviceName) throws IllegalArgumentException, UnknownHostException {
try {
Lookup l = new Lookup(serviceName);
Record[] records = l.run();
if (l.getResult() == Lookup.SUCCESSFUL) {
Set<String> endpointAddresses = new HashSet<>(records.length);
for (int i = 0; i < records.length; i++) {
ARecord aRecord = (ARecord) records[i];
endpointAddresses.add(aRecord.getAddress().getHostAddress());
}
return endpointAddresses;
} else {
LOG.warn("Lookup {} result: {}", serviceName, l.getErrorString());
}
} catch (TextParseException e) {
LOG.error("Unparseable service name: {}", serviceName, e);
} catch (ClassCastException e) {
LOG.error("Invalid response from DNS server - should have been A records", e);
}
return Collections.EMPTY_SET;
}
use of org.xbill.DNS.TextParseException in project ecf by eclipse.
the class BnRDnsSdServiceTypeID method getInternalQueries.
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.dnssd.DnsSdServiceTypeID#getInternalQueries()
*/
Lookup[] getInternalQueries() {
List result = new ArrayList();
for (int i = 0; i < scopes.length; i++) {
String scope = scopes[i];
// remove dangling "."
if (scope.endsWith(".")) {
// $NON-NLS-1$
scope = scope.substring(0, scope.length() - 1);
}
Lookup query;
try {
query = new // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Lookup(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
services[0] + "._udp" + "." + scope + ".", Type.PTR);
} catch (TextParseException e) {
continue;
}
result.add(query);
}
return (Lookup[]) result.toArray(new Lookup[result.size()]);
}
use of org.xbill.DNS.TextParseException in project Smack by igniterealtime.
the class DNSJavaResolver method lookupSrvRecords0.
@Override
protected List<SRV> lookupSrvRecords0(DnsName name, List<RemoteConnectionEndpointLookupFailure> lookupFailures, DnssecMode dnssecMode) {
Lookup lookup;
try {
lookup = new Lookup(name.ace, Type.SRV);
} catch (TextParseException e) {
RemoteConnectionEndpointLookupFailure failure = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, e);
lookupFailures.add(failure);
return null;
}
Record[] recs = lookup.run();
if (recs == null) {
// TODO: When does this happen? Do we want/need to record a lookup failure?
return null;
}
List<SRV> res = new ArrayList<>();
for (Record record : recs) {
org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
if (srvRecord != null && srvRecord.getTarget() != null) {
DnsName host = DnsName.from(srvRecord.getTarget().toString());
int port = srvRecord.getPort();
int priority = srvRecord.getPriority();
int weight = srvRecord.getWeight();
SRV r = new SRV(priority, weight, port, host);
res.add(r);
}
}
return res;
}
Aggregations