CORD GUI - Define runtime properties 'headnodeip' and 'headnodeport'.
- put scripts (pullwar.sh, run.me, stop.me) under revision control.

Change-Id: I58078e8134d643d976271b60fe80ff28f9458ca9
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
index 789737b..eeb8e17 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
@@ -64,7 +64,7 @@
      */
     CordModelCache() {
         log.info("Initialize model cache");
-        subscriberId = XosManager.INSTANCE.initDemoSubscriber();
+        subscriberId = XosManager.INSTANCE.initXosSubscriber();
         currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE);
         initUsers();
     }
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java
index f3007e7..d6bc2d4 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/XosManager.java
@@ -38,17 +38,22 @@
 
     private static final ObjectMapper MAPPER = new ObjectMapper();
 
-    private static final String TEST_XOS_SERVER_ADDRESS = "10.254.1.22";
+    private static final String HEAD_NODE_IP = "headnodeip";
+    private static final String HEAD_NODE_PORT = "headnodeport";
+    private static final int PORT_MIN = 1025;
+    private static final int PORT_MAX = 65535;
+
+    private static final String TEST_XOS_SERVER_IP = "10.254.1.22";
+    private static final String TEST_XOS_SERVER_PORT_STR = "8000";
     private static final int TEST_XOS_SERVER_PORT = 8000;
     private static final String URI_RS = "/rs/";
     private static final String URI_SUBSCRIBER = "/rs/subscriber/%d/";
     private static final String BUNDLE_URI_FORMAT = "services/%s/%s/";
 
 
-    private final XosManagerRestUtils xosUtilsRs =
-            new XosManagerRestUtils(TEST_XOS_SERVER_ADDRESS,
-                                    TEST_XOS_SERVER_PORT, URI_RS);
-
+    private String xosServerIp;
+    private int xosServerPort;
+    private XosManagerRestUtils xosUtilsRs;
     private XosManagerRestUtils xosUtils;
 
 
@@ -59,11 +64,38 @@
      */
     XosManager() {}
 
+    private String getXosServerIp() {
+        return System.getProperty(HEAD_NODE_IP, TEST_XOS_SERVER_IP);
+    }
+
+    private int getXosServerPort() {
+        String p = System.getProperty(HEAD_NODE_PORT, TEST_XOS_SERVER_PORT_STR);
+        int port;
+        try {
+            port = Integer.valueOf(p);
+        } catch (NumberFormatException e) {
+            port = TEST_XOS_SERVER_PORT;
+            log.warn("Could not parse port number [{}], using {}", p, port);
+        }
+        if (port < PORT_MIN || port > PORT_MAX) {
+            log.warn("Bad port number [{}], using {}", port, TEST_XOS_SERVER_PORT);
+            port = TEST_XOS_SERVER_PORT;
+        }
+        return port;
+    }
+
     /**
      * Queries XOS for the Demo Subscriber ID and caches it for future calls.
      */
-    public int initDemoSubscriber() {
+    public int initXosSubscriber() {
         log.info("intDemoSubscriber() called");
+        xosServerIp = getXosServerIp();
+        xosServerPort = getXosServerPort();
+        log.info("Using XOS server at {}:{}", xosServerIp, xosServerPort);
+
+        xosUtilsRs = new XosManagerRestUtils(xosServerIp, xosServerPort, URI_RS);
+
+        // ask XOS for the subscriber ID of the canned Demo account...
         String result = xosUtilsRs.getRest("initdemo/");
         log.info("from XOS: {}", result);
 
@@ -80,8 +112,7 @@
         log.info("Using DEMO subscriber ID {}.", demoId);
 
         String uri = String.format(URI_SUBSCRIBER, demoId);
-        xosUtils = new XosManagerRestUtils(TEST_XOS_SERVER_ADDRESS,
-                                           TEST_XOS_SERVER_PORT, uri);
+        xosUtils = new XosManagerRestUtils(xosServerIp, xosServerPort, uri);
         return demoId;
     }
 
diff --git a/apps/demo/cord-gui/src/scripts/pullwar.sh b/apps/demo/cord-gui/src/scripts/pullwar.sh
new file mode 100644
index 0000000..e015e1c
--- /dev/null
+++ b/apps/demo/cord-gui/src/scripts/pullwar.sh
@@ -0,0 +1 @@
+cp $ONOS_ROOT/apps/demo/cord-gui/target/cord-gui-1.2.0-SNAPSHOT.war .
diff --git a/apps/demo/cord-gui/src/scripts/run.me b/apps/demo/cord-gui/src/scripts/run.me
new file mode 100644
index 0000000..85bf294
--- /dev/null
+++ b/apps/demo/cord-gui/src/scripts/run.me
@@ -0,0 +1,32 @@
+#######------------------------------------------------------------
+# CORD Demo
+# =========
+
+export JETTY="-jar jetty-runner.jar"
+export CORD=./cord-gui-1.2.0-SNAPSHOT.war
+export LOGDBG=-Dorg.onosproject.cord.gui.LEVEL=DEBUG
+export DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
+export LOG=cord.log
+
+IP="$1"
+PORT="$2"
+
+if [ ! -z "$IP" ]
+then
+  PARAM1="-Dheadnodeip=$IP"
+else
+  PARAM1=""
+fi
+
+if [ ! -z "$PORT" ]
+then
+  PARAM2="-Dheadnodeport=$PORT"
+else
+  PARAM2=""
+fi
+
+java $PARAM1 $PARAM2 $LOGDBG $JETTY $CORD >$LOG 2>&1 &
+#java $PARAM1 $PARAM2 $LOGDBG $DEBUG $JETTY $CORD >$LOG 2>&1 &
+
+echo jetty-runner started {$PARAM1:$PARAM2}
+echo .. logging to $LOG
diff --git a/apps/demo/cord-gui/src/scripts/stop.me b/apps/demo/cord-gui/src/scripts/stop.me
new file mode 100644
index 0000000..331d9bb
--- /dev/null
+++ b/apps/demo/cord-gui/src/scripts/stop.me
@@ -0,0 +1,18 @@
+# script to stop the cord gui server
+#
+PID=$(ps | grep jetty-runner | grep -v grep | cut -c1-5)
+if [ -z "$PID" ]
+then
+  echo jetty-runner not running
+  exit 0
+fi
+kill $PID
+sleep 1
+
+PID=$(ps | grep jetty-runner | grep -v grep | cut -c1-5)
+if [ ! -z "$PID" ]
+then
+  echo jetty-runner still running ?
+else
+  echo jetty-runner stopped
+fi