add mmagent
[dmaap/kafka11aaf.git] / src / main / docker / create-topics.sh
1 #!/bin/bash
2
3 if [[ -n "$MM_AGENT_WAIT_TIME" ]]; then
4   ORD=$(eval $BROKER_ID_COMMAND)
5   if [ "$ORD" = "0" ]; then
6     echo "wait for $MM_AGENT_WAIT_TIME before start of the mirror maker agent"
7     sleep $MM_AGENT_WAIT_TIME
8     java -jar /tmp/dmaapMMAgent.jar
9   fi
10 fi
11
12
13 if [[ -z "$START_TIMEOUT" ]]; then
14     START_TIMEOUT=600
15 fi
16
17 start_timeout_exceeded=false
18 count=0
19 step=10
20 while netstat -lnt | awk '$4 ~ /:'$KAFKA_PORT'$/ {exit 1}'; do
21     echo "waiting for kafka to be ready"
22     sleep $step;
23     count=$(expr $count + $step)
24     if [ $count -gt $START_TIMEOUT ]; then
25         start_timeout_exceeded=true
26         break
27     fi
28 done
29
30 if $start_timeout_exceeded; then
31     echo "Not able to auto-create topic (waited for $START_TIMEOUT sec)"
32     exit 1
33 fi
34
35 if [[ -n $KAFKA_CREATE_TOPICS ]]; then
36     IFS=','; for topicToCreate in $KAFKA_CREATE_TOPICS; do
37         echo "creating topics: $topicToCreate"
38         IFS=':' read -a topicConfig <<< "$topicToCreate"
39         if [ ${topicConfig[3]} ]; then
40           JMX_PORT='' $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor ${topicConfig[2]} --partitions ${topicConfig[1]} --topic "${topicConfig[0]}" --config cleanup.policy="${topicConfig[3]}" --if-not-exists
41         else
42           JMX_PORT='' $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor ${topicConfig[2]} --partitions ${topicConfig[1]} --topic "${topicConfig[0]}" --if-not-exists
43         fi
44     done
45 fi