Sei sulla pagina 1di 12

#!

/bin/ksh
#*******************************************************************************
***********************
#@@@@@@@@@@@@@@@ Updated Wrapper Script supporting workflow instance concurrency
@@@@@@@@@@@@@@@@@@@@@#
* For more details switch to bottom of script
############################################ ROHIT SAINI (E20038884) ########
###################################
#*******************************************************************************
***********************
#*******************************************************************************
***********************
##################################################
##--- Source Informatica environment -----##
##################################################
. .infa_env
export
export
export
export
export

FOLDER=""
Parameterfile=""
INSTANCE_ID=""
WORKFLOW_NAME=""
wrkflw_log_file_name=""

write_log()
# write in the custom created log file c
reated in "log" folder
{
echo "`date` : $1" | tee -a ${LOG_FILE}
}
displyhelp()
# function to display the usage of wrapp
er script
{
echo "*USAGE=>SCRIPT -LOC <SCRIPT_ADDRESS> -FOLDER <FOLDER_NAME> -PAR
AM <Parameter_File> [-INST_ID <Instance_ID>] -WF <Workflow_Name> -INTGS [Integra
tion Servic]>"
echo "*Option within [] are optional"
echo "*USAGE==>> SCRIPT -HELP for help"
exit
}
wait_for_wrkflw()
one of the following state
{
sleep 5
export STATUS_ENV=$1
of pmcmd command

# wait for the workflow to get into into

# used here to capture execution status

WF_RUNID=`cat ${LOG_FILE} | grep "run id" | awk -F"[" '{print $3}' | a


wk -F"]" '{print $1}'`
$INFA_HOME/server/bin/pmcmd getworkflowdetails -sv $INTEG_SERVICE -d $DO
MAIN -uv User -pv PASS -f $FOLDER -rin $INSTANCE_ID $WORKFLOW_NAME 1> $REC_FILE
2> $REC_FILE
# needed most of the time , for example whi
le recovering the suspended session without any errcr correction

export WF_STATUS=`cat ${REC_FILE} | grep "Workflow run status" | awk -F"


[" '{print $2}' | awk -F"]" '{print $1}'`
if [ -z $WF_STATUS ];then # sometimes unable to catch the Workflow Run
Status while running through Instance ID so then run ID is required and mostly
it is vice-versa
$INFA_HOME/server/bin/pmcmd getworkflowdetails -sv $INTEG_SERVIC
E -d $DOMAIN -uv User -pv PASS -f $FOLDER -wfrunid $WF_RUNID $WORKFLOW_NAME 1>$
{REC_FILE} 2>${REC_FILE}
export WF_STATUS=`cat ${REC_FILE} | grep "Workflow run status" |
awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
fi
export WF_STATUS=`cat ${REC_FILE} | grep "Workflow run status" | awk -F"
[" '{print $2}' | awk -F"]" '{print $1}'`
case "$WF_STATUS" in
of startwrokflow as accordingly
Aborted)
export
;;
Disabled)
export
;;
Failed)
export
;;
Scheduled)
export
;;
Stopped)
export
;;
Succeeded)

# here we overwrite the status variable


STATUS_ENV=100
STATUS_ENV=101
STATUS_ENV=102
STATUS_ENV=103
STATUS_ENV=104

# STATUS_ENV is not assigned because pmc


md may return Succeeded but may any one of the condition mentioned in
# check_status may be true
;;
Suspended)
export STATUS_ENV=105
;;
Terminated)
export STATUS_ENV=106
;;
Unscheduled)
export STATUS_ENV=107
;;
"")
;;
# STATUS_ENV = remain as it is..
*)
# for example in running condtion, suspe
nding condition etc.
wait_for_wrkflw $STATUS_ENV # performing functio
n recursion to get the workflow status after running state:
esac
}

