Blame SOURCES/bz1395142-1-update-saphana-saphanatopology.patch

aa0b36
diff -uNr a/heartbeat/SAPHana b/heartbeat/SAPHana
aa0b36
--- a/heartbeat/SAPHana	2016-10-14 10:09:56.479051279 +0200
aa0b36
+++ b/heartbeat/SAPHana	2016-10-14 10:29:23.990066292 +0200
aa0b36
@@ -2,8 +2,8 @@
aa0b36
 #
aa0b36
 # SAPHana
aa0b36
 #
aa0b36
-# Description:  Manages two single SAP HANA Instance in System Replication
aa0b36
-#               Planned: do also manage scale-up scenarios
aa0b36
+# Description:  Manages two SAP HANA Databases in System Replication
aa0b36
+#               Planned: do also manage scale-out scenarios
aa0b36
 #               currently the SAPHana is dependent of the analysis of
aa0b36
 #               SAPHanaTopology
aa0b36
 #               For supported scenarios please read the README file provided
aa0b36
@@ -16,7 +16,7 @@
aa0b36
 # Support:      linux@sap.com
aa0b36
 # License:      GNU General Public License (GPL)
aa0b36
 # Copyright:    (c) 2013,2014 SUSE Linux Products GmbH
aa0b36
-# Copyright:    (c) 2015      SUSE Linux GmbH
aa0b36
+#               (c) 2015-2016 SUSE Linux GmbH
aa0b36
 #
aa0b36
 # An example usage:
aa0b36
 #      See usage() function below for more details...
aa0b36
@@ -29,12 +29,13 @@
aa0b36
 #   OCF_RESKEY_INSTANCE_PROFILE (optional, well known directories will be searched by default)
aa0b36
 #   OCF_RESKEY_PREFER_SITE_TAKEOVER (optional, default is no)
aa0b36
 #   OCF_RESKEY_DUPLICATE_PRIMARY_TIMEOUT (optional, time difference needed between two last-primary-tiemstampe (lpt))
aa0b36
-#   OCF_RESKEY_SAPHanaFilter    (optional, should only be set if been told by support or for debugging purposes)
aa0b36
+#   OCF_RESKEY_SAPHanaFilter    (outdated, replaced by cluster property hana_${sid}_glob_filter)
aa0b36
 #
aa0b36
 #
aa0b36
 #######################################################################
aa0b36
 #
aa0b36
 # Initialization:
aa0b36
+SAPHanaVersion="0.152.17"
aa0b36
 timeB=$(date '+%s')
aa0b36
 
aa0b36
 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
aa0b36
@@ -43,6 +44,12 @@
aa0b36
 #
aa0b36
 #######################################################################
aa0b36
 #
aa0b36
+log_attributes=false
aa0b36
+if ocf_is_true "$log_attributes"; then
aa0b36
+    log_attr_file="/var/log/fhATTRIBUTES"
aa0b36
+else
aa0b36
+    log_attr_file="/dev/null"
aa0b36
+fi
aa0b36
 
aa0b36
 HANA_STATE_PRIMARY=0
aa0b36
 HANA_STATE_SECONDARY=1
aa0b36
@@ -107,7 +114,7 @@
aa0b36
     cat <<-EOF
aa0b36
     usage: $0 ($methods)
aa0b36
 
aa0b36
-    $0 manages a SAP HANA Instance as an HA resource.
aa0b36
+    $0 manages two SAP HANA databases (scale-up) in system replication.
aa0b36
 
aa0b36
     The 'start'        operation starts the HANA instance or bring the "clone instance" to a WAITING status
aa0b36
     The 'stop'         operation stops the HANA instance
aa0b36
@@ -145,15 +152,14 @@
aa0b36
 
aa0b36
 
aa0b36
 <resource-agent name="SAPHana">
aa0b36
-<version>0.151.1</version>
aa0b36
+<version>$SAPHanaVersion</version>
aa0b36
 
aa0b36
-<shortdesc lang="en">Manages two SAP HANA instances in system replication (SR).</shortdesc>
aa0b36
+<shortdesc lang="en">Manages two SAP HANA database systems in system replication (SR).</shortdesc>
aa0b36
 <longdesc lang="en">
aa0b36
-The SAPHanaSR resource agent manages two SAP Hana instances (databases) which are configured
aa0b36
-in system replication. This first version is limited to the scale-up scenario. Scale-Out is
aa0b36
-not supported in this version.
aa0b36
+The SAPHanaSR resource agent manages two SAP HANA database systems which are configured
aa0b36
+in system replication. SAPHana supports Scale-Up scenarios.
aa0b36
 
aa0b36
-Managing the two SAP HANA instances means that the resource agent controls the start/stop of the
aa0b36
+Managing the two SAP HANA database systems means that the resource agent controls the start/stop of the
aa0b36
 instances. In addition the resource agent is able to monitor the SAP HANA databases to check their
aa0b36
 availability on landscape host configuration level. For this monitoring the resource agent relies on interfaces
aa0b36
 provided by SAP. A third task of the resource agent is to also check the synchronisation status
aa0b36
@@ -205,9 +211,10 @@
aa0b36
         <longdesc lang="en">Should cluster/RA prefer to switchover to slave instance instead of restarting master locally? Default="yes"
aa0b36
         no: Do prefer restart locally
aa0b36
         yes: Do prefer takever to remote site
aa0b36
+        never: Do never run a sr_takeover (promote) at the secondary side. THIS VALUE IS CURRENTLY NOT SUPPORTED.
aa0b36
         </longdesc>
aa0b36
         <shortdesc lang="en">Local or site recover preferred?</shortdesc>
aa0b36
-        <content type="boolean" default="yes" />
aa0b36
+        <content type="string" default="yes" />
aa0b36
     </parameter>
aa0b36
     <parameter name="AUTOMATED_REGISTER"  unique="0" required="0">
aa0b36
         <shortdesc lang="en">Define, if a former primary should automatically be registered.</shortdesc>
aa0b36
@@ -220,7 +227,7 @@
aa0b36
         <shortdesc lang="en">Time difference needed between to primary time stamps, if a dual-primary situation occurs</shortdesc>
aa0b36
         <longdesc lang="en">Time difference needed between to primary time stamps,
aa0b36
         if a dual-primary situation occurs. If the time difference is
aa0b36
-        less than the time gap, then the cluster hold one or both instances in a "WAITING" status. This is to give an admin
aa0b36
+        less than the time gap, then the cluster holds one or both instances in a "WAITING" status. This is to give an admin
aa0b36
         a chance to react on a failover. A failed former primary will be registered after the time difference is passed. After
aa0b36
         this registration to the new primary all data will be overwritten by the system replication.
aa0b36
         </longdesc>
aa0b36
@@ -290,6 +297,45 @@
aa0b36
     local rc=0; tr -d '"'; return $rc
aa0b36
 }
aa0b36
 
aa0b36
+# function: version: cpmpare two HANA version strings
aa0b36
+function ver_lt() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 0 && return 0 || return 1
aa0b36
+}
aa0b36
+
aa0b36
+function ver_le() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 0 -o $? -eq 1 && return 0 || return 1
aa0b36
+}
aa0b36
+
aa0b36
+function ver_gt() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 2 && return 0 || return 1
aa0b36
+}
aa0b36
+
aa0b36
+function ver_ge() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 2 -o $? -eq 1 && return 0 || return 1
aa0b36
+}
aa0b36
+#
aa0b36
+# function: version: cpmpare two HANA version strings
aa0b36
+#
aa0b36
+function version() {
aa0b36
+    if [ $# -eq 3 ]; then
aa0b36
+        case "$2" in
aa0b36
+            LE | le | "<=" ) ver_le $1 $3;;
aa0b36
+            LT | lt | "<" ) ver_lt $1 $3;;
aa0b36
+            GE | ge | ">=" ) ver_ge $1 $3;;
aa0b36
+            GT | gt | ">" ) ver_gt $1 $3;;
aa0b36
+            * ) return 1;
aa0b36
+        esac
aa0b36
+    elif [ $# -ge 5 ]; then
aa0b36
+        version $1 $2 $3 && shift 2 && version $*
aa0b36
+    else
aa0b36
+        return 1;
aa0b36
+    fi
aa0b36
+}
aa0b36
+
aa0b36
 #
aa0b36
 # function: remoteHost2remoteNode - convert a SAP remoteHost to the cluster node name
aa0b36
 # params:   remoteHost
aa0b36
@@ -372,12 +418,16 @@
aa0b36
     dstr=$(date)
aa0b36
     case "$attr_store" in
aa0b36
         reboot | forever )
aa0b36
-            echo "$dstr: SAPHana: crm_attribute -N ${attr_node} -G -n \"$attr_name\" -l $attr_store -q" >> /var/log/fhATTRIBUTE
aa0b36
-            crm_attribute -N ${attr_node} -G -n "$attr_name" -l $attr_store -q -d "$attr_default" 2>>/var/log/fhATTRIBUTE; rc=$?
aa0b36
+            if ocf_is_true "$log_attributes"; then
aa0b36
+                echo "$dstr: SAPHana: crm_attribute -N ${attr_node} -G -n \"$attr_name\" -l $attr_store -q" >> $log_attr_file
aa0b36
+            fi
aa0b36
+            crm_attribute -N ${attr_node} -G -n "$attr_name" -l $attr_store -q -d "$attr_default" 2>>$log_attr_file; rc=$?
aa0b36
             ;;
aa0b36
         props )
aa0b36
-            echo "$dstr: SAPHana: crm_attribute -G -n \"$attr_name\" -t crm_config -q" >> /var/log/fhATTRIBUTE
aa0b36
-            crm_attribute -G -n "$attr_name" -t crm_config -q -d "$attr_default" 2>>/var/log/fhATTRIBUTE; rc=$?
aa0b36
+            if ocf_is_true "$log_attributes"; then
aa0b36
+                echo "$dstr: SAPHana: crm_attribute -G -n \"$attr_name\" -t crm_config -q" >> $log_attr_file
aa0b36
+            fi
aa0b36
+            crm_attribute -G -n "$attr_name" -t crm_config -q -d "$attr_default" 2>>$log_attr_file; rc=$?
aa0b36
             ;;
aa0b36
     esac
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
@@ -405,12 +455,16 @@
aa0b36
         dstr=$(date)
aa0b36
         case "$attr_store" in
aa0b36
             reboot | forever )
aa0b36
-                echo "$dstr: SAPHana: crm_attribute -N $attr_node -v $attr_value -n \"$attr_name\" -l $attr_store" >> /var/log/fhATTRIBUTE
aa0b36
-                crm_attribute -N $attr_node -v $attr_value -n "$attr_name" -l $attr_store 2>>/var/log/fhATTRIBUTE; rc=$?
aa0b36
+                if ocf_is_true "$log_attributes"; then
aa0b36
+                    echo "$dstr: SAPHana: crm_attribute -N $attr_node -v $attr_value -n \"$attr_name\" -l $attr_store" >> $log_attr_file
aa0b36
+                fi
aa0b36
+                crm_attribute -N $attr_node -v $attr_value -n "$attr_name" -l $attr_store 2>>$log_attr_file; rc=$?
aa0b36
                 ;;
aa0b36
             props )
aa0b36
-                echo "$dstr: SAPHana: crm_attribute -v $attr_value -n \"$attr_name\" -t crm_config -s SAPHanaSR" >> /var/log/fhATTRIBUTE
aa0b36
-                crm_attribute -v $attr_value -n "$attr_name" -t crm_config  -s SAPHanaSR 2>>/var/log/fhATTRIBUTE; rc=$?
aa0b36
+                if ocf_is_true "$log_attributes"; then
aa0b36
+                    echo "$dstr: SAPHana: crm_attribute -v $attr_value -n \"$attr_name\" -t crm_config -s SAPHanaSR" >> $log_attr_file
aa0b36
+                fi
aa0b36
+                crm_attribute -v $attr_value -n "$attr_name" -t crm_config  -s SAPHanaSR 2>>$log_attr_file; rc=$?
aa0b36
                 ;;
aa0b36
         esac
aa0b36
     else
aa0b36
@@ -460,6 +514,10 @@
aa0b36
     # DONE: PRIO2: Only adjust master if value is really different (try to check that)
aa0b36
     oldscore=$(${HA_SBIN_DIR}/crm_master -G -q -l reboot)
aa0b36
     if [ "$oldscore" != "$score" ]; then
aa0b36
+       dstr=$(date)
aa0b36
+       if ocf_is_true "$log_attributes"; then
aa0b36
+           echo "$dstr: SAPHana: crm_master -v $score -l reboot " >> $log_attr_file
aa0b36
+       fi
aa0b36
        super_ocf_log debug "DBG: SET crm master: $score (old: $oldscore)"
aa0b36
        ${HA_SBIN_DIR}/crm_master -v $score -l reboot; rc=$?
aa0b36
     else
aa0b36
@@ -471,9 +529,9 @@
aa0b36
 }
aa0b36
 
aa0b36
 #
aa0b36
-# function: scoring_crm_master - score instance due to role ans sync match (table SCORING_TABLE_PREFERRED_SITE_TAKEOVER)
aa0b36
+# function: scoring_crm_master - score instance due to role ans sync match (table SCORING_TABLE)
aa0b36
 # params:   NODE_ROLES NODE_SYNC_STATUS
aa0b36
-# globals:  SCORING_TABLE_PREFERRED_SITE_TAKEOVER[@],
aa0b36
+# globals:  SCORING_TABLE[@],
aa0b36
 #
aa0b36
 scoring_crm_master()
aa0b36
 {
aa0b36
@@ -482,7 +540,7 @@
aa0b36
     local sync="$2"
aa0b36
     local skip=0
aa0b36
     local myScore=""
aa0b36
-    for scan in "${SCORING_TABLE_PREFERRED_SITE_TAKEOVER[@]}"; do
aa0b36
+    for scan in "${SCORING_TABLE[@]}"; do
aa0b36
         if [ $skip -eq 0 ]; then
aa0b36
             read rolePatt syncPatt score <<< $scan
aa0b36
             if grep "$rolePatt" <<< "$roles"; then
aa0b36
@@ -494,7 +552,7 @@
aa0b36
         fi
aa0b36
     done
aa0b36
     super_ocf_log debug "DBG: scoring_crm_master adjust score $myScore"
aa0b36
-    # TODO: PRIO1: DO Not Score, If we did not found our role/sync at this moment - bsc#919925
aa0b36
+    # DONE: PRIO1: DO Not Score, If we did not found our role/sync at this moment - bsc#919925
aa0b36
     if [ -n "$myScore" ]; then
aa0b36
         set_crm_master $myScore
aa0b36
     fi
aa0b36
@@ -514,28 +572,91 @@
aa0b36
 }
aa0b36
 
aa0b36
 #
