#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r720 src/43haes/usr/sbin/cluster/events/rg_move_acquire.sh 1.9.1.7 
#  
# Licensed Materials - Property 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 
# @(#)73	1.9.1.7 src/43haes/usr/sbin/cluster/events/rg_move_acquire.sh, hacmp.events, 61haes_r720, 1536A_hacmp720 8/31/15 04:52:15
# $Id$

#########################################################################
#
#   COMPONENT_NAME: EVENTS
#
#   FUNCTIONS: none
#
#########################################################################

#########################################################################
#                                                                       #
#       Name:           rg_move_acquire                                 #
#                                                                       #
#       Description:    This event script is called when a resource     #
#                       group needs to move.                            #
#                       This script calls the rg_move event script      #
#                       with the "ACQUIRE" argument.                    #
#                                                                       #
#       Called by:      cluster manager                                 #
#                                                                       #
#       Calls to:       rg_move                                         #
#                                                                       #
#       Arguments:      nodename rg_ID                                  #
#                                                                       #
#       Returns:        0       success                                 #
#                       1       failure                                 #
#                       2       bad argument                            #
#                                                                       #
#########################################################################

PROGNAME=$(basename ${0})
PATH="$($(dirname ${0})/../utilities/cl_get_path all)"
export PATH
eval export $(cllsparam -x)

[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
[[ "$VERBOSE_LOGGING" == "high" ]] && version='1.9.1.7'


set -u

if [ $# != 2 ]
then 
  cl_echo 6163 "Usage: $PROGNAME nodename RG_id\n" $PROGNAME
  exit 2
fi

set +u

RG=$(clodmget -n -q "id=$2" -f group HACMPgroup)
export RG

if [[ $EVENT_TYPE == "ACQUIRE_PRIMARY" ]]
then
  # Invoke Active Node Halt Policy before bringing
  # RG online

  typeset -i anhp_ret=0
  typeset -i scsi_ret=0

  typeset ANHP_ENABLED=$(clodmget -n -q "policy = anhp" -f value HACMPsplitmerge)
  if [[ $ANHP_ENABLED == "Yes" ]]
  then
       cl_chk_quarantine
       anhp_ret=$?
  fi

  # Invoke SCSIPR Disk Fencing before bringing RG Online

  typeset SCSIPR_ENABLED=$(clodmget -n -q "policy = scsi" -f value HACMPsplitmerge)
  if [[ $SCSIPR_ENABLED == "Yes" ]]
  then
    # Preempt the VGs which are part of HACMPresource from the node whose CAA state is down
    cl_scsipr_preempt
    scsi_ret=$?
  fi

  ## Following is the information of return codes for ANHP and SCSI Fencing
  ## 0 : quarantine policy is not configured
  ## 1 : quarantine policy is configured and exit with error
  ## 2 : quarantine policy is configured and succeded

  ## Will exit from rg_move_acquire in below cases
  ## a) both ANHP and SCSI fencing configured and failed
  ## b) ANHP is configured and failed, SCSI fencing is not configured
  ## c) SCSI fencing is configred and failed , ANHP is not configured


  if (( $anhp_ret == 1 && $scsi_ret == 1 ))
  then
     exit 1
  elif (( $anhp_ret == 1 && $scsi_ret == 0 ))
  then
     exit 1
  elif (( $scsi_ret == 1 && $anhp_ret == 0 ))
  then
     exit 1
  fi
fi

clcallev rg_move $1 $2 "ACQUIRE"
exit_status=$?
: exit status of clcallev rg_move $1 $2 "ACQUIRE" is: $exit_status
exit $exit_status
