# @(#)29 1.1 src/43haes/usr/sbin/cluster/sa/oraappsrv/sbin/ASUtilities.sh, hacmp, 61haes_r714 11/28/11 15:10:36
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/oraappsrv/sbin/ASUtilities.sh 1.1
#
# Licensed Materials - Property of IBM
#
# Restricted Materials of IBM
#
# COPYRIGHT International Business Machines Corp. 2009,2010
# 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
#----------------------------------------------------------------------------
# Global Definitions:
#----------------------------------------------------------------------------
. /usr/es/sbin/cluster/sa/oraappsrv/sbin/IO
#----------------------------------------------------------------------------
# Functions:
# osaSetASEnvs
# osaASFindComps
# osaASGetVGs
# osaASFindInstances
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# Functions:
# osaSetASEnvs
#
# Purpose:
# Should be called before any AS-related operations are performed.
# It is also VERY IMPORTANT to call (or re-call) it if $ORACLE_HOME
# has been modified in current process and future operations are
# going to be performed in this process.
#
# Arguments:
# (1) ORACLE_HOME
#
# Returns:
# 0 success
# <0 failure
#
function osaSetASEnvs {
[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
if [[ -n $1 ]]; then
ORACLE_HOME=$1
export ORACLE_HOME
fi
OSA_OPMN_CONF_FILE=$ORACLE_HOME/opmn/conf/opmn.xml
OPMN_BINPATH=$ORACLE_HOME/opmn/bin
export OSA_OPMN_CONF_FILE OPMN_BINPATH
}
#----------------------------------------------------------------------------
# Function:
# osaASGetConfigChecksum
#
# Purpose:
# Obtain the opmn.xml checksum to determine if the opmn configuration
# file has changed since the last time we've run verification
#
# Arguments:
# n/a
#
# Returns:
# 0 on success
# <0 on failure
#
function osaASGetConfigChecksum {
typeset m n file
[[ ! -f $OSA_OPMN_CONF_FILE ]] && return 1
/bin/cksum $OSA_OPMN_CONF_FILE | read m n file
echo $m-$n
return 0
}
#----------------------------------------------------------------------------
# Function:
# osaASFindComps
#
# Purpose:
# Find installed components (i.e., resource groups for AS).
# Done by looking up Oracle AS components configured within
# $ORACLE_HOME/opmn/conf/
#
# Arguments:
# n/a
#
# Output:
# List of Oracle Components installed
#
# Returns:
# 0 success
#
function osaASFindComps {
[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
set -A allASInstances
typeset -A comps
typeset line expr instance component index
[[ ! -f $OSA_OPMN_CONF_FILE ]] && return 1
while read line; do
if [[ -z $instance ]]; then # not in an instance section yet
# just keep looking for more the instance section
expr=${line##""} # clean up instance name
# echo "Instance definition found for: " $instance
fi
elif [[ $line == "" ]]; then
osaASPushInstance $instance comps
unset instance
unset comps
else # we are in an instance section so we now look for components
expr=${line##""} # clean up instance name
fi
done < $OSA_OPMN_CONF_FILE
if [[ $instance_name == $instance ]]; then
return 0
else
return 1
fi
}
#---------------------------------------------------------------------------=
# Function:
# osaASPushInstance
#
# Purpose:
# The following function is used to dump an instance configuration
# (i.e., instance name and all components associated with it)
#
# Arguments:
# $1 - instance name
# $2 - component reference (returned assoc array) by ref
#
# Returns:
#
function osaASPushInstance {
[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
typeset inst=$1
typeset -n compref=$2
typeset comp index
# For now we shall just populate it in memory, but eventually it should
# call App Discovery config storage functions.
(( index=${#allASInstances[*]} ))
allASInstances[$index]=$inst
# Need to change the name, remove . -> _
typeset instance_name=${inst//\./\_}
for index in ${!compref[*]}; do
key=${instance_name}"_"${index}
allASComponents[$key]="${compref[$index]}"
done
}
#----------------------------------------------------------------------------
# Function:
# osaASGetVGs
#
# Purpose:
# Returns the Volume Group containing $ORACLE_HOME
#
# Arguments:
# -none-
#
# Returns:
# Returns(echos) a VG name
#
function osaASGetVGs {
[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
typeset vg=$(KLIB_AIX_get_vg_by_path $ORACLE_HOME)
echo $vg
}
#----------------------------------------------------------------------------
# Function:
# osaASFindInstances
#
# Purpose:
# Find the Oracle Instances (Application Server)
#
# Arguments:
# n/a
#
# Output:
# list of instances
#
# Returns:
# n/a
#
function osaASFindInstances {
[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
osaASFindComps
typeset inst
for inst in ${allASInstances[*]}; do
echo $inst
done
}
#-----------------------------------------------------------------------------
# Function:
# osaASRemoveComponents
#
# Purpose:
# Remove the application monitors, application servers, and resource groups
# from the PowerHA SystemMirror configuration. In addition the SystemMirror metadata stored for
# this instance is removed from the cluster configuration.
#
# Arguments:
# (1) application name
#
# Returns:
# 0 on success
# 1 on failure
#
function osaASRemoveComponents {
[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
typeset -L32 appid=$1
for app in $(osaASGetResource $appid APPLICATIONS); do
MONITORS=$(clvt query application $app | grep ASSOCIATEDMONITORS | awk -F= '{ print $2 }' | sed -e "s/\"//g")
for monitor in $MONITORS; do
clvt delete application_monitor $monitor
(( $? != 0 )) && {
user_msg 30 21 $monitor
InternalErrorAbort
}
done
clvt delete application $app > /dev/null 2>&1
(( $? != 0 )) && {
user_msg 30 22 $app
InternalErrorAbort
}
done
for rg in $(osaASGetResourceGroups $appid); do
clvt delete resource_group $rg >/dev/null 2>&1
(( $? != 0 )) && {
user_msg 30 23 $rg
InternalErrorAbort
}
done
#Remove Filecollection
clvt delete file_collection $appid 2>/dev/null
# Remove the application (SA) references for this instance
clrmsaapp -a $appid
(( $? != 0 )) && {
user_msg 30 24 $appid
InternalErrorAbort
}
return 0
}