check_status()
# function to display the status of the
pmcmd command as well as act accordingly with failure of workflow
{
EXT_STATUS=$1
# status passed as an argument
if [ $1 -eq 0 ]
# if workflow successfully executed with
proper functioning of pmcmd command
then
(( RET_STATUS=RET_STATUS+EXT_STATUS ))
# customized ret
urn value for capturing in run environment

export wrkflw_log_file_name=`cat $REC_FILE | grep "Workf


low log file:" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`

# while recovering the workflow there is multiple occurance of same task


name in the ERROR as well as Execution Succeeded columns
set -A RECOVER_TASK_ARRAY ${Task_Name}
for i in ${RECOVER_TASK_ARRAY[@]}; # to get the session
log file all the failed session
do
succeeded_task=`cat $wrkflw_log_file_name | grep
"$i" | grep ": Execution succeeded."`
if [ ! -z ${TASK_NAME} ]
# delete the .rec file of successfull workflow
then
rm ${PMRootDir}/bin/${INSTANCE_ID}_${FO
LDER}_${WORKFLOW_NAME}_${TASK_NAME}.rec
fi
done

if [ ! -z ${TASK_NAME} ]
# delete the .re
c file of successfull workflow
then
rm ${PMRootDir}/bin/${INSTANCE_ID}_${FOLDER}_${WORKFLOW
_NAME}_${TASK_NAME}.rec
fi
else
case "$1" in
1)
write_log "Integration Service is not available,
or pmcmd cannot connect to the Integration Service. There is a problem with the
TCP/IP host name or port number or with the network."
;;
2)
write_log "Task name, workflow name, or folder n
ame does not exist."
exit RET_STATUS

;;
3)
write_log "An error occurred starting or running
the workflow or task."
;;
4)
write_log "Usage error. You passed the wrong opt
ions to pmcmd. "
;;
5)
write_log "An internal pmcmd error occurred. Con
tact Informatica Global Customer Support. "
;;
7)
write_log "You used an invalid user name or pass
word. "
;;
8)
write_log "You do not have the appropriate permi
ssions or privileges to perform this task. "
;;
9)
write_log "Connection to the Integration Service
timed out while sending the request. "
;;
12)
write_log "Integration Service cannot start reco
very because the session or workflow is scheduled, waiting for an event, waiting
, initializing, aborting, stopping, disabled, or running. "
;;
13)
write_log "User name environment variable is set
to an empty value. "
;;
14)
write_log "Password environment variable is set
to an empty value. "
;;
15)
write_log "User name environment variable is mis
sing. "
;;
16)
write_log "Password environment variable is miss
ing. "
;;

17)
write_log "Parameter file does not exist. "
;;
18)
write_log "Integration Service found the paramet
er file, but it did not have the initial values for the session parameters, such
as $input or $output. "
;;
19)
write_log "Integration Service cannot resume the
session because the workflow is configured to run continuously. "
;;
20)
write_log "A repository error has occurred. Make
sure that the Repository Service and the database are running and the number of
connections to the database is not exceeded. "
;;
21)
write_log "Integration Service is shutting down
and it is not accepting new requests. "
;;
22)
write_log "Integration Service cannot find a uni
que instance of the workflow/session you specified. Enter the command again with
the folder name and workflow name. "
;;
23)
write_log "There is no data available for the re
quest. "
;;
24)
write_log "Out of memory. "
;;
25)
write_log "Command is cancelled. "
;;
# xxxxxxxxxxxxxxxxxxxxxxxxxxx Custom created Error Codes for var
ious purpose xxxxxxxxxxxxxxxxxxxx
100)
;;
101)
write_log "Workflow -- $WORKFLOW_NAME -- is Disa
bled"
;;
102)
write_log "Workflow -- $WORKFLOW_NAME -- is Fail
ed"
;;
103)

write_log "Workflow -- $WORKFLOW_NAME -- is Sche