aa0b36
+# function: HANA_CALL
aa0b36
+# params:   timeout-in-seconds cmd-line
aa0b36
+# globals:  sid(r), SID(r), InstanceName(r)
aa0b36
+#
aa0b36
+function HANA_CALL()
aa0b36
+{
aa0b36
+    #
aa0b36
+    # TODO: PRIO 5: remove 'su - ${sidadm} later, when SAP HANA resoled issue with
aa0b36
+    #       root-user-called hdbnsutil -sr_state (which creates root-owned shared memory file in /var/lib/hdb/SID/shmgrp)
aa0b36
+    # TODO: PRIO 5: Maybe make "su" optional by a parameter
aa0b36
+    local timeOut=0
aa0b36
+    local onTimeOut=""
aa0b36
+    local rc=0
aa0b36
+    local use_su=1 # Default to be changed later (see TODO above)
aa0b36
+    local pre_cmd=""
aa0b36
+    local cmd=""
aa0b36
+    local pre_script=""
aa0b36
+    local output=""
aa0b36
+    while [ $# -gt 0 ]; do
aa0b36
+        case "$1" in
aa0b36
+            --timeout ) timeOut=$2; shift;;
aa0b36
+            --use-su  ) use_su=1;;
aa0b36
+            --on-timeout ) onTimeOut="$2"; shift;;
aa0b36
+            --cmd ) shift; cmd="$*"; break;;
aa0b36
+        esac
aa0b36
+        shift
aa0b36
+    done
aa0b36
+
aa0b36
+    if [ $use_su -eq 1 ]; then
aa0b36
+        pre_cmd="su - ${sid}adm -c"
aa0b36
+        pre_script="true"
aa0b36
+    else
aa0b36
+        # as root user we need the library path to the SAP kernel to be able to call sapcontrol
aa0b36
+        # check, if we already added DIR_EXECUTABLE at the beginning of LD_LIBRARY_PATH
aa0b36
+        if [ "${LD_LIBRARY_PATH%%*:}" != "$DIR_EXECUTABLE" ]
aa0b36
+        then
aa0b36
+            MY_LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
aa0b36
+        fi
aa0b36
+        pre_cmd="bash -c"
aa0b36
+        pre_script="LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH; export LD_LIBRARY_PATH"
aa0b36
+    fi
aa0b36
+    case $timeOut in
aa0b36
+        0 | inf )
aa0b36
+                  output=$($pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $cmd"); rc=$?
aa0b36
+                  ;;
aa0b36
+        *       )
aa0b36
+                  output=$(timeout $timeOut $pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $cmd"); rc=$?
aa0b36
+                  #
aa0b36
+                  # on timeout ...
aa0b36
+                  #
aa0b36
+                  if [ $rc -eq 124 -a -n "$onTimeOut" ]; then
aa0b36
+                      local second_output=""
aa0b36
+                      second_output=$($pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $onTimeOut");
aa0b36
+                  fi
aa0b36
+                  ;;
aa0b36
+    esac
aa0b36
+    echo "$output"
aa0b36
+    return $rc;
aa0b36
+}
aa0b36
+
aa0b36
+#
aa0b36
 # function: saphana_init - initialize variables for the resource agent
aa0b36
 # params:   InstanceName
aa0b36
-# globals:  OCF_*(r), SID(w), sid(rw), sidadm(w), InstanceName(w), InstanceNr(w), SAPVIRHOST(w), PreferSiteTakeover(w), 
aa0b36
-# globals:  sr_name(w), remoteHost(w), otherNodes(w), rem_SR_name(w)
aa0b36
+# globals:  OCF_*(r), SID(w), sid(rw), sidadm(w), InstanceName(w), InstanceNr(w), SAPVIRHOST(w), PreferSiteTakeover(w),
aa0b36
+# globals:  sr_name(w), remoteHost(w), otherNodes(w), remSR_name(w)
aa0b36
 # globals:  ATTR_NAME_HANA_SYNC_STATUS(w), ATTR_NAME_HANA_CLONE_STATE(w)
aa0b36
 # globals:  DIR_EXECUTABLE(w), SAPSTARTSRV(w), SAPCONTROL(w), DIR_PROFILE(w), SAPSTARTPROFILE(w), LD_LIBRARY_PATH(w), PATH(w)
aa0b36
 # globals:  LPA_DIRECTORY(w), SIDInstanceName(w), remoteNode(w), hdbSrQueryTimeout(w)
aa0b36
+# globals:  NODENAME(w), vNAME(w), hdbver(w),
aa0b36
 # saphana_init : Define global variables with default values, if optional parameters are not set
aa0b36
 #
aa0b36
 function saphana_init() {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=$OCF_SUCCESS
aa0b36
-    local vName
aa0b36
     local clN
aa0b36
     # local site
aa0b36
     # two parameter models (for transition only)
aa0b36
     # OLD: InstanceName
aa0b36
     # NEW: SID InstanceNumber
aa0b36
+    NODENAME=$(crm_node -n)
aa0b36
     SID=$OCF_RESKEY_SID
aa0b36
     InstanceNr=$OCF_RESKEY_InstanceNumber
aa0b36
     SIDInstanceName="${SID}_HDB${InstanceNr}"
aa0b36
     InstanceName="HDB${InstanceNr}"
aa0b36
+    export SAPSYSTEMNAME=$SID
aa0b36
     super_ocf_log debug "DBG: Used new method to get SID ($SID) and InstanceNr ($InstanceNr)"
aa0b36
     sid=$(echo "$SID" | tr [:upper:] [:lower:])
aa0b36
     sidadm="${sid}adm"
aa0b36
@@ -544,15 +665,23 @@
aa0b36
     # DONE: PRIO4: SAPVIRHOST might be different to NODENAME
aa0b36
     # DONE: PRIO1: ASK: Is the output format of ListInstances fix? Could we take that as an API? Answer: Yes
aa0b36
     # try to catch:  Inst Info : LNX - 42 - lv9041 - 740, patch 36, changelist 1444691
aa0b36
-    # We rely on the following format: SID is word#4, NR is work#6, vHost is word#8
aa0b36
-    vName=$(/usr/sap/hostctrl/exe/saphostctrl -function ListInstances \
aa0b36
-        | awk '$4 == SID && $6=NR { print $8 }' SID=$SID NR=$InstanceNr)
aa0b36
+    # We rely on the following format: SID is word#4, SYSNR is work#6, vHost is word#8
aa0b36
+    if [ -e /usr/sap/hostctrl/exe/saphostctrl ]; then
aa0b36
+        vName=$(/usr/sap/hostctrl/exe/saphostctrl -function ListInstances \
aa0b36
+            | awk '$4 == SID && $6 == SYSNR { print $8 }' SID=$SID SYSNR=$InstanceNr 2>/dev/null )
aa0b36
+        super_ocf_log debug "DBG: ListInstances: $(/usr/sap/hostctrl/exe/saphostctrl -function ListInstances)"
aa0b36
+    else
aa0b36
+        super_ocf_log error "ERR: SAPHOSTAGENT is not installed at /usr/sap/hostctrl/exe (saphostctrl missing)"
aa0b36
+    fi
aa0b36
     if [ -z "$vName" ]; then
aa0b36
        #
aa0b36
        # if saphostctrl does not know the answer, try to fallback to attribute provided by SAPHanaTopology
aa0b36
        #
aa0b36
        vName=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_VHOST[@]} "$NODENAME");
aa0b36
     fi
aa0b36
+    if [ -z "$vName" ]; then # last fallback if we are not able to figure out the virtual host name
aa0b36
+       vName="$NODENAME"
aa0b36
+    fi
aa0b36
     SAPVIRHOST=${vName}
aa0b36
     PreferSiteTakeover="$OCF_RESKEY_PREFER_SITE_TAKEOVER"
aa0b36
     AUTOMATED_REGISTER="${OCF_RESKEY_AUTOMATED_REGISTER:-false}"
aa0b36
@@ -571,6 +700,12 @@
aa0b36
     ATTR_NAME_HANA_SRMODE=("hana_${sid}_srmode" "forever")
aa0b36
     ATTR_NAME_HANA_VHOST=("hana_${sid}_vhost" "forever")
aa0b36
     ATTR_NAME_HANA_STATUS=("hana_${sid}_status" "reboot")
aa0b36
+    ATTR_NAME_HANA_OPERATION_MODE=("hana_${sid}_op_mode" "forever")
aa0b36
+    #
aa0b36
+    # new "central" attributes
aa0b36
+    #
aa0b36
+    ATTR_NAME_HANA_FILTER=("hana_${sid}_glob_filter" "props" "ra-act-dec-lpa")
aa0b36
+    SAPHanaFilter=$(get_hana_attribute "X" ${ATTR_NAME_HANA_FILTER[@]})
aa0b36
     #
aa0b36
     # TODO: PRIO4: Table for non-preferred-site-takeover
aa0b36
     #
aa0b36
@@ -591,9 +726,7 @@
aa0b36
     )
aa0b36
     SCORING_TABLE_PREFERRED_LOCAL_RESTART=(
aa0b36
        "[0-9]*:P:[^:]*:master .*  150"
aa0b36
-       "[0-9]*:P:[^:]*:slave  .*  140"
aa0b36
-       "[0-9]*:P:[^:]*:\?     .*    0"
aa0b36
-       "[0-9]*:P:[^:]*:-     .*     0"
aa0b36
+       "[0-9]*:P:[^:]*:.*     .*  140"
aa0b36
        "[0-9]*:S:[^:]*:master SOK    100"
aa0b36
        "[0-9]*:S:[^:]*:master SFAIL  -INFINITY"
aa0b36
        "[0-9]*:S:[^:]*:slave  SOK     10"
aa0b36
@@ -602,6 +735,25 @@
aa0b36
        "[0-9]*:S:[^:]*:-      .*    0"
aa0b36
        ".*                    .*   -1"
aa0b36
     )
aa0b36
+    SCORING_TABLE_PREFERRED_NEVER=(
aa0b36
+       "[234]*:P:[^:]*:master .*     150"
aa0b36
+       "[015-9]*:P:[^:]*:master .*    90"
aa0b36
+       "[0-9]*:P:[^:]*:.*     .*     -INFINITY"
aa0b36
+       "[0-9]*:S:[^:]*:.*     .*     -INFINITY"
aa0b36
+       ".*                    .*     -INFINITY"
aa0b36
+    )
aa0b36
+    if ocf_is_true $PreferSiteTakeover; then
aa0b36
+        SCORING_TABLE=("${SCORING_TABLE_PREFERRED_SITE_TAKEOVER[@]}")
aa0b36
+    else
aa0b36
+        case "$PreferSiteTakeover" in
aa0b36
+            never|NEVER|Never )
aa0b36
+                SCORING_TABLE=("${SCORING_TABLE_PREFERRED_NEVER[@]}")
aa0b36
+                ;;
aa0b36
+            * )
aa0b36
+                SCORING_TABLE=("${SCORING_TABLE_PREFERRED_LOCAL_RESTART[@]}")
aa0b36
+                ;;
aa0b36
+        esac
aa0b36
+    fi
aa0b36
     #
aa0b36
     DUPLICATE_PRIMARY_TIMEOUT="${OCF_RESKEY_DUPLICATE_PRIMARY_TIMEOUT:-7200}"
aa0b36
     super_ocf_log debug "DBG: DUPLICATE_PRIMARY_TIMEOUT=$DUPLICATE_PRIMARY_TIMEOUT"
aa0b36
@@ -615,7 +767,7 @@
aa0b36
     esac
aa0b36
     #
aa0b36
     #
aa0b36
-
aa0b36
+    #
aa0b36
     remoteHost=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_REMOTEHOST[@]});
aa0b36
     if [ -z "$remoteHost" ]; then
aa0b36
        if [ ${#otherNodes[@]} -eq 1 ]; then # we are a 2 node cluster, lets assume the other is the remote-host
aa0b36
@@ -640,7 +792,7 @@
aa0b36
         sr_mode="sync"
aa0b36
     fi
aa0b36
     if [ -n "$remoteNode" ]; then
aa0b36
-        rem_SR_name=$(get_hana_attribute ${remoteNode} ${ATTR_NAME_HANA_SITE[@]});
aa0b36
+        remSR_name=$(get_hana_attribute ${remoteNode} ${ATTR_NAME_HANA_SITE[@]});
aa0b36
     fi
aa0b36
     super_ocf_log debug "DBG: sr_name=$sr_name, remoteHost=$remoteHost, remoteNode=$remoteNode, sr_mode=$sr_mode"
aa0b36
     # optional OCF parameters, we try to guess which directories are correct
aa0b36
@@ -671,26 +823,21 @@
aa0b36
         #
aa0b36
         SAPSTARTPROFILE="$(ls -1 $DIR_PROFILE/${OCF_RESKEY_INSTANCE_PROFILE:-${SID}_${InstanceName}_*})"
aa0b36
     fi
aa0b36
-    # as root user we need the library path to the SAP kernel to be able to call sapcontrol
aa0b36
-    # check, if we already added DIR_EXECUTABLE at the beginning of LD_LIBRARY_PATH
aa0b36
-    if [ "${LD_LIBRARY_PATH%%*:}" != "$DIR_EXECUTABLE" ]
aa0b36
-    then
aa0b36
-        LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
aa0b36
-        export LD_LIBRARY_PATH
aa0b36
-    fi
aa0b36
     PATH=${PATH}:${DIR_EXECUTABLE}; export PATH
aa0b36
+    local ges_ver
aa0b36
+    ges_ver=$(HANA_CALL --timeout 10 --cmd "HDB version" | tr -d " " | awk -F: '$1 == "version" {print $2}')
aa0b36
+    hdbver=${ges_ver%.*.*}
aa0b36
+    #
aa0b36
+    # since rev 111.00 we should use a new hdbnsutil option to get the -sr_state
aa0b36
+    # since rev 112.03 the old option is changed and we should use -sr_stateConfiguration where ever possible
aa0b36
+    #
aa0b36
+    hdbState="hdbnsutil -sr_state"
aa0b36
+    hdbMap="hdbnsutil -sr_state"
aa0b36
+    if version "$hdbver" ">=" "1.00.111"; then
aa0b36
+        hdbState="hdbnsutil -sr_stateConfiguration"
aa0b36
+        hdbMap="hdbnsutil -sr_stateHostMapping"
aa0b36
+    fi
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$OCF_SUCCESS"
aa0b36
-    #############################
aa0b36
-    # TODO: PRIO9: To be able to call landscapeHostConfig.py without su (so as root)
aa0b36
-    # TODO: PRIO9: Research for environment script .htacces or something like that
aa0b36
-    #export SAPSYSTEMNAME=ZLF
aa0b36
-    #export DIR_INSTANCE=/usr/sap/ZLF/HDB02
aa0b36
-    #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR_INSTANCE/exe:$DIR_INSTANCE/exe/Python/lib
aa0b36
-    #export PYTHONPATH=$DIR_INSTANCE/$HOST:$DIR_INSTANCE/exe/python_support:$DIR_INSTANCE/exe
aa0b36
-    #export PYTHONHOME=$DIR_INSTANCE/exe/Python
aa0b36
-    #export SAP_RETRIEVAL_PATH=$DIR_INSTANCE/$HOST
aa0b36
-    #export DIR_EXECUTABLE=$DIR_INSTANCE/exe
aa0b36
-    #############################
aa0b36
     return $OCF_SUCCESS
aa0b36
 }
aa0b36
 
aa0b36
@@ -765,7 +912,11 @@
aa0b36
         # or ownership - they will be recreated by sapstartsrv during next start
aa0b36
         rm -f /tmp/.sapstream5${InstanceNr}13
aa0b36
         rm -f /tmp/.sapstream5${InstanceNr}14
aa0b36
-        $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
aa0b36
+        (
aa0b36
+          export PATH="$DIR_EXECUTABLE${PATH:+:}$PATH"
aa0b36
+          export LD_LIBRARY_PATH="$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
aa0b36
+          $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
aa0b36
+        )
aa0b36
         # now make sure the daemon has been started and is able to respond
aa0b36
         local srvrc=1
aa0b36
         while [ $srvrc -eq 1 -a $(pgrep -f "sapstartsrv.*$runninginst" | wc -l) -gt 0 ]
aa0b36
@@ -809,31 +960,47 @@
aa0b36
 function check_for_primary() {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=$HANA_STATE_DEFECT
aa0b36
-    node_full_status=$(su - ${sidadm} -c "hdbnsutil -sr_state" 2>/dev/null )
aa0b36
-    node_status=$(echo "$node_full_status" | awk '$1=="mode:" {print $2}')
aa0b36
-    super_ocf_log debug "DBG: check_for_primary: node_status=$node_status"
aa0b36
-    # TODO: PRIO2: Maybe we need to use a fallback interface when hdbnsitil does not answer properly -> lookup in config files?
aa0b36
+    # TODO: PRIO 3: Check beginning from which SPS does SAP support HDBSettings.sh?
aa0b36
+    # TODO: Limit the runtime of hdbnsutil and use getParameter.py as fallback
aa0b36
+    # TODO: PRIO2: Maybe we need to use a fallback interface when hdbnsutil does not answer properly -> lookup in config files?
aa0b36
     #              This might also solve some problems when we could not figure-out the ilocal or remote site name
aa0b36
-    for i in  1 2 3 4 5 6 7 8 9; do
aa0b36
+    local chkMethod=""
aa0b36
+    for chkMethod in  hU hU hU gP; do
aa0b36
+       case "$chkMethod" in
aa0b36
+           gP )
aa0b36
+                local gpKeys=""
aa0b36
+                gpKeys=$(echo --key=global.ini/system_replication/{mode,site_name,site_id})
aa0b36
+                node_full_status=$(HANA_CALL --timeout 60 --cmd "HDBSettings.sh getParameter.py $gpKeys --sapcontrol=1" 2>&1 | awk -F/ 'BEGIN {out=0} /^SAPCONTROL-OK: <begin>/ { out=1 } /^SAPCONTROL-OK: <end>/ { out=0 } /=/ {if (out==1) {print $3} }')
aa0b36
+                node_status=$(echo "$node_full_status" | awk -F= '$1=="mode" {print $2}')
aa0b36
+                super_ocf_log info "ACT: Using getParameter.py as fallback - node_status=$node_status"
aa0b36
+                ;;
aa0b36
+           hU | * )
aa0b36
+                # DONE: PRIO1: Begginning from SAP HANA rev 112.03 -sr_state is not longer supported
aa0b36
+                node_full_status=$(HANA_CALL --timeout 60 --cmd "$hdbState" 2>/dev/null )
aa0b36
+                node_status=$(echo "$node_full_status" | awk '$1=="mode:" {print $2}')
aa0b36
+                super_ocf_log debug "DBG: check_for_primary: node_status=$node_status"
aa0b36
+                ;;
aa0b36
+       esac
aa0b36
        case "$node_status" in
