Change name resolution order to Node name -> DNS

Change-Id: I2bbfc8d9d8469c444f6c70bd3a77654892aeb42f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1491
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 22c080a..5ae313d 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -108,7 +108,6 @@
     public static final int UNKNOWN_RECORD_FORMAT_FOR_META_PARSER = 3027;
     public static final int LIBRARY_JAVA_JOBJECTS_FIELD_ALREADY_DEFINED = 3028;
     public static final int LIBRARY_JAVA_JOBJECTS_UNKNOWN_FIELD = 3029;
-    public static final int NODE_RESOLVER_COULDNT_RESOLVE_ADDRESS = 3030;
     public static final int NODE_RESOLVER_NO_NODE_CONTROLLERS = 3031;
     public static final int NODE_RESOLVER_UNABLE_RESOLVE_HOST = 3032;
     public static final int INPUT_RECORD_CONVERTER_DCP_MSG_TO_RECORD_CONVERTER_UNKNOWN_DCP_REQUEST = 3033;
diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index f1e9836..440e2d3 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -93,7 +93,6 @@
 3027 = Unknown record format for a record with meta parser. Did you specify the parameter %1$s
 3028 = Field already defined in %1$s part
 3029 = Unknown field: %1$s
-3030 = Address passed: '%1$s' couldn't be resolved to an ip address and is not an NC id. Existing NCs are %2$s
 3031 = No node controllers found at the address: %1$s
 3032 = Unable to resolve hostname '%1$s' to an IP address
 3033 = Unknown DCP request: %1$s
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
index 9970f27..84346c4 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
@@ -38,46 +38,34 @@
 public class NodeResolver implements INodeResolver {
     //TODO: change this call and replace by calling AsterixClusterProperties
     private static final Random random = new Random();
-    private static final Map<InetAddress, Set<String>> ncMap = new HashMap<InetAddress, Set<String>>();
-    private static final Set<String> ncs = new HashSet<String>();
+    private static final Map<InetAddress, Set<String>> ncMap = new HashMap<>();
+    private static final Set<String> ncs = new HashSet<>();
 
     @Override
     public String resolveNode(String value) throws AsterixException {
-        UnknownHostException uhe = null;
         try {
             if (ncMap.isEmpty()) {
                 NodeResolver.updateNCs();
             }
+            if (ncs.contains(value)) {
+                return value;
+            } else {
+                NodeResolver.updateNCs();
+                if (ncs.contains(value)) {
+                    return value;
+                }
+            }
             InetAddress ipAddress = null;
             try {
                 ipAddress = InetAddress.getByName(value);
             } catch (UnknownHostException e) {
-                uhe = e;
-            }
-            if (ipAddress == null) {
-                if (ncs.contains(value)) {
-                    return value;
-                } else {
-                    NodeResolver.updateNCs();
-                    if (ncs.contains(value)) {
-                        return value;
-                    } else {
-                        throw new AsterixException(ErrorCode.NODE_RESOLVER_COULDNT_RESOLVE_ADDRESS, uhe, value,
-                                ncs.toString());
-                    }
-                }
-
+                throw new AsterixException(ErrorCode.NODE_RESOLVER_UNABLE_RESOLVE_HOST, e, value);
             }
             Set<String> nodeControllers = ncMap.get(ipAddress);
             if (nodeControllers == null || nodeControllers.isEmpty()) {
                 throw new AsterixException(ErrorCode.NODE_RESOLVER_NO_NODE_CONTROLLERS, value);
             }
-            String chosenNCId = nodeControllers.toArray(new String[] {})[random.nextInt(nodeControllers.size())];
-            return chosenNCId;
-        } catch (UnknownHostException e) {
-            throw new AsterixException(ErrorCode.NODE_RESOLVER_UNABLE_RESOLVE_HOST, value);
-        } catch (AsterixException ae) {
-            throw ae;
+            return nodeControllers.toArray(new String[] {})[random.nextInt(nodeControllers.size())];
         } catch (Exception e) {
             throw new AsterixException(e);
         }