#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2019,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_dependency_attributes.sh 1.5 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2011,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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_dependency_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_get_dependency_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect resource group dependency information (the RG # processing order is handled here, too). The clrgorder # and clrgdependency utilities are invoked to extract the # necessary 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_dependency_attributes { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_dependency_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset dependency=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then dependency= typeset -n properties=$1 elif [[ -n $3 && $2 != "properties" ]] || [[ -n $CLMGR_LOGGING && $3 == "|" ]]; then dependency="$dependency $2" [[ $3 != *=* ]] && typeset -n properties=$3 else [[ $2 != *=* ]] && 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 -i INDEX=0 rc=$RC_SUCCESS typeset -A id_list pcdeps stopafterdeps startafterdeps typeset key= DATA= typeset -i matches=0 typeset -u attr= uc_key= typeset -A clattrs queries properties typeset -i i=0 typeset DEPENDENCIES= #=================================================== : 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 $dependency ]]; then CL=$LINENO KLIB_HACMP_is_known_dependency "$dependency" "" DEPENDENCIES 2>/dev/null if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$dependency" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 142 "Available Dependencies:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_dependencies available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" rc=$RC_NOT_FOUND fi elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then ## ## ACQUIRE/RELEASE ORDER ## print "$0()[$LINENO]($SECONDS): clrgorder -s | grep -v '#'" >>$CLMGR_TMPLOG # Always log commands DATA=$(clrgorder -s 2>>$CLMGR_TMPLOG) print "$0()[$LINENO]($SECONDS): clrgorder RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" | grep -v '#' |\ IFS=: read sel_acq par_acq ser_rel par_rel dep= for rg in ${par_acq//,/ }; do [[ -n $dep ]] && dep="$dep," dep="$dep$rg" done if [[ -n $dep ]]; then DEPENDENCIES[$INDEX]="$dep (ACQUIRE_IN_PARALLEL)" (( INDEX++ )) fi dep= for rg in ${sel_acq//,/ }; do [[ -n $dep ]] && dep="$dep," dep="$dep$rg" done if [[ -n $dep ]]; then DEPENDENCIES[$INDEX]="$dep (ACQUIRE_SERIALLY)" (( INDEX++ )) fi dep= for rg in ${par_rel//,/ }; do [[ -n $dep ]] && dep="$dep," dep="$dep$rg" done if [[ -n $dep ]]; then DEPENDENCIES[$INDEX]="$dep (RELEASE_IN_PARALLEL)" (( INDEX++ )) fi dep= for rg in ${ser_rel//,/ }; do [[ -n $dep ]] && dep="$dep," dep="$dep$rg" done if [[ -n $dep ]]; then DEPENDENCIES[$INDEX]="$dep (RELEASE_SERIALLY)" (( INDEX++ )) fi ## ## PARENT/CHILD ## print "$0()[$LINENO]($SECONDS): clrgdependency -t PARENT_CHILD -sl | grep -v '#'" >>$CLMGR_TMPLOG # Always log commands DATA=$(clrgdependency -t PARENT_CHILD -sl 2>>$CLMGR_TMPLOG) print "$0()[$LINENO]($SECONDS): clrgdependency RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" | grep -v '#' |\ while read parent child; do if [[ -n $parent && -n $child ]] then if [[ -n ${pcdeps[$parent]} ]]; then pcdeps[$parent]="${pcdeps[$parent]},$child" else pcdeps[$parent]=$child fi fi done for parent in ${!pcdeps[*]}; do if [[ -n $parent ]] then DEPENDENCIES[$INDEX]="${parent}+${pcdeps[$parent]} (PARENT_CHILD)" (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done ## ## STOP AFTER ## print "$0()[$LINENO]($SECONDS): clrgdependency -t STOP_AFTER -sl | grep -v '#'" >>$CLMGR_TMPLOG # Always log commands DATA=$(clrgdependency -t STOP_AFTER -sl 2>>$CLMGR_TMPLOG) print "$0()[$LINENO]($SECONDS): clrgdependency RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" | grep -v '#' |\ while read source target; do if [[ -n $source && -n $target ]] then if [[ -n ${stopafterdeps[$target]} ]]; then stopafterdeps[$target]="${stopafterdeps[$target]},$source" else stopafterdeps[$target]=$source fi fi done for target in ${!stopafterdeps[*]}; do if [[ -n $target ]] then DEPENDENCIES[$INDEX]="${target}+${stopafterdeps[$target]} (STOP_AFTER)" (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done ## ## START AFTER ## print -- "$0()[$LINENO]($SECONDS): clrgdependency -t START_AFTER -sl | grep -v '#'" >>$CLMGR_TMPLOG # Always log commands DATA=$(clrgdependency -t START_AFTER -sl 2>>$CLMGR_TMPLOG) print "$0()[$LINENO]($SECONDS): clrgdependency RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" | grep -v '#' |\ while read source target; do if [[ -n $source && -n $target ]] then if [[ -n ${startafterdeps[$target]} ]]; then startafterdeps[$target]="${startafterdeps[$target]},$source" else startafterdeps[$target]=$source fi fi done for target in ${!startafterdeps[*]}; do if [[ -n $target ]] then DEPENDENCIES[$INDEX]="${target}+${startafterdeps[$target]} (START_AFTER)" (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done ## ## SAME SITE ## print -- "$0()[$LINENO]($SECONDS): clrgdependency -t SITECOLLOCATION -sl | grep -v '#'" >>$CLMGR_TMPLOG # Always log commands DATA=$(clrgdependency -t SITECOLLOCATION -sl 2>>$CLMGR_TMPLOG) print "$0()[$LINENO]($SECONDS): clrgdependency RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" | grep -v '#' |\ while read dep; do if [[ -n $dep ]] then dep=${dep//+([[:space:]])/,} DEPENDENCIES[$INDEX]="$dep (SAME_SITE)" (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done ## ## SAME NODE ## print -- "$0()[$LINENO]($SECONDS): clrgdependency -t NODECOLLOCATION -sl | grep -v '#'" >>$CLMGR_TMPLOG # Always log commands DATA=$(clrgdependency -t NODECOLLOCATION -sl 2>>$CLMGR_TMPLOG) print "$0()[$LINENO]($SECONDS): clrgdependency RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" | grep -v '#' |\ while read dep; do if [[ -n $dep ]] then dep=${dep//+([[:space:]])/,} DEPENDENCIES[$INDEX]="$dep (SAME_NODE)" (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done ## ## DIFFERENT NODES ## print -- "$0()[$LINENO]($SECONDS): clrgdependency -t ANTICOLLOCATION -sl | grep -v '#'" >>$CLMGR_TMPLOG # Always log commands DATA=$(clrgdependency -t ANTICOLLOCATION -sl 2>>$CLMGR_TMPLOG) print "$0()[$LINENO]($SECONDS): clrgdependency RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" | grep -v '#' |\ while IFS=: read high int low; do high=${high//+([[:space:]])/,} int=${int//+([[:space:]])/,} low=${low//+([[:space:]])/,} if [[ -n "$high$int$low" && "$high$int$low" != "::" ]]; then DEPENDENCIES[$INDEX]="${high}+${int}+${low} (DIFFERENT_NODES)" (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done else dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT fi (( $rc != RC_SUCCESS )) && unset DEPENDENCIES #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for (( INDEX=0; INDEX<${#DEPENDENCIES[*]}; INDEX++ )); do dependency=${DEPENDENCIES[$INDEX]} [[ $dependency == *([[:space:]]) ]] && continue : NOTE: DEPTYPE is exported from KLIB_HACMP_is_known_dependency CL=$LINENO KLIB_HACMP_is_known_dependency "$dependency" properties[NAME$INDEX]=${dependency%%*([[:space:]])\(*} properties[TYPE$INDEX]=$DEPTYPE if [[ $DEPTYPE == "PARENT_CHILD" ]]; then properties[PARENT$INDEX]=${properties[NAME$INDEX]%%\+*} properties[CHILD$INDEX]=${properties[NAME$INDEX]##*\+} properties[CHILD$INDEX]=${properties[CHILD$INDEX]//+([[:space:]])/,} unset properties[STOP$INDEX] unset properties[START$INDEX] unset properties[AFTER$INDEX] unset properties[HIGH$INDEX] unset properties[INTERMEDIATE$INDEX] unset properties[LOW$INDEX] elif [[ $DEPTYPE == "STOP_AFTER" ]]; then properties[AFTER$INDEX]=${properties[NAME$INDEX]%%\+*} properties[STOP$INDEX]=${properties[NAME$INDEX]##*\+} properties[STOP$INDEX]=${properties[STOP$INDEX]//+([[:space:]])/,} unset properties[PARENT$INDEX] unset properties[CHILD$INDEX] unset properties[START$INDEX] unset properties[HIGH$INDEX] unset properties[INTERMEDIATE$INDEX] unset properties[LOW$INDEX] elif [[ $DEPTYPE == "START_AFTER" ]]; then properties[AFTER$INDEX]=${properties[NAME$INDEX]%%\+*} properties[START$INDEX]=${properties[NAME$INDEX]##*\+} properties[START$INDEX]=${properties[START$INDEX]//+([[:space:]])/,} unset properties[PARENT$INDEX] unset properties[CHILD$INDEX] unset properties[STOP$INDEX] unset properties[HIGH$INDEX] unset properties[INTERMEDIATE$INDEX] unset properties[LOW$INDEX] elif [[ $DEPTYPE == "DIFFERENT_NODES" ]]; then typeset deps=${properties[NAME$INDEX]} properties[HIGH$INDEX]=${deps%%\+*} deps=${deps#*\+} properties[INTERMEDIATE$INDEX]=${deps%%\+*} deps=${deps#*\+} properties[LOW$INDEX]=${deps%\+*} unset properties[PARENT$INDEX] unset properties[CHILD$INDEX] unset properties[STOP$INDEX] unset properties[START$INDEX] unset properties[AFTER$INDEX] else properties[GROUPS$INDEX]=${properties[NAME$INDEX]} unset properties[PARENT$INDEX] unset properties[CHILD$INDEX] unset properties[STOP$INDEX] unset properties[START$INDEX] unset properties[AFTER$INDEX] unset properties[HIGH$INDEX] unset properties[INTERMEDIATE$INDEX] unset properties[LOW$INDEX] fi done #========================================================== : 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_dependency_attributes()" #============================================================================ # # Name: set_differences # # Description: Indicates if there are differences between two # sets of information. # # Inputs: The two sets that are to be compared. # # Outputs: None. # # Returns: 0: if no non-whitespace differences were found. # 1: if SET1 contained an item that SET2 did not # 2: if SET2 contained an item that SET1 did not #============================================================================ function set_differences { typeset SET1=$1 typeset SET2=" $2 " #=================================== : Declare and initialize variables #=================================== typeset ITEM= for ITEM in $SET1; do if [[ " $SET2 " == *\ $ITEM\ * ]]; then SET2="${SET2// $ITEM / }" else return 1 # SET1 contained an item that SET2 did not fi done [[ $SET2 != +([[:space:]]) ]] && return 2 # SET2 contained an item # that SET1 did not return 0 } # End of "set_differences()" #============================================================================ # # 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_dependency_attributes =head1 SYNOPSIS clmgr query dependency clmgr -v query dependency NOTE: the alias for "dependency" is "de". =head1 DESCRIPTION Retrieves the configuration data for the specified dependency. =head1 ARGUMENTS 1. dependency [REQUIRED] [string] The clmgr label/string of the dependency (comma or space separated) that is to be queried. 2. properties [REQUIRED] [hash ref] An associative array within which data about the queried object can be returned to the caller. =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 =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 #==============================================================================