openreplay/scripts/helm/helm/database-migrate/files/kafka.sh
2021-12-18 21:11:18 +05:30

41 lines
1 KiB
Bash

#!/bin/bash
set -e
topics=(
"raw"
"raw-ios"
"trigger"
"cache"
"analytics"
)
touch /tmp/config.txt
if [[ $KAFKA_SSL == "true" ]]; then
echo 'securty.protocol=SSL' > /tmp/config.txt
fi
function init() {
echo "Initializing kafka"
for topic in ${topics[*]}; do
echo "Creating topic: $topic"
# TODO: Have to check an idempotent way of creating topics.
kafka-topics.sh --create --bootstrap-server ${KAFKA_HOST}:${KAFKA_PORT} --replication-factor 2 --partitions 16 --topic ${topic} --command-config /tmp/config.txt || true
kafka-configs.sh --bootstrap-server ${KAFKA_HOST}:${KAFKA_PORT} --entity-type topics --alter --add-config retention.ms=3456000000 --entity-name=${topic} --command-config /tmp/config.txt || true
done
}
# /bin/bash kafka.sh migrate $migration_versions
case "$1" in
migrate)
init
;;
init)
init
;;
*)
echo "Unknown operation for kafka migration; exiting."
exit 1
;;
esac