private static Set<String> resolve(String rootClusterDNS) throws NamingException { Set<String> result; try { result = DnsResolver.getCNamesFromTxtRecord(rootClusterDNS); if (!rootClusterDNS.startsWith("txt.")) { result = DnsResolver.getCNamesFromTxtRecord("txt." + rootClusterDNS); } } catch (NamingException e) { if (!rootClusterDNS.startsWith("txt.")) { result = DnsResolver.getCNamesFromTxtRecord("txt." + rootClusterDNS); } else { throw e; } } return result; } }
/** * Look into A-record at a specific DNS address. * * @return resolved IP addresses or null if no A-record was present */ @Nullable public static List<String> resolveARecord(String rootDomainName) { if (isLocalOrIp(rootDomainName)) { return null; } try { Attributes attrs = getDirContext().getAttributes(rootDomainName, new String[]{A_RECORD_TYPE, CNAME_RECORD_TYPE}); Attribute aRecord = attrs.get(A_RECORD_TYPE); Attribute cRecord = attrs.get(CNAME_RECORD_TYPE); if (aRecord != null && cRecord == null) { List<String> result = new ArrayList<>(); NamingEnumeration<String> entries = (NamingEnumeration<String>) aRecord.getAll(); while (entries.hasMore()) { result.add(entries.next()); } return result; } } catch (Exception e) { logger.warn("Cannot load A-record for eureka server address {}", rootDomainName, e); return null; } return null; }
@Override public String resolveIp(String hostName) { return DnsResolver.resolve(hostName); }
@Nullable @Override public List<String> resolveARecord(String rootDomainName) { return DnsResolver.resolveARecord(rootDomainName); } }
/** * Looks up the DNS name provided in the JNDI context. */ public static Set<String> getCNamesFromTxtRecord(String discoveryDnsName) throws NamingException { Attributes attrs = getDirContext().getAttributes(discoveryDnsName, new String[]{TXT_RECORD_TYPE}); Attribute attr = attrs.get(TXT_RECORD_TYPE); String txtRecord = null; if (attr != null) { txtRecord = attr.get().toString(); /** * compatible splited txt record of "host1 host2 host3" but not "host1" "host2" "host3". * some dns service provider support txt value only format "host1 host2 host3" */ if (txtRecord.startsWith("\"") && txtRecord.endsWith("\"")) { txtRecord = txtRecord.substring(1, txtRecord.length() - 1); } } Set<String> cnamesSet = new TreeSet<String>(); if (txtRecord == null || txtRecord.trim().isEmpty()) { return cnamesSet; } String[] cnames = txtRecord.split(" "); Collections.addAll(cnamesSet, cnames); return cnamesSet; } }
@Nullable @Override public List<String> resolveARecord(String rootDomainName) { return DnsResolver.resolveARecord(rootDomainName); } }
/** * Looks up the DNS name provided in the JNDI context. */ public static Set<String> getCNamesFromTxtRecord(String discoveryDnsName) throws NamingException { Attributes attrs = getDirContext().getAttributes(discoveryDnsName, new String[]{TXT_RECORD_TYPE}); Attribute attr = attrs.get(TXT_RECORD_TYPE); String txtRecord = null; if (attr != null) { txtRecord = attr.get().toString(); /** * compatible splited txt record of "host1 host2 host3" but not "host1" "host2" "host3". * some dns service provider support txt value only format "host1 host2 host3" */ if (txtRecord.startsWith("\"") && txtRecord.endsWith("\"")) { txtRecord = txtRecord.substring(1, txtRecord.length() - 1); } } Set<String> cnamesSet = new TreeSet<String>(); if (txtRecord == null || txtRecord.trim().isEmpty()) { return cnamesSet; } String[] cnames = txtRecord.split(" "); Collections.addAll(cnamesSet, cnames); return cnamesSet; } }
if (isLocalOrIp(currentHost)) { return originalHost; String targetHost = null; do { Attributes attrs = getDirContext().getAttributes(currentHost, new String[]{A_RECORD_TYPE, CNAME_RECORD_TYPE}); Attribute attr = attrs.get(A_RECORD_TYPE); if (attr != null) {
dnsName = "txt." + dnsName; logger.debug("The zone url to be looked up is {} :", dnsName); Set<String> ec2UrlsForZone = DnsResolver.getCNamesFromTxtRecord(dnsName); for (String ec2Url : ec2UrlsForZone) { logger.debug("The eureka url for the dns name {} is {}", dnsName, ec2Url);
@Override public String resolveIp(String hostName) { return DnsResolver.resolve(hostName); }
if (isLocalOrIp(currentHost)) { return originalHost; String targetHost = null; do { Attributes attrs = getDirContext().getAttributes(currentHost, new String[]{A_RECORD_TYPE, CNAME_RECORD_TYPE}); Attribute attr = attrs.get(A_RECORD_TYPE); if (attr != null) {
Set<String> zoneCnamesForRegion = new TreeSet<String>(DnsResolver.getCNamesFromTxtRecord(discoveryDnsName)); Map<String, List<String>> zoneCnameMapForRegion = new TreeMap<String, List<String>>(); for (String zoneCname : zoneCnamesForRegion) {
/** * Look into A-record at a specific DNS address. * * @return resolved IP addresses or null if no A-record was present */ @Nullable public static List<String> resolveARecord(String rootDomainName) { if (isLocalOrIp(rootDomainName)) { return null; } try { Attributes attrs = getDirContext().getAttributes(rootDomainName, new String[]{A_RECORD_TYPE, CNAME_RECORD_TYPE}); Attribute aRecord = attrs.get(A_RECORD_TYPE); Attribute cRecord = attrs.get(CNAME_RECORD_TYPE); if (aRecord != null && cRecord == null) { List<String> result = new ArrayList<>(); NamingEnumeration<String> entries = (NamingEnumeration<String>) aRecord.getAll(); while (entries.hasMore()) { result.add(entries.next()); } return result; } } catch (Exception e) { logger.warn("Cannot load A-record for eureka server address {}", rootDomainName, e); return null; } return null; }
private static Set<String> resolve(String rootClusterDNS) throws NamingException { Set<String> result; try { result = DnsResolver.getCNamesFromTxtRecord(rootClusterDNS); if (!rootClusterDNS.startsWith("txt.")) { result = DnsResolver.getCNamesFromTxtRecord("txt." + rootClusterDNS); } } catch (NamingException e) { if (!rootClusterDNS.startsWith("txt.")) { result = DnsResolver.getCNamesFromTxtRecord("txt." + rootClusterDNS); } else { throw e; } } return result; } }
dnsName = "txt." + dnsName; logger.debug("The zone url to be looked up is {} :", dnsName); Set<String> ec2UrlsForZone = DnsResolver.getCNamesFromTxtRecord(dnsName); for (String ec2Url : ec2UrlsForZone) { logger.debug("The eureka url for the dns name {} is {}", dnsName, ec2Url);
Set<String> zoneCnamesForRegion = new TreeSet<String>(DnsResolver.getCNamesFromTxtRecord(discoveryDnsName)); Map<String, List<String>> zoneCnameMapForRegion = new TreeMap<String, List<String>>(); for (String zoneCname : zoneCnamesForRegion) {