Skip to content

Commit 36d9c69

Browse files
author
Daniil Fedotov
committed
Merge branch 'master' into rabbitmq-server-591
2 parents 20a2d28 + 71a7cc4 commit 36d9c69

16 files changed

+141
-45
lines changed

.travis.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
sudo: false
2+
services:
3+
- docker
24
language: erlang
35
notifications:
46
email:
@@ -11,14 +13,20 @@ otp_release:
1113
- "R16B03-1"
1214
- "17.5"
1315
- "18.0"
16+
env:
17+
matrix:
18+
- GROUP=1 GROUP=2
1419

1520
# The checkout made by Travis is a "detached HEAD". We switch back
1621
# to a tag or a branch. This pleases our git_rmq fetch method in
1722
# rabbitmq-components.mk and the proper tag/branch is selected in
1823
# dependencies too.
19-
before_script: (test "$TRAVIS_TAG" && git checkout "$TRAVIS_TAG") || (test "$TRAVIS_BRANCH" && git checkout "$TRAVIS_BRANCH")
24+
before_script:
25+
- ([ "${GROUP}" = "1" ] && ((test "$TRAVIS_TAG" && git checkout "$TRAVIS_TAG") || (test "$TRAVIS_BRANCH" && git checkout "$TRAVIS_BRANCH")) || /bin/true)
2026

21-
script: travis_wait make tests
27+
script:
28+
- ([ "${GROUP}" = "1" ] && travis_wait make tests)
29+
- ([ "${GROUP}" = "2" ] && sh ./scripts/travis_test_ocf_ra.sh)
2230

2331
cache:
2432
apt: true

docs/README-for-packages

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ An example configuration file is provided in the same directory as
1818
this README. Copy it to /etc/rabbitmq/rabbitmq.config to use it. The
1919
RabbitMQ server must be restarted after changing the configuration
2020
file.
21+
22+
An example policy file for HA queues is provided in the same directory
23+
as this README. Copy and chmod +x it to
24+
/usr/local/sbin/set_rabbitmq_policy to use it with the Pacemaker OCF RA.

docs/rabbitmq.conf.example

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,13 @@
402402
##
403403

404404
# QA: Maybe use IP type like in tcp_listener?
405-
# management.listeners.port = 12345
406-
# management.listeners.ip = 127.0.0.1
407-
# management.listeners.ssl = true
405+
# management.listener.port = 12345
406+
# management.listener.ip = 127.0.0.1
407+
# management.listener.ssl = true
408408

409-
# management.listeners.ssl_opts.cacertfile = /path/to/cacert.pem
410-
# management.listeners.ssl_opts.certfile = /path/to/cert.pem
411-
# management.listeners.ssl_opts.keyfile = /path/to/key.pem
409+
# management.listener.ssl_opts.cacertfile = /path/to/cacert.pem
410+
# management.listener.ssl_opts.certfile = /path/to/cert.pem
411+
# management.listener.ssl_opts.keyfile = /path/to/key.pem
412412

413413
## One of 'basic', 'detailed' or 'none'. See
414414
## http://www.rabbitmq.com/management.html#fine-stats for more details.

scripts/set_rabbitmq_policy.sh renamed to docs/set_rabbitmq_policy.sh.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
# cluster start up. It is a convenient place to set your cluster
33
# policy here, for example:
44
# ${OCF_RESKEY_ctl} set_policy ha-all "." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' --apply-to all --priority 0
5-

packaging/RPMS/Fedora/rabbitmq-server.spec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ RabbitMQ is an open source multi-protocol messaging broker.
2626
%define _rabbit_server_ocf scripts/rabbitmq-server.ocf
2727
%define _plugins_state_dir %{_localstatedir}/lib/rabbitmq/plugins
2828
%define _rabbit_server_ha_ocf scripts/rabbitmq-server-ha.ocf
29-
%define _set_rabbitmq_policy_sh scripts/set_rabbitmq_policy.sh
3029

3130

