summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Smith <ansmith@redhat.com>2017-05-21 11:15:01 -0400
committerAndrew Smith <ansmith@redhat.com>2017-05-22 13:50:20 -0400
commit05a09eb2cce0019c74394bf6e3141897cc348c01 (patch)
tree02cea28311182a0a3b91bcecd98a372acfd7c8af
parent22851398e68ba4feec466cd825ad1512cfae0c5b (diff)
Setup RPC and Notification hybrid messaging backends
Notes
Notes (review): Code-Review+2: Mehdi Abaakouk (sileht) <sileht@redhat.com> Code-Review+2: Ken Giusti <kgiusti@gmail.com> Workflow+1: Ken Giusti <kgiusti@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 23 May 2017 18:26:22 +0000 Reviewed-on: https://review.openstack.org/466539 Project: openstack/devstack-plugin-kafka Branch: refs/heads/master
-rw-r--r--devstack/plugin.sh366
-rw-r--r--devstack/settings14
-rw-r--r--tox.ini2
3 files changed, 343 insertions, 39 deletions
diff --git a/devstack/plugin.sh b/devstack/plugin.sh
index f7aef38..89074b6 100644
--- a/devstack/plugin.sh
+++ b/devstack/plugin.sh
@@ -1,38 +1,81 @@
1#!/bin/bash 1#!/bin/bash
2
3# devstack/plugin.sh
4# Functions to install and configure Apache Kafka
5# 2#
6# Dependencies: 3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership.
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License. You may obtain
10# a copy of the License at
7# 11#
8# - ``functions`` file 12# http://www.apache.org/licenses/LICENSE-2.0
9# 13#
10# ``stack.sh`` calls the entry points in this order: 14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17# License for the specific language governing permissions and limitations
18# under the License.
11# 19#
12# - download_kafka 20
13# - install_kafka 21# Install and configure Apache Kafka. Since kafka is only used for
14# - configure_kafka 22# oslo.messaging notifications, setup a hybrid messaging backend.
15# - init_kafka 23# The RPC transport backend will be amqp:// and the
16# - stop_kafka 24# Notification transport wil be kafka://
17# - cleanup_kafka 25#
26# Environment Configuration
27# RPC_HOST - the host used to connect to the RPC messaging service.
28# RPC_PORT - the port used to connect to the RPC messaging service.
29# Defaults to 5672.
30# RPC_{USERNAME,PASSWORD} - for authentication with RPC messaging service.
31# NOTIFY_HOST - the host used to connect to the Notification messaging service.
32# NOTIFY_PORT - the port used to connect to the Notification messaging service.
33# Defaults to 9092.
34# NOTIFY_{USERNAME,PASSWORD} - for authentication with Notification messaging
35# service.
18 36
19# Save trace setting 37# Save trace setting
20XTRACE=$(set +o | grep xtrace) 38XTRACE=$(set +o | grep xtrace)
21set +o xtrace 39set +o xtrace
22 40
41# builds rpc transport url string
42function _get_rpc_transport_url {
43 if [ -z "$RPC_USERNAME" ]; then
44 echo "amqp://$RPC_HOST:${RPC_PORT}/"
45 else
46 echo "amqp://$RPC_USERNAME:$RPC_PASSWORD@$RPC_HOST:${RPC_PORT}/"
47 fi
48}
49
50# builds notify transport url string
51function _get_notify_transport_url {
52 if [ -z "$NOTIFY_USERNAME" ]; then
53 echo "kafka://$NOTIFY_HOST:${NOTIFY_PORT}/"
54 else
55 echo "kafka://$NOTIFY_USERNAME:$NOTIFY_PASSWORD@$NOTIFY_HOST:${NOTIFY_PORT}/"
56 fi
57}
58
23# Functions 59# Functions
24# ------------ 60# ------------
25# download_kafka() - downloading kafka 61# _download_kafka() - downloading kafka
26function download_kafka { 62function _download_kafka {
27 if [ ! -f ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz ]; then 63 if [ ! -f ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz ]; then
28 wget ${KAFKA_BASEURL}/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz \ 64 wget ${KAFKA_BASEURL}/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz \
29 -O ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz 65 -O ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz
30 fi 66 fi
31} 67}
32 68
33# install_kafka() - installing Kafka with Scala and Zookeeper 69# install packages necessary for support of the oslo.messaging kafka
34function install_kafka { 70# driver
71function _install_kafka_python {
72 # Install kafka client API
73 pip_install_gr kafka-python
74}
35 75
76# _install_kafka_backend() - installing Kafka with Scala and Zookeeper
77function _install_kafka_backend {
78 echo_summary "Installing kafka service"
36 local scala_version=${SCALA_VERSION}.0 79 local scala_version=${SCALA_VERSION}.0
37 80
38 if is_ubuntu; then 81 if is_ubuntu; then
@@ -57,7 +100,7 @@ function install_kafka {
57 fi 100 fi
58 fi 101 fi
59 102
60 download_kafka 103 _download_kafka
61 104
62 if [ ! -d ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ]; then 105 if [ ! -d ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ]; then
63 tar -xvzf ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C ${FILES} 106 tar -xvzf ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C ${FILES}
@@ -66,58 +109,309 @@ function install_kafka {
66 mkdir -p ${KAFKA_DEST} 109 mkdir -p ${KAFKA_DEST}
67 mv ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ${KAFKA_DEST}/kafka 110 mv ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ${KAFKA_DEST}/kafka
68 fi 111 fi
112
113 _install_kafka_python
69} 114}
70 115
71# init_kafka() - starting Kafka and Zookeeper processes 116# _start_kafka_backend() - starting Kafka and Zookeeper processes
72function init_kafka { 117function _start_kafka_backend {
73 # start Zookeeper process before starting Kafka 118 # start Zookeeper process before starting Kafka
119 echo_summary "Initializing and starting kafka service"
74 ${KAFKA_DEST}/kafka/bin/zookeeper-server-start.sh -daemon ${KAFKA_DEST}/kafka/config/zookeeper.properties 120 ${KAFKA_DEST}/kafka/bin/zookeeper-server-start.sh -daemon ${KAFKA_DEST}/kafka/config/zookeeper.properties
75 ${KAFKA_DEST}/kafka/bin/kafka-server-start.sh -daemon ${KAFKA_DEST}/kafka/config/server.properties 121 ${KAFKA_DEST}/kafka/bin/kafka-server-start.sh -daemon ${KAFKA_DEST}/kafka/config/server.properties
76} 122}
77 123
78# configure_kafka() - configuring Kafka service 124# _configure_kafka() - configuring Kafka service
79function configure_kafka { 125function _configure_kafka {
80 # currently a no op 126 # currently a no op
81 : 127 :
82} 128}
83 129
84# stop_kafka() - stopping Kafka process 130# _stop_kafka() - stopping Kafka process
85function stop_kafka { 131function _stop_kafka {
132 echo_summary "Shut down kafka service"
86 ${KAFKA_DEST}/kafka/bin/kafka-server-stop.sh 133 ${KAFKA_DEST}/kafka/bin/kafka-server-stop.sh
87 ${KAFKA_DEST}/kafka/bin/zookeeper-server-stop.sh 134 ${KAFKA_DEST}/kafka/bin/zookeeper-server-stop.sh
88} 135}
89 136
90# cleanup_kafka() - removing Kafka files 137# _cleanup_kafka() - removing Kafka files
91# make sure this function is called only after calling stop_kafka() function 138# make sure this function is called only after calling stop_kafka() function
92function cleanup_kafka { 139function _cleanup_kafka {
140 echo_summary "Clean up kafka service"
93 rm ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz 141 rm ${FILES}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz
94 rm -rf ${KAFKA_DEST}/kafka 142 rm -rf ${KAFKA_DEST}/kafka
95} 143}
96 144
145# Set up the various configuration files used by the qpid-dispatch-router (qdr)
146function _configure_qdr {
147
148 # the location of the configuration is /etc/qpid-dispatch
149 local qdr_conf_file
150 if [ -e /etc/qpid-dispatch/qdrouterd.conf ]; then
151 qdr_conf_file=/etc/qpid-dispatch/qdrouterd.conf
152 else
153 exit_distro_not_supported "qdrouterd.conf file not found!"
154 fi
155
156 # ensure that the qpid-dispatch-router service can read its config
157 sudo chmod o+r $qdr_conf_file
158
159 # qdouterd.conf file customization for devstack deployment
160 # Define attributes related to the AMQP container
161 # Create stand alone router
162 cat <<EOF | sudo tee $qdr_conf_file
163router {
164 mode: standalone
165 id: Router.A
166 workerThreads: 4
167 saslConfigPath: /etc/sasl2
168 saslConfigName: qdrouterd
169 debugDump: /opt/stack/amqp1
170}
171
172EOF
173
174 # Create a listener for incoming connect to the router
175 cat <<EOF | sudo tee --append $qdr_conf_file
176listener {
177 addr: 0.0.0.0
178 port: ${RPC_PORT}
179 role: normal
180EOF
181 if [ -z "$RPC_USERNAME" ]; then
182 #no user configured, so disable authentication
183 cat <<EOF | sudo tee --append $qdr_conf_file
184 authenticatePeer: no
185}
186
187EOF
188 else
189 # configure to use PLAIN authentication
190 if [ -z "$RPC_PASSWORD" ]; then
191 read_password RPC_PASSWORD "ENTER A PASSWORD FOR QPID DISPATCH USER $RPC_USERNAME"
192 fi
193 cat <<EOF | sudo tee --append $qdr_conf_file
194 authenticatePeer: yes
195}
196
197EOF
198 # Add user to SASL database
199 local sasl_conf_file=/etc/sasl2/qdrouterd.conf
200 cat <<EOF | sudo tee $sasl_conf_file
201pwcheck_method: auxprop
202auxprop_plugin: sasldb
203sasldb_path: /var/lib/qdrouterd/qdrouterd.sasldb
204mech_list: PLAIN
205sql_select: dummy select
206EOF
207 local sasl_db
208 sasl_db=`sudo grep sasldb_path $sasl_conf_file | cut -f 2 -d ":" | tr -d [:blank:]`
209 if [ ! -e $sasl_db ]; then
210 sudo mkdir -p -m 755 `dirname $sasl_db`
211 fi
212 echo $RPC_PASSWORD | sudo saslpasswd2 -c -p -f $sasl_db $RPC_USERNAME
213 sudo chmod o+r $sasl_db
214 fi
215
216 # Create fixed address prefixes
217 cat <<EOF | sudo tee --append $qdr_conf_file
218address {
219 prefix: unicast
220 distribution: closest
221}
222
223address {
224 prefix: exclusive
225 distribution: closest
226}
227
228address {
229 prefix: broadcast
230 distribution: multicast
231}
232
233address {
234 prefix: openstack.org/om/rpc/multicast
235 distribution: multicast
236}
237
238address {
239 prefix: openstack.org/om/rpc/unicast
240 distribution: closest
241}
242
243address {
244 prefix: openstack.org/om/rpc/anycast
245 distribution: balanced
246}
247
248address {
249 prefix: openstack.org/om/notify/multicast
250 distribution: multicast
251}
252
253address {
254 prefix: openstack.org/om/notify/unicast
255 distribution: closest
256}
257
258address {
259 prefix: openstack.org/om/notify/anycast
260 distribution: balanced
261}
262
263EOF
264
265 local log_file=$LOGDIR/qdrouterd.log
266
267 sudo touch $log_file
268 sudo chmod a+rw $log_file # qdrouterd user can write to it
269
270 # Create log file configuration
271 cat <<EOF | sudo tee --append $qdr_conf_file
272log {
273 module: DEFAULT
274 enable: info+
275 output: $log_file
276}
277
278EOF
279
280}
281
282# install packages necessary for support of the oslo.messaging AMQP
283# 1.0 driver
284function _install_pyngus {
285 # Install pyngus client API
286 if is_fedora; then
287 # TODO(kgiusti) due to a bug in the way pip installs wheels,
288 # do not let pip install the proton python bindings as it will
289 # put them in the wrong path:
290 # https://github.com/pypa/pip/issues/2940
291 install_package python-qpid-proton
292 elif is_ubuntu; then
293 # ditto
294 install_package python-qpid-proton
295 fi
296 pip_install_gr pyngus
297}
298
299# install and configure the amqp1 backend
300# dispatch-router for hybrid deployment with kakfa
301function _install_qdr_backend {
302 echo_summary "Installing amqp1 service qdrouterd"
303 if is_fedora; then
304 # expects epel is already added to the yum repos
305 install_package cyrus-sasl-lib
306 install_package cyrus-sasl-plain
307 install_package qpid-dispatch-router
308 elif is_ubuntu; then
309 install_package sasl2-bin
310 # qdrouterd and proton only available via the qpid PPA
311 sudo add-apt-repository -y ppa:qpid/released
312 #sudo apt-get update
313 REPOS_UPDATED=False
314 update_package_repo
315 install_package qdrouterd
316 else
317 exit_distro_not_supported "amqp1 qdrouterd installation"
318 fi
319
320 _install_pyngus
321 _configure_qdr
322}
323
324function _start_qdr_backend {
325 echo_summary "Starting qdrouterd backend"
326 # restart, since qdrouterd may already be running
327 restart_service qdrouterd
328}
329
330function _stop_qdr_backend {
331 echo_summary "Stopping qdrouterd backend"
332 stop_service qdrouterd
333}
334
335# remove packages used by oslo.messaging AMQP 1.0 driver
336function _remove_pyngus {
337 # TODO(ansmith) no way to pip uninstall?
338 # pip_install_gr pyngus
339 :
340}
341
342function _cleanup_qdr_backend {
343 if is_fedora; then
344 uninstall_package qpid-dispatch-router
345 # TODO(ansmith) can we pull these, or will that break other
346 # packages that depend on them?
347
348 # install_package cyrus_sasl_lib
349 # install_package cyrus_sasl_plain
350 elif is_ubuntu; then
351 uninstall_package qdrouterd
352 # install_package sasl2-bin
353 else
354 exit_distro_not_supported "amqp1 qdrouterd installation"
355 fi
356
357 _remove_pyngus
358}
359
360if is_service_enabled kafka; then
361
362 # Note: this is the only tricky part about out of tree
363 # oslo.messaging plugins, you must overwrite the functions
364 # so that the correct settings files are made.
365 function iniset_rpc_backend {
366 local package=$1
367 local file=$2
368 local section=${3:-DEFAULT}
369 iniset $file $section transport_url $(_get_rpc_transport_url)
370 iniset $file oslo_messaging_notifications transport_url $(_get_notify_transport_url)
371 }
372 function get_transport_url {
373 # TODO (ansmith) introduce separate get_*_transport calls in devstak
374 _get_rpc_transport_url $@
375 }
376 function get_notification_url {
377 _get_notify_transport_url $@
378 }
379 export -f iniset_rpc_backend
380 export -f get_transport_url
381 export -f get_notification_url
382fi
383
97# check for kafka service 384# check for kafka service
98if is_service_enabled devstack-plugin-kafka; then 385if is_service_enabled kafka; then
99 if [[ "$1" == "source" ]]; then 386 if [[ "$1" == "source" ]]; then
100 # Initial source 387 # Initial source
101 source $TOP_DIR/lib/kafka 388 source $TOP_DIR/lib/kafka
102 389
390 elif [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
391 # nothing needed here
392 :
393
103 elif [[ "$1" == "stack" && "$2" == "install" ]]; then 394 elif [[ "$1" == "stack" && "$2" == "install" ]]; then
104 # Perform installation of service source 395 # Install and configure the messaging services
105 echo_summary "Installing kafka" 396 _install_kafka_backend
106 install_kafka 397 _install_qdr_backend
107 398
108 echo_summary "Initializing kafka" 399 elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
109 init_kafka 400 # Start the messaging service processes, this happens before
401 # any services start
402 _start_kafka_backend
403 _start_qdr_backend
110 404
111 elif [[ "$1" == "unstack" ]]; then 405 elif [[ "$1" == "unstack" ]]; then
112 # Shut down kafka services 406 # Shut down messaging services
113 echo_summary "Shut down kafka service" 407 _stop_kafka
114 stop_kafka 408 _stop_qdr
115 409
116 elif [[ "$1" == "clean" ]]; then 410 elif [[ "$1" == "clean" ]]; then
117 # Remove state and transient data 411 # Remove state and transient data
118 # Remember clean.sh first calls unstack.sh 412 # Remember clean.sh first calls unstack.sh
119 echo_summary "Clean up kafka service" 413 _cleanup_kafka
120 cleanup_kafka 414 _cleanup_qdr
121 fi 415 fi
122fi 416fi
123 417
diff --git a/devstack/settings b/devstack/settings
index 52d8002..fc297fd 100644
--- a/devstack/settings
+++ b/devstack/settings
@@ -6,9 +6,19 @@ enable_service kafka
6KAFKA_DEST=${KAFKA_DEST:-/opt/stack/devstack-plugin-kafka} 6KAFKA_DEST=${KAFKA_DEST:-/opt/stack/devstack-plugin-kafka}
7 7
8# Specify Kafka version 8# Specify Kafka version
9KAFKA_VERSION=${KAFKA_VERSION:-0.9.0.1} 9KAFKA_VERSION=${KAFKA_VERSION:-0.10.2.1}
10KAFKA_BASEURL=${KAFKA_BASEURL:-http://www.us.apache.org/dist/kafka} 10KAFKA_BASEURL=${KAFKA_BASEURL:-http://www.us.apache.org/dist/kafka}
11 11
12# Specify Scala version 12# Specify Scala version
13SCALA_VERSION=${SCALA_VERSION:-2.10} 13SCALA_VERSION=${SCALA_VERSION:-2.12}
14SCALA_BASEURL=${SCALA_BASEURL:-http://www.scala-lang.org/files/archive} 14SCALA_BASEURL=${SCALA_BASEURL:-http://www.scala-lang.org/files/archive}
15
16# RPC
17RPC_HOST=${RPC_HOST:-$SERVICE_HOST}
18RPC_PORT=${RPC_PORT:-5672}
19
20# Notify
21NOTIFY_HOST=${NOTIFY_HOST:-$SERVICE_HOST}
22NOTIFY_PORT=${NOTIFY_PORT:-9092}
23
24disable_service rabbit
diff --git a/tox.ini b/tox.ini
index 8e75f0d..4c6b332 100644
--- a/tox.ini
+++ b/tox.ini
@@ -22,4 +22,4 @@ commands = bash -c "find {toxinidir} \
22 -name functions\* -or \ 22 -name functions\* -or \
23 -wholename \*/lib/\* \ 23 -wholename \*/lib/\* \
24 \) \ 24 \) \
25 -print0 | xargs -0 bashate -v" 25 -print0 | xargs -0 bashate -v -iE006"