Skip to content

Commit 33a96ff

Browse files
committed
Zookeeper for DLM scenarios
In Tokyo, there was a cross project session on distributed key locking: https://etherpad.openstack.org/p/mitaka-cross-project-dlm In support of the discussion there, we'll need support for a zookeeper service in Devstack and ability to use libraries like Tooz for DLM functionality. In this review, we pick up some configuration files from monasca-api and copy the lib/template to implement the zookeeper lifecycle. Those services that need zookeeper need to add "zookeeper" in ENABLED_SERVICES. Change-Id: Icef26e5cdaa930a581e27d330e47706776a7f98f
1 parent c9f6f11 commit 33a96ff

10 files changed

Lines changed: 289 additions & 1 deletion

File tree

files/debs/zookeeper

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zookeeperd

files/rpms/zookeeper

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zookeeper

files/zookeeper/environment

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
#    http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
# implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# Modified from http://packages.ubuntu.com/saucy/zookeeperd
19+
NAME=zookeeper
20+
ZOOCFGDIR=/etc/zookeeper/conf
21+
22+
# seems, that log4j requires the log4j.properties file to be in the classpath
23+
CLASSPATH="$ZOOCFGDIR:/usr/share/java/jline.jar:/usr/share/java/log4j-1.2.jar:/usr/share/java/xercesImpl.jar:/usr/share/java/xmlParserAPIs.jar:/usr/share/java/netty.jar:/usr/share/java/slf4j-api.jar:/usr/share/java/slf4j-log4j12.jar:/usr/share/java/zookeeper.jar"
24+
25+
ZOOCFG="$ZOOCFGDIR/zoo.cfg"
26+
ZOO_LOG_DIR=/var/log/zookeeper
27+
USER=$NAME
28+
GROUP=$NAME
29+
PIDDIR=/var/run/$NAME
30+
PIDFILE=$PIDDIR/$NAME.pid
31+
SCRIPTNAME=/etc/init.d/$NAME
32+
JAVA=/usr/bin/java
33+
ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain"
34+
ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
35+
JMXLOCALONLY=false
36+
JAVA_OPTS=""

files/zookeeper/log4j.properties

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
#    http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
# implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# From http://packages.ubuntu.com/saucy/zookeeperd
19+
20+
# ZooKeeper Logging Configuration
21+
#
22+
23+
# Format is "<default threshold> (, <appender>)+
24+
25+
log4j.rootLogger=${zookeeper.root.logger}
26+
27+
# Example: console appender only
28+
# log4j.rootLogger=INFO, CONSOLE
29+
30+
# Example with rolling log file
31+
#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
32+
33+
# Example with rolling log file and tracing
34+
#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
35+
36+
#
37+
# Log INFO level and above messages to the console
38+
#
39+
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
40+
log4j.appender.CONSOLE.Threshold=INFO
41+
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
42+
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
43+
44+
#
45+
# Add ROLLINGFILE to rootLogger to get log file output
46+
# Log DEBUG level and above messages to a log file
47+
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
48+
log4j.appender.ROLLINGFILE.Threshold=WARN
49+
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/zookeeper.log
50+
51+
# Max log file size of 10MB
52+
log4j.appender.ROLLINGFILE.MaxFileSize=10MB
53+
# uncomment the next line to limit number of backup files
54+
#log4j.appender.ROLLINGFILE.MaxBackupIndex=10
55+
56+
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
57+
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
58+
59+
60+
#
61+
# Add TRACEFILE to rootLogger to get log file output
62+
# Log DEBUG level and above messages to a log file
63+
log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
64+
log4j.appender.TRACEFILE.Threshold=TRACE
65+
log4j.appender.TRACEFILE.File=${zookeeper.log.dir}/zookeeper_trace.log
66+
67+
log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
68+
### Notice we are including log4j's NDC here (%x)
69+
log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L][%x] - %m%n

files/zookeeper/myid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