3231
%define _maindir %{buildroot}%{_rabbit_erllibdir}
@@ -51,7 +50,6 @@ mkdir -p %{buildroot}%{_localstatedir}/log/rabbitmq
5150
install -p -D -m 0755 %{S:1} %{buildroot}%{_initrddir}/rabbitmq-server
5251
install -p -D -m 0755 %{_rabbit_server_ocf} %{buildroot}%{_exec_prefix}/lib/ocf/resource.d/rabbitmq/rabbitmq-server
5352
install -p -D -m 0755 %{_rabbit_server_ha_ocf} %{buildroot}%{_exec_prefix}/lib/ocf/resource.d/rabbitmq/rabbitmq-server-ha
54-
install -p -D -m 0644 %{_set_rabbitmq_policy_sh} %{buildroot}%{_exec_prefix}/lib/ocf/resource.d/rabbitmq/set_rabbitmq_policy.sh.example
5553
install -p -D -m 0644 %{S:2} %{buildroot}%{_sysconfdir}/logrotate.d/rabbitmq-server
5654

5755
mkdir -p %{buildroot}%{_sysconfdir}/rabbitmq
@@ -127,6 +125,7 @@ done
127125
%doc LICENSE*
128126
%doc README
129127
%doc docs/rabbitmq.config.example
128+
%doc docs/set_rabbitmq_policy.sh.example
130129

131130
%clean
132131
rm -rf %{buildroot}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
docs/rabbitmq.config.example
2+
docs/set_rabbitmq_policy.sh.example

packaging/debs/Debian/debian/rules

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ override_dh_auto_install:
4949
$(DEB_DESTDIR)$(PREFIX)/lib/ocf/resource.d/rabbitmq/rabbitmq-server
5050
install -p -D -m 0755 scripts/rabbitmq-server-ha.ocf \
5151
$(DEB_DESTDIR)$(PREFIX)/lib/ocf/resource.d/rabbitmq/rabbitmq-server-ha
52-
install -p -D -m 0644 scripts/set_rabbitmq_policy.sh \
53-
$(DEB_DESTDIR)$(PREFIX)/lib/ocf/resource.d/rabbitmq/set_rabbitmq_policy.sh.example
5452

5553
rm $(DEB_DESTDIR)$(RMQ_ERLAPP_DIR)/LICENSE* \
5654
$(DEB_DESTDIR)$(RMQ_ERLAPP_DIR)/INSTALL

scripts/rabbitmq-defaults

100644100755
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ ADVANCED_CONFIG_FILE=${SYS_PREFIX}/etc/rabbitmq/advanced
4343
SCHEMA_DIR=${RABBITMQ_HOME}/priv/schema
4444

4545
PLUGINS_DIR="${RABBITMQ_HOME}/plugins"
46-
IO_THREAD_POOL_SIZE=64
4746

4847
CONF_ENV_FILE=${SYS_PREFIX}/etc/rabbitmq/rabbitmq-env.conf

scripts/rabbitmq-server

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,23 @@ fi
128128
# there is no other way of preventing their expansion.
129129
set -f
130130

