forked from AndreyBozhko/TaxiOptimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka-run.sh
executable file
·71 lines (47 loc) · 1.88 KB
/
kafka-run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
S3CONFIGFILE=$PWD/config/s3bucket.config
SCHEMAFILE=$PWD/config/schema_for_streaming.config
KAFKACONFIGFILE=$PWD/config/kafka.config
TOPIC=`grep TOPIC $KAFKACONFIGFILE | sed s/"TOPIC"//g | sed s/[:," "\"]//g`
NUM_PARTITIONS=`grep PARTITIONS $KAFKACONFIGFILE | sed s/[^[:digit:]]//g`
REPL_FACTOR=`grep REPL_FACTOR $KAFKACONFIGFILE | sed s/[^[:digit:]]//g`
RETENTION=`grep RETENTION $KAFKACONFIGFILE | sed s/[^[:digit:]]//g`
ZOOKEEPER_IP=`grep ZOOKEEPER $KAFKACONFIGFILE | sed s/".*_IP"//g | sed s/[" "\"]//g | sed s/^.//g | sed s/.$//g`
BROKERS_IP=`grep BROKERS $KAFKACONFIGFILE | sed s/".*_IP"//g | sed s/[" "\"]//g | sed s/^.//g | sed s/.$//g`
convert () {
ans=""
for item in `echo $1 | sed s/","/" "/g` ; do
left=`echo $item | sed s/":.*"//g`
right=`echo $item | sed s/".*:"//g`
it=`echo $left | sed s/^.//g`
ans="$ans,${!it}:$right"
done
ans=`echo $ans | sed s/^.//g`
echo $ans
}
ZOOKEEPER_IP=$(convert $ZOOKEEPER_IP)
BROKERS_IP=$(convert $BROKERS_IP)
case $1 in
--create)
kafka-topics.sh --create --zookeeper $ZOOKEEPER_IP \
--topic $TOPIC \
--partitions $NUM_PARTITIONS \
--replication-factor $REPL_FACTOR \
--config retention.ms=$RETENTION
;;
--produce)
python kafka/main_produce.py $KAFKACONFIGFILE $SCHEMAFILE $S3CONFIGFILE &
;;
--describe)
kafka-topics.sh --describe --zookeeper $ZOOKEEPER_IP --topic $TOPIC
;;
--delete)
kafka-topics.sh --delete --zookeeper $ZOOKEEPER_IP --topic $TOPIC
;;
--console-consume)
kafka-console-consumer.sh --bootstrap-server $BROKERS_IP --from-beginning --topic $TOPIC
;;
*)
echo "Usage: ./kafka-run.sh [--create|--delete|--describe|--produce|--console-consume]"
;;
esac