#!/bin/bash # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # Install and configure Apache Kafka. Since kafka is only used for # oslo.messaging notifications, setup a hybrid messaging backend. # The RPC transport backend will be amqp:// and the # Notification transport wil be kafka:// # # Environment Configuration # RPC_SERVICE - the messaging backend service for RPC # RPC_HOST - the host used to connect to the RPC messaging service. # RPC_PORT - the port used to connect to the RPC messaging service. # Defaults to 5672. # RPC_{USERNAME,PASSWORD} - for authentication with RPC messaging service. # NOTIFY_SERVICE - the messaging backend service for Notification # NOTIFY_HOST - the host used to connect to the Notification messaging service. # NOTIFY_PORT - the port used to connect to the Notification messaging service. # Defaults to 9092. # NOTIFY_{USERNAME,PASSWORD} - for authentication with Notification messaging # service. # Save trace setting XTRACE=$(set +o | grep xtrace) set +o xtrace # builds rpc transport url string function _get_rpc_transport_url { local virtual_host=$1 if [ "$RPC_SERVICE" == "rabbit" ]; then echo $(_get_rabbit_transport_url $virtual_host) elif [ -z "$RPC_USERNAME" ]; then echo "$RPC_SERVICE://$RPC_HOST:${RPC_PORT}/$virtual_host" else echo "$RPC_SERVICE://$RPC_USERNAME:$RPC_PASSWORD@$RPC_HOST:${RPC_PORT}/$virtual_host" fi } # builds notify transport url string function _get_notify_transport_url { local virtual_host=$1 if [ -z "$NOTIFY_USERNAME" ]; then echo "$NOTIFY_SERVICE://$NOTIFY_HOST:${NOTIFY_PORT}/$virtual_host" else echo "$NOTIFY_SERVICE://$NOTIFY_USERNAME:$NOTIFY_PASSWORD@$NOTIFY_HOST:${NOTIFY_PORT}/$virtual_host" fi } # override the default in devstack function _rpc_add_vhost { if [ "$RPC_SERVICE" == "rabbit" ]; then _rabbit_rpc_backend_add_vhost $@ fi # no configuration necessary for amqp backend return 0 } # Functions # ------------ # _download_kafka() - downloading kafka function _download_kafka { if [ ! -f ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz ]; then wget ${KAFKA_BASEURL}/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz \ -O ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz fi } # install packages necessary for support of the oslo.messaging kafka # driver function _install_kafka_python { # Install kafka client API pip_install_gr confluent-kafka } # _install_kafka_backend() - installing Kafka with Scala and Zookeeper function _install_kafka_backend { echo_summary "Installing kafka service" local scala_version=${SCALA_VERSION}.0 if is_ubuntu; then sudo apt-get install -y scala librdkafka1 elif is_fedora; then install_package librdkafka is_package_installed java-1.8.0-openjdk-headless || install_package java-1.8.0-openjdk-headless if [ ! -f ${FILES}/scala-${scala_version}.tar.gz ]; then wget ${SCALA_BASEURL}/scala-${scala_version}.tgz \ -O ${FILES}/scala-${scala_version}.tar.gz fi if [ ! -d ${FILES}/scala-${scala_version} ]; then tar -xvzf ${FILES}/scala-${scala_version}.tar.gz -C ${FILES} fi if [ ! -d /usr/lib/scala-${scala_version} ]; then sudo mv ${FILES}/scala-${scala_version} /usr/lib sudo ln -s /usr/lib/scala-${scala_version} /usr/lib/scala export PATH=$PATH:/usr/lib/scala/bin fi fi _download_kafka if [ ! -d ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ]; then tar -xvzf ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C ${FILES} fi if [ ! -d ${KAFKA_DEST}/kafka ]; then mkdir -p ${KAFKA_DEST} mv ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ${KAFKA_DEST}/kafka fi _install_kafka_python } # _start_kafka_backend() - starting Kafka and Zookeeper processes function _start_kafka_backend { # start Zookeeper process before starting Kafka echo_summary "Initializing and starting kafka service" ${KAFKA_DEST}/kafka/bin/zookeeper-server-start.sh -daemon ${KAFKA_DEST}/kafka/config/zookeeper.properties ${KAFKA_DEST}/kafka/bin/kafka-server-start.sh -daemon ${KAFKA_DEST}/kafka/config/server.properties } # _configure_kafka() - configuring Kafka service function _configure_kafka { # currently a no op : } # _stop_kafka() - stopping Kafka process function _stop_kafka { echo_summary "Shut down kafka service" ${KAFKA_DEST}/kafka/bin/kafka-server-stop.sh ${KAFKA_DEST}/kafka/bin/zookeeper-server-stop.sh } # _cleanup_kafka() - removing Kafka files # make sure this function is called only after calling stop_kafka() function function _cleanup_kafka { echo_summary "Clean up kafka service" rm ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz rm -rf ${KAFKA_DEST}/kafka if is_ubuntu; then uninstall_package librdkafka1 elif is_fedora; then uninstall_package librdkafka else exit_distro_not_supported "kafka installation" fi } # Set up the various configuration files used by the qpid-dispatch-router (qdr) function _configure_qdr { # the location of the configuration is /etc/qpid-dispatch local qdr_conf_file if [ -e /etc/qpid-dispatch/qdrouterd.conf ]; then qdr_conf_file=/etc/qpid-dispatch/qdrouterd.conf else exit_distro_not_supported "qdrouterd.conf file not found!" fi # ensure that the qpid-dispatch-router service can read its config sudo chmod o+r $qdr_conf_file # qdouterd.conf file customization for devstack deployment # Define attributes related to the AMQP container # Create stand alone router cat <