-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate-topic.sh
executable file
·100 lines (81 loc) · 2.28 KB
/
create-topic.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
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
set -e
#############################################################################################
#
# This script will verify that you can create and delete topics on your Kafka instance,
# using the RHOAS CLI and OpenShift Streams API by performing the following actions:
#
# - Login to the rhoas CLI and OpenShift Streams Control Plane usig the provided credentials
# - Select the given Kafka instance as the instance to performa actions on.
# - Create a topic.
# - Verify that the topic exists by retrieving the topic information.
# - Delete the topic.
#
#############################################################################################
# Source function library.
if [ -f /etc/init.d/functions ]
then
. /etc/init.d/functions
fi
################################################ Parse input parameters #############################################
function usage {
echo "\n"
echo "Usage: create-topic.sh [args...]"
echo "where args include:"
echo " -k The name of the Kafka instance you want to use"
echo " -t The name of the topic to be created."
}
#Parse the params
while getopts ":k:t:h" opt; do
case $opt in
k)
KAFKA_NAME=$OPTARG
;;
t)
TOPIC_NAME=$OPTARG
;;
h)
usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
PARAMS_NOT_OK=false
#Check params
if [ -z "$KAFKA_NAME" ]
then
echo "No Kafka name specified!"
PARAMS_NOT_OK=true
fi
if [ -z "$TOPIC_NAME" ]
then
echo "No topic name specified!"
PARAMS_NOT_OK=true
fi
if $PARAMS_NOT_OK
then
usage
exit 1
fi
################################################ Setup params. #############################################
#Load kafka functions.
source ./kafka.sh
################################################ Run topic creation health check. #############################################
startHealthCheck
checkRhoasCliAvailable
login
useKafka $KAFKA_NAME
createTopic $TOPIC_NAME
echo "Waiting for topic to be created."
sleep 5
describeTopic $TOPIC_NAME
echo "Cleaning up topic."
deleteTopic $TOPIC_NAME
completeHealthCheck