#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2019,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_rg_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_get_rg_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect resource group information. It invokes the # "cllsres" utility and mines its output for all relevant # resource group data. # # Inputs: See the "devDoc()" function at the bottom of this file. # # 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 at the bottom of this file for # the standard return code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_get_rg_attributes { . $HALIBROOT/log_entry "$0()" "$CL" : version="@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_rg_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM" : INPUTS: $* typeset rg=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then rg= typeset -n properties=$1 else typeset -n properties=$2 fi [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset startup= fallover= fallback= nodelist= name= value= resourcename= typeset -i INDEX=0 rc=$RC_SUCCESS typeset key= RGS= data= typeset -i matches=0 i=0 typeset -u attr= uc_key= typeset -A queries integer rg_count=0 [[ $CLMGR_CMD_GROUP_SIZE != +([0-9]) ]] && CLMGR_CMD_GROUP_SIZE=10 (( $CLMGR_CMD_GROUP_SIZE < 1 )) && CLMGR_CMD_GROUP_SIZE=1 export CLMGR_CMD_GROUP_SIZE #=================================================== : Check for any specified attribute=value pairs. : If any are found, use those to query the output. #=================================================== while (( $# > 0 )); do value="$1" if [[ $value == *=* ]]; then attr=${value%%=*} # "attr" makes this uppercase queries[$attr]="${value#*=}" fi shift done #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then rc=$RC_MISSING_DEPENDENCY #======================================= : Make sure we have something to query #======================================= elif [[ -n $rg ]]; then for rg in ${rg//,/ }; do CL=$LINENO KLIB_HACMP_is_known_rg "$rg" 2>/dev/null if (( $? != RC_SUCCESS )); then if [[ $CLMGR_PROGNAME == "clmgr" ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$rg" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 154 "Available Resource Groups:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_resourcegroups available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi rc=$RC_NOT_FOUND else RGS="$RGS $rg" (( rg_count++ )) fi done elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then print -- "$0()[$LINENO]($SECONDS): clodmget -f group -n HACMPgroup" >>$CLMGR_TMPLOG # Always log commands clodmget -f group -n HACMPgroup |\ while read name; do [[ -n $RGS ]] && RGS="$RGS " RGS="$RGS$name" (( rg_count++ )) done else if [[ $CLMGR_PROGNAME == "clmgr" ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 fi rc=$RC_MISSING_INPUT fi (( $rc != RC_SUCCESS )) && unset RGS #================================================================= # The variable "INDEX" is used to implement a two-dimensional # array in KSH (to hold values for multiple RGs). Unfortunately, # it is a little tricky and can break certain cases # (i.e. EXPORT_FILESYSTEM_V4 is one such field). So to minimize # this exposure, we use the INDEX mechanism only when multiple # RGs are being queried in a single command invocation. #================================================================= (( rg_count == 1 )) && unset INDEX if [[ -z $CL_SNAPSHOT ]] then #======================================================================= : Collecting RG states is slow. So those retrievals are launched first : as backgrounded processes, so they can run while the rest of the RG : data is being collected. 30% performance improvement. #======================================================================= typeset STATE_PIDS="" typeset STATE_DATA="$TMPDIR/clmgr.KHgrga.rg.$$.$RANDOM" integer CMD_COUNT=0 for rg in $RGS; do ( typeset -A rgattrs CL=$LINENO KLIB_HACMP_get_resourcegroup_state "$rg" rgattrs print "properties[CURRENT_NODE$INDEX]=\"${rgattrs[CURRENT_NODE]}\"" >>$STATE_DATA print "properties[TYPE$INDEX]=\"${rgattrs[TYPE]}\"" >>$STATE_DATA print "properties[STATE$INDEX]=\"${rgattrs[STATE]}\"" >>$STATE_DATA typeset -i XSITE=0 if [[ $CLUSTER_TYPE != "NSC" && -n $(odmget HACMPsite 2>/dev/null) ]] then typeset NODES=" $(clodmget -q group=$rg -n -f nodes HACMPgroup) " typeset ORIG_NODES="$NODES" for SITE in $(clodmget -f name -n HACMPsite); do typeset SITE_NODES=$(clodmget -q name=$SITE -f nodelist -n HACMPsite) for NODE in ${SITE_NODES//,/ }; do NODES=${NODES/ $NODE / } done if [[ $NODES != $ORIG_NODES && \ $NODES != *([[:space:]]) ]] then XSITE=1 fi break done unset NODES if (( $XSITE )); then if [[ ${rgattrs[PRIMARYNODES]} != *([[:space:]]) ]]; then print "properties[NODES$INDEX]=\"${rgattrs[PRIMARYNODES]}\"" >>$STATE_DATA fi print "properties[CURRENT_SECONDARY_NODE$INDEX]=\"${rgattrs[CURRENT_SECONDARY_NODE]}\"" >>$STATE_DATA print "properties[SECONDARYNODES$INDEX]=\"${rgattrs[SECONDARYNODES]}\"" >>$STATE_DATA print "properties[SECONDARY_STATE$INDEX]=\"${rgattrs[SECONDARY_STATE]}\"" >>$STATE_DATA fi fi )& STATE_PIDS="$STATE_PIDS $!" (( CMD_COUNT++ )) if [[ $CLMGR_CMD_GROUP_SIZE == +([0-9]) ]] && (( CMD_COUNT >= CLMGR_CMD_GROUP_SIZE )) then wait $STATE_PIDS STATE_PIDS="" CMD_COUNT=0 fi if [[ -n $INDEX ]]; then (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done if [[ $CLMGR_CMD_GROUP_SIZE == +([0-9]) && -n $STATE_PIDS ]] then : Handle any leftove PIDs wait $STATE_PIDS STATE_PIDS="" fi unset CMD_COUNT fi #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ [[ -n $INDEX ]] && INDEX=0 for rg in $RGS; do print "$0()[$LINENO]($SECONDS): clodmget -q \"group=$rg\" -n -f startup_pref,fallover_pref,fallback_pref,nodes,stype HACMPgroup" >>$CLMGR_TMPLOG # Always log commands clodmget -q "group=$rg" -n -f startup_pref,fallover_pref,fallback_pref,nodes,stype HACMPgroup | IFS=: read properties[STARTUP$INDEX] properties[FALLOVER$INDEX] properties[FALLBACK$INDEX] properties[NODES$INDEX] properties[SITE_TYPE$INDEX] rest print "$0()[$LINENO]($SECONDS): clodmget RC: $?" >>$CLMGR_TMPLOG # Always log command result (( ${#properties[*]} == 0 )) && break properties[NAME$INDEX]=$rg : Get the field names print "$0()[$LINENO]($SECONDS): cllsres -c -s -g \"$rg\" | grep \"^#\"" >>$CLMGR_TMPLOG # Always log commands data=$(cllsres -c -s -g "$rg" | grep "^#") print "$0()[$LINENO]($SECONDS): cllsres RC: $?; data == \"$data\"" >>$CLMGR_TMPLOG # Always log command result data=${data#\#} ORIGIFS="$IFS" IFS=: i=0 for key in $data; do attrs[$i]=$key (( i++ )) done i=0 print "$0()[$LINENO]($SECONDS): cllsres -c -s -g \"$rg\" | grep -v \"^#\"" >>$CLMGR_TMPLOG # Always log commands data=$(cllsres -c -s -g "$rg" | grep -v "^#") print "$0()[$LINENO]($SECONDS): cllsres RC: $?; data == \"$data\"" >>$CLMGR_TMPLOG # Always log command result for value in $data; do value=${value//\"/} value=${value##+([[:space:]])} value=${value%%+([[:space:]])} if [[ ${attrs[$i]} == "RAW_DISK" ]]; then [[ -n $value ]] && properties[DISK$INDEX]=$value elif [[ ${attrs[$i]} == "CONCURRENT_VOLUME_GROUP" ]]; then [[ -n $value ]] && properties[VOLUME_GROUP$INDEX]=$value elif [[ ${attrs[$i]} == "SDNP_SCRIPT_PATH" ]]; then [[ -n $value ]] && properties[NODE_PRIORITY_POLICY_SCRIPT$INDEX]=$value elif [[ ${attrs[$i]} == "SDNP_SCRIPT_TIMEOUT" ]]; then [[ -n $value ]] && properties[NODE_PRIORITY_POLICY_TIMEOUT$INDEX]=$value else # # If FILESYSTEM is empty, it means the actual value is ALL. # But this only makes sense to display if there is a volume # group also specified. In that scenario, update the value # field so it will be more useful in the clmgr output. # if [[ ${attrs[$i]} == "FILESYSTEM" ]] then if [[ -z $value && -n ${properties[VOLUME_GROUP$INDEX]} ]] then value="ALL" fi fi properties[${attrs[$i]}$INDEX]=$value fi (( i++ )) done IFS="$ORIGIFS" # Restore the default field separator case "${properties[NODE_PRIORITY_POLICY$INDEX]}" in cl_highest_idle_cpu) properties[NODE_PRIORITY_POLICY$INDEX]="cpu" ;; cl_lowest_disk_busy) properties[NODE_PRIORITY_POLICY$INDEX]="disk" ;; cl_highest_free_mem) properties[NODE_PRIORITY_POLICY$INDEX]="mem" ;; cl_highest_udscript_rc) properties[NODE_PRIORITY_POLICY$INDEX]="most" ;; cl_lowest_nonzero_udscript_rc) properties[NODE_PRIORITY_POLICY$INDEX]="least" ;; *) properties[NODE_PRIORITY_POLICY$INDEX]="default" ;; esac for RR_TYPE in GENXD_REP_RESOURCE ERCMF_REP_RESOURCE \ SVCPPRC_REP_RESOURCE SRDF_REP_RESOURCE SR_REP_RESOURCE \ TRUCOPY_REP_RESOURCE TC_REP_RESOURCE do typeset MG=$(clodmget -n -q "group=$rg and name=$RR_TYPE" -f value HACMPresource) if [[ $MG != *([[:space:]]) ]]; then properties[MIRROR_GROUP$INDEX]=$MG break fi done if [[ -z ${properties[SITE_POLICY$INDEX]} ]]; then properties[SITE_POLICY$INDEX]="ignore" fi #============================================================== : Even if there is no value for a given attribute, we want to : display a placeholder for it, so the customer always sees a : consistent, complete set of attributes. #============================================================== for key in ${_COLON_ATTR_ORDER[resource_group]}; do if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done if (( ! XSITE )); then if [[ -z $CLMGR_ATTRS ]]; then unset properties[SECONDARYNODES$INDEX] unset properties[SECONDARY_STATE$INDEX] fi fi if [[ $CLUSTER_TYPE == "NSC" || -z $(odmget HACMPsite 2>/dev/null) ]] then if [[ -z $CLMGR_ATTRS ]]; then unset properties[SITE_POLICY$INDEX] fi fi #========================================= : If this is a Standard Edition cluster, : remove the Enterprise-only attributes. #========================================= CL=$LINENO isEnterprise if (( $? == 0 )); then if [[ -z $CLMGR_ATTRS ]]; then for key in RELATIONSHIP SRELATIONSHIP GMD_REP_RESOURCE \ PPRC_REP_RESOURCE ERCMF_REP_RESOURCE SRDF_REP_RESOURCE \ SR_REP_RESOURCE TRUCOPY_REP_RESOURCE TC_REP_RESOURCE \ SVCPPRC_REP_RESOURCE GMVG_REP_RESOURCE SECONDARYNODES \ SECONDARY_STATE MIRROR_GROUP do unset properties[$key$INDEX] done fi else #================================================================= : Convert SRELATIONSHIP to SITE_POLICY, to match the add/modify : input parameters. Also, convert the value to match the input : values associated with add/modify. This is more consistent for : customers. #================================================================= typeset -u SPOL=${properties[SRELATIONSHIP$INDEX]} unset properties[SRELATIONSHIP$INDEX] case $SPOL in *@(PPS|PRIMARY)*) properties[SITE_POLICY$INDEX]="primary" ;; *@(OES|EITHER)*) properties[SITE_POLICY$INDEX]="either" ;; *@(OBS|BOTH)*) properties[SITE_POLICY$INDEX]="both" ;; esac fi if [[ -n $CL_SNAPSHOT ]] then # : Remove the attributes that cannot be obtained from a snapshot # Meaning, they require a live cluster. # if [[ -z $CLMGR_ATTRS ]]; then for key in STATE CURRENT_NODE CURRENT_SECONDARY_NODE TYPE do unset properties[$key$INDEX] done fi fi if [[ -n $INDEX ]]; then (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done # End of the resource groups loop #========================================================================== : Make sure the RG state retrievals are complete, then collect any results #========================================================================== if [[ $CLMGR_CMD_GROUP_SIZE != +([0-9]) && -n $STATE_PIDS ]]; then wait $STATE_PIDS if [[ -f $STATE_DATA && -s $STATE_DATA ]]; then data=$(cat $STATE_DATA) eval "$data" rm -f $STATE_DATA fi elif [[ $CLMGR_CMD_GROUP_SIZE == +([0-9]) ]] then if [[ -f $STATE_DATA && -s $STATE_DATA ]]; then data=$(cat $STATE_DATA) eval "$data" rm -f $STATE_DATA fi fi #========================================================== : If any searches/filters were specified, handle them now #========================================================== if (( $rc == RC_SUCCESS && ${#queries[*]} > 0 )); then CL=$LINENO search_properties queries properties rc=$? fi (( $rc == RC_SUCCESS )) && CL=$LINENO prune_indexes properties log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_get_rg_attributes()" #============================================================================ # # 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_rg_attributes =head1 VERSION Version Number: 1.18.1.4 Last Extracted: 9/27/16 18:23:12 Last Changed: 9/26/16 17:26:40 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_rg_attributes.sh, hacmp.assist, 61haes_r721, 1639A_hacmp721 =head1 SYNOPSIS clmgr query resource_group [,,,...] clmgr -v query resource_group NOTE: the alias for "resource_group" is "rg". =head1 DESCRIPTION Retrieves the configuration data for one or more resource groups. =head1 ARGUMENTS 1. rg [REQUIRED] [string] The label of one or more resource groups (comma or space separated) that are to be queried. 2. properties [REQUIRED] [hash ref] An associative array within which data about the queried objects can be returned to the caller. Environment variable "CLMGR_CMD_GROUP_SIZE" [optional] [posint] Specifies how many backgrounded processes to allow to run at any one time. If you want them all to run concurrently, set it to a higher number. Setting it to one causes all the data lookups to be done serially. This variable allows the process table impact to be controlled a bit, and can also be used to tune performance to some degree. =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 COPYRIGHT International Business Machines Corp. 2006,2015 All Rights Reserved =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 #==============================================================================