#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  Copyright (C) Altran ACT S.A.S. 2017,2021.  All rights reserved.
#
#  ALTRAN_PROLOG_END_TAG
#
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r720 src/43haes/usr/sbin/cluster/events/utils/cl_rrmethods2call.sh 1.26 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2002,2015 
# 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 
#
# @(#)  7de1449 43haes/usr/sbin/cluster/events/utils/cl_rrmethods2call.sh, 726, 2147A_aha726, Nov 01 2021 05:16 PM
###############################################################################
#
#   COMPONENT_NAME: EVENTUTILS
#
#   FUNCTIONS: none
#
###############################################################################

###############################################################################
#  
#  Name:  cl_rrmethods2call
#
#  Returns:
#        None
#
#  This function will output through stdout the names of the replicated
#  resource methods to call based on output from clsetenvres, which is
#  assumed to have been called prior to calling this function.
#
#  Arguments: None
#              
#  Environment: VERBOSE_LOGGING, PATH
#
###############################################################################

typeset PROGNAME=${0##*/}
export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"
if [[ $VERBOSE_LOGGING == "high" ]]; then
    set -x
    version='%I%'
fi


#
# RRMETHODS must be set to the aggregate of all methods to be called
# based on the presence of each type of replicated resource.  This command
# can be called in either of two situations:
#
# 1.  The event processing is currently processing a replicated resource
#     group and needs to configure the replicated resources that belong
#     to that resource group.  In that case the event processing has
#     already set up the *_REP_RESOURCE environment variable for that
#     resource group, and we just want to call the method for that
#     replicated resource type, if one exists.
#
# 2.  There are replicated resource method callouts for events that are
#     not specific to any one replicated resource group.  For example, if
#     this is a network_down or site_isolation event, the event processing
#     may need to call replicated resource methods for one or more
#     replicated resource types.  In this case the *_REP_RESOURCE environment
#     variables are not already set by the event processing, so we need to
#     set them ourselves.  This is done so that we do not call a replicated
#     resource method if there are no replicated resource groups of that
#     type in the cluster.  For example, if HAGEO is installed but there
#     are no HAGEO resource groups, then we do not want to call any of
#     the HAGEO replicated resource methods.
#
RRMETHODS=""
NEED_RR_ENV_VARS="no"

case $1 in
    "net_cleanup" | "net_initialization")
	#    
	: The network methods are returned if the Network type is XD_data.
	#
        RRNET=$(clodmget -q"name=$NETWORKNAME" -f nimname -n HACMPnetwork)
           
	if [[ $RRNET == "XD_data" ]]
	then
	    NEED_RR_ENV_VARS="yes"
	else
	    return 0
	fi
    ;;
           
    "ss_unload" | "ss_load")
	#
	:   The load and unload methods if defined are returned on the 
	:   local node
	#
	if [[ $NODENAME == $LOCALNODENAME ]]
	then
	    NEED_RR_ENV_VARS="yes"
	else
	    return 0
	fi
    ;;
           
    "site_initialization" | "site_cleanup" | "site_isolation" | "site_merge")
	#
	:   The site related method names are returned if defined
	#
	NEED_RR_ENV_VARS="yes"
    ;;
     
    "postrg_move")
           # The rg_move related method names are returned if defined
           NEED_RR_ENV_VARS="yes"
           ;;
esac

#
:   Set the \*_REP_RESOURCE variables if needed.
#
if [[ $NEED_RR_ENV_VARS == "yes" ]]
then
    eval $(cllsres 2>/dev/null)
fi


if [[ -n $GMD_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=1' -f $1 -n HACMPrresmethods)"
fi

if [[ -n $PPRC_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=2' -f $1 -n HACMPrresmethods)"
fi

if [[ -n $SVCPPRC_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=4' -f $1 -n HACMPrresmethods)"
fi

if [[ -n $GMVG_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=5' -f $1 -n HACMPrresmethods)"
fi

if [[ -n $SR_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=6' -f $1 -n HACMPrresmethods)"
fi

if [[ -n $TC_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=7' -f $1 -n HACMPrresmethods)"
fi

if [[ -n $GENXD_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=8' -f $1 -n HACMPrresmethods)"
fi

if [[ -n $REMOTECOPY_REP_RESOURCE ]]
then
   RRMETHODS="$RRMETHODS $(clodmget -q 'type=9' -f $1 -n HACMPrresmethods)"
fi

#Always invoke genxd_predisk_available for GENXD_REP_RESOURCE  to consider system and cluster MGs
#It is needed as System and Cluster MGs are not part of RG, hence cllsres can not
#give details
# NOTE: No more changes should be made to RRMETHODS after this section
# All new RRMETHODS should be added before this section.
if [[ -z $RRMETHODS ]]
then
    typeset sysmgdata
    typeset reposmgdata
    if [[ -x /usr/es/sbin/cluster/xd_generic/xd_cli/clxd_list_mg_smit ]]
    then
        sysmgdata=$(/usr/es/sbin/cluster/xd_generic/xd_cli/clxd_list_mg_smit -s ds8k_inband_mm system)
        reposmgdata=$(/usr/es/sbin/cluster/xd_generic/xd_cli/clxd_list_mg_smit -s ds8k_inband_mm repository)
    fi
    [[ -n $sysmgdata || -n $reposmgdata ]] &&
    {
        RRMETHODS="$RRMETHODS $(clodmget -q 'type=8' -f $1 -n HACMPrresmethods)"
    }
fi

echo "$RRMETHODS"

return 0