aa0b36
            primary )
aa0b36
-               super_ocf_log info "FLOW: $FUNCNAME rc=HANA_STATE_PRIMARY"
aa0b36
-               return $HANA_STATE_PRIMARY;;
aa0b36
+               rc=$HANA_STATE_PRIMARY
aa0b36
+               break;;
aa0b36
            syncmem | sync | async )
aa0b36
-               super_ocf_log info "FLOW: $FUNCNAME rc=HANA_STATE_SECONDARY"
aa0b36
-               return $HANA_STATE_SECONDARY;;
aa0b36
+               rc=$HANA_STATE_SECONDARY
aa0b36
+               break;;
aa0b36
            none ) # have seen that mode on second side BEFEORE we registered it as replica
aa0b36
-               super_ocf_log info "FLOW: $FUNCNAME rc=HANA_STATE_STANDALONE"
aa0b36
-               return $HANA_STATE_STANDALONE;;
aa0b36
+               rc=$HANA_STATE_STANDALONE
aa0b36
+               break;;
aa0b36
            * )
aa0b36
                super_ocf_log err "ACT: check_for_primary:  we didn't expect node_status to be: <$node_status>"
aa0b36
                dump=$( echo $node_status | hexdump -C );
aa0b36
                super_ocf_log err "ACT: check_for_primary:  we didn't expect node_status to be: DUMP <$dump>"
aa0b36
-               node_full_status=$(su - ${sidadm} -c "hdbnsutil -sr_state" 2>/dev/null )
aa0b36
-               node_status=$(echo "$node_full_status" | awk '$1=="mode:" {print $2}')
aa0b36
+               # TODO: Limit the runtime of hdbnsutil and use getParameter.py as fallback
aa0b36
+               # SAP_CALL
aa0b36
                super_ocf_log debug "DEC: check_for_primary: loop=$i: node_status=$node_status"
aa0b36
                # TODO: PRIO1: Maybe we need to keep the old value for P/S/N, if hdbnsutil just crashes
aa0b36
        esac;
aa0b36
+       sleep 2
aa0b36
     done
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
     return $rc
aa0b36
@@ -854,12 +1021,18 @@
aa0b36
 {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=-1 srRc=0 all_nodes_other_side="" n="" siteParam=""
aa0b36
-    if [ -n "$rem_SR_name" ]; then
aa0b36
-       siteParam="--site=$rem_SR_name"
aa0b36
+    if [ -n "$remSR_name" ]; then
aa0b36
+       siteParam="--site=$remSR_name"
aa0b36
     fi
aa0b36
-    FULL_SR_STATUS=$(su - $sidadm -c "python $DIR_EXECUTABLE/python_support/systemReplicationStatus.py $siteParam" 2>/dev/null); srRc=$?
aa0b36
-    super_ocf_log info "DEC $FUNCNAME systemReplicationStatus.py (to site '$rem_SR_name')-> $srRc"
aa0b36
-    super_ocf_log info "FLOW $FUNCNAME systemReplicationStatus.py (to site '$rem_SR_name')-> $srRc"
aa0b36
+    # TODO: Get rid of the su by using a new interface:
aa0b36
+    # SAPSYSTEMNAME=SLE /usr/sap/SLE/HDB00/HDBSettings.sh systemReplicationStatus.py $siteParam
aa0b36
+    # TODO: Check beginning from which SPS does SAP support HDBSettings.sh?
aa0b36
+    # TODO: Limit the runtime of systemReplicationStatus.py
aa0b36
+    # SAP_CALL
aa0b36
+    # FULL_SR_STATUS=$(su - $sidadm -c "python $DIR_EXECUTABLE/python_support/systemReplicationStatus.py $siteParam" 2>/dev/null); srRc=$?
aa0b36
+    FULL_SR_STATUS=$(HANA_CALL --timeout 60 --cmd "systemReplicationStatus.py" 2>/dev/null); srRc=$?
aa0b36
+    super_ocf_log info "DEC $FUNCNAME systemReplicationStatus.py (to site '$remSR_name')-> $srRc"
aa0b36
+    super_ocf_log info "FLOW $FUNCNAME systemReplicationStatus.py (to site '$remSR_name')-> $srRc"
aa0b36
     #
aa0b36
     # TODO: PRIO2: Here we might also need to filter additional sites (if multi tier should be supported)
aa0b36
     #              And is the check for return code capable for chains?
aa0b36
@@ -890,7 +1063,7 @@
aa0b36
           # ok we should be careful and set secondary to SFAIL
aa0b36
           super_ocf_log info "FLOW $FUNCNAME SFAIL"
aa0b36
           set_hana_attribute "$remoteNode" "SFAIL" ${ATTR_NAME_HANA_SYNC_STATUS[@]}
aa0b36
-          super_ocf_log info "ACT site=$sr_name, seting SFAIL for secondary (5) - srRc=$srRc lss=$lss"
aa0b36
+          super_ocf_log info "ACT site=$sr_name, setting SFAIL for secondary (5) - srRc=$srRc lss=$lss"
aa0b36
           # TODO: PRIO1 - P004: need to check LSS again to avoid dying primary to block (SFAIL) secondary
aa0b36
           lpa_set_lpt 10 "$remoteNode"
aa0b36
           rc=1
aa0b36
@@ -898,7 +1071,7 @@
aa0b36
     else
aa0b36
        super_ocf_log info "FLOW $FUNCNAME SFAIL"
aa0b36
        set_hana_attribute "$remoteNode" "SFAIL" ${ATTR_NAME_HANA_SYNC_STATUS[@]}
aa0b36
-       super_ocf_log info "ACT site=$sr_name, seting SFAIL for secondary (2) - srRc=$srRc"
aa0b36
+       super_ocf_log info "ACT site=$sr_name, setting SFAIL for secondary (2) - srRc=$srRc"
aa0b36
        # TODO: PRIO1 - P004: need to check LSS again to avoid dying primary to block (SFAIL) secondary
aa0b36
        lpa_set_lpt 10 "$remoteNode"
aa0b36
        rc=1;
aa0b36
@@ -992,14 +1165,28 @@
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=0
aa0b36
     #
aa0b36
-    su - $sidadm -c "python $DIR_EXECUTABLE/python_support/landscapeHostConfiguration.py" 1>/dev/null 2>/dev/null; rc=$?
aa0b36
+    # TODO: Get rid of the su by using a new interface:
aa0b36
+    # SAPSYSTEMNAME=SLE /usr/sap/SLE/HDB00/HDBSettings.sh landscapeHostConfiguration.py
aa0b36
+    # TODO: Check beginning from which SPS does SAP support HDBSettings.sh?
aa0b36
+    # DONE: Limit the runtime of landscapeHostConfiguration.py
aa0b36
+    HANA_CALL --timeout 60 --cmd "landscapeHostConfiguration.py" 1>/dev/null 2>/dev/null; rc=$?
aa0b36
+    if [ $rc -eq 124 ]; then
aa0b36
+        # TODO: PRIO 1: Check, if we should loop here like 'for i in 1 2 3 ...' ?
aa0b36
+        # landscape timeout
aa0b36
+        sleep 20
aa0b36
+        HANA_CALL --timeout 60 --cmd "landscapeHostConfiguration.py" 1>/dev/null 2>/dev/null; rc=$?
aa0b36
+        if [ $rc -eq 124 ]; then
aa0b36
+           # TODO PRIO2: How to handle still hanging lss - current solution is to say "FATAL"
aa0b36
+           rc=0
aa0b36
+        fi
aa0b36
+    fi
aa0b36
     return $rc;
aa0b36
 }
aa0b36
 
aa0b36
 #
aa0b36
 # function: register_hana_secondary - register local hana as secondary to the other site
aa0b36
 # params:   -
aa0b36
-# globals:  sidadm(r), remoteHost(r), InstanceNr(r), sr_mode(r), sr_name(r)
aa0b36
+# globals:  sidadm(r), remoteHost(r), InstanceNr(r), sr_mode(r), sr_name(r), hdbver(r)
aa0b36
 # register_hana_secondary
aa0b36
 #
aa0b36
 function register_hana_secondary()
aa0b36
@@ -1007,17 +1194,31 @@
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=2;
aa0b36
     local remoteInstance="";
aa0b36
+    local newParameter=0
aa0b36
     remoteInstance=$InstanceNr
aa0b36
+
aa0b36
+
aa0b36
+    if version "$hdbver" ">=" "1.00.110"; then
aa0b36
+        newParameter=1
aa0b36
+    fi
aa0b36
+
aa0b36
     if ocf_is_true ${AUTOMATED_REGISTER}; then
aa0b36
-       #
aa0b36
-       #
aa0b36
-       #
aa0b36
-       #
aa0b36
-       #
aa0b36
-       super_ocf_log info "ACT: REGISTER: hdbnsutil -sr_register --remoteHost=$remoteHost --remoteInstance=$remoteInstance --mode=$sr_mode --name=$sr_name"
aa0b36
-       #
aa0b36
-       #
aa0b36
-       su - $sidadm -c "hdbnsutil -sr_register --remoteHost=$remoteHost --remoteInstance=$remoteInstance --mode=$sr_mode --name=$sr_name"; rc=$?
aa0b36
+       # TODO: Get rid of the su by using a new interface:
aa0b36
+       # SAPSYSTEMNAME=SLE /usr/sap/SLE/HDB00/HDBSettings.sh hdbnsutil -sr_register ...
aa0b36
+       # TODO: Check beginning from which SPS does SAP support HDBSettings.sh?
aa0b36
+       # TODO: Limit the runtime of hdbnsutil -sr_register ????
aa0b36
+       if [ $newParameter -eq 1 ]; then
aa0b36
+           local hanaOM=""
aa0b36
+           hanaOM=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_OPERATION_MODE[@]})
aa0b36
+           if [ -n "$hanaOM" ]; then
aa0b36
+               hanaOM="--operationMode=$hanaOM"
aa0b36
+           fi
aa0b36
+           super_ocf_log info "ACT: REGISTER: hdbnsutil -sr_register --remoteHost=$remoteHost --remoteInstance=$remoteInstance --replicationMode=$sr_mode $hanaOM --name=$sr_name"
aa0b36
+           HANA_CALL --timeout inf --use-su --cmd "hdbnsutil -sr_register --remoteHost=$remoteHost --remoteInstance=$remoteInstance --replicationMode=$sr_mode $hanaOM --name=$sr_name"; rc=$?
aa0b36
+       else
aa0b36
+           super_ocf_log info "ACT: REGISTER: hdbnsutil -sr_register --remoteHost=$remoteHost --remoteInstance=$remoteInstance --mode=$sr_mode --name=$sr_name"
aa0b36
+           HANA_CALL --timeout inf --use-su --cmd "hdbnsutil -sr_register --remoteHost=$remoteHost --remoteInstance=$remoteInstance --mode=$sr_mode --name=$sr_name"; rc=$?
aa0b36
+       fi
aa0b36
        # backup_global_and_nameserver
aa0b36
     else
aa0b36
        super_ocf_log info "ACT: SAPHANA DROP REGISTER because AUTOMATED_REGISTER is set to FALSE"
aa0b36
@@ -1051,7 +1252,7 @@
aa0b36
     check_sapstartsrv
aa0b36
     rc=$?
aa0b36
     #
aa0b36
-    # TODO: ASK: PRIO5: For SCALE-OUT - do we need to use an other call like StartSystem? Or better to use the HDB command?
aa0b36
+    # DONE: ASK: PRIO5: For SCALE-OUT - do we need to use an other call like StartSystem? Or better to use the HDB command?
aa0b36
     #
aa0b36
     if [ $rc -eq $OCF_SUCCESS ]; then
aa0b36
         output=$($SAPCONTROL -nr $InstanceNr -function Start)
aa0b36
@@ -1169,7 +1370,7 @@
aa0b36
         0 ) # LPA says start-up
aa0b36
             lpa_advice="start"
aa0b36
             # TODO: PRIO1: We need to do a special handling for remote being a 234-Secondary in SR Status SOK
aa0b36
-            # if ( remote_role like [234]:S )  && ( remote_sync_status is SOK|PRIM ) && ( PreferSiteTakeover ) 
aa0b36
+            # if ( remote_role like [234]:S )  && ( remote_sync_status is SOK|PRIM ) && ( PreferSiteTakeover )
aa0b36
             #   then lpa_advice="wait"
aa0b36
             remoteRole=$(get_hana_attribute $remoteNode ${ATTR_NAME_HANA_ROLES[@]})
aa0b36
             remoteSync=$(get_hana_attribute $remoteNode ${ATTR_NAME_HANA_SYNC_STATUS[@]})
aa0b36
@@ -1193,17 +1394,20 @@
aa0b36
         1)  # LPA says register!
aa0b36
             lpa_advice="register"
aa0b36
             ;;
aa0b36
-        2)  # LPA says wait for second LPT
aa0b36
+        2)  # LPA says wait for older LPA to expire
aa0b36
+            lpa_advice="wait"
aa0b36
+            ;;
aa0b36
+        3) # LPA says to wait for remote LPA to be reported/announced
aa0b36
             lpa_advice="wait"
aa0b36
             ;;
aa0b36
-        3 | 4 ) # LPA says something is completely wrong - FAIL resource # TODO: PRIO1: RC3 for waiting remote side to report lss
aa0b36
+        4) # LPA says something is completely wrong - FAIL resource # TODO: PRIO1: RC3 for waiting remote side to report lss
aa0b36
             lpa_advice="fail"
aa0b36
             ;;
aa0b36
-        * ) # LPA failed with an unkonown status - FAIL resource
aa0b36
+        *) # LPA failed with an unkonown status - FAIL resource
aa0b36
             lpa_advice="fail"
aa0b36
             ;;
aa0b36
     esac
aa0b36
-    
aa0b36
+
aa0b36
     # DONE: PRIO2: Do we need to differ 0 and 1 here? While 0 is a fatal SAP error, 1 for down/error
aa0b36
     if [ $lss -eq 0 ]; then
aa0b36
        super_ocf_log err "ACT: get_hana_landscape_status reports FATAL"
aa0b36
@@ -1218,7 +1422,7 @@
aa0b36
                 2 | 3 | 4 ) # as landcape says we are up - just set the scores and return code
