cleanup

 - refactor getNumberOfIODevices
 - remove unused inner class AsterixCluster
 - replace NPE with an IllegalStateException with a message
 - cleaner log message

Change-Id: Iecad33440bb154b7e438f49755a1d8a2b0c8d677
Reviewed-on: http://fulliautomatix.ics.uci.edu:8443/117
Reviewed-by: Ian Maxon <imaxon@uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
index 8ccf50b..1f0c91d 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
@@ -58,7 +58,7 @@
         ncApplicationContext = ncAppCtx;
         nodeId = ncApplicationContext.getNodeId();
         if (LOGGER.isLoggable(Level.INFO)) {
-            LOGGER.info("Starting Asterix node controller  TAKE NOTE: " + nodeId);
+            LOGGER.info("Starting Asterix node controller: " + nodeId);
         }
 
         runtimeContext = new AsterixAppRuntimeContext(ncApplicationContext);
@@ -118,7 +118,6 @@
 
     @Override
     public void notifyStartupComplete() throws Exception {
-        IAsterixStateProxy proxy = (IAsterixStateProxy) ncApplicationContext.getDistributedState();
         AsterixMetadataProperties metadataProperties = ((IAsterixPropertiesProvider) runtimeContext)
                 .getMetadataProperties();
 
@@ -135,6 +134,7 @@
             localResourceRepository.initialize(nodeId, metadataProperties.getStores().get(nodeId)[0], true, null);
         }
 
+        IAsterixStateProxy proxy = null;
         isMetadataNode = nodeId.equals(metadataProperties.getMetadataNodeName());
         if (isMetadataNode) {
             if (LOGGER.isLoggable(Level.INFO)) {
@@ -142,6 +142,11 @@
             }
             MetadataNode.INSTANCE.initialize(runtimeContext);
 
+            proxy = (IAsterixStateProxy) ncApplicationContext.getDistributedState();
+            if (proxy == null) {
+                throw new IllegalStateException("Metadata node cannot access distributed state");
+            }
+
             // This is a special case, we just give the metadataNode directly.
             // This way we can delay the registration of the metadataNode until
             // it is completely initialized.
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/AsterixClusterProperties.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/AsterixClusterProperties.java
index 9362844..8e393d7 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/AsterixClusterProperties.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/AsterixClusterProperties.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,10 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashSet;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -97,34 +97,27 @@
 
     /**
      * Returns the number of IO devices configured for a Node Controller
-     * 
+     *
      * @param nodeId
      *            unique identifier of the Node Controller
      * @return number of IO devices. -1 if the node id is not valid. A node id
      *         is not valid if it does not correspond to the set of registered
      *         Node Controllers.
      */
-    public synchronized int getNumberOfIODevices(String nodeId) {
-        Map<String, String> ncConfig = ncConfiguration.get(nodeId);
-        if (ncConfig == null) {
-            if (LOGGER.isLoggable(Level.WARNING)) {
-                LOGGER.warning("Configuration parameters for nodeId " + nodeId
-                        + " not found. The node has not joined yet or has left.");
-            }
-            return -1;
-        }
-        return ncConfig.get(IO_DEVICES).split(",").length;
+    public int getNumberOfIODevices(String nodeId) {
+        String[] ioDevs = getIODevices(nodeId);
+        return ioDevs == null ? -1 : ioDevs.length;
     }
 
     /**
      * Returns the IO devices configured for a Node Controller
-     * 
+     *
      * @param nodeId
      *            unique identifier of the Node Controller
      * @return a list of IO devices. null if node id is not valid. A node id is not valid
      *         if it does not correspond to the set of registered Node Controllers.
      */
-    public String[] getIODevices(String nodeId) {
+    public synchronized String[] getIODevices(String nodeId) {
         Map<String, String> ncConfig = ncConfiguration.get(nodeId);
         if (ncConfig == null) {
             if (LOGGER.isLoggable(Level.WARNING)) {
@@ -181,67 +174,6 @@
         clusterPartitionConstraint = new AlgebricksAbsolutePartitionConstraint(cluster);
     }
 
-    private static class AsterixCluster {
-
-        private final String asterixInstance;
-        private Map<String, AsterixNode> asterixNodes;
-
-        public AsterixCluster(Cluster cluster) {
-            asterixInstance = cluster.getInstanceName();
-            asterixNodes = new HashMap<String, AsterixNode>();
-            for (Node node : cluster.getNode()) {
-                AsterixNode aNode = new AsterixNode(node, AsterixNode.NodeRole.PARTICIPANT,
-                        AsterixNode.NodeState.INACTIVE);
-                asterixNodes.put(asterixInstance + "_" + node.getId(), aNode);
-            }
-
-            for (Node node : cluster.getSubstituteNodes().getNode()) {
-                AsterixNode aNode = new AsterixNode(node, AsterixNode.NodeRole.SUBSTITUTE,
-                        AsterixNode.NodeState.INACTIVE);
-                asterixNodes.put(asterixInstance + "_" + node.getId(), aNode);
-            }
-        }
-
-        private static class AsterixNode {
-
-            private final Node node;
-            private NodeRole role;
-            private NodeState state;
-
-            public enum NodeRole {
-                PARTICIPANT,
-                SUBSTITUTE
-            }
-
-            public enum NodeState {
-                ACTIVE,
-                INACTIVE
-            }
-
-            public AsterixNode(Node node, NodeRole role, NodeState state) {
-                this.node = node;
-                this.role = role;
-                this.state = state;
-            }
-
-            @Override
-            public String toString() {
-                return node.getId() + "_" + role + "_" + state;
-            }
-        }
-
-        public void notifyChangeState(String nodeId, AsterixNode.NodeRole newRole, AsterixNode.NodeState newState) {
-            AsterixNode node = asterixNodes.get(nodeId);
-            if (node != null) {
-                node.role = newRole;
-                node.state = newState;
-            } else {
-                throw new IllegalStateException("Unknown nodeId" + nodeId);
-            }
-
-        }
-    }
-
     public boolean isGlobalRecoveryCompleted() {
         return globalRecoveryCompleted;
     }