Search in sources :

Example 21 with TextParseException

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;
}
Also used : ARecord(org.xbill.DNS.ARecord) Lookup(org.xbill.DNS.Lookup) SRVRecord(org.xbill.DNS.SRVRecord) ARecord(org.xbill.DNS.ARecord) Record(org.xbill.DNS.Record) HashSet(java.util.HashSet) TextParseException(org.xbill.DNS.TextParseException)

Example 22 with TextParseException

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()]);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Lookup(org.xbill.DNS.Lookup) TextParseException(org.xbill.DNS.TextParseException)

Example 23 with TextParseException

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;
}
Also used : DnsName(org.minidns.dnsname.DnsName) RemoteConnectionEndpointLookupFailure(org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure) ArrayList(java.util.ArrayList) SRV(org.minidns.record.SRV) Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

TextParseException (org.xbill.DNS.TextParseException)23 Lookup (org.xbill.DNS.Lookup)14 Record (org.xbill.DNS.Record)12 ArrayList (java.util.ArrayList)11 ARecord (org.xbill.DNS.ARecord)11 SRVRecord (org.xbill.DNS.SRVRecord)9 UnknownHostException (java.net.UnknownHostException)7 Name (org.xbill.DNS.Name)5 InetAddress (java.net.InetAddress)4 IOException (java.io.IOException)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)3 AAAARecord (org.xbill.DNS.AAAARecord)3 MXRecord (org.xbill.DNS.MXRecord)3 NSRecord (org.xbill.DNS.NSRecord)3 SOARecord (org.xbill.DNS.SOARecord)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 X509Certificate (java.security.cert.X509Certificate)2