files/zookeeper/zoo.cfg

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
2+
# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
#    http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
# implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# http://hadoop.apache.org/zookeeper/docs/current/zookeeperAdmin.html
18+
19+
# The number of milliseconds of each tick
20+
tickTime=2000
21+
# The number of ticks that the initial
22+
# synchronization phase can take
23+
initLimit=10
24+
# The number of ticks that can pass between
25+
# sending a request and getting an acknowledgement
26+
syncLimit=5
27+
# the directory where the snapshot is stored.
28+
dataDir=/var/lib/zookeeper
29+
# Place the dataLogDir to a separate physical disc for better performance
30+
# dataLogDir=/disk2/zookeeper
31+
32+
# the port at which the clients will connect
33+
clientPort=2181
34+
35+
# Maximum number of clients that can connect from one client
36+
maxClientCnxns=60
37+
38+
# specify all zookeeper servers
39+
# The fist port is used by followers to connect to the leader
40+
# The second one is used for leader election
41+
42+
server.0=127.0.0.1:2888:3888
43+
44+
# To avoid seeks ZooKeeper allocates space in the transaction log file in
45+
# blocks of preAllocSize kilobytes. The default block size is 64M. One reason
46+
# for changing the size of the blocks is to reduce the block size if snapshots
47+
# are taken more often. (Also, see snapCount).
48+
#preAllocSize=65536
49+
50+
# Clients can submit requests faster than ZooKeeper can process them,
51+
# especially if there are a lot of clients. To prevent ZooKeeper from running
52+
# out of memory due to queued requests, ZooKeeper will throttle clients so that
53+
# there is no more than globalOutstandingLimit outstanding requests in the
54+
# system. The default limit is 1,000.ZooKeeper logs transactions to a
55+
# transaction log. After snapCount transactions are written to a log file a
56+
# snapshot is started and a new transaction log file is started. The default
57+
# snapCount is 10,000.
58+
#snapCount=1000
59+
60+
# If this option is defined, requests will be will logged to a trace file named
61+
# traceFile.year.month.day.
62+
#traceFile=
63+
64+
# Leader accepts client connections. Default value is "yes". The leader machine
65+
# coordinates updates. For higher update throughput at thes slight expense of
66+
# read throughput the leader can be configured to not accept clients and focus
67+
# on coordination.
68+
#leaderServes=yes
69+
70+
# Autopurge every hour to avoid using lots of disk in bursts
71+
# Order of the next 2 properties matters.
72+
# autopurge.snapRetainCount must be before autopurge.purgeInterval.
73+
autopurge.snapRetainCount=3
74+
autopurge.purgeInterval=1