aa0b36
                     super_ocf_log info "LPA: landcape: UP, LPA: start ==> keep running"
aa0b36
                     LPTloc=$(date '+%s')
aa0b36
-                    lpa_set_lpt $LPTloc
aa0b36
+                    lpa_set_lpt $LPTloc $NODENAME
aa0b36
                     rc=$OCF_SUCCESS
aa0b36
                     ;;
aa0b36
                 1 ) # landcape says we are down, lets start and adjust scores and return code
aa0b36
@@ -1226,7 +1430,7 @@
aa0b36
                     saphana_start
aa0b36
                     rc=$?
aa0b36
                     LPTloc=$(date '+%s')
aa0b36
-                    lpa_set_lpt $LPTloc
aa0b36
+                    lpa_set_lpt $LPTloc $NODENAME
aa0b36
                     ;;
aa0b36
             esac
aa0b36
             scoring_crm_master "$my_role" "$my_sync"
aa0b36
@@ -1250,11 +1454,11 @@
aa0b36
                         if [ $primary_status -eq $HANA_STATE_SECONDARY ]; then
aa0b36
                             super_ocf_log info "ACT: Register successful"
aa0b36
                             lpa_push_lpt 10
aa0b36
-                            lpa_set_lpt  10
aa0b36
+                            lpa_set_lpt  10 $NODENAME
aa0b36
                             set_crm_master  0
aa0b36
                             saphana_start_secondary
aa0b36
                             rc=$?
aa0b36
-                            lpa_set_lpt  10
aa0b36
+                            lpa_set_lpt  10 $NODENAME
aa0b36
                         else
aa0b36
                             super_ocf_log err "ACT: Register failed"
aa0b36
                             rc=$OCF_NOT_RUNNING
aa0b36
@@ -1279,11 +1483,19 @@
aa0b36
                     rc=$OCF_ERR_GENERIC
aa0b36
                     ;;
aa0b36
                 1 ) # we are down, so we should wait --> followup in next monitor
aa0b36
-                    super_ocf_log info "LPA: landcape: DOWN, LPA: wait ==> keep waiting"
aa0b36
-                    # TODO: PRIO3: Check, if WAITING is correct here
aa0b36
-                    set_hana_attribute ${NODENAME} "WAITING4LPA" ${ATTR_NAME_HANA_CLONE_STATE[@]}
aa0b36
-                    set_crm_master -9000
aa0b36
-                    rc=$OCF_SUCCESS
aa0b36
+                    # DONE: PRIO3: Check, if WAITING is correct here
aa0b36
+                    if ocf_is_true "$AUTOMATED_REGISTER" ; then
aa0b36
+                        super_ocf_log info "LPA: landcape: DOWN, LPA: wait ==> keep waiting"
aa0b36
+                        super_ocf_log info "RA: landcape: DOWN, LPA: wait ==> keep waiting"
aa0b36
+                        set_hana_attribute ${NODENAME} "WAITING4LPA" ${ATTR_NAME_HANA_CLONE_STATE[@]}
aa0b36
+                        set_crm_master -9000
aa0b36
+                        rc=$OCF_SUCCESS
aa0b36
+                    else
aa0b36
+                        super_ocf_log warning "LPA: OLD primary needs manual registration (AUTOMATED_REGISTER='false')"
aa0b36
+                        set_hana_attribute ${NODENAME} "WAITING4REG" ${ATTR_NAME_HANA_CLONE_STATE[@]}
aa0b36
+                        set_crm_master -9000
aa0b36
+                        rc=$OCF_NOT_RUNNING
aa0b36
+                    fi
aa0b36
                     ;;
aa0b36
             esac
aa0b36
             ;;
aa0b36
@@ -1309,22 +1521,24 @@
aa0b36
     local ch ch_role
aa0b36
     #
aa0b36
     # get actual list of cluster members
aa0b36
-    # 
aa0b36
+    #
aa0b36
     if [ -n "$otherNodes" ]; then
aa0b36
         for ch in ${otherNodes[@]}; do
aa0b36
             if [ $rc -eq 1 ]; then
aa0b36
                 ch_role=$(get_hana_attribute ${ch} ${ATTR_NAME_HANA_ROLES[@]})
aa0b36
-# TODO: PRIO3: check if [0-9], [234] or [34] is correct
aa0b36
-# TODO: PRIO4: Do we need different checks like "any-primary-master" or "running-primary-master" ?
aa0b36
-#                grep '[0-9]*:P:[^:]*:master:' <<< $ch_role && rc=0
aa0b36
-#                grep '[34]:P:[^:]*:master:' <<< $ch_role && rc=0
aa0b36
-#               Match "Running+Available Primary" Master -> Match field 1: 3/4, 2: P, 4: master 
aa0b36
-                awk -F: 'BEGIN { rc=1 } 
aa0b36
-                         $1 ~ "[34]" && $2 ="P" && $4="master" { rc=0 } 
aa0b36
-                         END { exit rc }' <<< $ch_role  ; rc=$? 
aa0b36
+                # TODO: PRIO3: check if [0-9], [234] or [34] is correct
aa0b36
+                # TODO: PRIO4: Do we need different checks like "any-primary-master" or "running-primary-master" ?
aa0b36
+                #                grep '[0-9]*:P:[^:]*:master:' <<< $ch_role && rc=0
aa0b36
+                #                grep '[34]:P:[^:]*:master:' <<< $ch_role && rc=0
aa0b36
+                #               Match "Running+Available Primary" Master -> Match field 1: 3/4, 2: P, 4: master
aa0b36
+                super_ocf_log debug "DBG: check_for_primary_master (3) ch_role=$ch_role"
aa0b36
+                awk -F: 'BEGIN { rc=1 }
aa0b36
+                         $1 ~ "[34]" && $2 == "P" && $4 == "master" { rc=0 }
aa0b36
+                         END { exit rc }' <<< $ch_role  ; rc=$?
aa0b36
+                super_ocf_log debug "DBG: check_for_primary_master (4) rc=$rc"
aa0b36
             fi
aa0b36
         done
aa0b36
-    fi 
aa0b36
+    fi
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
     return $rc
aa0b36
 }
aa0b36
@@ -1378,7 +1592,7 @@
aa0b36
     ####### LPA - begin
aa0b36
     #
aa0b36
     lpa_push_lpt 10
aa0b36
-    lpa_set_lpt  10
aa0b36
+    lpa_set_lpt  10 $NODENAME
aa0b36
     #
aa0b36
     ####### LPA - end
aa0b36
     #
aa0b36
@@ -1404,7 +1618,7 @@
aa0b36
                rc=$OCF_SUCCESS
aa0b36
            fi
aa0b36
        else
aa0b36
-           lpa_set_lpt  10
aa0b36
+           lpa_set_lpt  10 $NODENAME
aa0b36
        fi
aa0b36
     else
aa0b36
        super_ocf_log info "ACT: wait_for_primary_master ==> WAITING"
aa0b36
@@ -1454,7 +1668,7 @@
aa0b36
         then
aa0b36
           if [ $STATE -eq $OCF_NOT_RUNNING ]
aa0b36
           then
aa0b36
-            [ "$MONLOG" != "NOLOG" ] && ocf_log err "SAP instance service $SERVICE is not running with status $COLOR !"
aa0b36
+            [ "$MONLOG" != "NOLOG" ] && ocf_log err "SAP instance service $SERVICE status color is $COLOR !"
aa0b36
             rc=$STATE
aa0b36
           fi
aa0b36
           count=1
aa0b36
@@ -1511,13 +1725,17 @@
aa0b36
     local crm_rc=1
aa0b36
     local lpt=$1
aa0b36
     local clpt=-1
aa0b36
-    local node=${2:-${NODENAME}}
aa0b36
+    local node=$2
aa0b36
     set_hana_attribute ${node} "$lpt" ${LPA_ATTR[@]}; crm_rc=$?
aa0b36
-    clpt=$(lpa_get_lpt $NODENAME)
aa0b36
-    if [ "$lpt" != "$clpt" ]; then
aa0b36
-        rc=2
aa0b36
+    if [ -n "$node" ]; then
aa0b36
+        clpt=$(lpa_get_lpt $NODENAME)
aa0b36
+        if [ "$lpt" != "$clpt" ]; then
aa0b36
+            rc=2
aa0b36
+        else
aa0b36
+            rc=0
aa0b36
+        fi
aa0b36
     else
aa0b36
-        rc=0
aa0b36
+        super_ocf_log info "DEC: lpa_set_lpt ignore to change value for empty node name"
aa0b36
     fi
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
     return $rc
aa0b36
@@ -1608,7 +1826,7 @@
aa0b36
         else
aa0b36
             rc=2
aa0b36
         fi
aa0b36
-    lpa_set_lpt $LPTloc
aa0b36
+    lpa_set_lpt $LPTloc $NODENAME
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
     return $rc
aa0b36
 }
aa0b36
@@ -1621,9 +1839,10 @@
aa0b36
 #
aa0b36
 # Returncodes:
aa0b36
 #    0: start
aa0b36
-#    1: register than start
aa0b36
-#    2: wait4gab
aa0b36
-#    3: wait4other
aa0b36
+#    1: register    (then start)
aa0b36
+#    2: wait4gab    (WAIT4LPA - Older LPA needs to expire)
aa0b36
+#    3: wait4other  (WAIT4LPA - Remote LPA needs to be announced)
aa0b36
+#    4: lpa internal error
aa0b36
 #
aa0b36
 # Initializing (if NO local LPT-file):
aa0b36
 #    SECONDARY sets to 10
aa0b36
@@ -1648,7 +1867,7 @@
aa0b36
 #
aa0b36
 function lpa_check_lpt_status() {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
-    local rc=0
aa0b36
+    local rc=4
aa0b36
     local LPTloc=-1
aa0b36
     local LPTrem=-1
aa0b36
     local LPTMark=1000
aa0b36
@@ -1666,16 +1885,16 @@
aa0b36
         if [ -z "$LPTloc" -o "$LPTloc" -eq -1 -o "$lparc" -ne 0 ]; then
aa0b36
             # last option - try to initialize as PRIMARY
aa0b36
             lpa_push_lpt 20
aa0b36
-            lpa_set_lpt  20
aa0b36
+            lpa_set_lpt  20 $NODENAME
aa0b36
             LPTloc=20                           # DEFAULT
aa0b36
         fi
aa0b36
     fi
aa0b36
-            # TODO PRIO1: REMOVE remoteNode dependency - lpa_get_lpt
aa0b36
+    # TODO PRIO1: REMOVE remoteNode dependency - lpa_get_lpt
aa0b36
     LPTrem=$(lpa_get_lpt $remoteNode); lparc=$?
aa0b36
     if [ $lparc -ne 0 ]; then
aa0b36
         # LPT of the other node could not be evaluated - LPA says WAIT
aa0b36
         super_ocf_log debug "DBG: LPA: LPTloc=$LPTloc, LPTrem undefined ==> WAIT"
aa0b36
-        rc=2
aa0b36
+        rc=3
aa0b36
     else
aa0b36
         super_ocf_log debug "DBG: LPA: LPTloc ($LPTloc) LPTrem ($LPTrem) delta ($delta)"
aa0b36
         if [ $LPTloc -lt $LPTMark -a $LPTrem -lt $LPTMark ]; then
aa0b36
@@ -1683,11 +1902,11 @@
aa0b36
         else
aa0b36
            delta=$DUPLICATE_PRIMARY_TIMEOUT   # at least one of the lpts is a real timestamp so include delta-gap
aa0b36
         fi
aa0b36
-        if (( delta < LPTloc - LPTrem )); then 
aa0b36
+        if (( delta < LPTloc - LPTrem )); then
aa0b36
             # We are the winner - LPA says STARTUP
aa0b36
             super_ocf_log debug "DBG: LPA: LPTloc wins $LPTloc > $LPTrem + $delta ==> START"
aa0b36
             rc=0
aa0b36
-        elif (( delta < LPTrem - LPTloc )); then 
aa0b36
+        elif (( delta < LPTrem - LPTloc )); then
aa0b36
             if ocf_is_true "$AUTOMATED_REGISTER" ; then
aa0b36
                 # The other one has won - LPA says REGISTER
aa0b36
                 super_ocf_log debug "DBG: LPA: LPTrem wins $LPTrem > $LPTloc + $delta ==> REGISTER"
aa0b36
@@ -1697,12 +1916,12 @@
aa0b36
                 rc=2
aa0b36
             fi
aa0b36
 
aa0b36
-        else                                     
aa0b36
+        else
aa0b36
             super_ocf_log debug "DBG: LPA: Difference between LPTloc and LPTrem is less than delta ($delta) ==> WAIT"
aa0b36
             # TODO: PRIO3: ADD STALEMATE-HANDLING HERE; currently admin should set one of the lpa to 20
aa0b36
             rc=2
aa0b36
-        fi        
aa0b36
-    fi    
aa0b36
+        fi
aa0b36
+    fi
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
     return $rc
aa0b36
 }
aa0b36
@@ -1716,6 +1935,7 @@
aa0b36
 {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=0
aa0b36
+    # always true for scale-up
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
     return $rc
aa0b36
 }
aa0b36
@@ -1728,23 +1948,15 @@
aa0b36
 #