duled"
;;
104)
write_log "Workflow -- $WORKFLOW_NAME -- is Stop
ped"
;;
105)
write_log "Workflow -- $WORKFLOW_NAME -- is Susp
ended"
;;
106)
write_log "Workflow -- $WORKFLOW_NAME -- is Term
inated"
;;
107)
write_log "Workflow -- $WORKFLOW_NAME -- is Unsc
heduled"
;;
esac
write_log "Task Failed :[Error Code : $1 ] Go to sessio
n log for details"
(( RET_STATUS=RET_STATUS+EXT_STATUS ))
if [ ! -z ${TASK_NAME} ]
then
rm -rf ${PMRootDir}/bin/${INSTANCE_ID}_${FOLDER
}_${WORKFLOW_NAME}_${TASK_NAME}.rec
fi
# work flow log file created after the executio
n of getworkflow details
export wrkflw_log_file_name=`cat $REC_FILE | grep "Work
flow log file:" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
export Task_Name=`cat $wrkflw_log_file_name | grep "ERR
OR :" | grep "Session task instance" | awk -F"[" '{print $3}' | awk -F"]" '{pri
nt $1}' | sort | uniq `
# NOTE :- there can be more than one task
that can be failed
# while recovering the workflow there is multiple occurance of same task
name in the ERROR as well as Execution Succeeded columns
echo " ROHIT SAINI "
set -A RECOVER_TASK_ARRAY ${Task_Name}
for i in ${RECOVER_TASK_ARRAY[@]}; # to get the session
log file all the failed session
do
succeeded_task=`cat $wrkflw_log_file_name | grep "$i" |

grep ": Execution succeeded."`


if [ -z $succeeded_task ];then
rec_file=${PMRootDir}/bin/${INSTANCE_ID}
_${FOLDER}_${WORKFLOW_NAME}_${i}.rec
echo "Work Flow Name: [ ${WORKFLOW_NAME}
]" >${rec_file}
echo "Task Failed: [ $i ]">>${rec_file}
write_log "Failed Task Name = $i"
$INFA_HOME/server/bin/pmcmd gettaskdetai
ls -sv $INTEG_SERVICE -d $DOMAIN -uv User -pv PASS -f $FOLDER -workflow $WORKFL
OW_NAME -rin $INSTANCE_ID $i 1> ${SESSION_LOG_FILE}_$i 2> ${SESSION_LOG_FILE}_$i
else
# needed to delete successful task name related .rec file because during suspend
ed condition successful task comes twice in rows containing both failed and suc
cessfull column of detailed log file from where task name is fetched
rm -rf ${PMRootDir}/bin/${INSTANCE_ID}_$
{FOLDER}_${WORKFLOW_NAME}_${i}.rec
fi
done

echo "ROHIT *********************************************** "


write_log "Session Failed "
write_log "Session log path : $SESSION_LOG_FILE "
fi
}

while [ ! -z $1 ]
eters
do
case $1 in
"-LOC")
shift
export LOC=$1
;;
"-FOLDER")
shift
export FOLDER=$1
;;
"-PARAM")
shift
export PARMFILE=$1
;;
"-INST_ID")
shift
export INSTANCE_ID=$1
;;

# executing till last command task param

"-WF")
shift
export WORKFLOW_NAME=$1
;;
"-WF")
shift
export WORKFLOW_NAME=$1
;;
"-INTGS")
shift
export INTGS=$1
;;
"-HELP")
displyhelp
;;
"-help")
displyhelp
;;
*)
echo "

<<<< Not Val

id >>>>"
displyhelp
exit
;;
esac
shift
done
if [ -z $LOC ] || [ -z $FOLDER ] || [ -z $PARMFILE ] || [ -z $WORKFLOW_NAME ] ;
then
echo " INVALID ARGUMENTS.. missing LOCATION or FOLDER or PARMFILE or WOR
KFLOW_NAME or Integration Service "
displyhelp
exit 1
fi
. $LOC/${FOLDER}_config.cfg
f the script configuration file

# specify the location o

if [ -z $INSTANCE_ID ]
es then assign default session_id to the workflow
then
export INSTANCE_ID="Default_Inst_ID"
fi

