blob: fa623a1b65c9ae2929d6dfce715707fb90941c69 [file] [log] [blame]
Lusheng Jie380f6b2018-05-14 22:45:56 -04001#!/bin/bash
2# ================================================================================
3# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4# ================================================================================
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# ============LICENSE_END=========================================================
17
18
19
20SUB_TOPIC=${3:-unauthenticated.VES_MEASUREMENT_OUTPUT}
21MR_LOCATION=${1:-10.0.11.1}
22MR_PORT=${2:-3904}
23MR_PROTO='http'
24
25
26TOPIC_LIST_URL="${MR_PROTO}://${MR_LOCATION}:${MR_PORT}/topics"
27TEST_PUB_URL="${MR_PROTO}://${MR_LOCATION}:${MR_PORT}/events/${SUB_TOPIC}"
28
29unset RES
30echo "==> Check topic [${SUB_TOPIC}] availbility on ${MR_LOCATION}:${MR_PORT}"
31until [ -n "$RES" ]; do
32 URL="$TOPIC_LIST_URL"
33 HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" "$URL")
34 HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
35 HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
36 if [ "${HTTP_STATUS}" != "200" ]; then
37 echo " ==> MR topic listing not ready, retry in 30 seconds"
38 sleep 30
39 continue
40 fi
41
42 echo " ==> MR topic listing received, check topic availbility"
43 RES=$(echo "${HTTP_BODY}" |jq .topics |grep "\"$SUB_TOPIC\"")
44 if [ -z "${RES}" ]; then
45 echo " ==> No topic [${SUB_TOPIC}] found, send test publish"
46 URL="$TEST_PUB_URL"
47 HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -H "Content-Type:text/plain" -X POST -d "{}" "$URL")
48 HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
49 HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
50
51 if [ "$HTTP_STATUS" != "200" ]; then
52 echo " ==> Testing MR topic publishing received status $HTTP_STATUS != 200, retesting in 30 seconds"
53 sleep 30
54 else
55 echo " ==> Testing MR topic publishing received status $HTTP_STATUS, topic [$SUB_TOPIC] created"
56 fi
57 fi
58done
59echo "==> Topic [${SUB_TOPIC}] ready"