aa0b36
 function saphana_start_clone() {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
-	local primary_status sync_attr score_master rc=$OCF_NOT_RUNNING
aa0b36
+    local primary_status sync_attr score_master rc=$OCF_NOT_RUNNING
aa0b36
     local sqlrc;
aa0b36
-    local chkusr;
aa0b36
-    # TODO: PRIO4: remove check_secstore_users later
aa0b36
-    secUser=$(check_secstore_users SAPHANA${SID}SR SLEHALOC RHELHALOC) ; chkusr=$?
aa0b36
-    if [ $chkusr -ne 0 ]; then
aa0b36
-        super_ocf_log err  "ACT: Secure store users are missing (see best practice manual how to setup the users)"
aa0b36
-        rc=$OCF_ERR_CONFIGURED
aa0b36
+    set_hana_attribute ${NODENAME} "DEMOTED" ${ATTR_NAME_HANA_CLONE_STATE[@]}
aa0b36
+    check_for_primary; primary_status=$?
aa0b36
+    if [ $primary_status -eq $HANA_STATE_PRIMARY ]; then
aa0b36
+        saphana_start_primary; rc=$?
aa0b36
     else
aa0b36
-        set_hana_attribute ${NODENAME} "DEMOTED" ${ATTR_NAME_HANA_CLONE_STATE[@]}
aa0b36
-        check_for_primary; primary_status=$?
aa0b36
-        if [ $primary_status -eq $HANA_STATE_PRIMARY ]; then
aa0b36
-            saphana_start_primary; rc=$?
aa0b36
-        else
aa0b36
-            lpa_set_lpt  10
aa0b36
-            saphana_start_secondary; rc=$?
aa0b36
-        fi
aa0b36
+        lpa_set_lpt  10 $NODENAME
aa0b36
+        saphana_start_secondary; rc=$?
aa0b36
     fi
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
     return $rc
aa0b36
@@ -1761,9 +1973,10 @@
aa0b36
     local rc=0
aa0b36
     local primary_status="x"
aa0b36
     set_hana_attribute ${NODENAME} "UNDEFINED" ${ATTR_NAME_HANA_CLONE_STATE[@]}
aa0b36
+    super_ocf_log debug "DBG: SET UNDEFINED"
aa0b36
     check_for_primary; primary_status=$?
aa0b36
     if [ $primary_status -eq $HANA_STATE_SECONDARY ]; then
aa0b36
-        lpa_set_lpt  10
aa0b36
+        lpa_set_lpt  10 $NODENAME
aa0b36
     fi
aa0b36
     saphana_stop; rc=$?
aa0b36
     return $rc
aa0b36
@@ -1813,26 +2026,42 @@
aa0b36
                     # seems admin already decided that for us? -> we are running - set DEMOTED
aa0b36
                     promoted=0;
aa0b36
                     LPTloc=$(date '+%s')
aa0b36
-                    lpa_set_lpt $LPTloc
aa0b36
+                    lpa_set_lpt $LPTloc $NODENAME
aa0b36
                 fi
aa0b36
                 lpa_check_lpt_status; lparc=$?
aa0b36
-                # TODO: PRIO1: Need to differ lpa_check_lpt_status return codes
aa0b36
-                if [ $lparc -lt 2 ]; then
aa0b36
-                    # lpa - no need to wait any longer - lets try a new start
aa0b36
-                    saphana_start_clone
aa0b36
-                    rc=$?
aa0b36
-                    super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
-                    return $rc
aa0b36
-                else
aa0b36
-                    lpa_init_lpt $HANA_STATE_PRIMARY
aa0b36
-                    # still waiting for second site to report lpa-lpt
aa0b36
-                    if ocf_is_true "$AUTOMATED_REGISTER" ; then
aa0b36
-                       super_ocf_log info "LPA: Still waiting for remote site to report LPA status"
aa0b36
-                    else
aa0b36
-                       super_ocf_log info "LPA: Dual primary detected and AUTOMATED_REGISTER='false' ==> WAITING"
aa0b36
-                    fi
aa0b36
-                    return $OCF_SUCCESS
aa0b36
-                fi
aa0b36
+                # DONE: PRIO1: Need to differ lpa_check_lpt_status return codes
aa0b36
+                case "$lparc" in
aa0b36
+                   0 | 1 )
aa0b36
+                        # lpa - no need to wait any longer - lets try a new start
aa0b36
+                        saphana_start_clone
aa0b36
+                        rc=$?
aa0b36
+                        super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
+                        return $rc
aa0b36
+                        ;;
aa0b36
+                    2 )
aa0b36
+                        lpa_init_lpt $HANA_STATE_PRIMARY
aa0b36
+                        # still waiting for second site to expire
aa0b36
+                        if ocf_is_true "$AUTOMATED_REGISTER" ; then
aa0b36
+                           super_ocf_log info "LPA: Still waiting for remote site to report LPA status"
aa0b36
+                        else
aa0b36
+                           super_ocf_log info "LPA: Dual primary detected and AUTOMATED_REGISTER='false' ==> WAITING"
aa0b36
+                           super_ocf_log info "LPA: You need to manually sr_register the older primary"
aa0b36
+                        fi
aa0b36
+                        return $OCF_SUCCESS
aa0b36
+                    ;;
aa0b36
+                    3 )
aa0b36
+                        lpa_init_lpt $HANA_STATE_PRIMARY
aa0b36
+                        # still waiting for second site to report lpa-lpt
aa0b36
+                        super_ocf_log info "LPA: Still waiting for remote site to report LPA status"
aa0b36
+                        return $OCF_SUCCESS
aa0b36
+                    ;;
aa0b36
+                    4 )
aa0b36
+                        # lpa internal error
aa0b36
+                        # TODO PRIO3: Impplement special handling for this issue - should we fail the ressource?
aa0b36
+                        super_ocf_log info "LPA: LPA reports an internal error"
aa0b36
+                        return $OCF_SUCCESS
aa0b36
+                    ;;
aa0b36
+                esac
aa0b36
                 promoted=0;
aa0b36
                 ;;
aa0b36
             UNDEFINED )
aa0b36
@@ -1848,7 +2077,7 @@
aa0b36
                 ;;
aa0b36
         esac
aa0b36
     fi
aa0b36
-    get_hana_landscape_status; lss=$? 
aa0b36
+    get_hana_landscape_status; lss=$?
aa0b36
     super_ocf_log debug "DBG: saphana_monitor_clone: get_hana_landscape_status=$lss"
aa0b36
     case "$lss" in
aa0b36
         0 ) # FATAL or ERROR
aa0b36
@@ -1876,19 +2105,20 @@
aa0b36
                         #
aa0b36
             # TODO PRIO1: REMOVE remoteNode dependency - get_sync_status
aa0b36
                         remoteSync=$(get_hana_attribute $remoteNode ${ATTR_NAME_HANA_SYNC_STATUS[@]})
aa0b36
+            # TODO HANDLING OF "NEVER"
aa0b36
                         case "$remoteSync" in
aa0b36
                             SOK | PRIM )
aa0b36
                                  super_ocf_log info "DEC: PreferSiteTakeover selected so decrease promotion score here (and reset lpa)"
aa0b36
                                  set_crm_master 5
aa0b36
                                  if check_for_primary_master; then
aa0b36
-                                     lpa_set_lpt 20
aa0b36
+                                     lpa_set_lpt 20 $NODENAME
aa0b36
                                  fi
aa0b36
                                  ;;
aa0b36
                             SFAIL )
aa0b36
-                                 super_ocf_log info "DEC: PreferSiteTakeover selected BUT remoteHost is not in sync (SFAIL) ==> local restart preferred"                            
aa0b36
+                                 super_ocf_log info "DEC: PreferSiteTakeover selected BUT remoteHost is not in sync (SFAIL) ==> local restart preferred"
aa0b36
                                  ;;
aa0b36
                             * )
aa0b36
-                                 super_ocf_log info "DEC: PreferSiteTakeover selected BUT remoteHost is not in sync ($remoteSync) ==> local restart preferred"                            
aa0b36
+                                 super_ocf_log info "DEC: PreferSiteTakeover selected BUT remoteHost is not in sync ($remoteSync) ==> local restart preferred"
aa0b36
                                  ;;
aa0b36
                         esac
aa0b36
                     else
aa0b36
@@ -1916,7 +2146,7 @@
aa0b36
                 rc=$OCF_SUCCESS
aa0b36
             else
aa0b36
                 LPTloc=$(date '+%s')
aa0b36
-                lpa_set_lpt $LPTloc
aa0b36
+                lpa_set_lpt $LPTloc $NODENAME
aa0b36
                 lpa_push_lpt $LPTloc
aa0b36
                 if [ "$promoted" -eq 1 ]; then
aa0b36
                     set_hana_attribute "$NODENAME" "PRIM" ${ATTR_NAME_HANA_SYNC_STATUS[@]}
aa0b36
@@ -1931,12 +2161,14 @@
aa0b36
                 fi
aa0b36
                 my_sync=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_SYNC_STATUS[@]})
aa0b36
                 my_role=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_ROLES[@]})
aa0b36
-                case "$my_role" in 
aa0b36
+                case "$my_role" in
aa0b36
                     [12]:P:*:master:*  ) # primary is down or may not anser hdbsql query so drop analyze_hana_sync_status
aa0b36
                         ;;
aa0b36
                     [34]:P:*:*:*  ) # primary is up and should now be able to anser hdbsql query
aa0b36
                         if [ -f $DIR_EXECUTABLE/python_support/systemReplicationStatus.py ]; then
aa0b36
-                            analyze_hana_sync_statusSRS
aa0b36
+                            if [ "$promote_attr" = "PROMOTED" ]; then
aa0b36
+                                analyze_hana_sync_statusSRS
aa0b36
+                            fi
aa0b36
                         else
aa0b36
                             analyze_hana_sync_statusSQL
aa0b36
                         fi
aa0b36
@@ -1949,8 +2181,8 @@
aa0b36
                        [234]:P:* ) # dual primary, but other instance marked as PROMOTED by the cluster
aa0b36
                            lpa_check_lpt_status; again_lpa_rc=$?
aa0b36
                            if [ $again_lpa_rc -eq 2 ]; then
aa0b36
-                              super_ocf_log info "DEC: Dual primary detected, other instance is PROMOTED and lpa stalemate ==> local restart"                            
aa0b36
-                              lpa_set_lpt 10
aa0b36
+                              super_ocf_log info "DEC: Dual primary detected, other instance is PROMOTED and lpa stalemate ==> local restart"
aa0b36
+                              lpa_set_lpt 10 $NODENAME
aa0b36
                               lpa_push_lpt 10
aa0b36
                               rc=$OCF_NOT_RUNNING
aa0b36
                            fi
aa0b36
@@ -1993,7 +2225,7 @@
aa0b36
     # OK, we are running as HANA SECONDARY
aa0b36
     #
aa0b36
     if ! lpa_get_lpt ${NODENAME}; then
aa0b36
-        lpa_set_lpt  10
aa0b36
+        lpa_set_lpt  10 $NODENAME
aa0b36
         lpa_push_lpt 10
aa0b36
     fi
aa0b36
     promote_attr=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_CLONE_STATE[@]})
aa0b36
@@ -2042,17 +2274,25 @@
aa0b36
         0 ) # FATAL
aa0b36
             # DONE: PRIO1: Maybe we need to differ between 0 and 1. While 0 is a fatal sap error, 1 is down/error
aa0b36
             # TODO: PRIO3: is OCF_ERR_GENERIC best option?
aa0b36
-            lpa_set_lpt  10
aa0b36
+            lpa_set_lpt  10 $NODENAME
aa0b36
             rc=$OCF_ERR_GENERIC
aa0b36
             ;;
aa0b36
         1 ) # ERROR
aa0b36
-            lpa_set_lpt  10
aa0b36
+            lpa_set_lpt  10 $NODENAME
aa0b36
             rc=$OCF_NOT_RUNNING
aa0b36
             ;;
aa0b36
         2 | 3 | 4 ) # WARN INFO OK
aa0b36
             rc=$OCF_SUCCESS
aa0b36
-            lpa_set_lpt  30
aa0b36
+            lpa_set_lpt  30 $NODENAME
aa0b36
             sync_attr=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_SYNC_STATUS[@]})
aa0b36
+            local hanaOM=""
aa0b36
+            local hanaOut1=""
aa0b36
+            # TODO: PRIO 3: check, if using getParameter.py is the best option to analyze the set operationMode
aa0b36
+            # DONE: PRIO 3: Should we default to logreplay for SAP HANA >= SPS11 ?
aa0b36
+            hanaOut1=$(HANA_CALL --timeout 10 --use-su --cmd "getParameter.py --key=global.ini/system_replication/operation_mode --sapcontrol=1")
aa0b36
+            hanaFilter1=$(echo "$hanaOut1" | awk -F/ 'BEGIN {out=0} /^SAPCONTROL-OK: <begin>/ { out=1 } /^SAPCONTROL-OK: <end>/ { out=0 } /=/ {if (out==1) {print $3} }')
aa0b36
+            hanaOM=$(echo "$hanaFilter1" | awk -F= '$1=="operation_mode" {print $2}')
aa0b36
+            set_hana_attribute ${NODENAME} "$hanaOM" ${ATTR_NAME_HANA_OPERATION_MODE[@]}
aa0b36
             super_ocf_log debug "DBG: sync_attr=$sync_attr"
aa0b36
             case "$sync_attr" in
aa0b36
                 "SOK"   ) # This is a possible node to promote, when primary is missing
aa0b36
@@ -2112,7 +2352,7 @@
aa0b36
 	fi
aa0b36
 	#
aa0b36
 	# First check, if we are PRIMARY or SECONDARY
aa0b36
-	# 
aa0b36
+	#
aa0b36
 	check_for_primary; primary_status=$?
aa0b36
     if [ $primary_status -eq $HANA_STATE_PRIMARY ]; then
aa0b36
         # FIX: bsc#919925 Leaving Node Maintenance stops HANA Resource Agent
aa0b36
@@ -2145,7 +2385,7 @@
aa0b36
 #
aa0b36
 # function: saphana_promote_clone - promote a hana clone
aa0b36
 # params:   -
aa0b36
-# globals:  OCF_*(r), NODENAME(r), HANA_STATE_*, SID(r), InstanceName(r), 
aa0b36
+# globals:  OCF_*(r), NODENAME(r), HANA_STATE_*, SID(r), InstanceName(r),
aa0b36
 # saphana_promote_clone:
aa0b36
 #    In a Master/Slave configuration get Master being the primary OR by running hana takeover
aa0b36
 #
aa0b36
@@ -2169,7 +2409,7 @@
aa0b36
   else
aa0b36
      if [ $primary_status -eq $HANA_STATE_SECONDARY ]; then
aa0b36
         #
aa0b36
-        # we are SECONDARY/SLAVE and need to takepover ...
aa0b36
+        # we are SECONDARY/SLAVE and need to takeover ...  promote on the replica (secondary) side...
aa0b36
         # promote on the replica side...
aa0b36
         #
aa0b36
         hana_sync=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_SYNC_STATUS[@]})
aa0b36
@@ -2178,9 +2418,14 @@
aa0b36
                 super_ocf_log info "ACT: !!!!!!! Promote REPLICA $SID-$InstanceName to be primary. !!!!!!"
aa0b36
                 LPTloc=$(date '+%s')
aa0b36
                 # lpa_set_lpt 20 $remoteNode
aa0b36
-                lpa_set_lpt $LPTloc
aa0b36
+                lpa_set_lpt $LPTloc $NODENAME
aa0b36
                 lpa_push_lpt $LPTloc
aa0b36
-                su - $sidadm -c "hdbnsutil -sr_takeover"
aa0b36
+    # TODO: Get rid of the su by using a new interface:
aa0b36
+    # SAPSYSTEMNAME=SLE /usr/sap/SLE/HDB00/HDBSettings.sh hdbnsutil -sr_takeover ...
aa0b36
+    # TODO: Check beginning from which SPS does SAP support HDBSettings.sh?
aa0b36
+    # TODO: Limit the runtime of hdbnsutil -sr_takeover ????
aa0b36
+    # SAP_CALL
aa0b36
+                HANA_CALL --timeout inf --use-su --cmd "hdbnsutil -sr_takeover"
aa0b36
                 #
aa0b36
                 # now gain check, if we are primary NOW
aa0b36
                 #
aa0b36
@@ -2248,7 +2493,6 @@
aa0b36
 SAPSTARTPROFILE=""
aa0b36
 SAPHanaFilter="ra-act-dec-lpa"
aa0b36
 
aa0b36
-NODENAME=$(crm_node -n)
aa0b36
 
aa0b36
 
