#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2019,2020,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_resourcegroup_state.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: get_rg_state # # Description: Parses the clRGinfo output to determine the resource group's # current state, and which node(s) it is active on (if any). # # Inputs: rginfo The clRGinfo output to be parsed. # nodes The node(s) that the resource group can run on # secondary An indicator that secondary nodes might exist # for the resource group # # Outputs: The current node(s) (if any) and resource group state are # returned on STDOUT in the format: "nodes|state" # # Returns: 0, if a status is successfully identifed, otherwise non-zero. # #============================================================================ function get_rg_state { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_resourcegroup_state.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset rginfo=${1//\"/} typeset nodes=${2//\"/} typeset secondary=${3//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset rgname= rgstate= rgnode= rem= current_nodes= integer status=$RC_ERROR # Assume the worst, until proven otherwise! integer ERRORS=0 OFFLINE=0 ONLINE=0 UNKNOWN=0 integer ACQUIRING=0 RELEASING=0 ERRORS_SEC=0 ACQUIRING_SEC=0 integer RELEASING_SEC=0 ONLINE_SEC=0 UNMANAGED=0 UNMANAGED_SEC=0 #============================================================================ : Modfied OFFLINE nodes count equal to total number of nodes present in site : And for Standard cluster will check primary site count #============================================================================ integer SECONDARY_SITE_COUNT=0 SECONDARY_OFFLINE=0 PRIMARY_SITE_COUNT=0 PRIMARY_OFFLINE=0 print -- "$rginfo" |\ while IFS=: read rgname rgstate rgnode rem; do case $rgstate in *OFFLINE*) if [[ -n $secondary && $rgstate == *SEC* ]] then (( SECONDARY_SITE_COUNT++ )) (( SECONDARY_OFFLINE++ )) else #============================================================================= : For Standard cluster it check OFFLINE node count equal to primary site count #============================================================================= (( PRIMARY_SITE_COUNT++ )) (( PRIMARY_OFFLINE++ )) fi ;; *ERROR*) if [[ -n $secondary && $rgstate == *SEC* ]] then (( ERRORS_SEC++ )) elif [[ -z $secondary && $rgstate != *SEC* ]] then (( ERRORS++ )) fi ;; *UNMANAGED*) if [[ -n $secondary && $rgstate == *SEC* ]] then (( UNMANAGED_SEC++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" elif [[ -z $secondary && $rgstate != *SEC* ]] then (( UNMANAGED++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" fi ;; *ACQUIRING*) if [[ -n $secondary && $rgstate == *SEC* ]] then (( ACQUIRING_SEC++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" elif [[ -z $secondary && $rgstate != *SEC* ]] then (( ACQUIRING++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" fi ;; *RELEASING*) if [[ -n $secondary && $rgstate == *SEC* ]] then (( RELEASING_SEC++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" elif [[ -z $secondary && $rgstate != *SEC* ]] then (( RELEASING++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" fi ;; *ONLINE*) if [[ -n $secondary && $rgstate == *SEC* ]] then (( ONLINE_SEC++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" elif [[ -z $secondary && $rgstate != *SEC* ]] then (( ONLINE++ )) current_nodes="${current_nodes:+$current_nodes }$rgnode" fi ;; *) (( UNKNOWN++ )) ;; esac done print -n -- "$current_nodes|" if (( ERRORS )); then print "ERROR" elif (( UNMANAGED )); then print "UNMANAGED" elif (( ONLINE )); then print "ONLINE" elif (( ACQUIRING )); then print "ACQUIRING" elif (( RELEASING )); then print "RELEASING" elif (( ERRORS_SEC )); then print "ERROR SECONDARY" elif (( UNMANAGED_SEC )); then print "UNMANAGED SECONDARY" elif (( ONLINE_SEC )); then print "ONLINE SECONDARY" elif (( ACQUIRING_SEC )); then print "ACQUIRING SECONDARY" elif (( RELEASING_SEC )); then print "RELEASING SECONDARY" elif (( PRIMARY_OFFLINE == PRIMARY_SITE_COUNT )); then print "OFFLINE" elif (( SECONDARY_OFFLINE == SECONDARY_SITE_COUNT )); then print "OFFLINE" else print "UNKNOWN" fi log_return_msg "$status" "$0()" "$LINENO" return $? } # End of "get_rg_state()" #============================================================================ # # Name: KLIB_HACMP_get_resourcegroup_state # # Description: This is the main, FPATH function that is invoked by clmgr # to collect the state of a resource group. # # Inputs: Please refer to the detailed listing, and associated # descriptions, in the "ARGUMENTS" section of the "devDoc()" # function, above. # # Outputs: The properties hash is populated. The only other outputs # are any error messages that might be needed. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function, above, for the standard return # code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_get_resourcegroup_state { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_resourcegroup_state.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset rg=$1 typeset -n properties=$2 [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset -u header= typeset rginfo= typeset rgname= typeset rgstate= typeset rgnode= typeset rgtype= typeset rem= typeset HEADER_LINE= typeset -i all_nodes=29 typeset -i site_pol=30 typeset -i primary=38 typeset -i secondary=39 typeset -i i=0 cmd_rc=$RC_UNKNOWN typeset cllsres_data="" pn_str="" sn_str="" sp_str="" rest="" properties=( [CURRENT_NODE]="" [STATE]="UNKNOWN" [TYPE]="" [SECONDARY_STATE]="" ) #====================================== : Get the primary and secondary nodes #====================================== # From "cllsres": # # #DISK:VOLUME_GROUP:CONCURRENT_VOLUME_GROUP:FORCED_VARYON:FILESYSTEM:FSCHECK_TOOL:RECOVERY_METHOD:EXPORT_FILESYSTEM:SHARED_TAPE_RESOURCES:AIX_CONNECTIONS_SERVICES:AIX_FAST_CONNECT_SERVICES:COMMUNICATION_LINKS:APPLICATIONS:MOUNT_FILESYSTEM:SERVICE_LABEL:MISC_DATA:SSA_DISK_FENCING:VG_AUTO_IMPORT:INACTIVE_TAKEOVER:CASCADE_WO_FALLBACK:FS_BEFORE_IPADDR:NFS_NETWORK:NODE_PRIORITY_POLICY:MOUNT_ALL_FS:WLM_PRIMARY:WLM_SECONDARY:FALLBACK_AT:RELATIONSHIP:NODES:SRELATIONSHIP:GMD_REP_RESOURCE:PPRC_REP_RESOURCE:ERCMF_REP_RESOURCE:SR_REP_RESOURCE:TC_REP_RESOURCE:GENXD_REP_RESOURCE:SVCPPRC_REP_RESOURCE:GMVG_REP_RESOURCE:PRIMARYNODES:SECONDARYNODES:EXPORT_FILESYSTEM_V4:STABLE_STORAGE_PATH:WPAR_NAME:VARYON_WITH_MISSING_UPDATES:DATA_DIVERGENCE_RECOVERY:USERDEFINED_RESOURCES:SDNP_SCRIPT_PATH:SDNP_SCRIPT_TIMEOUT:RAW_DISK:MANAGE_RDISK print "$0()[$LINENO]($SECONDS): cllsres -c -s -g \"$rg\" | grep \"^#\"" >>$CLMGR_TMPLOG # Always log commands HEADER_LINE=$(cllsres -c -s -g "$rg" | grep "^#") print "$0()[$LINENO]($SECONDS): cllsres HEADER_LINE == \"$HEADER_LINE\"" >>$CLMGR_TMPLOG # Always log command result for header in ${HEADER_LINE//:/ }; do (( i++ )) case $header in "NODES") all_nodes=$i ;; "PRIMARYNODES") primary=$i ;; "SECONDARYNODES") secondary=$i ;; "SRELATIONSHIP") site_pol=$i ;; esac done print "$0()[$LINENO]($SECONDS): cllsres -c -s -g \"$rg\"" >>$CLMGR_TMPLOG cllsres_data=$(cllsres -c -s -g "$rg") cmd_rc=$? print "$0()[$LINENO]($SECONDS): cllsres RC: $cmd_rc" >>$CLMGR_TMPLOG if (( cmd_rc == RC_SUCCESS )); then print -- "$cllsres_data" | grep -v "^#" |\ cut -d: -f$site_pol,$primary,$secondary |\ IFS=: read sp_str pn_str sn_str rest properties[SITE_POLICY]="$sp_str" properties[PRIMARYNODES]="$pn_str" properties[SECONDARYNODES]="$sn_str" print "$0()[$LINENO]($SECONDS): PRIMARYNODES == \"${properties[PRIMARYNODES]}\"" >>$CLMGR_TMPLOG print "$0()[$LINENO]($SECONDS): SECONDARYNODES == \"${properties[SECONDARYNODES]}\"" >>$CLMGR_TMPLOG print "$0()[$LINENO]($SECONDS): SITE_POLICY == \"${properties[SITE_POLICY]}\"" >>$CLMGR_TMPLOG if [[ ${properties[SITE_POLICY]} == "ignore" && -n ${properties[SECONDARYNODES]} ]] then properties[PRIMARYNODES]="${properties[PRIMARYNODES]} ${properties[SECONDARYNODES]}" properties[SECONDARYNODES]="" fi fi #========================================================================= : Get the state of the resource group on the primary and secondary nodes #========================================================================= print "$0()[$LINENO]($SECONDS): clRGinfo -c \"$rg\"" >>$CLMGR_TMPLOG # Always log commands rginfo=$(VERBOSE_LOGGING="" clRGinfo -c "$rg" 2>>$CLMGR_TMPLOG) typeset -i clRGinfo_rc=$? print "$0()[$LINENO]($SECONDS): clRGinfo RC: $clRGinfo_rc; rginfo == \"$rginfo\"" >>$CLMGR_TMPLOG # Always log command result if (( $clRGinfo_rc == RC_SUCCESS )) && [[ -n $rginfo ]] then properties[TYPE]=$(print -- "$rginfo" | tail -n 1 | cut -d: -f 4) if [[ ${properties[PRIMARYNODES]} != *([[:space:]]) ]]; then data=$(CL=$LINENO get_rg_state "$rginfo" "${properties[PRIMARYNODES]}") properties[STATE]=${data##*\|} properties[CURRENT_NODE]=${data%%\|*} if [[ ${properties[SITE_POLICY]} != "ignore" ]]; then data=$(CL=$LINENO get_rg_state "$rginfo" "${properties[SECONDARYNODES]}" secondary) properties[SECONDARY_STATE]=${data##*\|} properties[CURRENT_SECONDARY_NODE]=${data%%\|*} fi else data=$(cllsres -c -s -g "$rg" | grep -v "^#" | cut -d: -f$all_nodes) data=$(CL=$LINENO get_rg_state "$rginfo" "$data") properties[STATE]=${data##*\|} properties[CURRENT_NODE]=${data%%\|*} fi else : We did not get reliable, or possibly any, output from clRGinfo typeset STARTUP="" print "$0()[$LINENO]($SECONDS): clodmget -q \"group=$rg\" -f startup_pref -n HACMPgroup" >>$CLMGR_TMPLOG STARTUP=$(clodmget -q "group=$rg" -f startup_pref -n HACMPgroup) print "$0()[$LINENO]($SECONDS): clodmget RC: $? (STARTUP == \"$STARTUP\")" >>$CLMGR_TMPLOG properties[TYPE]="non-concurrent" [[ $STARTUP == "OAAN" ]] && properties[TYPE]="concurrent" # : Confirm if all nodes are offline. If so, set the state to offline. : If we are not able to set STATE here, it will be reported as "UNKNOWN". # typeset DATA=$(clcmd lssrc -ls clstrmgrES 2>/dev/null | grep "Current state:") DATA=${DATA//@(Current state: |ST_INIT|NOT_CONFIGURED)/ } [[ $DATA == *([[:space:]]) ]] && properties[STATE]="OFFLINE" # : If site policy is "ignore" then we always report SECONDARY_STATE as blank regardless : of any info from clRGinfo. # if [[ ${properties[SITE_POLICY]} != "ignore" ]]; then properties[SECONDARY_STATE]="OFFLINE" fi fi log_return_msg 0 "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_get_resourcegroup_state()" #============================================================================ # # Name: devDoc # # Description: This is a never-to-be-called, wrapper function that all the # clmgr FPATH functions implement in order to hide embedded # syntax from trace logging. This information is implemented # in POD format, and can be viewed in a number of ways using # POD tools. Some viewing suggestions for this function's POD- # formatted information are: # # perldoc # pod2text -c # pod2text -c --code # pod2html # # However, the more important use for this information is that # it is parsed by clmgr to display the syntax for this file's # operation. The information in the "SYNOPSIS" section is used # for this purpose. This feature was originally implemented # using the man page information. However, in a code review it # was pointed out that this approach had to be changed because # customers do not have to install the man pages! Therefore, a # built-in dependency on man page information would break the # automatic help feature of clmgr. So the SYNPOSIS section must # be used instead. # # IMPORTANT: As a result of this, it is imperative that the # information in this SYNOPSIS be kept in sync # with the man page information, which is owned # by the IDD team. # # Inputs: None. # # Outputs: None. # # Returns: n/a (not intended to be invoked) # #============================================================================ function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_get_resourcegroup_state =head1 VERSION Version Number: 1.10 Last Extracted: 8/6/13 13:32:28 Last Changed: 8/2/13 13:03:34 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_resourcegroup_state.sh, hacmp.assist, 61haes_r713, 1332A_hacmp713 =head1 SYNOPSIS KLIB_HACMP_get_resourcegroup_state =head1 RETURN 0: no errors were detected; the operation appears to have been successful 1: a general error has occurred 2: a specified resource does not exist, or could not be found 3: some required input was missing 4: some detected input was incorrect in some way 5: a required dependency does not exist 6: a specified search failed to match any data =head1 COPYRIGHT =cut } # End of "devDoc()" #============================================================================== # The following, comment block attempts to enforce coding standards when this # file is edited via emacs or vim. This block _must_ appear at the very end # of the file, or the editor will not find it, and it will be ignored. #============================================================================== # Local Variables: # indent-tabs-mode: nil # tab-width: 4 # End: #============================================================================== # vim: tabstop=4 shiftwidth=4 expandtab #==============================================================================