-
Notifications
You must be signed in to change notification settings - Fork 0
/
connector-init.sh
36 lines (33 loc) · 1.39 KB
/
connector-init.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
#!/bin/bash
# Wait for Kafka Connect listener
echo "Waiting for Kafka Connect to start listening on $CONNECT_REST_HOST_NAME:$CONNECT_REST_PORT"
while : ; do
curl_status=$(curl -s -o /dev/null -w %{http_code} http://$CONNECT_REST_HOST_NAME:$CONNECT_REST_PORT/connectors)
echo -e $(date) " Kafka Connect listener HTTP state: " $curl_status " (waiting for 200)"
if [ $curl_status -eq 200 ] ; then
break
fi
sleep 5
done
json_files=`ls /opt/kafka-connect/connectors/*.json`
if [ -z $json_files ] ; then
echo "can't found json files in /opt/kafka-connect/connectors. ##### exit #####"
kill 1
fi
for entry in $json_files
do
connector_name=`basename $entry|cut -d'.' -f1`
echo "try create connector[$connector_name]"
curl_status=$(curl -s -o /dev/null -w %{http_code} -X PUT http://$CONNECT_REST_HOST_NAME:$CONNECT_REST_PORT/connectors/$connector_name/config \
-H 'Content-Type: application/json; charset=utf-8' \
-d "@$entry")
if [ ! $curl_status -eq 200 ] ; then
echo "create connector[$connector_name] unsuccessfully. response status code: $curl_status . ##### exit #####"
kill 1
else
echo "create connector[$connector_name] successfully"
fi
done
echo "###################################################"
echo "######## Connectors Initialize Over ###############"
echo "###################################################"