--- /dev/null
+#!/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"
TCA_PATH_APP="${CDAP_HOST}:${CDAP_PORT}/v3/namespaces/${TCA_NAMESPACE}/apps/${TCA_APPNAME}"
TCA_PATH_ARTIFACT="${CDAP_HOST}:${CDAP_PORT}/v3/namespaces/${TCA_NAMESPACE}/artifacts"
+MR_WATCHDOG_PATH="${TCA_FILE_PATH}/mr-watchdog.sh"
+
+
+WORKER_COUNT='0'
CONSUL_HOST=${CONSUL_HOST:-consul}
CONSUL_PORT=${CONSUL_PORT:-8500}
echo "Generting preference file"
+DMAAPSUBGROUP=${DMAAPSUBGROUP:-OpenDCAEc12}
+DMAAPSUBID=${DMAAPSUBID:=c12}
sed -i 's/{{DMAAPHOST}}/'"${DMAAPHOST}"'/g' ${TCA_PREF}
sed -i 's/{{DMAAPPORT}}/'"${DMAAPPORT}"'/g' ${TCA_PREF}
sed -i 's/{{DMAAPPUBTOPIC}}/'"${DMAAPPUBTOPIC}"'/g' ${TCA_PREF}
sed -i 's/{{DMAAPSUBTOPIC}}/'"${DMAAPSUBTOPIC}"'/g' ${TCA_PREF}
-sed -i 's/{{DMAAPSUBGROUP}}/OpenDCAEc12/g' ${TCA_PREF}
-sed -i 's/{{DMAAPSUBID}}/c12/g' ${TCA_PREF}
+sed -i 's/{{DMAAPSUBGROUP}}/'"${DMAAPSUBGROUP}"'/g' ${TCA_PREF}
+sed -i 's/{{DMAAPSUBID}}/'"${DMAAPSUBID}"'/g' ${TCA_PREF}
sed -i 's/{{AAIHOST}}/'"${AAIHOST}"'/g' ${TCA_PREF}
sed -i 's/{{AAIPORT}}/'"${AAIPORT}"'/g' ${TCA_PREF}
if [ -z "$REDISHOSTPORT" ]; then
function tca_status {
+ WORKER_COUNT='0'
echo
- echo "TCADMaaPMRPublisherWorker status: "
- curl -s "http://${TCA_PATH_APP}/workers/TCADMaaPMRPublisherWorker/status"
+ STATUS=$(curl -s "http://${TCA_PATH_APP}/workers/TCADMaaPMRPublisherWorker/status")
+ echo "TCADMaaPMRPublisherWorker status: $STATUS"
+ INC=$(echo "$STATUS" | jq . |grep RUNNING |wc -l)
+ WORKER_COUNT=$((WORKER_COUNT+INC))
+
+ STATUS=$(curl -s "http://${TCA_PATH_APP}/workers/TCADMaaPMRSubscriberWorker/status")
+ echo "TCADMaaPMRSubscriberWorker status: $STATUS"
+ INC=$(echo "$STATUS" | jq . |grep RUNNING |wc -l)
+ WORKER_COUNT=$((WORKER_COUNT+INC))
+
+ STATUS=$(curl -s "http://${TCA_PATH_APP}/flows/TCAVESCollectorFlow/status")
+ echo "TCAVESCollectorFlow status: $STATUS"
+ INC=$(echo "$STATUS" | jq . |grep RUNNING |wc -l)
+ WORKER_COUNT=$((WORKER_COUNT+INC))
echo
- echo "TCADMaaPMRSubscriberWorker status: "
- curl -s "http://${TCA_PATH_APP}/workers/TCADMaaPMRSubscriberWorker/status"
- echo
- echo "TCAVESCollectorFlow status"
- curl -s "http://${TCA_PATH_APP}/flows/TCAVESCollectorFlow/status"
- echo; echo
}
+function tca_restart {
+ MR_HOST=$(jq .subscriberHostName ${TCA_PREF} |sed -e 's/\"//g')
+ MR_PORT=$(jq .subscriberHostPort ${TCA_PREF} |sed -e 's/\"//g')
+ MR_TOPIC=$(jq .subscriberTopicName ${TCA_PREF} |sed -e 's/\"//g')
+ echo "Verifying DMaaP topic: ${MR_TOPIC}@${MR_HOST}:${MR_PORT} (will block until topic ready)"
+ "${MR_WATCHDOG_PATH}" "${MR_HOST}" "${MR_PORT}" "${MR_TOPIC}"
+ tca_stop
+ tca_delete
+ tca_load_artifact
+ tca_load_conf
+ tca_start
+ sleep 5
+ tca_status
+}
+
function tca_poll_policy {
URL0="${CBS_HOST}:${CBS_PORT}/service_component_all/${MY_NAME}"
echo "tca_poll_policy: Retrieving all-in-one config at ${URL0}"
if [[ "$PERF_CHANGED" == "1" || "$CONF_CHANGED" == "1" ]]; then
echo "Newly received configuration/preference differ from the running instance's. reload confg"
- tca_stop
- tca_delete
- tca_load_artifact
- tca_load_conf
- tca_start
- tca_status
+ tca_restart
+ else
+ echo "Newly received configuration/preference identical from the running instance's"
fi
}
# starting CDAP SDK in background
cdap sdk start
-echo "Started, waiting CDAP ready on port 11015 ..."
+echo "CDAP Started, waiting CDAP ready on ${CDAP_HOST}:${CDAP_PORT} ..."
while ! nc -z ${CDAP_HOST} ${CDAP_PORT}; do
- sleep 0.1 # wait for 1/10 of the second before check again
+ sleep 1 # wait for 1 second before check again
done
echo "Creating namespace cdap_tca_hi_lo ..."
# stop programs
tca_stop
-
# delete application
tca_delete
-
# load artifact
tca_load_artifact
tca_load_conf
-
# start programs
tca_start
# get status of programs
tca_status
-echo "TCA-CDAP standalone mode initialization completed"
+echo "TCA-CDAP standalone mode initialization completed, with $WORKER_COUNT / 3 up"
while echo
do
- echo "$(date): ======================================================"
+ echo "======================================================> $(date)"
+ tca_status
+
+ while [ "$WORKER_COUNT" != "3" ]; do
+ echo "Status checking: worker count is $WORKER_COUNT, needs a reset"
+ sleep 5
+
+ tca_restart
+ echo "TCA restarted"
+ done
+
+
if [[ -z "$CBS_HOST" || -z "$CBS_PORT" ]]; then
echo "Retrieving host and port for ${CBS_SERVICE_NAME} from ${CONSUL_HOST}:${CONSUL_PORT}"
sleep 2