Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OCF HA] Add ocf_get_private_attr function to RabbitMQ OCF script #926

Merged
merged 1 commit into from
Aug 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions scripts/rabbitmq-server-ha.ocf
Original file line number Diff line number Diff line change
Expand Up @@ -1362,25 +1362,18 @@ check_timeouts() {
local op_name=$3

if [ $op_rc -ne 124 -a $op_rc -ne 137 ]; then
ocf_run attrd_updater -p --name $timeouts_attr_name --update 0
ocf_update_private_attr $timeouts_attr_name 0
return 0
fi

local count
count=`attrd_updater --name $timeouts_attr_name --query 2>/dev/null`
if [ $? -ne 0 ]; then
# the attrd_updater exited with error. In that case most probably it printed garbage
# instead of the number we need. So defensively assume that it is zero.

count=0
fi
count=`echo "${count}" | awk '{print $3}' | awk -F "=" '{print $2}' | sed -e '/(null)/d'`
count=$(ocf_get_private_attr $timeouts_attr_name 0)

count=$((count+1))
# There is a slight chance that this piece of code will be executed twice simultaneously.
# As a result, $timeouts_attr_name's value will be one less than it should be. But we don't need
# precise calculation here.
ocf_run attrd_updater -p --name $timeouts_attr_name --update $count
ocf_update_private_attr $timeouts_attr_name $count

if [ $count -lt $OCF_RESKEY_max_rabbitmqctl_timeouts ]; then
ocf_log warn "${LH} 'rabbitmqctl $op_name' timed out $count of max. $OCF_RESKEY_max_rabbitmqctl_timeouts time(s) in a row. Doing nothing for now."
Expand Down Expand Up @@ -1634,6 +1627,18 @@ get_monitor() {
return $rc
}

ocf_get_private_attr() {
local attr_name="${1:?}"
local attr_default_value="${2:?}"
local count
count=$(attrd_updater -p --name "$attr_name" --query)
if [ $? -ne 0 ]; then
echo $attr_default_value
else
echo "$count" | awk -vdef_val="$attr_default_value" '{ gsub(/"/, "", $3); split($3, vals, "="); if (vals[2] != "(null)") print vals[2]; else print def_val }'
fi
}

ocf_update_private_attr() {
local attr_name="${1:?}"
local attr_value="${2:?}"
Expand Down