Blame SOURCES/bz1493915-1-support-per-host-per-bundle-attribs.patch

3052fb
From 708e11c13ac25e1db5a4552db699a652f4e32353 Mon Sep 17 00:00:00 2001
3052fb
From: Michele Baldessari <michele@acksyn.org>
3052fb
Date: Thu, 7 Sep 2017 18:56:24 +0200
3052fb
Subject: [PATCH 1/2] Introduce helper functions for container-attribute-target
3052fb
3052fb
In this change we introduce the ocf_attribute_target() function that helps
3052fb
RAs decide where to store per-node attributes. The rationale is that
3052fb
when an OCF resource runs in a bundle (e.g. rabbitmq-bundle-0) the
3052fb
NODENAME will point to the bundle name and not to the physical node
3052fb
running the bundle. Since a bundle can run on any cluster node, this
3052fb
is not ideal in the situations in which an RA wants to remember on which
3052fb
*host* a bundle was running (this is typically the case when there is no
3052fb
shared storage)
3052fb
3052fb
The way this new ocf_attribute_target() function works is the following:
3052fb
A) When the meta-attr 'container-attribute-target' == 'host' and the
3052fb
   function is called without arguments it will return the physical
3052fb
   hostname the resource is running on.
3052fb
B) When the meta-attr 'container-attribute-target' != 'host' and the
3052fb
   function is called without arguments it will return the NODENAME
3052fb
   (default)
3052fb
C) When the meta-attr 'container-attribute-target' == 'host' and the
3052fb
   function is called with an argument it will return the physical
3052fb
   hostname on which the corresponding argument is running on.
3052fb
D) When the meta-attr 'container-attribute-target' != 'host' and the
3052fb
   function is called with an argument it will return the NODENAME
3052fb
   (default)
3052fb
3052fb
The basic idea is that if resources need to store per-host attributes
3052fb
you will set the meta attribute 'container-attribute-target' equal to
3052fb
host (the no-shared storage case). If resources need to store attributes
3052fb
on a per-bundle basis (because they access data from shared-storage)
3052fb
then no change is needed on meta attributes (this is the default
3052fb
behaviour).
3052fb
3052fb
Signed-off-by: Andrew Beekhof <abeekhof@redhat.com>
3052fb
Tested-by: Michele Baldessari <michele@acksyn.org>
3052fb
Tested-by: Damien Ciabrini <dciabrin@redhat.com>
3052fb
---
3052fb
 heartbeat/ocf-shellfuncs.in | 38 ++++++++++++++++++++++++++++++++++++++
3052fb
 1 file changed, 38 insertions(+)
3052fb
3052fb
diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
3052fb
index 9b6b99f88a56..ddd6854e9487 100644
3052fb
--- a/heartbeat/ocf-shellfuncs.in
3052fb
+++ b/heartbeat/ocf-shellfuncs.in
3052fb
@@ -989,6 +989,44 @@ ocf_stop_trace() {
3052fb
 	set +x
3052fb
 }
3052fb
 
3052fb
+# Helper functions to map from nodename/bundle-name and physical hostname
3052fb
+# list_index_for_word "node0 node1 node2 node3 node4 node5" node4 --> 5
3052fb
+# list_word_at_index "NA host1 host2 host3 host4 host5" 3      --> host2
3052fb
+
3052fb
+# list_index_for_word "node1 node2 node3 node4 node5" node7 --> ""
3052fb
+# list_word_at_index "host1 host2 host3 host4 host5" 8      --> ""
3052fb
+
3052fb
+# attribute_target node1                                    --> host1
3052fb
+list_index_for_word() {
3052fb
+	echo $1 | tr ' ' '\n' | awk -v x="$2" '$0~x {print NR}'
3052fb
+}
3052fb
+
3052fb
+list_word_at_index() {
3052fb
+	echo $1 | tr ' ' '\n' | awk -v n="$2" 'n == NR'
3052fb
+}
3052fb
+
3052fb
+ocf_attribute_target() {
3052fb
+	if [ x$1 = x ]; then
3052fb
+		if [ x$OCF_RESKEY_CRM_meta_container_attribute_target = xhost -a x$OCF_RESKEY_CRM_meta_physical_host != x ]; then
3052fb
+			echo $OCF_RESKEY_CRM_meta_physical_host
3052fb
+		else
3052fb
+			echo $OCF_RESKEY_CRM_meta_on_node
3052fb
+		fi
3052fb
+		return
3052fb
+	elif [ x"$OCF_RESKEY_CRM_meta_notify_all_uname" != x ]; then
3052fb
+		index=$(list_index_for_word "$OCF_RESKEY_CRM_meta_notify_all_uname" $1)
3052fb
+		mapping=""
3052fb
+		if [ x$index != x ]; then
3052fb
+			mapping=$(list_word_at_index "$OCF_RESKEY_CRM_meta_notify_all_hosts" $index)
3052fb
+		fi
3052fb
+		if [ x$mapping != x -a x$mapping != xNA ]; then
3052fb
+			echo $mapping
3052fb
+			return
3052fb
+		fi
3052fb
+	fi
3052fb
+	echo $1
3052fb
+}
3052fb
+
3052fb
 __ocf_set_defaults "$@"
3052fb
 
3052fb
 : ${OCF_TRACE_RA:=$OCF_RESKEY_trace_ra}
3052fb
-- 
3052fb
2.13.5
3052fb