From b55d5b3b17177a4a8ed8b890216aa35eebf08969 Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Tue, 3 Oct 2017 22:22:00 +0000 Subject: Change the init chef to wait until hbase is up When vm1 and vm2 are deployed independently the vm1 needs to manually check the port on hbase container and see if the hbase is open when the port is open, wait a couple of seconds and then start the create db schema script Issue-ID: AAI-411 Change-Id: I329cb15de73fecd6c4057c6ee2c406bbf03a0272 Signed-off-by: Venkata Harish K Kajur --- .../src/main/resources/docker/init-chef.sh | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'aai-resources/src/main') diff --git a/aai-resources/src/main/resources/docker/init-chef.sh b/aai-resources/src/main/resources/docker/init-chef.sh index 4c49a27..416c25f 100644 --- a/aai-resources/src/main/resources/docker/init-chef.sh +++ b/aai-resources/src/main/resources/docker/init-chef.sh @@ -59,6 +59,45 @@ chef-solo \ -j /var/chef/aai-config/cookbooks/runlist-aai-resources.json \ -E ${AAI_CHEF_ENV}; +TITAN_REALTIME="/opt/app/aai-resources/bundleconfig/etc/appprops/titan-realtime.properties"; + +if [ ! -f ${TITAN_REALTIME} ]; then + echo "Unable to find the titan realtime file"; + exit 1; +fi + +HBASE_HOSTNAME=$(grep "storage.hostname" ${TITAN_REALTIME} | cut -d"=" -f2-); +HBASE_PORT="${HBASE_PORT:-2181}"; +NUM_OF_RETRIES=${NUM_OF_RETRIES:-200}; +retry=0; + +# Tries to connect to hbase on port 2181 until success +# or until the number of retries by default 500 times +# with each time giving a sleep of 5 seconds between +# each time it pings the port on that host + +while ! nc -z ${HBASE_HOSTNAME} ${HBASE_PORT} ; +do + if [ $retry -eq $NUM_OF_RETRIES ]; then + echo "Unable to connect to hbase after $NUM_OF_RETRIES retries, please check if hbase server is properly configured and be able to connect"; + exit 1; + fi; + + echo "Waiting for hbase to be up"; + sleep 5; + + retry=$((retry + 1)); +done + +HBASE_STARTUP_ARTIFICIAL_DELAY=${HBASE_STARTUP_ARTIFICIAL_DELAY:-50}; + +# By default the artificial delay will be introduced +# the user can override it by set DISABLE_HBASE_STARTUP_ARTIFICIAL_DELAY to some string + +if [ -z "${DISABLE_HBASE_STARTUP_ARTIFICIAL_DELAY}" ]; then + sleep ${HBASE_STARTUP_ARTIFICIAL_DELAY}; +fi; + /opt/app/aai-resources/bin/createDBSchema.sh || { echo "Error: Unable to create the db schema, please check if the hbase host is configured and up"; exit 1; -- cgit 1.2.3-korg