#!/bin/bash
IPagent=""
GROUP_MEMBERS=""
DBTYPE=ORA

source wowlib2
#
# sfex
#
#NGM=rsc_sfex_${SFEXID}_${SFEX_INDEX}_$SAPSID
NGM=""
GROUP_MEMBERS="$GROUP_MEMBERS $NGM"
#
# ip
#
if [ -z "$IPagent" ]; then
	IPagent=$DEFAULT_IPagent
fi
for ip_label in $IP_LABELS; do
	ipaddr=${ip_label#*,}
	ipname=${ip_label%,*}
	NGM=rsc_ip_${SAPSID}_${ipname} 
	GROUP_MEMBERS="$GROUP_MEMBERS $NGM"
done
#
# CLX
#
for clx_application in $CLX_APPLICATION; do
	NGM=rsc_clx_${SAPSID}_${clx_application}
	GROUP_MEMBERS="$GROUP_MEMBERS $NGM"
done
#
# LVM
#
for volumegroup in $LVM_VOLUMEGROUPS; do
	NGM=rsc_lvm_${SAPSID}_${volumegroup} 
	GROUP_MEMBERS="$GROUP_MEMBERS $NGM"
done
#
# FS
# 
while read dev dir fsid fstype moptions
do 
	if [ -n "${dev%%\#*}" ]; then # neither an empty line nor a comemnt line (# is first char)
		NGM=rsc_fs_${SAPSID}_${fsid} 
		GROUP_MEMBERS="$GROUP_MEMBERS $NGM"
	fi
done <<< "$FS_FILESYSTEMS"
#
# DB
#
 case "$DBTYPE" in
	ORA ) cli=01-sapdb_ora.cli
		;;
	* )   cli=01-sapdb.cli
		;;
 esac
 NGM=rsc_sapdb_$SAPSID 
GROUP_MEMBERS="$GROUP_MEMBERS $NGM"
#
# SAPINST
#
while read sap_type sap_inst sap_prof sap_parm; do
	if [ "$sap_type" == "${sap_type#\#}" ]; then
		NGM=rsc_sapinst_${sap_inst}  
		GROUP_MEMBERS="$GROUP_MEMBERS $NGM"
	fi
	done <<< "$SAP_INSTANCE_DEF"

woweng2 UUID=grp_sap_${SAPSID} \
    GROUP_MEMBERS="$GROUP_MEMBERS" \
    $wowcli/01-grp-sap.cli
#
# LOC
#

#
# sap scores per node
#
mySCORE=$SAP_SCORES
for node in $ALLNODES
do
        nSCORE=$(firstof_var mySCORE); shift_var mySCORE
        woweng2 UUID=loc_${GRPID}_on_${node} RESOURCE=$GRPID SCORE=$nSCORE  NODE=${node} $wowcli/03-loc.cli
#        woweng $WOWCONSTMODIFY CONSTID=loc_${GRPID}_on_${node} UUID=prefered_loc_${GRPID}_on_${node} SCORE=$nSCORE $wowxml/03-constraint_rule.xml
#        woweng $WOWCONSTMODIFY RULEID=prefered_loc_${GRPID}_on_${node} UUID=prefered_loc_${GRPID}_on_${node}_name ATTRIBUTE="#uname" OPERATOR="eq" VALUE="${node}" $wowxml/03-constraint_rule_expression.xml
done