131+
# Lazy initialization of threed pool size - if it wasn't set
132+
# explicitly. This parameter is only needed when server is starting,
133+
# so it makes no sense to do this calculations in rabbitmq-env or
134+
# rabbitmq-defaults scripts.
135+
ensure_thread_pool_size() {
136+
if [ -z "${RABBITMQ_IO_THREAD_POOL_SIZE}" ]; then
137+
RABBITMQ_IO_THREAD_POOL_SIZE=$(
138+
${ERL_DIR}erl -pa "$RABBITMQ_EBIN_ROOT" \
139+
-boot "${CLEAN_BOOT_FILE}" \
140+
-noinput \
141+
-s rabbit_misc report_default_thread_pool_size
142+
)
143+
fi
144+
}
145+
131146
start_rabbitmq_server() {
147+
ensure_thread_pool_size
132148
check_start_params &&
133149
RABBITMQ_CONFIG_FILE=$RABBITMQ_CONFIG_FILE \
134150
exec ${ERL_DIR}erl \

scripts/rabbitmq-server-ha.ocf

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#
1414
# See usage() function below for more details ...
1515
#
16-
# Note that the script uses set_rabbitmq_policy.sh script located in the
17-
# same directory to setup RabbitMQ policies.
16+
# Note that the script uses an external file to setup RabbitMQ policies
17+
# so make sure to create it from an example shipped with the package.
1818
#
1919
#######################################################################
2020
# Initialization:
@@ -46,6 +46,7 @@ OCF_RESKEY_erlang_cookie_file_default="/var/lib/rabbitmq/.erlang.cookie"
4646
OCF_RESKEY_use_fqdn_default=false
4747
OCF_RESKEY_fqdn_prefix_default=""
4848
OCF_RESKEY_max_rabbitmqctl_timeouts_default=3
49+
OCF_RESKEY_policy_file_default="/usr/local/sbin/set_rabbitmq_policy"
4950

5051
: ${HA_LOGTAG="lrmd"}
5152
: ${HA_LOGFACILITY="daemon"}
@@ -66,6 +67,7 @@ OCF_RESKEY_max_rabbitmqctl_timeouts_default=3
6667
: ${OCF_RESKEY_use_fqdn=${OCF_RESKEY_use_fqdn_default}}
6768
: ${OCF_RESKEY_fqdn_prefix=${OCF_RESKEY_fqdn_prefix_default}}
6869
: ${OCF_RESKEY_max_rabbitmqctl_timeouts=${OCF_RESKEY_max_rabbitmqctl_timeouts_default}}
70+
: ${OCF_RESKEY_policy_file=${OCF_RESKEY_policy_file_default}}
6971

7072
#######################################################################
7173

@@ -288,6 +290,14 @@ If too many timeouts happen in a raw, the monitor call will return with error.
288290
<content type="string" default="${OCF_RESKEY_max_rabbitmqctl_timeouts_default}" />
289291
</parameter>
290292
293+
<parameter name="policy_file" unique="0" required="0">
294+
<longdesc lang="en">
295+
A path to the shell script to setup RabbitMQ policies
296+
</longdesc>
297+
<shortdesc lang="en">A policy file path</shortdesc>
298+
<content type="string" default="${OCF_RESKEY_policy_file_default}" />
299+
</parameter>
300+
291301
$EXTENDED_OCF_PARAMS
292302
293303
</parameters>
@@ -668,8 +678,8 @@ reset_mnesia() {
668678
# remove mnesia files, if required
669679
if $make_amnesia ; then
670680
kill_rmq_and_remove_pid
671-
ocf_run rm -rf "${MNESIA_FILES}/*"
672-
ocf_log warn "${LH} Mnesia files appear corrupted and have been removed."
681+
ocf_run rm -rf "${MNESIA_FILES}"
682+
ocf_log warn "${LH} Mnesia files appear corrupted and have been removed from ${MNESIA_FILES}."
673683
fi
674684
# always return OCF SUCCESS
675685
return $OCF_SUCCESS
@@ -2098,8 +2108,7 @@ action_promote() {
20982108
exit $OCF_FAILED_MASTER
20992109
fi
21002110

2101-
local set_policy_path="$(dirname $0)/set_rabbitmq_policy.sh"
2102-
[ -f $set_policy_path ] && . $set_policy_path
2111+
[ -f "${OCF_RESKEY_policy_file}" ] && . "${OCF_RESKEY_policy_file}"
21032112

21042113
# create timestamp file
21052114
nowtime="$(now)"

scripts/rabbitmq-server.bat

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ if "!RABBITMQ_NODE_ONLY!"=="" (
109109
)
110110

111111
if "!RABBITMQ_IO_THREAD_POOL_SIZE!"=="" (
112-
set RABBITMQ_IO_THREAD_POOL_ARG=30
113-
) else (
114-
set RABBITMQ_IO_THREAD_POOL_ARG=!RABBITMQ_IO_THREAD_POOL_SIZE!
115-
)
112+
set RABBITMQ_IO_THREAD_POOL_SIZE=64
113+
)
114+
116115

117116
set ENV_OK=true
118117
CALL :check_not_empty "RABBITMQ_BOOT_MODULE" !RABBITMQ_BOOT_MODULE!

scripts/rabbitmq-service.bat

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if not exist "!RABBITMQ_BASE!" (
106106
)
107107

108108
set ENV_OK=true
109-
CALL :check_not_empty "RABBITMQ_BOOT_MODULE" !RABBITMQ_BOOT_MODULE!
109+
CALL :check_not_empty "RABBITMQ_BOOT_MODULE" !RABBITMQ_BOOT_MODULE!
110110
CALL :check_not_empty "RABBITMQ_NAME_TYPE" !RABBITMQ_NAME_TYPE!
111111
CALL :check_not_empty "RABBITMQ_NODENAME" !RABBITMQ_NODENAME!
112112

@@ -150,10 +150,11 @@ if ERRORLEVEL 3 (
150150

151151
if not exist "!RABBITMQ_SCHEMA_DIR!\rabbitmq.schema" (
152152
copy "!RABBITMQ_HOME!\priv\schema\rabbitmq.schema" "!RABBITMQ_SCHEMA_DIR!\rabbitmq.schema"
153-
REM Try to create config file, if it doesn't exist
154-
REM It still can fail to be created, but at least not for default install
155-
if not exist "!RABBITMQ_CONFIG_FILE!.config" (
156-
echo []. > !RABBITMQ_CONFIG_FILE!.config
153+
)
154+
REM Try to create advanced config file, if it doesn't exist
155+
REM It still can fail to be created, but at least not for default install
156+
if not exist "!RABBITMQ_ADVANCED_CONFIG_FILE!.config" (
157+
echo []. > !RABBITMQ_ADVANCED_CONFIG_FILE!.config
157158
)
158159

159160
if exist "!RABBITMQ_CONFIG_FILE!.config" (
@@ -191,7 +192,7 @@ if "!RABBITMQ_NODE_ONLY!"=="" (
191192
)
192193

193194
if "!RABBITMQ_IO_THREAD_POOL_SIZE!"=="" (
194-
set RABBITMQ_IO_THREAD_POOL_SIZE=30
195+
set RABBITMQ_IO_THREAD_POOL_SIZE=64
195196
)
196197

197198
if "!RABBITMQ_SERVICE_RESTART!"=="" (
@@ -262,7 +263,7 @@ EXIT /B 0
262263
if "%~2"=="" (
263264
ECHO "Error: ENV variable should be defined: %1. Please check rabbitmq-env, rabbitmq-default, and !RABBITMQ_CONF_ENV_FILE! script files. Check also your Environment Variables settings"
264265
set ENV_OK=false
265-
EXIT /B 78
266+
EXIT /B 78
266267
)
267268
EXIT /B 0
268269

scripts/travis_test_ocf_ra.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh -eux
2+
# Prepare and run a smoke test against the RabbitMQ OCF RA only if
3+
# the scripts/rabbitmq-server-ha.ocf has changes
4+
if ! git diff HEAD~ --name-only | grep -q scripts/rabbitmq-server-ha.ocf
5+
then
6+
exit 0
7+
fi
8+
9+
export VAGRANT_VERSION=1.8.1
10+
export DOCKER_IMAGE=bogdando/rabbitmq-cluster-ocf-wily
11+
export UPLOAD_METHOD=none
12+
export DOCKER_MOUNTS="$(pwd)/scripts/rabbitmq-server-ha.ocf:/tmp/rabbitmq-server-ha"
13+
14+
# Install vagrant and requirements
15+
sudo apt-get install -qq git wget
16+
wget --no-verbose https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb
17+
sudo dpkg -i --force-all ./vagrant_${VAGRANT_VERSION}_x86_64.deb
18+
vagrant plugin install vagrant-triggers
19+
20+
# Update docker and prepare images
21+
sudo apt-get update
22+
sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install --only-upgrade docker-engine
23+
sudo service docker restart
24+
docker pull $DOCKER_IMAGE
25+
26+
# Prepare and run a smoke test for a rabbitmq cluster by the OCF RA
27+
git clone https://github.com/bogdando/rabbitmq-cluster-ocf-vagrant.git
28+
cd ./rabbitmq-cluster-ocf-vagrant
29+
vagrant up --provider docker
30+
docker exec -it n1 /bin/bash /vagrant/vagrant_script/test_rabbitcluster.sh rabbit@n1 rabbit@n2

src/rabbit_cli.erl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
-include("rabbit_cli.hrl").
1919

2020
-export([main/3, start_distribution/0, start_distribution/1,
21-
parse_arguments/4, rpc_call/4, rpc_call/5, rpc_call/7]).
21+
parse_arguments/4, filter_opts/2,
22+
rpc_call/4, rpc_call/5, rpc_call/7]).
2223

2324
%%----------------------------------------------------------------------------
2425

2526
-ifdef(use_specs).
2627

28+
-type(option_name() :: string()).
29+
-type(option_value() :: string() | node() | boolean()).
2730
-type(optdef() :: flag | {option, string()}).
28-
-type(parse_result() :: {'ok', {atom(), [{string(), string()}], [string()]}} |
31+
-type(parse_result() :: {'ok', {atom(), [{option_name(), option_value()}], [string()]}} |
2932
'no_command').
3033

31-
3234
-spec(main/3 :: (fun (([string()], string()) -> parse_result()),
3335
fun ((atom(), atom(), [any()], [any()]) -> any()),
3436
atom()) -> no_return()).
@@ -38,6 +40,9 @@
3840
-spec(parse_arguments/4 ::
3941
([{atom(), [{string(), optdef()}]} | atom()],
4042
[{string(), optdef()}], string(), [string()]) -> parse_result()).
43+
44+
-spec(filter_opts/2 :: ([{option_name(), option_value()}], [option_name()]) -> [boolean()]).
45+
4146
-spec(rpc_call/4 :: (node(), atom(), atom(), [any()]) -> any()).
4247
-spec(rpc_call/5 :: (node(), atom(), atom(), [any()], number()) -> any()).
4348
-spec(rpc_call/7 :: (node(), atom(), atom(), [any()], reference(), pid(),
@@ -244,6 +249,22 @@ process_opts(Defs, C, [A | As], Found, KVs, Outs) ->
244249
{none, _, _} -> no_command
245250
end.
246251

252+
%% When we have a set of flags that are used for filtering, we want by
253+
%% default to include every such option in our output. But if a user
254+
%% explicitly specified any such flag, we want to include only items
255+
%% which he has requested.
256+
filter_opts(CurrentOptionValues, AllOptionNames) ->
257+
Explicit = lists:map(fun(OptName) ->
258+
proplists:get_bool(OptName, CurrentOptionValues)
259+
end,
260+
AllOptionNames),
261+
case lists:member(true, Explicit) of
262+
true ->
263+
Explicit;
264+
false ->
265+
lists:duplicate(length(AllOptionNames), true)
266+
end.
267+
247268
%%----------------------------------------------------------------------------
248269

249270
fmt_stderr(Format, Args) -> rabbit_misc:format_stderr(Format ++ "~n", Args).

src/rabbit_control_main.erl

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
{clear_policy, [?VHOST_DEF]},
7474
{list_policies, [?VHOST_DEF]},
7575

76-
{list_queues, [?VHOST_DEF]},
76+
{list_queues, [?VHOST_DEF, ?OFFLINE_DEF, ?ONLINE_DEF]},
7777
{list_exchanges, [?VHOST_DEF]},
7878
{list_bindings, [?VHOST_DEF]},
7979
{list_connections, [?VHOST_DEF]},
@@ -610,10 +610,11 @@ action(list_user_permissions, Node, Args = [_Username], _Opts, Inform, Timeout)
610610
true);
611611

612612
action(list_queues, Node, Args, Opts, Inform, Timeout) ->
613+
[Online, Offline] = rabbit_cli:filter_opts(Opts, [?ONLINE_OPT, ?OFFLINE_OPT]),
613614
Inform("Listing queues", []),
614615
VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)),
615616
ArgAtoms = default_if_empty(Args, [name, messages]),
616-
call(Node, {rabbit_amqqueue, info_all, [VHostArg, ArgAtoms]},
617+
call(Node, {rabbit_amqqueue, info_all, [VHostArg, ArgAtoms, Online, Offline]},
617618
ArgAtoms, Timeout);
618619

619620
action(list_exchanges, Node, Args, Opts, Inform, Timeout) ->
@@ -750,15 +751,26 @@ default_if_empty(List, Default) when is_list(List) ->
750751
true -> [list_to_atom(X) || X <- List]
751752
end.
752753

754+
display_info_message_row(IsEscaped, Result, InfoItemKeys) ->
755+
display_row([format_info_item(
756+
case proplists:lookup(X, Result) of
757+
none when is_list(Result), length(Result) > 0 ->
758+
exit({error, {bad_info_key, X}});
759+
none -> Result;
760+
{X, Value} -> Value
761+
end, IsEscaped) || X <- InfoItemKeys]).
762+
753763
display_info_message(IsEscaped) ->
754-
fun(Result, InfoItemKeys) ->
755-
display_row([format_info_item(
756-
case proplists:lookup(X, Result) of
757-
none when is_list(Result), length(Result) > 0 ->
758-
exit({error, {bad_info_key, X}});
759-
none -> Result;
760-
{X, Value} -> Value
761-
end, IsEscaped) || X <- InfoItemKeys])
764+
fun ([], _) ->
765+
ok;
766+
([FirstResult|_] = List, InfoItemKeys) when is_list(FirstResult) ->
767+
lists:foreach(fun(Result) ->
768+
display_info_message_row(IsEscaped, Result, InfoItemKeys)
769+
end,
770+
List),
771+
ok;
772+
(Result, InfoItemKeys) ->
773+
display_info_message_row(IsEscaped, Result, InfoItemKeys)
762774
end.
763775

764776
display_info_list(Results, InfoItemKeys) when is_list(Results) ->

0 commit comments

Comments
 (0)