Hi,
for exploring master/slave dynamics in pacemaker I augmented RA Dummy 
accordingly.
Others might be interested as well.

- holger

# HG changeset patch
# User Holger Teutsch <holger.teut...@web.de>
# Date 1296207379 -3600
# Node ID 9d5115dafab350a4826e71a93a1719c4b9eed657
# Parent  c9373b3d7d8e5bd0e01525e51096a411e5bb022a
Low: Dummy: Add master/slave support to Dummy
New methods promote/demote/notify + track M/S status in state file.

diff -r c9373b3d7d8e -r 9d5115dafab3 heartbeat/Dummy
--- a/heartbeat/Dummy   Mon Jan 24 10:16:08 2011 +0100
+++ b/heartbeat/Dummy   Fri Jan 28 10:36:19 2011 +0100
@@ -47,6 +47,9 @@
 keep track of whether its running or not.
 Its purpose in life is for testing and to serve as a template for RA writers.
 
+You can configure Dummy as a Master/Slave resource. For this purpose the
+optional methods promote/demote/notify are present as well.
+
 NB: Please pay attention to the timeouts specified in the actions
 section below. They should be meaningful for the kind of resource
 the agent manages. They should be the minimum advised timeouts,
@@ -54,7 +57,7 @@
 instances. So, try to be neither overly generous nor too stingy,
 but moderate. The minimum timeouts should never be below 10 seconds.
 </longdesc>
-<shortdesc lang="en">Example stateless resource agent</shortdesc>
+<shortdesc lang="en">Example resource agent</shortdesc>
 
 <parameters>
 <parameter name="state" unique="1">
@@ -80,6 +83,9 @@
 <action name="stop"         timeout="20" />
 <action name="monitor"      timeout="20" interval="10" depth="0" />
 <action name="reload"       timeout="20" />
+<action name="promote"      timeout="20" />
+<action name="demote"       timeout="20" />
+<action name="notify"       timeout="20" />
 <action name="migrate_to"   timeout="20" />
 <action name="migrate_from" timeout="20" />
 <action name="meta-data"    timeout="5" />
@@ -93,7 +99,7 @@
 
 dummy_usage() {
        cat <<END
-usage: $0 {start|stop|monitor|migrate_to|migrate_from|validate-all|meta-data}
+usage: $0 
{start|stop|monitor|promote|demote|notify|migrate_to|migrate_from|validate-all|meta-data}
 
 Expects to have a fully populated OCF RA-compliant environment set.
 END
@@ -105,6 +111,11 @@
        return $OCF_SUCCESS
     fi
     touch ${OCF_RESKEY_state}
+
+    # only relevant for M/S: assign some score to get things rolling
+    ${HA_SBIN_DIR}/crm_master -Q -l reboot -v 1000
+
+    return $OCF_SUCCESS
 }
 
 dummy_stop() {
@@ -121,6 +132,9 @@
        # That is THREE states, not just yes/no.
        
        if [ -f ${OCF_RESKEY_state} ]; then
+           grep MASTER ${OCF_RESKEY_state} >/dev/null 2>&1 && \
+               return $OCF_RUNNING_MASTER
+
            return $OCF_SUCCESS
        fi
        if false ; then
@@ -129,6 +143,82 @@
        return $OCF_NOT_RUNNING
 }
 
+dummy_promote() {
+    local rc
+
+    dummy_monitor
+    rc=$?
+    case "$rc" in
+        "$OCF_SUCCESS")
+            ;;
+
+        "$OCF_RUNNING_MASTER")
+            # Already a master. Unexpected, but not a problem.
+            ocf_log info "Resource ${OCF_RESOURCE_INSTANCE} is already running 
as Master"
+            return $OCF_SUCCESS
+            ;;
+        "$OCF_NOT_RUNNING")
+            # Currently not running. Need to start before promoting.
+            ocf_log info "Resource ${OCF_RESOURCE_INSTANCE} is currently not 
running"
+            dummy_start
+            ;;
+        *)
+            # Failed resource. Let the cluster manager recover.
+            ocf_log err "Unexpected error, cannot promote"
+            exit $rc
+            ;;
+    esac
+
+    # do the promotion
+    echo MASTER > ${OCF_RESKEY_state} || exit $OCF_ERR_GENERIC
+
+    ocf_log info "Resource ${OCF_RESOURCE_INSTANCE} promoted"
+    return $OCF_SUCCESS
+}
+
+dummy_demote() {
+    local rc
+
+    dummy_monitor
+    rc=$?
+    case "$rc" in
+        "$OCF_RUNNING_MASTER")
+            ;;
+        "$OCF_SUCCESS")
+            # Alread running as slave. Nothing to do.
+            ocf_log debug "Resource ${OCF_RESOURCE_INSTANCE} is currently 
running as Slave"
+            return $OCF_SUCCESS
+            ;;
+        "$OCF_NOT_RUNNING")
+            # Currently not running. Getting a demote action
+            # in this state is unexpected. Exit with an error
+            # and let the cluster manager recover.
+            ocf_log err "Resource ${OCF_RESOURCE_INSTANCE} is currently not 
running"
+            exit $OCF_ERR_GENERIC
+            ;;
+        *)
+            # Failed resource. Let the cluster manager recover.
+            ocf_log err "Resource ${OCF_RESOURCE_INSTANCE} unexpected error, 
cannot demote"
+            exit $rc
+            ;;
+    esac
+
+    # do the demote
+    echo '' > ${OCF_RESKEY_state} || exit $OCF_ERR_GENERIC
+
+    ocf_log info "Resource ${OCF_RESOURCE_INSTANCE} demoted"
+    return $OCF_SUCCESS
+}
+
+dummy_notify() {
+    local type_op
+
+    
type_op="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}"
+
+    ocf_log info "Resource ${OCF_RESOURCE_INSTANCE} received $type_op 
notification."
+    return $OCF_SUCCESS 
+}
+
 dummy_validate() {
     
     # Is the state directory writable? 
@@ -152,6 +242,9 @@
 start)         dummy_start;;
 stop)          dummy_stop;;
 monitor)       dummy_monitor;;
+promote)       dummy_promote;;
+demote)                dummy_demote;;
+notify)         dummy_notify;;
 migrate_to)    ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to 
${OCF_RESKEY_CRM_meta_migrate_target}."
                dummy_stop
                ;;


_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to