/** * 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; } }
/** * 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; }
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) {
/** * 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; } }
/** * 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; }
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) {