lib/zookeeper

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
#
3+
# lib/zookeeper
4+
# Functions to control the installation and configuration of **zookeeper**
5+
6+
# Dependencies:
7+
#
8+
# - ``functions`` file
9+
10+
# ``stack.sh`` calls the entry points in this order:
11+
#
12+
# - is_zookeeper_enabled
13+
# - install_zookeeper
14+
# - configure_zookeeper
15+
# - init_zookeeper
16+
# - start_zookeeper
17+
# - stop_zookeeper
18+
# - cleanup_zookeeper
19+
20+
# Save trace setting
21+
XTRACE=$(set +o | grep xtrace)
22+
set +o xtrace
23+
24+
25+
# Defaults
26+
# --------
27+
28+
# <define global variables here that belong to this project>
29+
30+
# Set up default directories
31+
ZOOKEEPER_DATA_DIR=$DEST/data/zookeeper
32+
ZOOKEEPER_CONF_DIR=/etc/zookeeper
33+
34+
35+
# Entry Points
36+
# ------------
37+
38+
# Test if any zookeeper service us enabled
39+
# is_zookeeper_enabled
40+
function is_zookeeper_enabled {
41+
[[ ,${ENABLED_SERVICES}, =~ ,"zookeeper", ]] && return 0
42+
return 1
43+
}
44+
45+
# cleanup_zookeeper() - Remove residual data files, anything left over from previous
46+
# runs that a clean run would need to clean up
47+
function cleanup_zookeeper {
48+
sudo rm -rf $ZOOKEEPER_DATA_DIR
49+
}
50+
51+
# configure_zookeeper() - Set config files, create data dirs, etc
52+
function configure_zookeeper {
53+
sudo cp $FILES/zookeeper/* $ZOOKEEPER_CONF_DIR
54+
sudo sed -i -e 's|.*dataDir.*|dataDir='$ZOOKEEPER_DATA_DIR'|' $ZOOKEEPER_CONF_DIR/zoo.cfg
55+
}
56+
57+
# init_zookeeper() - Initialize databases, etc.
58+
function init_zookeeper {
59+
# clean up from previous (possibly aborted) runs
60+
# create required data files
61+
sudo rm -rf $ZOOKEEPER_DATA_DIR
62+
sudo mkdir -p $ZOOKEEPER_DATA_DIR
63+
}
64+
65+
# install_zookeeper() - Collect source and prepare
66+
function install_zookeeper {
67+
install_package zookeeperd
68+
}
69+
70+
# start_zookeeper() - Start running processes, including screen
71+
function start_zookeeper {
72+
start_service zookeeper
73+
}
74+
75+
# stop_zookeeper() - Stop running processes (non-screen)
76+
function stop_zookeeper {
77+
stop_service zookeeper
78+
}
79+
80+
# Restore xtrace
81+
$XTRACE
82+
83+
# Tell emacs to use shell-script-mode
84+
## Local variables:
85+
## mode: shell-script
86+
## End:

stack.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ source $TOP_DIR/lib/heat
539539
source $TOP_DIR/lib/neutron-legacy
540540
source $TOP_DIR/lib/ldap
541541
source $TOP_DIR/lib/dstat
542+
source $TOP_DIR/lib/zookeeper
542543

543544
# Extras Source
544545
# --------------
@@ -729,6 +730,11 @@ run_phase stack pre-install
729730

730731
install_rpc_backend
731732

733+
if is_service_enabled zookeeper; then
734+
cleanup_zookeeper
735+
configure_zookeeper
736+
init_zookeeper
737+
fi
732738
if is_service_enabled $DATABASE_BACKENDS; then
733739
install_database
734740
fi
@@ -968,6 +974,15 @@ save_stackenv $LINENO
968974
start_dstat
969975

970976

977+
# Zookeeper
978+
# -----
979+
980+
# zookeeper for use with tooz for Distributed Lock Management capabilities etc.,
981+
if is_service_enabled zookeeper; then
982+
start_zookeeper
983+
fi
984+
985+
971986
# Keystone
972987
# --------
973988

stackrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if ! isset ENABLED_SERVICES ; then
6969
# Dashboard
7070
ENABLED_SERVICES+=,horizon
7171
# Additional services
72-
ENABLED_SERVICES+=,rabbit,tempest,mysql,dstat
72+
ENABLED_SERVICES+=,rabbit,tempest,mysql,dstat,zookeeper
7373
fi
7474

7575
# SQLAlchemy supports multiple database drivers for each database server

unstack.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ source $TOP_DIR/lib/heat
6969
source $TOP_DIR/lib/neutron-legacy
7070
source $TOP_DIR/lib/ldap
7171
source $TOP_DIR/lib/dstat
72+
source $TOP_DIR/lib/zookeeper
7273

7374
# Extras Source
7475
# --------------
@@ -172,6 +173,10 @@ if is_service_enabled dstat; then
172173
stop_dstat
173174
fi
174175

176+
if is_service_enabled zookeeper; then
177+
stop_zookeeper
178+
fi
179+
175180
# Clean up the remainder of the screen processes
176181
SCREEN=$(which screen)
177182
if [[ -n "$SCREEN" ]]; then

0 commit comments

Comments
 (0)