aa0b36
 if [ $# -ne 1 ]
aa0b36
@@ -2306,8 +2550,7 @@
aa0b36
 fi
aa0b36
 
aa0b36
 # What kind of method was invoked?
aa0b36
-THE_VERSION=$(saphana_meta_data | grep '
aa0b36
-super_ocf_log info "RA ==== begin action $ACTION$CLACT ($THE_VERSION) ===="
aa0b36
+super_ocf_log info "RA ==== begin action $ACTION$CLACT ($SAPHanaVersion) ===="
aa0b36
 ra_rc=$OCF_ERR_UNIMPLEMENTED
aa0b36
 case "$ACTION" in
aa0b36
     start|stop|monitor|promote|demote) # Standard controling actions
aa0b36
@@ -2329,6 +2572,6 @@
aa0b36
 esac
aa0b36
 timeE=$(date '+%s')
aa0b36
 (( timeR = timeE - timeB ))
aa0b36
-#super_ocf_log info "RA ==== SAPHanaFilter=$SAPHanaFilter"
aa0b36
-super_ocf_log info "RA ==== end action $ACTION$CLACT with rc=${ra_rc} ($THE_VERSION) (${timeR}s)===="
aa0b36
+super_ocf_log debug "DBG: ==== SAPHanaFilter=$SAPHanaFilter"
aa0b36
+super_ocf_log info "RA ==== end action $ACTION$CLACT with rc=${ra_rc} ($SAPHanaVersion) (${timeR}s)===="
aa0b36
 exit ${ra_rc}
aa0b36
diff -uNr a/heartbeat/SAPHanaTopology b/heartbeat/SAPHanaTopology
aa0b36
--- a/heartbeat/SAPHanaTopology	2016-10-14 10:09:56.480051268 +0200
aa0b36
+++ b/heartbeat/SAPHanaTopology	2016-10-14 10:29:45.384831725 +0200
aa0b36
@@ -14,7 +14,7 @@
aa0b36
 # Support:      linux@sap.com
aa0b36
 # License:      GNU General Public License (GPL)
aa0b36
 # Copyright:    (c) 2014 SUSE Linux Products GmbH
aa0b36
-#               (c) 2015 SUSE Linux GmbH
aa0b36
+#               (c) 2015-2016 SUSE Linux GmbH
aa0b36
 #
aa0b36
 # An example usage:
aa0b36
 #      See usage() function below for more details...
aa0b36
@@ -23,17 +23,25 @@
aa0b36
 #   OCF_RESKEY_SID            (LNX, NDB, SLE)
aa0b36
 #   OCF_RESKEY_InstanceNumber (00..99)
aa0b36
 #	OCF_RESKEY_DIR_EXECUTABLE   (optional, well known directories will be searched by default)
aa0b36
-#   OCF_RESKEY_SAPHanaFilter
aa0b36
+#   OCF_RESKEY_SAPHanaFilter    (outdated, replaced by cluster property hana_${sid}_glob_filter)
aa0b36
 #
aa0b36
 #######################################################################
aa0b36
 #
aa0b36
 # Initialization:
aa0b36
+SAPHanaVersion="0.152.17"
aa0b36
 timeB=$(date '+%s')
aa0b36
 
aa0b36
 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
aa0b36
 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
aa0b36
 
aa0b36
 #######################################################################
aa0b36
+#
aa0b36
+log_attributes=false
aa0b36
+if ocf_is_true "$log_attributes"; then
aa0b36
+    log_attr_file="/var/log/fhATTRIBUTES"
aa0b36
+else
aa0b36
+    log_attr_file="/dev/null"
aa0b36
+fi
aa0b36
 
aa0b36
 HANA_STATE_PRIMARY=0
aa0b36
 HANA_STATE_SECONDARY=1
aa0b36
@@ -125,7 +133,7 @@
aa0b36
 
aa0b36
 
aa0b36
 <resource-agent name="SAPHanaTopology">
aa0b36
-    <version>0.151.1</version>
aa0b36
+    <version>$SAPHanaVersion</version>
aa0b36
     <shortdesc lang="en">Analyzes SAP HANA System Replication Topology.</shortdesc>
aa0b36
     <longdesc lang="en">This RA analyzes the SAP HANA topology and "sends" all findings via the node status attributes to
aa0b36
         all nodes in the cluster. These attributes are taken by the SAPHana RA to control the SAP Hana Databases.
aa0b36
@@ -207,12 +215,12 @@
aa0b36
     dstr=$(date)
aa0b36
     case "$attr_store" in
aa0b36
         reboot | forever )
aa0b36
-            echo "$dstr: SAPHanaTopology: crm_attribute -N ${attr_node} -G -n \"$attr_name\" -l $attr_store -q" >> /var/log/fhATTRIBUTE
aa0b36
-            crm_attribute -N ${attr_node} -G -n "$attr_name" -l $attr_store -q -d "$attr_default" 2>>/var/log/fhATTRIBUTE; rc=$?
aa0b36
+            echo "$dstr: SAPHanaTopology: crm_attribute -N ${attr_node} -G -n \"$attr_name\" -l $attr_store -q" >> $log_attr_file
aa0b36
+            crm_attribute -N ${attr_node} -G -n "$attr_name" -l $attr_store -q -d "$attr_default" 2>>$log_attr_file; rc=$?
aa0b36
             ;;
aa0b36
         props )
aa0b36
-            echo "$dstr: SAPHanaTopology: crm_attribute -G -n \"$attr_name\" -t crm_config -q" >> /var/log/fhATTRIBUTE
aa0b36
-            crm_attribute -G -n "$attr_name" -t crm_config -q -d "$attr_default" 2>>/var/log/fhATTRIBUTE; rc=$?
aa0b36
+            echo "$dstr: SAPHanaTopology: crm_attribute -G -n \"$attr_name\" -t crm_config -q" >> $log_attr_file
aa0b36
+            crm_attribute -G -n "$attr_name" -t crm_config -q -d "$attr_default" 2>>$log_attr_file; rc=$?
aa0b36
             ;;
aa0b36
     esac
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
@@ -282,6 +290,53 @@
aa0b36
 }
aa0b36
 
aa0b36
 #
aa0b36
+# function: dequote - filter: remove quotes (") from stdin
aa0b36
+# params:   -
aa0b36
+# globals:  -
aa0b36
+function dequote()
aa0b36
+{
aa0b36
+    local rc=0; tr -d '"'; return $rc
aa0b36
+}
aa0b36
+
aa0b36
+# function: version: cpmpare two HANA version strings
aa0b36
+function ver_lt() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 0 && return 0 || return 1
aa0b36
+}
aa0b36
+
aa0b36
+function ver_le() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 0 -o $? -eq 1 && return 0 || return 1
aa0b36
+}
aa0b36
+
aa0b36
+function ver_gt() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 2 && return 0 || return 1
aa0b36
+}
aa0b36
+
aa0b36
+function ver_ge() {
aa0b36
+    ocf_version_cmp $1 $2
aa0b36
+    test $? -eq 2 -o $? -eq 1 && return 0 || return 1
aa0b36
+}
aa0b36
+#
aa0b36
+# function: version: cpmpare two HANA version strings
aa0b36
+#
aa0b36
+function version() {
aa0b36
+    if [ $# -eq 3 ]; then
aa0b36
+        case "$2" in
aa0b36
+            LE | le | "<=" ) ver_le $1 $3;;
aa0b36
+            LT | lt | "<" ) ver_lt $1 $3;;
aa0b36
+            GE | ge | ">=" ) ver_ge $1 $3;;
aa0b36
+            GT | gt | ">" ) ver_gt $1 $3;;
aa0b36
+            * ) return 1;
aa0b36
+        esac
aa0b36
+    elif [ $# -ge 5 ]; then
aa0b36
+        version $1 $2 $3 && shift 2 && version $*
aa0b36
+    else
aa0b36
+        return 1;
aa0b36
+    fi
aa0b36
+}
aa0b36
+#
aa0b36
 # function: is_clone - report, if resource is configured as a clone (also master/slave)
aa0b36
 # params:   -
aa0b36
 # globals:  OCF_*(r)
aa0b36
@@ -314,12 +369,74 @@
aa0b36
 }
aa0b36
 
aa0b36
 #
aa0b36
+# function: HANA_CALL
aa0b36
+# params:   timeout-in-seconds cmd-line
aa0b36
+# globals:  sid(r), SID(r), InstanceName(r)
aa0b36
+#
aa0b36
+function HANA_CALL()
aa0b36
+{
aa0b36
+    #
aa0b36
+    # TODO: PRIO 5: remove 'su - ${sidadm} later, when SAP HANA resoled issue with
aa0b36
+    #       root-user-called hdbnsutil -sr_state (which creates root-owned shared memory file in /var/lib/hdb/SID/shmgrp)
aa0b36
+    # TODO: PRIO 5: Maybe make "su" optional by a parameter
aa0b36
+    local timeOut=0
aa0b36
+    local onTimeOut=""
aa0b36
+    local rc=0
aa0b36
+    local use_su=1 # Default to be changed later (see TODO above)
aa0b36
+    local pre_cmd=""
aa0b36
+    local cmd=""
aa0b36
+    local pre_script=""
aa0b36
+    local output=""
aa0b36
+    while [ $# -gt 0 ]; do
aa0b36
+        case "$1" in
aa0b36
+            --timeout ) timeOut=$2; shift;;
aa0b36
+            --use-su  ) use_su=1;;
aa0b36
+            --on-timeout ) onTimeOut="$2"; shift;;
aa0b36
+            --cmd ) shift; cmd="$*"; break;;
aa0b36
+        esac
aa0b36
+        shift
aa0b36
+    done
aa0b36
+
aa0b36
+    if [ $use_su -eq 1 ]; then
aa0b36
+        pre_cmd="su - ${sid}adm -c"
aa0b36
+        pre_script="true"
aa0b36
+    else
aa0b36
+        # as root user we need the library path to the SAP kernel to be able to call sapcontrol
aa0b36
+        # check, if we already added DIR_EXECUTABLE at the beginning of LD_LIBRARY_PATH
aa0b36
+        if [ "${LD_LIBRARY_PATH%%*:}" != "$DIR_EXECUTABLE" ]
aa0b36
+        then
aa0b36
+            MY_LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
aa0b36
+        fi
aa0b36
+        pre_cmd="bash -c"
aa0b36
+        pre_script="LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH; export LD_LIBRARY_PATH"
aa0b36
+    fi
aa0b36
+    case $timeout in
aa0b36
+        0 | inf )
aa0b36
+                  output=$($pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $cmd"); rc=$?
aa0b36
+                  ;;
aa0b36
+        *       )
aa0b36
+                  output=$(timeout $timeOut $pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $cmd"); rc=$?
aa0b36
+                  #
aa0b36
+                  # on timeout ...
aa0b36
+                  #
aa0b36
+                  if [ $rc -eq 124 -a -n "$onTimeOut" ]; then
aa0b36
+                      local second_output=""
aa0b36
+                      second_output=$($pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $onTimeOut");
aa0b36
+                  fi
aa0b36
+                  ;;
aa0b36
+    esac
aa0b36
+    echo "$output"
aa0b36
+    return $rc;
aa0b36
+}
aa0b36
+
aa0b36
+#
aa0b36
 # function: sht_init - initialize variables for the resource agent
aa0b36
 # params:   -
aa0b36
 # globals:  OCF_*(r), SID(w), sid(rw), sidadm(w), InstanceName(w), InstanceNr(w),
aa0b36
-# globals:  meta_notify_master_uname(w), HANA_SR_TOLOPOGY(w), sr_name(w), remoteHost(w)
aa0b36
+# globals:  meta_notify_master_uname(w), HANA_SR_TOLOPOGY(w), sr_name(w)
aa0b36
 # globals:  ATTR_NAME_HANA_SYNC_STATUS(w), ATTR_NAME_HANA_PRIMARY_AT(w), ATTR_NAME_HANA_CLONE_STATE(w)
aa0b36
 # globals:  DIR_EXECUTABLE(w), SAPSTARTSRV(w), SAPCONTROL(w), DIR_PROFILE(w), SAPSTARTPROFILE(w), LD_LIBRARY_PATH(w), PATH(w), nodelist(w)
aa0b36
+# globals:  NODENAME(w), hdbver(w)
aa0b36
 # sht_init : Define global variables with default values, if optional parameters are not set
aa0b36
 #
aa0b36
 #
aa0b36
@@ -331,12 +448,14 @@
aa0b36
     local hdbANSWER=""
aa0b36
     local siteID
aa0b36
     local siteNAME
aa0b36
+    local chkMethod=""
aa0b36
     HOSTEXECNAME=saphostexec
aa0b36
     USRSAP=/usr/sap
aa0b36
     SAPSERVICE_PATH=${USRSAP}/sapservices
aa0b36
     SAPHOSTCTRL_PATH=${USRSAP}/hostctrl/exe
aa0b36
     HOSTEXEC_PATH=${SAPHOSTCTRL_PATH}/${HOSTEXECNAME}
aa0b36
     HOSTEXEC_PROFILE_PATH=${SAPHOSTCTRL_PATH}/host_profile
aa0b36
+    NODENAME=$(crm_node -n)
aa0b36
     SID=$OCF_RESKEY_SID
aa0b36
     InstanceNr=$OCF_RESKEY_InstanceNumber
aa0b36
     myInstanceName="${SID}_HDB${InstanceNr}"
aa0b36
@@ -382,13 +501,6 @@
aa0b36
         DIR_PROFILE="$OCF_RESKEY_DIR_PROFILE"
aa0b36
     fi
aa0b36
 
aa0b36
-    # as root user we need the library path to the SAP kernel to be able to call sapcontrol
aa0b36
-    # check, if we already added DIR_EXECUTABLE at the beginning of LD_LIBRARY_PATH
aa0b36
-    if [ "${LD_LIBRARY_PATH%%*:}" != "$DIR_EXECUTABLE" ]
aa0b36
-    then
aa0b36
-        LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
aa0b36
-        export LD_LIBRARY_PATH
aa0b36
-    fi
aa0b36
 
aa0b36
     PATH=${PATH}:${DIR_EXECUTABLE}
aa0b36
     #
aa0b36
@@ -399,12 +511,45 @@
aa0b36
        *openais* ) nodelist=$(crm_node -l | awk '/member/ {print $2}');;
aa0b36
        *cman*    ) nodelist=$(crm_node -l);;
aa0b36
     esac
aa0b36
+    #
aa0b36
+    # get HANA version
aa0b36
+    #
aa0b36
+    local ges_ver
aa0b36
+    ges_ver=$(HANA_CALL --timeout 10 --cmd "HDB version" | tr -d " " | awk -F: '$1 == "version" {print $2}')
aa0b36
+    hdbver=${ges_ver%.*.*}
aa0b36
+    #
aa0b36
+    # since rev 111.00 we should use a new hdbnsutil option to get the -sr_state
aa0b36
+    # since rev 112.03 the old option is changed and we should use -sr_stateConfiguration where ever possible
aa0b36
+    #
aa0b36
+    hdbState="hdbnsutil -sr_state"
aa0b36
+    hdbMap="hdbnsutil -sr_state"
aa0b36
+    if version "$hdbver" ">=" "1.00.111"; then
aa0b36
+        hdbState="hdbnsutil -sr_stateConfiguration"
aa0b36
+        hdbMap="hdbnsutil -sr_stateHostMapping"
aa0b36
+    fi
aa0b36
     #### SAP-CALL
aa0b36
     # hdbnsutil was a bit unstable in some tests so we recall the tool, if it fails to report the srmode
aa0b36
-    for i in  1 2 3 4 5 6 7 8 9; do
aa0b36
-        hdbANSWER=$(su - ${sidadm} -c "hdbnsutil -sr_state --sapcontrol=1" 2>/dev/null)
aa0b36
-        super_ocf_log debug "DBG2: hdbANSWER=\$\(su - ${sidadm} -c \"hdbnsutil -sr_state --sapcontrol=1\"\)"
aa0b36
-        srmode=$(echo "$hdbANSWER" | awk -F= '/mode/ {print $2}')
aa0b36
+    for chkMethod in  hU hU hU gP ; do
aa0b36
+        # DONE: Limit the runtime of hdbnsutil.
aa0b36
+        # TODO: Use getParameter.py if we get no answer
aa0b36
+        # SAP_CALL
aa0b36
+        #super_ocf_log debug "DBG2: hdbANSWER=$hdbANSWER"
aa0b36
+        #srmode=$(echo "$hdbANSWER" | awk -F= '/mode/ {print $2}')
aa0b36
+        case "$chkMethod" in
aa0b36
+            gP ) # call getParameter (gP)
aa0b36
+                local gpKeys=""
aa0b36
+                gpKeys=$(echo --key=global.ini/system_replication/{mode,site_name,site_id})
aa0b36
+                hdbANSWER=$(HANA_CALL --timeout 60 --cmd "HDBSettings.sh getParameter.py $gpKeys --sapcontrol=1" 2>&1 | awk -F/ 'BEGIN {out=0} /^SAPCONTROL-OK: <begin>/ { out=1 } /^SAPCONTROL-OK: <end>/ { out=0 } /=/ {if (out==1) {print $3} }')
aa0b36
+                srmode=$(echo "$hdbANSWER" | awk -F= '$1=="mode" {print $2}')
aa0b36
+                super_ocf_log info "ACT: hdbnsutil not answering - using global.ini as fallback - srmode=$srmode"
aa0b36
+                ;;
aa0b36
+            hU | * ) # call hdbnsUtil (hU) ( also for unknown chkMethod )
aa0b36
+                # DONE: PRIO1: Begginning from SAP HANA rev 112.03 -sr_state is not longer supported
aa0b36
+                hdbANSWER=$(HANA_CALL --timeout 60 --cmd "$hdbState --sapcontrol=1" 2>/dev/null)
aa0b36
+                super_ocf_log debug "DBG2: hdbANSWER=$hdbANSWER"
aa0b36
+                srmode=$(echo "$hdbANSWER" | awk -F= '$1=="mode" {print $2}')
aa0b36
+                ;;
aa0b36
+        esac
aa0b36
         case "$srmode" in