# if session_id not pass

export DATE=`date '+%Y%m%d'`


export LOG_FILE=${PMRootDir}/log/${INSTANCE_ID}_${FOLDER}_${WORKFLOW_NAME}_${DAT
E}.log
export SESSION_LOG_FILE=${PMRootDir}/SessLogs/${INSTANCE_ID}_${FOLDER}_${WORKFLO
W_NAME}_${DATE}.log
export REC_FILE=${PMRootDir}/bin/${INSTANCE_ID}_${FOLDER}_${WORKFLOW_NAME}.rec

if [ ! -z $INTGS ]
# provides with the defa
ult Integration Service
then
export INTEG_SERVICE=$INTGS
elif [ -z $INTEG_SERVICE ]
then
echo "INTEGRATION SERVICE NOT SET....PLEASE SET IT"
exit 99
fi
# following code make the script backward compatible
if [ $VERSION != "V2.0" ];then
# check for the version
defined in Config file and prepare the execution accordingly
echo " Informatica Wrapper Version : INFORMATICA_WRAPPER_${VERSION}.ksh
"
case $VERSION in
"V1.0")
return_value=`$LOC/INFORMATICA_WRAPPER_${VERSION}.ksh $FOLDER $P
ARMFILE $WORKFLOW_NAME $INTEG_SERVICE`
echo " Return Status of Script ===> $return_value "
exit $return_value
;;
*)
echo " INVALID Version Defined In Config File "
;;
esac
fi
write_log "Using integration service = $INTEG_SERVICE"
write_log "PMCMD_start_Normal_mode: Running workflow"
write_log "Log Path for capturing any failed session in workflow -> ${REC_FILE}"
export RET_STATUS=0
if [ -s ${REC_FILE} ]
then

# if rec file exist

export RECOVER_FLAG=`cat ${REC_FILE} | grep "Workflow run status:" | awk


-F"[" '{print $2}' | awk -F"]" '{print $1}'`
export REC_BASE_NAME=`basename $REC_FILE ".rec"`
export TASK_REC=`ls ${REC_BASE_NAME}_* `

# recovery files of the

task
write_log
OOOOOOOOOOOOOO"
write_log
write_log
write_log
OOOOOOOOOOOOOO"

"OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
"
Recovery File exists........."
"
Running in Recovery mode"
"OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

if [ -z $TASK_REC ] || [ $RECOVER_FLAG == "Suspended" ] # whenever task


name is not captured recovery mode should be decided here
then
write_log " $WORKFLOW_NAME RECOVERY STARTED -recoverworkflow"
WF_RUNID=`grep "WORKFLOW_RUN_ID" ${LOG_FILE} | cut -d'=' -f2`
$INFA_HOME/server/bin/pmcmd recoverworkflow -sv $INTEG_SERVICE d $DOMAIN -uv User -pv PASS -f $FOLDER -rin $INSTANCE_ID $WORKFLOW_NAME 1> $LOG
_FILE 2> $LOG_FILE
export STATUS_ENV=$?
wait_for_wrkflw $STATUS_ENV
hat see the workflow status
check_status $STATUS_ENV

# calling the function t

if [ $STATUS_ENV -eq 0 ];then


