-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkafka-connect-cli
executable file
·146 lines (123 loc) · 3.34 KB
/
kafka-connect-cli
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
# Check required binaries: curl
CURL=$(which curl)
if [[ -z ${CURL} ]]; then
echo "curl not installed; exit."
exit 1
fi
ProgName=$(basename $0)
# functions:
# _run
# _help
# _connector
# _connector_help
# _connector_list
# _plugin
# _plugin_help
# _plugin_list
# _plugin_validate
function _run {
if [ "${DRY_RUN}" = "1" ]; then
echo $1
else
eval $1
fi
}
function _help {
echo "Usage: $ProgName <subcommand> [options]"
echo ""
echo "Subcommands:"
echo ""
echo " connector connector commands."
echo " plugin plugin commands."
echo ""
echo "For help with each subcommand, run:"
echo ""
echo " $ProgName <subcommand> -h|--help"
echo ""
echo "For Rest API documentation, see:"
echo ""
echo " https://docs.confluent.io/current/connect/references/restapi.html"
echo ""
}
# connector functions
function _connector {
subcommand=$1
case $subcommand in
"" | "-h" | "--help")
_connector_help
;;
*)
shift
_connector_${subcommand} $@
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand of $ProgName connector." >&2
echo "Run '$ProgName subject --help' for a list of known subcommands." >&2
return 1
fi
;;
esac
}
function _connector_help {
echo "Usage: $ProgName connector <subcommand> [options]"
echo ""
echo "Subcommands:"
echo " list Get a list of active connectors."
echo ""
}
function _connector_list {
_run "curl -s -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" http://$KAFKA_CONNECT_URL/connectors"
}
# plugin functions
function _plugin {
subcommand=$1
case $subcommand in
"" | "-h" | "--help")
_plugin_help
;;
*)
shift
_plugin_${subcommand} $@
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand of $ProgName plugin." >&2
echo "Run '$ProgName subject --help' for a list of known subcommands." >&2
return 1
fi
;;
esac
}
function _plugin_help {
echo "Usage: $ProgName plugin <subcommand> [options]"
echo ""
echo "Subcommands:"
echo " list Return a list of connector plugins installed in the Kafka Connect cluster."
echo " validate Validate the provided configuration values against the configuration definition."
echo ""
}
function _plugin_list {
_run "curl -s -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" http://$KAFKA_CONNECT_URL/connector-plugins"
}
function _plugin_validate {
[[ -z $1 ]] && echo "Usage: $ProgName plugin {plugin} {config}"&& return 1
[[ -z $2 ]] && echo "Usage: $ProgName plugin {plugin} {config}"&& return 1
_run "curl -s -X PUT -H \"Accept: application/json\" -H \"Content-Type: application/json\" --data $2 http://$KAFKA_CONNECT_URL/connector-plugins/$1/config/validate"
}
KAFKA_CONNECT_HOST=${KAFKA_CONNECT_HOST:-localhost}
KAFKA_CONNECT_PORT=${KAFKA_CONNECT_PORT:8083}
KAFKA_CONNECT_URL=${KAFKA_CONNECT_URL:-${KAFKA_CONNECT_HOST}:${KAFKA_CONNECT_PORT}}
DRY_RUN=${DRY_RUN:0}
subcommand=$1
case $subcommand in
"" | "-h" | "--help")
_help
;;
*)
shift
_${subcommand} $@
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand." >&2
echo "Run '$ProgName --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac