Hazelcast Debug CLI.

Prep. work for ONOS-1767
Wrapping HZ bundled TestApp CLI, to use ONOS hazelcast.xml

Could be used for simple performance measurements.
Example: measure Throughput from 5000 increments)

  hazelcast[default] > #5000 a.inc
  ...
  ops/s = 1238

Change-Id: Ia728b339bf569cd521061d1f119143ea287207be
diff --git a/src/main/java/net/onrc/onos/core/datagrid/HazelcastCLI.java b/src/main/java/net/onrc/onos/core/datagrid/HazelcastCLI.java
new file mode 100644
index 0000000..1ed4d75
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/datagrid/HazelcastCLI.java
@@ -0,0 +1,45 @@
+package net.onrc.onos.core.datagrid;
+
+import com.hazelcast.config.Config;
+import com.hazelcast.config.ExecutorConfig;
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.examples.TestApp;
+
+/**
+ * Hazelcast CLI.
+ */
+public class HazelcastCLI extends TestApp {
+
+    private static final int LOAD_EXECUTORS_COUNT = 16;
+
+    /**
+     * hazelcast CLI.
+     *
+     * @param hazelcast Hazelcast instance.
+     */
+    public HazelcastCLI(HazelcastInstance hazelcast) {
+        super(hazelcast);
+    }
+
+    /**
+     * {@link TestApp} modified to read conf/hazelcast.xml.
+     *
+     * @param args none expected
+     * @throws Exception exception
+     */
+    public static void main(String[] args) throws Exception {
+        final String configFilename = System.getProperty(
+                "net.onrc.onos.core.datagrid.HazelcastDatagrid.datagridConfig",
+                "conf/hazelcast.xml");
+        Config config = HazelcastDatagrid.loadHazelcastConfig(configFilename);
+
+        for (int k = 1; k <= LOAD_EXECUTORS_COUNT; k++) {
+            config.addExecutorConfig(new ExecutorConfig("e" + k).setPoolSize(k));
+        }
+
+        HazelcastCLI cli = new HazelcastCLI(Hazelcast.newHazelcastInstance(config));
+        cli.start(args);
+    }
+
+}
diff --git a/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java b/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java
index 855d6a4..ec870e4 100644
--- a/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java
+++ b/src/main/java/net/onrc/onos/core/datagrid/HazelcastDatagrid.java
@@ -13,6 +13,7 @@
 import net.floodlightcontroller.core.module.IFloodlightService;
 import net.floodlightcontroller.restserver.IRestApiService;
 import net.onrc.onos.core.datagrid.web.DatagridWebRoutable;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,8 +53,11 @@
      * Load the Hazelcast Datagrid configuration file.
      *
      * @param configFilename the configuration filename.
+     * @return Hazelcast configuration
      */
-    public void loadHazelcastConfig(String configFilename) {
+    public static Config loadHazelcastConfig(String configFilename) {
+
+        Config hzConfig = null;
         /*
         System.setProperty("hazelcast.socket.receive.buffer.size", "32");
         System.setProperty("hazelcast.socket.send.buffer.size", "32");
@@ -62,29 +66,32 @@
 
         // Init from configuration file
         try {
-            hazelcastConfig = new FileSystemXmlConfig(configFilename);
+            hzConfig = new FileSystemXmlConfig(configFilename);
         } catch (FileNotFoundException e) {
             log.error("Error opening Hazelcast XML configuration. File not found: " + configFilename, e);
 
             // Fallback mechanism to support running unit test without setup.
             log.error("Falling back to default Hazelcast XML {}", HAZELCAST_DEFAULT_XML);
             try {
-                hazelcastConfig = new FileSystemXmlConfig(HAZELCAST_DEFAULT_XML);
+                hzConfig = new FileSystemXmlConfig(HAZELCAST_DEFAULT_XML);
             } catch (FileNotFoundException e2) {
                 log.error("Error opening fall back Hazelcast XML configuration. "
                         + "File not found: " + HAZELCAST_DEFAULT_XML, e2);
                 // XXX probably should throw some exception to kill ONOS instead.
+                hzConfig = new Config();
             }
         }
 
         // set the name of Hazelcast instance in this JVM.
-        hazelcastConfig.setInstanceName(ONOS_HAZELCAST_INSTANCE);
+        hzConfig.setInstanceName(ONOS_HAZELCAST_INSTANCE);
 
         /*
         hazelcastConfig.setProperty(GroupProperties.PROP_IO_THREAD_COUNT, "1");
         hazelcastConfig.setProperty(GroupProperties.PROP_OPERATION_THREAD_COUNT, "1");
         hazelcastConfig.setProperty(GroupProperties.PROP_EVENT_THREAD_COUNT, "1");
         */
+
+        return hzConfig;
     }
 
     /**
@@ -160,7 +167,7 @@
         // Get the configuration file name and configure the Datagrid
         Map<String, String> configMap = context.getConfigParams(this);
         String configFilename = configMap.get(HAZELCAST_CONFIG_FILE);
-        this.loadHazelcastConfig(configFilename);
+        hazelcastConfig = loadHazelcastConfig(configFilename);
     }
 
     /**