aa0b36
             primary | syncmem | sync | async | none )
aa0b36
               # we can leave the loop as we already got a result
aa0b36
@@ -417,27 +562,51 @@
aa0b36
         esac
aa0b36
     done
aa0b36
     # TODO PRIO3: Implement a file lookup, if we did not get a result
aa0b36
-    siteID=$(echo "$hdbANSWER" | awk -F= '/site id/ {print $2}')
aa0b36
-    siteNAME=$(echo "$hdbANSWER" | awk -F= '/site name/ {print $2}')
aa0b36
+    siteID=$(echo "$hdbANSWER" | awk -F= '/site.id/ {print $2}')       # allow 'site_id' AND 'site id'
aa0b36
+    siteNAME=$(echo "$hdbANSWER" | awk -F= '/site.name/ {print $2}')
aa0b36
     site=$siteNAME
aa0b36
     srmode=$(echo "$hdbANSWER" | awk -F= '/mode/ {print $2}')
aa0b36
-    MAPPING=$(echo "$hdbANSWER" | awk -F[=/] '$1 ~ "mapping" && $3 !~ site { print $4 }' site=$site)
aa0b36
-    super_ocf_log debug "DBG: site=$site, mode=$srmode, MAPPING=$MAPPING"
aa0b36
     #
aa0b36
-    # filter all non-cluster mappings
aa0b36
+    # for rev >= 111 we use the new mapping query
aa0b36
     #
aa0b36
-    # DONE: PRIO2: Need mapping between HANA HOSTS not cluster NODES
aa0b36
-    local hanaVHost
aa0b36
-    hanaRemoteHost=$(for n1 in $nodelist; do
aa0b36
-          hanaVHost=$(get_hana_attribute ${n1} ${ATTR_NAME_HANA_VHOST[@]})
aa0b36
-          for n2 in $MAPPING; do
aa0b36
-             if [ "$hanaVHost" == "$n2" ]; then
aa0b36
-                echo $hanaVHost;
aa0b36
-             fi;
aa0b36
-          done;
aa0b36
-          done )
aa0b36
-    super_ocf_log info "DEC: site=$site, mode=$srmode, MAPPING=$MAPPING, hanaRemoteHost=$hanaRemoteHost"
aa0b36
-    super_ocf_log debug "DBG: site=$site, mode=$srmode, MAPPING=$MAPPING, hanaRemoteHost=$hanaRemoteHost"
aa0b36
+    if version "$hdbver" ">=" "1.00.111"; then
aa0b36
+        hdbANSWER=$(HANA_CALL --timeout 60 --cmd "$hdbMap --sapcontrol=1" 2>/dev/null)
aa0b36
+    fi
aa0b36
+    MAPPING=$(echo "$hdbANSWER" | awk -F[=/] '$1 == "mapping" && $3 != site { print $4 }' site=$site)
aa0b36
+    super_ocf_log debug "DBG: site=$site, mode=$srmode, MAPPING=$MAPPING"
aa0b36
+    if [ -n "$MAPPING" ]; then
aa0b36
+        # we have a mapping from HANA, lets use it
aa0b36
+        #
aa0b36
+        # filter all non-cluster mappings
aa0b36
+        #
aa0b36
+        local hanaVHost=""
aa0b36
+        local n1=""
aa0b36
+        hanaRemoteHost=""
aa0b36
+        for n1 in $nodelist; do
aa0b36
+              hanaVHost=$(get_hana_attribute ${n1} ${ATTR_NAME_HANA_VHOST[@]})
aa0b36
+              for n2 in $MAPPING; do
aa0b36
+                 if [ "$hanaVHost" == "$n2" ]; then
aa0b36
+                    hanaRemoteHost="$hanaVHost"
aa0b36
+                 fi;
aa0b36
+              done;
aa0b36
+        done
aa0b36
+        super_ocf_log info "DEC: site=$site, mode=$srmode, MAPPING=$MAPPING, hanaRemoteHost=$hanaRemoteHost"
aa0b36
+        super_ocf_log debug "DBG: site=$site, mode=$srmode, MAPPING=$MAPPING, hanaRemoteHost=$hanaRemoteHost"
aa0b36
+    else
aa0b36
+        # HANA DID NOT TOLD THE MAPPING, LETS TRY TO USE THE SITE ATTRIBUTES
aa0b36
+        local n1=""
aa0b36
+        local hanaSite=""
aa0b36
+        for n1 in $nodelist; do
aa0b36
+            # TODO: PRIO9 - For multi tier with more than 2 chain/star members IN the cluster we might need to be
aa0b36
+            #       able to catch more than one remoteHost
aa0b36
+            #       currently having more than 2 HANA in a chain/star members IN the cluster is not allowed, the third must be external
aa0b36
+            if [ "$NODENAME" != "$n1" ]; then
aa0b36
+                hanaSite=$(get_hana_attribute ${n1} ${ATTR_NAME_HANA_SITE[@]})
aa0b36
+                hanaRemoteHost="$n1"
aa0b36
+            fi
aa0b36
+        done
aa0b36
+        super_ocf_log info "DEC: site=$site, mode=$srmode, hanaRemoteHost=$hanaRemoteHost - found by remote site ($hanaSite)"
aa0b36
+    fi
aa0b36
     super_ocf_log info "FLOW $FUNCNAME rc=$OCF_SUCCESS"
aa0b36
     return $OCF_SUCCESS
aa0b36
 }
aa0b36
@@ -446,38 +615,29 @@
aa0b36
 # function: check_for_primary - check if local SAP HANA is configured as primary
aa0b36
 # params:   -
aa0b36
 # globals:  HANA_STATE_PRIMARY(r), HANA_STATE_SECONDARY(r), HANA_STATE_DEFECT(r), HANA_STATE_STANDALONE(r)
aa0b36
+#           srmode(r)
aa0b36
 #
aa0b36
 function check_for_primary() {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=0
aa0b36
-    node_status=$srmode
aa0b36
-    super_ocf_log debug "DBG2: check_for_primary: node_status=$node_status"
aa0b36
-    super_ocf_log debug "DBG: check_for_primary: node_status=$node_status"
aa0b36
-    for i in  1 2 3 4 5 6 7 8 9; do
aa0b36
-        case "$node_status" in
aa0b36
-           primary )
aa0b36
-                  super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_PRIMARY"
aa0b36
-                  return $HANA_STATE_PRIMARY;;
aa0b36
-           syncmem | sync | async )
aa0b36
-                  super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_SECONDARY"
aa0b36
-                  return $HANA_STATE_SECONDARY;;
aa0b36
-           none ) # have seen that mode on second side BEFEORE we registered it as replica
aa0b36
-                  super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_STANDALONE"
aa0b36
-                  return $HANA_STATE_STANDALONE;;
aa0b36
-           * )
aa0b36
-              # TODO: PRIO1: Should we set SFAIL?
aa0b36
-              # TODO: PRIO2: Maybe we need to keep the old value for P/S/N, if hdbnsutil just crashes
aa0b36
-              dump=$( echo $node_status | hexdump -C );
aa0b36
-              super_ocf_log err "ACT: check_for_primary:  we didn't expect node_status to be: DUMP: <$dump>"
aa0b36
-              #### SAP-CALL
aa0b36
-              node_full_status=$(su - ${sidadm} -c "hdbnsutil -sr_state" 2>/dev/null )
aa0b36
-              node_status=$(echo "$node_full_status" | awk '$1=="mode:" {print $2}')
aa0b36
-              super_ocf_log info "DEC: check_for_primary: loop=$i: node_status=$node_status"
aa0b36
-              # TODO: PRIO1: Maybe we need to keep the old value for P/S/N, if hdbnsutil just crashes
aa0b36
-       esac;
aa0b36
-   done
aa0b36
-   super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_DEFECT"
aa0b36
-   return $HANA_STATE_DEFECT
aa0b36
+    super_ocf_log debug "DBG: check_for_primary: srmode=$srmode"
aa0b36
+    case "$srmode" in
aa0b36
+       primary )
aa0b36
+              super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_PRIMARY"
aa0b36
+              rc=$HANA_STATE_PRIMARY;;
aa0b36
+       syncmem | sync | async )
aa0b36
+              super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_SECONDARY"
aa0b36
+              rc=$HANA_STATE_SECONDARY;;
aa0b36
+       none ) # have seen that mode on second side BEFEORE we registered it as replica
aa0b36
+              super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_STANDALONE"
aa0b36
+              rc=$HANA_STATE_STANDALONE;;
aa0b36
+       * )
aa0b36
+          dump=$( echo $srmode | hexdump -C );
aa0b36
+          super_ocf_log err "ACT: check_for_primary:  we didn't expect srmode to be: DUMP: <$dump>"
aa0b36
+          rc=$HANA_STATE_DEFECT
aa0b36
+   esac;
aa0b36
+   super_ocf_log info "FLOW $FUNCNAME rc=$rc"
aa0b36
+   return $rc
aa0b36
 }
aa0b36
 
aa0b36
 
aa0b36
@@ -653,7 +813,7 @@
aa0b36
 function sht_stop_clone() {
aa0b36
     super_ocf_log info "FLOW $FUNCNAME ($*)"
aa0b36
     local rc=0
aa0b36
-	check_for_primary; primary_status=$?
aa0b36
+    check_for_primary; primary_status=$?
aa0b36
     if [ $primary_status -eq $HANA_STATE_PRIMARY ]; then
aa0b36
         hanaPrim="P"
aa0b36
     elif [ $primary_status -eq $HANA_STATE_SECONDARY ]; then
aa0b36
@@ -663,7 +823,7 @@
aa0b36
     else
aa0b36
         hanaPrim="-"
aa0b36
     fi
aa0b36
-    set_hana_attribute "${NODENAME}" "1:$hanaPrim:-:-:-:-" ${ATTR_NAME_HANA_ROLES[@]} 
aa0b36
+    set_hana_attribute "${NODENAME}" "1:$hanaPrim:-:-:-:-" ${ATTR_NAME_HANA_ROLES[@]}
aa0b36
     sht_stop; rc=$?
aa0b36
     return $rc
aa0b36
 }
aa0b36
@@ -718,28 +878,49 @@
aa0b36
     fi
aa0b36
     # DONE: PRIO1: ASK: Is the output format of ListInstances fix? Could we take that as an API?
aa0b36
     # try to catch:  Inst Info : LNX - 42 - lv9041 - 740, patch 36, changelist 1444691
aa0b36
-    # We rely on the following format: SID is word#4, NR is work#6, vHost is word#8
aa0b36
+    # We rely on the following format: SID is word#4, SYSNR is word#6, vHost is word#8
aa0b36
     #### SAP-CALL
aa0b36
     vName=$(/usr/sap/hostctrl/exe/saphostctrl -function ListInstances \
aa0b36
-        | awk '$4 == SID && $6=NR { print $8 }' SID=$SID NR=$InstanceNr 2>/dev/null )
aa0b36
+        | awk '$4 == SID && $6 == SYSNR { print $8 }' SID=$SID SYSNR=$InstanceNr 2>/dev/null )
aa0b36
     # super_ocf_log debug "DBG: ListInstances: $(/usr/sap/hostctrl/exe/saphostctrl -function ListInstances)"
aa0b36
     if [ -n "$vName" ]; then
aa0b36
-       set_hana_attribute ${NODENAME} "$vName" ${ATTR_NAME_HANA_VHOST[@]} 
aa0b36
+       set_hana_attribute ${NODENAME} "$vName" ${ATTR_NAME_HANA_VHOST[@]}
aa0b36
     else
aa0b36
        vName=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_VHOST[@]})
aa0b36
     fi
aa0b36
     #site=$(get_site_name)
aa0b36
     #### SAP-CALL
aa0b36
-    hanaANSWER=$(su - $sidadm -c "python exe/python_support/landscapeHostConfiguration.py" 2>/dev/null); hanalrc="$?" 
aa0b36
-    hanarole=$(echo "$hanaANSWER" | tr -d ' ' | awk -F'|' '$2 == host {  printf "%s:%s:%s:%s\n",$10,$11,$12,$13 }  ' host=${vName})
aa0b36
+    # SAP_CALL
aa0b36
+    #hanaANSWER=$(su - $sidadm -c "python exe/python_support/landscapeHostConfiguration.py" 2>/dev/null); hanalrc="$?"
aa0b36
+    #
aa0b36
+    # since rev 09x SAP has added the --sapcontrol option for the landscapeHostConfiguration interface
aa0b36
+    # we begin to use --sapcontrol with rev 100
aa0b36
+    # since rev 120 we need to use the --sapcontrol, because SAP changed the tool output
aa0b36
+    #
aa0b36
+    if version "$hdbver" ">=" "1.00.100"; then
aa0b36
+        hanaANSWER=$(HANA_CALL --timeout 60 --cmd "landscapeHostConfiguration.py --sapcontrol=1" 2>/dev/null); hanalrc="$?"
aa0b36
+        # TODO: PRIO9: Do we need to check the lines: 'SAPCONTROL-OK: <begin>' and 'SAPCONTROL-OK: <end>'?
aa0b36
+        hanarole=$(echo "$hanaANSWER" | tr -d ' ' | \
aa0b36
+            awk -F= '$1 == "nameServerConfigRole"    {f1=$2}
aa0b36
+                     $1 == "nameServerActualRole"    {f2=$2}
aa0b36
+                     $1 == "indexServerConfigRole"   {f3=$2}
aa0b36
+                     $1 == "indexServerActualRole"   {f4=$2}
aa0b36
+                     END { printf "%s:%s:%s:%s\n", f1, f2, f3,f4 }')
aa0b36
+    else
aa0b36
+        #
aa0b36
+        # old code for backward compatability
aa0b36
+        #
aa0b36
+        hanaANSWER=$(HANA_CALL --timeout 60 --cmd "landscapeHostConfiguration.py" 2>/dev/null); hanalrc="$?"
aa0b36
+        hanarole=$(echo "$hanaANSWER" | tr -d ' ' | awk -F'|' '$2 == host {  printf "%s:%s:%s:%s\n",$10,$11,$12,$13 }  ' host=${vName})
aa0b36
+    fi
aa0b36
     #if [ -z "$MAPPING" ]; then
aa0b36
     #   super_ocf_log info "ACT: Did not find remote Host at this moment"
aa0b36
     #fi
aa0b36
     # FH TODO PRIO3: TRY TO GET RID OF "ATTR_NAME_HANA_REMOTEHOST"
aa0b36
     if [ -n "$hanaRemoteHost" ]; then
aa0b36
-        set_hana_attribute ${NODENAME} "$hanaRemoteHost" ${ATTR_NAME_HANA_REMOTEHOST[@]} 
aa0b36
+        set_hana_attribute ${NODENAME} "$hanaRemoteHost" ${ATTR_NAME_HANA_REMOTEHOST[@]}
aa0b36
     fi
aa0b36
-    set_hana_attribute ${NODENAME} "$hanalrc:$hanaPrim:$hanarole" ${ATTR_NAME_HANA_ROLES[@]} 
aa0b36
+    set_hana_attribute ${NODENAME} "$hanalrc:$hanaPrim:$hanarole" ${ATTR_NAME_HANA_ROLES[@]}
aa0b36
     if [ -n "$site" ]; then
aa0b36
         set_hana_attribute ${NODENAME} "$site" ${ATTR_NAME_HANA_SITE[@]}
aa0b36
     fi
aa0b36
@@ -748,8 +929,8 @@
aa0b36
         S ) # only secondary may propargate its sync status
aa0b36
         case $(crm_attribute --type crm_config --name cluster-infrastructure -q) in
aa0b36
            *corosync* ) nodelist=$(crm_node -l | awk '{ print $2 }');;
