Modified onos.sh so that Hazelcast port can be configured.
Change-Id: I0152f8361dc51899db412014058a77ff3ab5752e
Modified onos.sh to use utils.sh functions.
Fixed onos-cluster.sh potential strings bug.
Change-Id: I41dbf22801f697567658d4201b80da7917f2160f
diff --git a/cluster-mgmt/onos-cluster.sh b/cluster-mgmt/onos-cluster.sh
index e1cceb8..2c8ee9b 100755
--- a/cluster-mgmt/onos-cluster.sh
+++ b/cluster-mgmt/onos-cluster.sh
@@ -79,11 +79,11 @@
for host in ${CLUSTER_HOSTS}; do
local zk_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.zk.host")
- if [ -z ${zk_host_string} ]; then
+ if [ -z "${zk_host_string}" ]; then
# falling back to ip
zk_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.ip")
fi
- if [ -z ${zk_host_string} ]; then
+ if [ -z "${zk_host_string}" ]; then
# falling back to hostname
zk_host_string=${host}
fi
@@ -101,12 +101,12 @@
for host in ${CLUSTER_HOSTS}; do
local hc_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.hazelcast.ip")
- if [ -z ${hc_host_string} ]; then
+ if [ -z "${hc_host_string}" ]; then
# falling back to ip
hc_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.ip")
fi
- if [ -z ${hc_host_string} ]; then
+ if [ -z "${hc_host_string}" ]; then
# falling back to hostname
hc_host_string=${host}
fi
@@ -124,12 +124,12 @@
# creation of pssh config file
for host in ${CLUSTER_HOSTS}; do
local user=$(read-conf ${CLUSTER_CONF} remote.${host}.ssh.user)
- if [ -z ${user} ]; then
+ if [ -z "${user}" ]; then
# falling back to common setting
user=$(read-conf ${CLUSTER_CONF} remote.common.ssh.user)
fi
- if [ -z ${user} ]; then
+ if [ -z "${user}" ]; then
echo ${host} >> ${tempfile}
else
echo ${user}@${host} >> ${tempfile}
@@ -143,7 +143,7 @@
function create-onos-conf {
local host_name=${1}
- if [ -z ${host_name} ]; then
+ if [ -z "${host_name}" ]; then
echo "FAILED"
echo "[ERROR] invalid hostname ${host_name}"
exit 1
@@ -241,7 +241,7 @@
fi
local user=$(read-conf ${CLUSTER_CONF} "remote.${host}.ssh.user")
- if [ -z ${user} ]; then
+ if [ -z "${user}" ]; then
# falling back to common setting
user=$(read-conf ${CLUSTER_CONF} "remote.common.ssh.user")
fi
diff --git a/conf/onos_node.conf b/conf/onos_node.conf
index 183f696..07716fd 100644
--- a/conf/onos_node.conf
+++ b/conf/onos_node.conf
@@ -46,6 +46,9 @@
# RAMCloud server option detectFailures [0=disabled] (0 by default for ONOS development)
#ramcloud.detectFailures = 0
+# Port number of Hazelcast (5701 by default)
+#hazelcast.host.port = 5701
+
# List of hostname/ip[:port] which forms Hazelcast grid
# If this value is empty, Hazelcast will be set to multicast mode.
# Inversely, if this value is set, multicast settings will be ignored.
diff --git a/conf/template/hazelcast.xml.template b/conf/template/hazelcast.xml.template
index 77db87c..b23c7e9 100644
--- a/conf/template/hazelcast.xml.template
+++ b/conf/template/hazelcast.xml.template
@@ -89,7 +89,7 @@
</topic>
<network>
- <port auto-increment="true">5701</port>
+ <port auto-increment="true">__HC_PORT__</port>
<join>
__HC_NETWORK__
<aws enabled="false">
diff --git a/onos.sh b/onos.sh
index 750078a..dbf2739 100755
--- a/onos.sh
+++ b/onos.sh
@@ -13,23 +13,17 @@
# $ZK_HOME : path of root directory of ZooKeeper (~/zookeeper-3.4.5)
# $ZK_LIB_DIR : path of ZooKeeper library (/var/lib/zookeeper)
# $JVM_OPTS : JVM options ONOS starts with
+# $ZK_CONF : path of ZooKeeper config file (~/ONOS/conf/zoo.cfg)
+# $HC_CONF : path of Hazelcast config file (~/ONOS/conf/hazelcast.xml)
+# $RAMCLOUD_CONF : path of RAMCloud config file (~/ONOS/conf/ramcloud.conf)
#####################################################
-
-# read-conf {filename} {parameter name} [default value]
-function read-conf {
- local value=`grep ^${2} ${1} | cut -d "=" -f 2 | sed -e 's/^[ \t]*//'`
- if [ -z "${value}" ]; then
- echo $3
- else
- echo ${value}
- fi
-}
-
ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)}
ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf}
ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.`hostname`.conf}
+source ${ONOS_HOME}/scripts/common/utils.sh
+
if [ ! -f ${ONOS_CONF} ]; then
# falling back to default config file
ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf
@@ -52,6 +46,7 @@
RC_SERVER_PROTOCOL=$(read-conf ${ONOS_CONF} ramcloud.server.protocol "fast+udp")
RC_SERVER_IP=$(read-conf ${ONOS_CONF} ramcloud.server.ip ${ONOS_HOST_IP})
RC_SERVER_PORT=$(read-conf ${ONOS_CONF} ramcloud.server.port 12242)
+HC_HOST_PORT=$(read-conf ${ONOS_CONF} hazelcast.host.port 5701)
HC_TCPIP_MEMBERS=$(read-conf ${ONOS_CONF} hazelcast.tcp-ip.members)
HC_MULTICAST_GROUP=$(read-conf ${ONOS_CONF} hazelcast.multicast.group "224.2.2.3")
HC_MULTICAST_PORT=$(read-conf ${ONOS_CONF} hazelcast.multicast.port 54327)
@@ -64,22 +59,21 @@
LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
ZK_HOME=${ZK_HOME:-~/zookeeper-3.4.5}
-ZK_CONF_FILE=zoo.cfg
-ZK_CONF=${ONOS_CONF_DIR}/${ZK_CONF_FILE}
+ZK_CONF=${ZK_CONF:-${ONOS_CONF_DIR}/zoo.cfg}
ZK_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/zoo.cfg.template
# Adding ONOS_HOST_NAME dir since file name (zookeeper.out) cannot be controlled.
ZK_LOG_DIR=${ONOS_HOME}/onos-logs/${ONOS_HOST_NAME}
ZK_LIB_DIR=${ZK_LIB_DIR:-/var/lib/zookeeper}
ZK_MY_ID=${ZK_LIB_DIR}/myid
-HC_CONF=${ONOS_CONF_DIR}/hazelcast.xml
+HC_CONF=${HC_CONF:-${ONOS_CONF_DIR}/hazelcast.xml}
HC_CONF_TEMPLATE=${ONOS_TEMPLATE_DIR}/hazelcast.xml.template
RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
RAMCLOUD_COORD_LOG=${LOGDIR}/ramcloud.coordinator.${ONOS_HOST_NAME}.log
RAMCLOUD_SERVER_LOG=${LOGDIR}/ramcloud.server.${ONOS_HOST_NAME}.log
RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
-RAMCLOUD_CONF=${ONOS_CONF_DIR}/ramcloud.conf
+RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_CONF_DIR}/ramcloud.conf}
export LD_LIBRARY_PATH=${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}:$LD_LIBRARY_PATH
@@ -209,21 +203,6 @@
exit 1
}
-# revert-file {filename}
-# revert "filename" from "filename.bak" if "filename.tmp" exists.
-function revert-file {
- local filename=$1
- local temp="${filename}.tmp"
- local backup="${filename}.bak"
-
- if [ -f "${temp}" ]; then
- echo -n "reverting ${filename} ... "
- mv ${backup} ${filename}
- rm ${temp}
- echo "DONE"
- fi
-}
-
# revert-confs [error message]
function revert-confs {
echo -n "ERROR occurred ... "
@@ -240,7 +219,7 @@
function create-zk-conf {
echo -n "Creating ${ZK_CONF} ... "
-
+
# Create the ZooKeeper lib directory
if [ ! -d ${ZK_LIB_DIR} ]; then
local SUDO=${SUDO:-}
@@ -257,18 +236,7 @@
fi
# creation of ZooKeeper config
-
- local temp_zk="${ZK_CONF}.tmp"
- if [ -f ${temp_zk} ]; then
- rm ${temp_zk}
- fi
- touch ${temp_zk}
-
- if [ -f ${ZK_CONF} ]; then
- mv ${ZK_CONF} ${ZK_CONF}.bak
- local filename=`basename ${ZK_CONF}`
- echo -n "backup old file to ${filename}.bak ... "
- fi
+ local temp_zk=`begin-conf-creation ${ZK_CONF}`
hostarr=`echo ${ZK_HOSTS} | tr "," " "`
@@ -288,6 +256,7 @@
fi
if [ -f "${ZK_MY_ID}" ]; then
+ # sudo will be needed if ZK_MY_ID is already created by other (old) script
local SUDO=${SUDO:-}
{
${SUDO} mv -f ${ZK_MY_ID} ${ZK_MY_ID}.old
@@ -309,16 +278,17 @@
for host in ${hostarr}; do
# TODO: ports might be configurable
local hostline="server.${i}=${host}:2888:3888"
- echo $hostline >> "${temp_zk}"
+ echo $hostline
i=`expr $i + 1`
done
elif [[ $line =~ __DATADIR__ ]]; then
- echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|" >> ${temp_zk}
+ echo $line | sed -e "s|__DATADIR__|${ZK_LIB_DIR}|"
else
- echo $line >> ${temp_zk}
+ echo $line
fi
- done < ${ZK_CONF_TEMPLATE}
- mv ${temp_zk} ${ZK_CONF}
+ done < ${ZK_CONF_TEMPLATE} > ${temp_zk}
+
+ end-conf-creation ${ZK_CONF}
echo "DONE"
}
@@ -326,17 +296,7 @@
function create-hazelcast-conf {
echo -n "Creating ${HC_CONF} ... "
- local temp_hc="${HC_CONF}.tmp"
- if [ -f ${temp_hc} ]; then
- rm ${temp_hc}
- fi
- touch ${temp_hc}
-
- if [ -f ${HC_CONF} ]; then
- mv ${HC_CONF} ${HC_CONF}.bak
- local filename=`basename ${HC_CONF}`
- echo -n "backup old file to ${filename}.bak ... "
- fi
+ local temp_hc=`begin-conf-creation ${HC_CONF}`
# To keep indent of XML file, change IFS
local IFS=''
@@ -360,12 +320,14 @@
echo '</multicast>'
echo '<tcp-ip enabled="false" />'
fi
+ elif [[ $line =~ __HC_PORT__ ]]; then
+ echo $line | sed -e "s|__HC_PORT__|${HC_HOST_PORT}|"
else
echo "${line}"
fi
done < ${HC_CONF_TEMPLATE} > ${temp_hc}
- mv ${temp_hc} ${HC_CONF}
+ end-conf-creation ${HC_CONF}
echo "DONE"
}
@@ -373,21 +335,12 @@
function create-ramcloud-conf {
echo -n "Creating ${RAMCLOUD_CONF} ... "
- local temp_hc="${RAMCLOUD_CONF}.tmp"
- if [ -f ${temp_hc} ]; then
- rm ${temp_hc}
- fi
- touch ${temp_hc}
+ local temp_rc=`begin-conf-creation ${RAMCLOUD_CONF}`
+
+ echo "ramcloud.coordinatorIp=${RC_COORD_PROTOCOL}:host=${RC_COORD_IP}" > ${temp_rc}
+ echo "ramcloud.coordinatorPort=port=${RC_COORD_PORT}" >> ${temp_rc}
- if [ -f ${RAMCLOUD_CONF} ]; then
- mv ${RAMCLOUD_CONF} ${RAMCLOUD_CONF}.bak
- local filename=`basename ${RAMCLOUD_CONF}`
- echo -n "backup old file to ${filename}.bak ... "
- fi
- echo "ramcloud.coordinatorIp=${RC_COORD_PROTOCOL}:host=${RC_COORD_IP}" > ${temp_hc}
- echo "ramcloud.coordinatorPort=port=${RC_COORD_PORT}" >> ${temp_hc}
-
- mv ${temp_hc} ${RAMCLOUD_CONF}
+ end-conf-creation ${RAMCLOUD_CONF}
echo "DONE"
}
@@ -396,47 +349,23 @@
echo -n "Creating ${ONOS_LOGBACK} ... "
# creation of logback config
- if [ -f $ONOS_LOGBACK ]; then
- local logback_file=`basename ${ONOS_LOGBACK}`
- mv ${ONOS_LOGBACK} ${ONOS_LOGBACK}.bak
- local filename=`basename ${ONOS_LOGBACK}`
- echo -n "backup old file to ${filename}.bak ... "
- fi
- sed -e "s|__FILENAME__|${ONOS_LOG}|" ${ONOS_LOGBACK_TEMPLATE} > ${ONOS_LOGBACK}
+ local temp_lb=`begin-conf-creation ${ONOS_LOGBACK}`
+
+ sed -e "s|__FILENAME__|${ONOS_LOG}|" ${ONOS_LOGBACK_TEMPLATE} > ${temp_lb}
+
+ end-conf-creation ${ONOS_LOGBACK}
echo "DONE"
}
-# create-conf-interactive {filename} {function to create conf}
-function create-conf-interactive {
- local filepath=$1
- local filename=`basename ${filepath}`
- local func=$2
-
- if [ -f ${filepath} ]; then
- # confirmation to overwrite existing config file
- echo -n "Overwriting ${filename} [Y/n]? "
- while [ 1 ]; do
- read key
- if [ -z "${key}" -o "${key}" == "Y" -o "${key}" == "y" ]; then
- ${func}
- break
- elif [ "${key}" == "N" -o "${key}" == "n" ]; then
- break
- fi
- echo "[Y/n]?"
- done
- else
- ${func}
- fi
-}
-
function create-confs {
local key
local filename
trap handle-error ERR
+ echo "Config file : ${ONOS_CONF}"
+
if [ "$1" == "-f" ]; then
create-zk-conf
create-hazelcast-conf
@@ -476,16 +405,24 @@
esac
}
+function load-zk-cfg {
+ if [ -f "${ZK_CONF}" ]; then
+ local filename=`basename ${ZK_CONF}`
+ local dirname=`dirname ${ZK_CONF}`
+
+ # Run ZooKeeper with our configuration
+ export ZOOCFG=${filename}
+ export ZOOCFGDIR=${dirname}
+ fi
+}
+
function start-zk {
echo -n "Starting ZooKeeper ... "
export ZOO_LOG_DIR=${ZK_LOG_DIR}
mkdir -p ${ZK_LOG_DIR}
- if [ -f "${ZK_CONF}" ]; then
- # Run ZooKeeper with our configuration
- export ZOOCFG=${ZK_CONF_FILE}
- export ZOOCFGDIR=${ONOS_CONF_DIR}
- fi
+
+ load-zk-cfg
${ZK_HOME}/bin/zkServer.sh start
}
@@ -495,10 +432,7 @@
}
function status-zk {
- if [ -f ${ZK_CONF} ]; then
- export ZOOCFG=${ZK_CONF_FILE}
- export ZOOCFGDIR=${ONOS_CONF_DIR}
- fi
+ load-zk-cfg
${ZK_HOME}/bin/zkServer.sh status
}