summaryrefslogtreecommitdiffstats
path: root/tca-cdap-container/mr-watchdog.sh
diff options
context:
space:
mode:
authorLusheng Ji <lji@research.att.com>2018-05-14 22:45:56 -0400
committerLusheng Ji <lji@research.att.com>2018-05-14 23:02:39 -0400
commite380f6bb14fb0e5fae4e9a6d9b9af40a9340f11a (patch)
tree5888b27d73d51e58403ab3873af972b734068cd2 /tca-cdap-container/mr-watchdog.sh
parent430b6b44fcd1dfa917cb599962ae6ef332581ede (diff)
Increase robustness for TCA
Enhanced TCA robustness against unprovisioned topics. When the configuration tells TCA to subscribe to a non-existent MR topic, TCA will attempt but stop because subscribing to such topics resulted failure. The enhancements implemented here will test for sub topic, and if non-existent, make a publish to create the topic. Additional enhancements include: 1. restart TCA is the number of workers is below expected (3); 2. allow MR subscriber group and id be set via environment variables DMAAPSUBGROUP and DMAAPSUBID. 3. Minor version is bumped. Issue-ID: DCAEGEN2-502 Change-Id: I3414a96706a1b720184cd657324db4d11db12590 Signed-off-by: Lusheng Ji <lji@research.att.com>
Diffstat (limited to 'tca-cdap-container/mr-watchdog.sh')
-rwxr-xr-xtca-cdap-container/mr-watchdog.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/tca-cdap-container/mr-watchdog.sh b/tca-cdap-container/mr-watchdog.sh
new file mode 100755
index 0000000..fa623a1
--- /dev/null
+++ b/tca-cdap-container/mr-watchdog.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+# ================================================================================
+# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
+
+
+SUB_TOPIC=${3:-unauthenticated.VES_MEASUREMENT_OUTPUT}
+MR_LOCATION=${1:-10.0.11.1}
+MR_PORT=${2:-3904}
+MR_PROTO='http'
+
+
+TOPIC_LIST_URL="${MR_PROTO}://${MR_LOCATION}:${MR_PORT}/topics"
+TEST_PUB_URL="${MR_PROTO}://${MR_LOCATION}:${MR_PORT}/events/${SUB_TOPIC}"
+
+unset RES
+echo "==> Check topic [${SUB_TOPIC}] availbility on ${MR_LOCATION}:${MR_PORT}"
+until [ -n "$RES" ]; do
+ URL="$TOPIC_LIST_URL"
+ HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" "$URL")
+ HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
+ HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
+ if [ "${HTTP_STATUS}" != "200" ]; then
+ echo " ==> MR topic listing not ready, retry in 30 seconds"
+ sleep 30
+ continue
+ fi
+
+ echo " ==> MR topic listing received, check topic availbility"
+ RES=$(echo "${HTTP_BODY}" |jq .topics |grep "\"$SUB_TOPIC\"")
+ if [ -z "${RES}" ]; then
+ echo " ==> No topic [${SUB_TOPIC}] found, send test publish"
+ URL="$TEST_PUB_URL"
+ HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -H "Content-Type:text/plain" -X POST -d "{}" "$URL")
+ HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
+ HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
+
+ if [ "$HTTP_STATUS" != "200" ]; then
+ echo " ==> Testing MR topic publishing received status $HTTP_STATUS != 200, retesting in 30 seconds"
+ sleep 30
+ else
+ echo " ==> Testing MR topic publishing received status $HTTP_STATUS, topic [$SUB_TOPIC] created"
+ fi
+ fi
+done
+echo "==> Topic [${SUB_TOPIC}] ready"