write_log " Workflow Recovered Successfully "
for i in $TASK_REC
do
rm -rf $i
done
rm -rf $REC_FILE
fi
exit $STATUS_ENV
else
write_log " $WORKFLOW_NAME RECOVERY STARTED -startworkflow recov
ery"
for i in $TASK_REC
do
export TASK_NAME=`echo $i |sed 's/'${REC_BASE_NAME}_'//'
|sed 's/\.rec//'`
export wrkflw_log_file_name=`cat $REC_FILE | grep "Work
flow log file:" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
$INFA_HOME/server/bin/pmcmd startworkflow -sv $INTEG_SER
VICE -d $DOMAIN -uv User -pv PASS -f $FOLDER -paramfile $PMRootDir/BWParam/$PAR
MFILE -startfrom $TASK_NAME -recovery -rin $INSTANCE_ID $WORKFLOW_NAME 1> $LOG
_FILE 2> $LOG_FILE
export STATUS_ENV=$?
$INFA_HOME/server/bin/pmcmd getworkflowdetails -sv $INTE
G_SERVICE -d $DOMAIN -uv User -pv PASS -f $FOLDER -rin $INSTANCE_ID $WORKFLOW_N
AME > ${REC_FILE}
wait_for_wrkflw $STATUS_ENV
# calling the function t
hat see the workflow status
check_status $STATUS_ENV
write_log "Task --> $TASK_NAME recovered successfully"

done
if [ $STATUS_ENV -eq 0 ];then
rm -rf $REC_FILE
fi
exit $STATUS_ENV
fi
write_log "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOO"
write_log "
Running workflow in re-start mode ENDS
"
write_log "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOO"
#----------------------------- end of RECOVER TASK -------------------------------#
else
$INFA_HOME/server/bin/pmcmd startworkflow -sv $INTEG_SERVICE -d
$DOMAIN -uv User -pv PASS -f $FOLDER -paramfile $PMRootDir/BWParam/$PARMFILE -r
in $INSTANCE_ID $WORKFLOW_NAME 1>$LOG_FILE 2> $LOG_FILE
export STATUS_ENV=$?
wait_for_wrkflw $STATUS_ENV
hat see the workflow status
check_status $STATUS_ENV

# calling the function t

if [ $STATUS_ENV -eq 0 ]
then
write_log " Process completed successfully "
fi

fi
if [ $RET_STATUS -eq 0 ]
then
rm -rf ${REC_FILE}
fi
exit $RET_STATUS

#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx---- end of script ------xxxxxxxxxxxxxxxxxx


xxxxxxxxxxxxxxxxxxxxxxxxxx
####################### SELF EXPLANATORY POINTS TO REMEMBER IN THIS SCRIPT #####
##########################
#--------------- 1) ************** Do not confuse Wrapper path with Config file
path ***************

#--------------- 2) Same Instance ID for the two concurrent Instance within the
same workflow is not allowed in this script
#--------------- 3) pmcmd -wait option is not being used here to prevent from t
he suspended conditions
#--------------- 4) Should be aware of the difference between failed, aborted,
suspended, terminated workflow conditions
#--------------- 5) Yet scheduled and unscheduled concept is not being introduc
ed in this wrapper script
#--------------- 6) recoverworkflow is being used when task name cannot be reco
vered ,so startworkflow -startfrom is used in other conditions
#--------------- 7) Two or more concurrent INSTANCES cannot run on the default
INSTANCE ID, in that case INSTANCE_ID is mandatory
#--------------- 8) We have two different "full detailed workflow log file" and
"customized log file"
#--------------- 9) Custom Workflow log file can be found in "log" directory an
d Session log file in "SessLogs" directory as designed by architect team
#--------------- 10) sleep <seconds> is used to wait for the response from the I
nformatica..
#--------------- 11) If somehow your workflow is not able to get execute, then y
ou would not be able to recover it because of no recovery points
#--------------- 12) If you are not able to recover the workflow than delete all
related ".rec" files and have restart of the workflow through this script
#--------------- 13) Sometime Informatica Integration Service may go down so don
't get panic!
#--------------- 14) Recovery Strategy should be decided properly.
#--------------- 15) Option ==> "Write Backward Compatible Workflow Log File" sh
ould be checked.
#--------------- 16) Many times session log could not be fetched out so no file
would be generated in SessLogs folder
#--------------- 17) Options - commit type, commit interval, HA Recovery should
be taken into consideration as they plays a major role in recovery process.
#--------------- 18) Once one of the failed sessions is recovered , but other do
es not , then while re-running of the recovery process would not touch the recov
ered session.

Potrebbero piacerti anche