#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/events/call_replicated_methods.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2005,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)57	1.4 src/43haes/usr/sbin/cluster/events/call_replicated_methods.sh, hacmp.events, 61haes_r714 3/26/07 17:53:24



call_replicated_methods ()
{
    typeset PS4_FUNC="call_replicated_methods"
    [[ "$VERBOSE_LOGGING" = "high" ]] && set -x

    TYPE=$1;
    NODENAME=$2;
    GROUPS=$3;

    if [[ -z $TYPE ]]
    then
        echo "call_replicated_methods: No type"
        return 1;
    fi

# Return Code
    rc=0

    if [[ -z $GROUPS ]]
    then
        METHODS=$(cl_rrmethods2call $TYPE)
	
        for method in $METHODS
        do
            if [[ -x $method ]]
            then
                if ! $method $*
                then
                    rc=1
                fi
            fi
        done
    else
        for siblingGroup in $GROUPS
        do
            set -a
            eval $(clsetrepenv $siblingGroup)
            set +a

            export GROUPNAME=$siblingGroup
            METHODS=$(cl_rrmethods2call $TYPE)
            for method in $METHODS
            do
	            if [[ -x $method ]]
	            then
		            if ! $method "$NODENAME"
		            then
		                rc=1
		            fi
	            fi
	        done
        done
    fi
    return $rc
}

#
# main starts here
#

echo "call_replicated_methods: CALLED arguments $1 $2 $3"
call_replicated_methods "$1" "$2" "$3"
exit $?
