+# Create a dmaap mr topic
+# args: <topic name> <topic-description>
+__create_topic() {
+ echo -ne " Creating read topic: $1"$SAMELINE
+
+ json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}"
+ echo $json_topic > ./tmp/$1.json
+
+ curlString="$MR_DMAAP_PATH/topics/create -X POST -H Content-Type:application/json -d@./tmp/$1.json"
+ topic_retries=5
+ while [ $topic_retries -gt 0 ]; do
+ let topic_retries=topic_retries-1
+ result=$(__do_curl "$curlString")
+ if [ $? -eq 0 ]; then
+ topic_retries=0
+ echo -e " Creating read topic: $1 $GREEN OK $EGREEN"
+ fi
+ if [ $? -ne 0 ]; then
+ if [ $topic_retries -eq 0 ]; then
+ echo -e " Creating read topic: $1 $RED Failed $ERED"
+ ((RES_CONF_FAIL++))
+ return 1
+ else
+ sleep 1
+ fi
+ fi
+ done
+ return 0
+}
+
+# Do a pipeclean of a topic - to overcome dmaap mr bug...
+# args: <topic> <post-url> <read-url>
+__dmaap_pipeclean() {
+ pipeclean_retries=50
+ echo -ne " Doing dmaap-mr pipe cleaning on topic: $1"$SAMELINE
+ while [ $pipeclean_retries -gt 0 ]; do
+ echo "{\"pipeclean-$1\":$pipeclean_retries}" > ./tmp/pipeclean.json
+ let pipeclean_retries=pipeclean_retries-1
+ curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:application/json -d@./tmp/pipeclean.json"
+ result=$(__do_curl "$curlString")
+ if [ $? -ne 0 ]; then
+ sleep 1
+ else
+ curlString="$MR_DMAAP_PATH$3"
+ result=$(__do_curl "$curlString")
+ if [ $? -eq 0 ]; then
+ if [ $result != "[]" ]; then
+ echo -e " Doing dmaap-mr pipe cleaning on topic: $1 $GREEN OK $EGREEN"
+ return 0
+
+ else
+ sleep 1
+ fi
+ fi
+ fi
+ done
+ echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED"
+ return 1
+}
+
+