Handle Spaces in Path For Sample Cluster

Fixes ASTERIXDB-1842- start-sample-cluster.sh with user name ending with
space.

Change-Id: Id4b17698762e3cb2959152e6f957dad175d0f99b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1747
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-server/src/main/opt/local/bin/start-sample-cluster.sh b/asterixdb/asterix-server/src/main/opt/local/bin/start-sample-cluster.sh
index 4db0770..f7e0e34 100755
--- a/asterixdb/asterix-server/src/main/opt/local/bin/start-sample-cluster.sh
+++ b/asterixdb/asterix-server/src/main/opt/local/bin/start-sample-cluster.sh
@@ -48,23 +48,23 @@
   "$JAVA_HOME/bin/java" -version
   exit 2
 }
-DIRNAME=$(dirname $0)
+DIRNAME=$(dirname "$0")
 [ $(echo $DIRNAME | wc -l) -ne 1 ] && {
   echo "Paths with spaces are not supported"
   exit 3
 }
 
-CLUSTERDIR=$(cd $DIRNAME/..; echo $PWD)
-INSTALLDIR=$(cd $CLUSTERDIR/../..; echo $PWD)
+CLUSTERDIR=$(cd "$DIRNAME/.."; echo $PWD)
+INSTALLDIR=$(cd "$CLUSTERDIR/../.."; echo $PWD)
 LOGSDIR=$CLUSTERDIR/logs
 
 echo "CLUSTERDIR=$CLUSTERDIR"
 echo "INSTALLDIR=$INSTALLDIR"
 echo "LOGSDIR=$LOGSDIR"
 echo
-cd $CLUSTERDIR
-mkdir -p $LOGSDIR
-$INSTALLDIR/bin/${HELPER_COMMAND} get_cluster_state -quiet \
+cd "$CLUSTERDIR"
+mkdir -p "$LOGSDIR"
+"$INSTALLDIR/bin/${HELPER_COMMAND}" get_cluster_state -quiet \
     && echo "ERROR: sample cluster address (localhost:${LISTEN_PORT}) already in use" && exit 1
 
 if ps -ef | grep 'java.*org\.apache\.hyracks\.control\.[cn]c\.\([CN]CDriver\|service\.NCService\)' > /tmp/$$_pids; then
@@ -91,10 +91,10 @@
   echo "--------------------------"
   date
   echo "--------------------------"
-) | tee -a $LOGSDIR/blue-service.log | tee -a $LOGSDIR/red-service.log >> $LOGSDIR/cc.log
+) | tee -a "$LOGSDIR/blue-service.log" | tee -a "$LOGSDIR/red-service.log" >> "$LOGSDIR/cc.log"
 echo "INFO: Starting sample cluster..."
-$INSTALLDIR/bin/${NC_SERVICE_COMMAND} -logdir - -config-file $CLUSTERDIR/conf/blue.conf >> $LOGSDIR/blue-service.log 2>&1 &
-$INSTALLDIR/bin/${NC_SERVICE_COMMAND} -logdir - >> $LOGSDIR/red-service.log 2>&1 &
-$INSTALLDIR/bin/${CC_COMMAND} -config-file $CLUSTERDIR/conf/cc.conf >> $LOGSDIR/cc.log 2>&1 &
-$INSTALLDIR/bin/${HELPER_COMMAND} wait_for_cluster -timeout 30
+"$INSTALLDIR/bin/${NC_SERVICE_COMMAND}" -logdir - -config-file "$CLUSTERDIR/conf/blue.conf" >> "$LOGSDIR/blue-service.log" 2>&1 &
+"$INSTALLDIR/bin/${NC_SERVICE_COMMAND}" -logdir - >> "$LOGSDIR/red-service.log" 2>&1 &
+"$INSTALLDIR/bin/${CC_COMMAND}" -config-file "$CLUSTERDIR/conf/cc.conf" >> "$LOGSDIR/cc.log" 2>&1 &
+"$INSTALLDIR/bin/${HELPER_COMMAND}" wait_for_cluster -timeout 30
 exit $?
diff --git a/asterixdb/asterix-server/src/main/opt/local/bin/stop-sample-cluster.sh b/asterixdb/asterix-server/src/main/opt/local/bin/stop-sample-cluster.sh
index 4ba5789..dbce377 100755
--- a/asterixdb/asterix-server/src/main/opt/local/bin/stop-sample-cluster.sh
+++ b/asterixdb/asterix-server/src/main/opt/local/bin/stop-sample-cluster.sh
@@ -48,17 +48,17 @@
   "$JAVA_HOME/bin/java" -version
   exit 2
 }
-DIRNAME=$(dirname $0)
+DIRNAME=$(dirname "$0")
 [ $(echo $DIRNAME | wc -l) -ne 1 ] && {
   echo "Paths with spaces are not supported"
   exit 3
 }
 
-CLUSTERDIR=$(cd $DIRNAME/..; echo $PWD)
-INSTALLDIR=$(cd $CLUSTERDIR/../..; echo $PWD)
-$INSTALLDIR/bin/${HELPER_COMMAND} get_cluster_state -quiet
+CLUSTERDIR=$(cd "$DIRNAME/.."; echo $PWD)
+INSTALLDIR=$(cd "$CLUSTERDIR/../.."; echo $PWD)
+"$INSTALLDIR/bin/${HELPER_COMMAND}" get_cluster_state -quiet
 if [ $? -ne 1 ]; then
-  $INSTALLDIR/bin/${HELPER_COMMAND} shutdown_cluster_all
+  "$INSTALLDIR/bin/${HELPER_COMMAND}" shutdown_cluster_all
   first=1
   tries=0
   echo -n "INFO: Waiting up to 60s for cluster to shutdown"
@@ -91,3 +91,4 @@
   fi
 fi
 rm /tmp/$$_pids
+
diff --git a/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
index 61128c5..496d4cf 100644
--- a/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
+++ b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
@@ -52,7 +52,7 @@
 
     // Directory where the NCs create and store all data, as configured by
     // src/test/resources/NCServiceExecutionIT/cc.conf.
-    private static final String OUTPUT_DIR = FileUtil.joinPath(TARGET_DIR, "sample-local-cluster");
+    private static final String OUTPUT_DIR = FileUtil.joinPath(TARGET_DIR, "sample local cluster");
 
     private static final String LOCAL_SAMPLES_DIR = FileUtil.joinPath(OUTPUT_DIR, "opt", "local");