aa0b36
-           *openais* ) nodelist=$(crm_node -l | awk '/member/ {print $2}');;    
aa0b36
-           *cman*    ) nodelist=$(crm_node -l);; 
aa0b36
+           *openais* ) nodelist=$(crm_node -l | awk '/member/ {print $2}');;
aa0b36
+           *cman*    ) nodelist=$(crm_node -l);;
aa0b36
         esac
aa0b36
 
aa0b36
         for n in ${nodelist}; do
aa0b36
@@ -789,7 +970,6 @@
aa0b36
 InstanceNr=""
aa0b36
 DIR_EXECUTABLE=""
aa0b36
 SAPHanaFilter="ra-act-dec-lpa"
aa0b36
-NODENAME=$(crm_node -n)
aa0b36
 
aa0b36
 if [ $# -ne 1 ]
aa0b36
 then
aa0b36
@@ -846,8 +1026,7 @@
aa0b36
     fi
aa0b36
 fi
aa0b36
 
aa0b36
-THE_VERSION=$(sht_meta_data | grep '
aa0b36
-super_ocf_log info "RA ==== begin action $ACTION$CLACT ($THE_VERSION) ===="
aa0b36
+super_ocf_log info "RA ==== begin action $ACTION$CLACT ($SAPHanaVersion) ===="
aa0b36
 ra_rc=$OCF_ERR_UNIMPLEMENTED
aa0b36
 case "$ACTION" in
aa0b36
     start|stop|monitor) # Standard controling actions
aa0b36
@@ -865,5 +1044,5 @@
aa0b36
 esac
aa0b36
 timeE=$(date '+%s')
aa0b36
 (( timeR = timeE - timeB ))
aa0b36
-super_ocf_log info "RA ==== end action $ACTION$CLACT with rc=${ra_rc} ($THE_VERSION) (${timeR}s)===="
aa0b36
+super_ocf_log info "RA ==== end action $ACTION$CLACT with rc=${ra_rc} ($SAPHanaVersion) (${timeR}s)===="
aa0b36
 exit ${ra_rc}
aa0b36
diff -uNr a/tools/show_SAPHanaSR_attributes b/tools/show_SAPHanaSR_attributes
aa0b36
--- a/tools/show_SAPHanaSR_attributes	2016-10-14 10:09:56.467051414 +0200
aa0b36
+++ b/tools/show_SAPHanaSR_attributes	2016-10-14 10:31:28.051676675 +0200
aa0b36
@@ -1,19 +1,78 @@
aa0b36
 #!/usr/bin/perl
aa0b36
 #
aa0b36
-# get_all_lnx_attributes
aa0b36
-#
aa0b36
-# license: GPL
aa0b36
-# author:  fabian.herschel@suse.com
aa0b36
-# date:    2014-05-13
aa0b36
-# 
aa0b36
+# SAPHanaSR-showAttr
aa0b36
+# (c) 2014 SUSE Linux Products GmbH, Nuremberg, Germany
aa0b36
+# (c) 2015-2016 SUSE Linux GmbH, Nuremberg Germany
aa0b36
+# Author: Fabian Herschel <fabian.herschel@suse.com>
aa0b36
+# License: GPL v2+
aa0b36
+my $Version="0.18.2016.02.16.1";
aa0b36
 #
aa0b36
+##################################################################
aa0b36
 use POSIX;
aa0b36
 use strict;
aa0b36
+use Sys::Syslog;
aa0b36
+use Sys::Hostname;
aa0b36
+use File::Path;
aa0b36
+use Getopt::Long;
aa0b36
+use lib '/usr/share/SAPHanaSR/tests';
aa0b36
+use SAPHanaSRTools;
aa0b36
+
aa0b36
+###################################
aa0b36
+## this part is not for scale out and currently NOT zero-config
aa0b36
+
aa0b36
+my $ClusterNodes=2;
aa0b36
+my $ClusterPrimaries=1;
aa0b36
+my $ClusterSecondaries=1;
aa0b36
+my %Name;
aa0b36
+my %Host;
aa0b36
+my $host = hostname();
aa0b36
 
aa0b36
+my $varlib='/var/lib/SAPHanaTD';
aa0b36
+my $testfile='SAPHanaTD.status';
aa0b36
+my $testcount=0;
aa0b36
+my $first_test=1;
aa0b36
 my $sid="";
aa0b36
-my $table_title = "Host \\ Attr";
aa0b36
-my %Name;
aa0b36
+my @sids;
aa0b36
+my $ino="";
aa0b36
+my $sortBy="";
aa0b36
+my $table_titleH = "Host";
aa0b36
+#my %Name;
aa0b36
 my %Host;
aa0b36
+my %Site;
aa0b36
+my %Global;
aa0b36
+my %HName;
aa0b36
+my %SName;
aa0b36
+my %GName;
aa0b36
+my $help;
aa0b36
+my $version;
aa0b36
+my $cibFile="";
aa0b36
+
aa0b36
+sub init()
aa0b36
+{
aa0b36
+	my $result = GetOptions ("sid=s" => \@sids,
aa0b36
+	                      "sort=s" => \$sortBy,
aa0b36
+	                      "cib=s" => \$cibFile,
aa0b36
+                          "version" => \$version,
aa0b36
+                          "help" => \$help,
aa0b36
+		 );
aa0b36
+   return 0;
aa0b36
+}
aa0b36
+
aa0b36
+init();
aa0b36
+
aa0b36
+if ( $help ) {
aa0b36
+   printf "SAPHanaSR-showAttr {[--sid=<sid[:instNr]>]} [--sort=<SortBy>] [--cib=<OfflineCibFile>]\n";
aa0b36
+   printf "";
aa0b36
+   exit 0;
aa0b36
+}
aa0b36
+if ( $version ) {
aa0b36
+   printf "%s\n", $Version;
aa0b36
+   exit 0;
aa0b36
+}
aa0b36
+
aa0b36
+if ( $cibFile ne "" ) {
aa0b36
+   printf "Using cib file %s\n", $cibFile;
aa0b36
+}
aa0b36
 
aa0b36
 sub max { # thanks to http://www.perlunity.de/perl/forum/thread_018329.shtml
aa0b36
  my $a = shift;
aa0b36
@@ -21,113 +80,75 @@
aa0b36
  return $a > $b ? $a : $b;
aa0b36
 }
aa0b36
 
aa0b36
-sub print_attr_host()
aa0b36
-{
aa0b36
-    my ($HKey, $AKey);
aa0b36
-	printf "%-22s", "Attribute \\ Host";
aa0b36
-	foreach $HKey (sort keys %Host) {
aa0b36
-	   printf "%-16s ", $HKey;
aa0b36
-	}
aa0b36
-	printf "\n";
aa0b36
-
aa0b36
-	printf "%s\n", "-" x 120 ;
aa0b36
-
aa0b36
-	foreach $AKey (sort keys %Name) {
aa0b36
-	   printf "%-22s", $AKey;
aa0b36
-	   foreach $HKey (sort keys %Host) {
aa0b36
-		   printf "%-16.16s ", $Host{$HKey} -> {$AKey};
aa0b36
-		}
aa0b36
-
aa0b36
-	   printf "\n";
aa0b36
-	}
aa0b36
-	return 0;
aa0b36
-}
aa0b36
-
aa0b36
-sub print_host_attr()
aa0b36
-{
aa0b36
-    my ($AKey, $HKey, $len, $line_len, $hclen);
aa0b36
-    $hclen=$Name{_hosts}->{_length};
aa0b36
-    $line_len=$hclen+1;
aa0b36
-	printf "%-$hclen.${hclen}s ", "$table_title";
aa0b36
-	foreach $AKey (sort keys %Name) {
aa0b36
-       if ($AKey ne "_hosts") {
aa0b36
-           $len = $Name{$AKey}->{_length};
aa0b36
-           $line_len=$line_len+$len+1;
aa0b36
-           printf "%-$len.${len}s ", $Name{$AKey}->{_title};
aa0b36
+sub read_cib($) {
aa0b36
+    my $sid = shift();
aa0b36
+    if ( $cibFile eq "" ) {
aa0b36
+        printf "Open live cib\n";
aa0b36
+        open CIB, "cibadmin -Ql |" or die "CIB could not be read from cluster";
aa0b36
+    } else {
aa0b36
+        open CIB, "<$cibFile" or die "CIB file $cibFile not found or not able to read it";
aa0b36
+    }
aa0b36
+    while (<CIB>) {
aa0b36
+       chomp;
aa0b36
+       my ($host, $name, $site, $value);
aa0b36
+       if ( $_ =~ /cib-last-written="([^"]*)"/ ) {
aa0b36
+          printf "CIB-time: %s\n", $1;
aa0b36
        }
aa0b36
-	}
aa0b36
-	printf "\n";
aa0b36
-	printf "%s\n", "-" x $line_len ;
aa0b36
-	foreach $HKey (sort keys %Host) {
aa0b36
-	   printf "%-$hclen.${hclen}s ", $HKey;
aa0b36
-	   foreach $AKey (sort keys %Name) {
aa0b36
-           if ($AKey ne "_hosts") {
aa0b36
-               $len = $Name{$AKey}->{_length};
aa0b36
-               printf "%-$len.${len}s ", $Host{$HKey} -> {$AKey};
aa0b36
-            }
aa0b36
-        }
aa0b36
-	   printf "\n";
aa0b36
-	}
aa0b36
-	return 0;
aa0b36
-}
aa0b36
-
aa0b36
-open ListInstances, "/usr/sap/hostctrl/exe/saphostctrl -function ListInstances|";
aa0b36
-while (<ListInstances>) {
aa0b36
-   # try to catch:  Inst Info : LNX - 42 - lv9041 - 740, patch 36, changelist 1444691
aa0b36
-   chomp;
aa0b36
-   if ( $_ =~ /:\s+([A-Z][A-Z0-9][A-Z0-9])\s+-/ ) {
aa0b36
-      $sid=tolower("$1");
aa0b36
-   }
aa0b36
-}
aa0b36
-close ListInstances;
aa0b36
-
aa0b36
-
aa0b36
-open CIB, "cibadmin -Ql |";
aa0b36
-while (<CIB>) {
aa0b36
-   chomp;
aa0b36
-   my ($host, $name, $value);
aa0b36
-   my $found=0;
aa0b36
-   if ( $_ =~ /nvpair.*name="(\w+_${sid}_\w+)"/ ) {
aa0b36
-      $name=$1;
aa0b36
-      # find attribute in forever and reboot store :)
aa0b36
-      if ( $_ =~ /id="(status|nodes)-([a-zA-Z0-9\_\-]+)-/ ) {
aa0b36
-         $host=$2;
aa0b36
-      }
aa0b36
-      if ( $_ =~ /value="([^"]+)"/ ) {
aa0b36
-         $value=$1;
aa0b36
-         $found=1;
aa0b36
-      }
aa0b36
-   }
aa0b36
-   if ( $found == 1 ) {
aa0b36
-       #
aa0b36
-       # handle the hosts name and table-title
aa0b36
-       #
aa0b36
-       $Host{$host}->{$name}=${value};
aa0b36
-       if ( defined ($Name{_hosts}->{_length})) {
aa0b36
-          $Name{_hosts}->{_length} = max($Name{_hosts}->{_length}, length($host ));
aa0b36
-       } else {
aa0b36
-          $Name{_hosts}->{_length} = length($host );
aa0b36
+       if ( $_ =~ /node_state id=".+" uname="([a-zA-Z0-9\-\_]+)" .*crmd="([a-zA-Z0-9\-\_]+)"/ ) {
aa0b36
+           insertAttribute($sid, \%Host, \%HName, $1, "node_status", $2);
aa0b36
        }
aa0b36
-       $Name{_hosts}->{_length} = max($Name{_hosts}->{_length}, length( $table_title));
aa0b36
-       #
aa0b36
-       # now handle the attributes name and value
aa0b36
-       #
aa0b36
-       $Name{$name}->{$host}=${value};
aa0b36
-       if ( defined ($Name{$name}->{_length})) {
aa0b36
-          $Name{$name}->{_length} = max($Name{$name}->{_length}, length($value ));
aa0b36
-       } else {
aa0b36
-          $Name{$name}->{_length} = length($value );
aa0b36
+       if ( $_ =~ /nvpair.*name="([a-zA-Z0-9\_\-]+_${sid}_([a-zA-Z0-9\-\_]+))"/ ) {
aa0b36
+          $name=$1;
aa0b36
+          if ( $_ =~ /id=.(status|nodes)-([a-zA-Z0-9\_\-]+)-/ ) {
aa0b36
+             # found attribute in nodes forever and reboot store
aa0b36
+             $host=$2;
aa0b36
+             if ( $_ =~ /value="([^"]+)"/ ) {
aa0b36
+                 $value=$1;
aa0b36
+                 insertAttribute($sid, \%Host, \%HName, $host, $name, $value);
aa0b36
+             }
aa0b36
+          } elsif ( $_ =~ /id=.SAPHanaSR-[a-zA-Z0-9\_\-]+_site_[a-zA-Z0-9\-]+_([a-zA-Z0-9\_\-]+)/) {
aa0b36
+             # found a site attribute
aa0b36
+             $site=$1;
aa0b36
+             if ( $name =~ /[a-zA-Z0-9\_\-]+_site_([a-zA-Z0-9\-]+)/ ) {
aa0b36
+                $name = $1;
aa0b36
+             }
aa0b36
+             if ( $_ =~ /value="([^"]+)"/ ) {
aa0b36
+                 $value=$1;
aa0b36
+                 insertAttribute($sid, \%Site, \%SName, $site, $name, $value);
aa0b36
+             }
aa0b36
+          } elsif ( $_ =~ /id=.SAPHanaSR-[a-zA-Z0-9\_\-]+_glob_[a-zA-Z0-9\_\-]+/) {
aa0b36
+             # found a global attribute
aa0b36
+             $host="GLOBAL";
aa0b36
+             if ( $name =~ /([a-zA-Z0-9\_\-]+)_glob_([a-zA-Z0-9\_\-]+)/ ) {
aa0b36
+                $name = $2;
aa0b36
+             }
aa0b36
+             if ( $_ =~ /value="([^"]+)"/ ) {
aa0b36
+                 $value=$1;
aa0b36
+                 insertAttribute($sid, \%Global, \%GName, "global", $name, $value);
aa0b36
+             }
aa0b36
+          }
aa0b36
        }
aa0b36
-       if ( $name =~ /hana_${sid}_(.*)/ ) {
aa0b36
-          $Name{$name}->{_title} =  $1;
aa0b36
-       } else {
aa0b36
-          $Name{$name}->{_title} = $name; 
aa0b36
-       }
aa0b36
-       $Name{$name}->{_length} = max($Name{$name}->{_length}, length( $Name{$name}->{_title}));
aa0b36
-       # printf "%-8s %-20s %-30s\n", $1, $2, $3;
aa0b36
-   }
aa0b36
+    }
aa0b36
+    close CIB;
aa0b36
 }
aa0b36
-close CIB;
aa0b36
 
aa0b36
-#print_attr_host;
aa0b36
-print_host_attr;
aa0b36
+if ( 0 == @sids ) {
aa0b36
+    my $sid_ino_list;
aa0b36
+       ( $sid_ino_list ) = get_sid_and_InstNr();
aa0b36
+       @sids = split(",", $sid_ino_list);
aa0b36
+
aa0b36
+}
aa0b36
+
aa0b36
+foreach $sid (@sids) {
aa0b36
+    ( $sid, $ino ) = split(":", $sid);
aa0b36
+    $sid=tolower("$sid");
aa0b36
+    %Host=();
aa0b36
+    %HName=();
aa0b36
+    read_cib($sid);
aa0b36
+    get_hana_attributes($sid);
aa0b36
+    if ( keys(%Host) == 0 ) {
aa0b36
+        printf "No attributes found for SID=%s\n", $sid;
aa0b36
+    } else {
aa0b36
+        print_host_attr(\%Host,   \%HName, "Hosts",  $sortBy);
aa0b36
+    }
aa0b36
+}