public List < String > getCandidateIps ( ) throws MalformedURLException { InstanceInfo myInfo = applicationInfoManager . getInfo ( ) ; String myZone = ( ( AmazonInfo ) myInfo . getDataCenterInfo ( ) ) . get ( AmazonInfo . MetaDataKey . availabilityZone ) ; Collection < String > candidates = clientConfig . shouldUseDnsForFetchingServiceUrls ( ) ? getIPsForZoneFromDNS ( myZone ) : getIPsForZoneFromConfig ( myZone ) ; if ( candidates == null || candidates . size ( ) == 0 ) { throw new RuntimeException ( "Could not get any ips from the pool for zone :" + myZone ) ; } List < String > ips = Lists . newArrayList ( ) ; for ( String candidate : candidates ) { String host = new URL ( candidate ) . getHost ( ) ; if ( InetAddresses . isInetAddress ( host ) ) { ips . add ( host ) ; } else { // ip-172-31-55-172.ec2.internal -> ip-172-31-55-172 String firstPartOfHost = Splitter . on ( "." ) . splitToList ( host ) . get ( 0 ) ; // ip-172-31-55-172 -> [172,31,55,172] List < String > noIpPrefix = Splitter . on ( "-" ) . splitToList ( firstPartOfHost ) . subList ( 1 , 5 ) ; // [172,31,55,172] -> 172.31.55.172 String ip = Joiner . on ( "." ) . join ( noIpPrefix ) ; if ( InetAddresses . isInetAddress ( ip ) ) { ips . add ( ip ) ; } else { throw new IllegalArgumentException ( "Illegal internal hostname " + host + " translated to '" + ip + "'" ) ; } } } return ips ; }
Based on shouldUseDnsForFetchingServiceUrls configuration either retrieves candidates from dns records or from configuration properties .