Search in sources :

Example 1 with ResolverConfig

use of org.xbill.DNS.ResolverConfig in project helios by spotify.

the class HostResolver method create.

static HostResolver create(HeliosClient client) throws InterruptedException, ExecutionException {
    final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig();
    final Name[] path;
    if (currentConfig != null) {
        final Name[] possiblePath = currentConfig.searchPath();
        if (possiblePath != null) {
            path = possiblePath;
        } else {
            path = EMPTY_PATH;
        }
    } else {
        path = EMPTY_PATH;
    }
    return new HostResolver(Sets.newHashSet(client.listHosts().get()), path);
}
Also used : ResolverConfig(org.xbill.DNS.ResolverConfig) Name(org.xbill.DNS.Name)

Example 2 with ResolverConfig

use of org.xbill.DNS.ResolverConfig in project helios by spotify.

the class Output method shortHostname.

public static String shortHostname(final String host) {
    final Name root = Name.fromConstantString(".");
    final Name hostname;
    try {
        hostname = Name.fromString(host, root);
    } catch (TextParseException e) {
        throw new IllegalArgumentException("Invalid hostname '" + host + "'");
    }
    final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig();
    if (currentConfig != null) {
        final Name[] searchPath = currentConfig.searchPath();
        if (searchPath != null) {
            for (final Name domain : searchPath) {
                if (hostname.subdomain(domain)) {
                    return hostname.relativize(domain).toString();
                }
            }
        }
    }
    return hostname.toString();
}
Also used : ResolverConfig(org.xbill.DNS.ResolverConfig) Name(org.xbill.DNS.Name) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

Name (org.xbill.DNS.Name)2 ResolverConfig (org.xbill.DNS.ResolverConfig)2 TextParseException (org.xbill.DNS.TextParseException)1