-
Notifications
You must be signed in to change notification settings - Fork 21
/
SAPHanaTopology
executable file
·1124 lines (1054 loc) · 39.1 KB
/
SAPHanaTopology
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# SAPHanaTopology
#
# Description: Clone resource to analyze SAPHana-Topology
#
###################################################################################################################
#
# Thanks to Alexander Krauth for providing SAPInstance and SAPDatabase
#
# SAPHanaTopology: (short sht)
# Author: Fabian Herschel, February 2014
# Support: linux@sap.com
# License: GNU General Public License (GPL)
# Copyright: (c) 2014 SUSE Linux Products GmbH
# (c) 2015-2018 SUSE Linux GmbH
# (c) 2019 SUSE LLC
#
# An example usage:
# See usage() function below for more details...
#
# OCF instance parameters:
# OCF_RESKEY_SID (LNX, NDB, SLE)
# OCF_RESKEY_InstanceNumber (00..99)
# OCF_RESKEY_DIR_EXECUTABLE (optional, well known directories will be searched by default)
# OCF_RESKEY_SAPHanaFilter (outdated, replaced by cluster property hana_${sid}_glob_filter)
#
#######################################################################
# DONE PRIO 1: AFTER(!) SAP HANA SPS12 is available we could use hdbnsutil --sr_stateConfiguration
SAPHanaTopologyVersion="0.154.0"
#
# Initialization:
timeB=$(date '+%s')
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
#######################################################################
log_attributes=false
if ocf_is_true "$log_attributes"; then
log_attr_file="/var/log/fhATTRIBUTES"
else
log_attr_file="/dev/null"
fi
HANA_STATE_PRIMARY=0
HANA_STATE_SECONDARY=1
HANA_STATE_STANDALONE=2
HANA_STATE_DEFECT=3
HANA_CALL_TIMEOUT=60
debug_attributes=0
SH=/bin/sh
#
# function: super_ocf_log - wrapper function for ocf log in order catch usual logging into super log
# params: LOG_MESSAGE
# globals: SUPER_LOG_PATH, SAPHanaFilter
function super_ocf_log() {
local level="$1"
local message="$2"
local skip=1
local mtype=""
local search=0
local shf="${SAPHanaFilter:-all}"
#ocf_log "info" "super_ocf_log: f:$shf l:$level m:$message"
# message levels: (dbg)|info|warn|err|error
#
# message types: (ACT|RA|FLOW|DBG|LPA|DEC
case "$level" in
dbg | debug | warn | err | error ) skip=0
;;
info )
case "$shf" in
all) skip=0
;;
none )
skip=1
;;
* ) mtype=${message%% *}
mtype=${mtype%:}
mtype=${mtype#fh}
echo "$shf"| grep -iq ${mtype}; search=$?
if [ $search -eq 0 ]; then
skip=0
else
skip=1
fi
;;
esac
;;
esac
if [ $skip -eq 0 ]; then
ocf_log "$level" "$message"
fi
}
#
# function: sht_usage - short usage info
# params: -
# globals: $0(r)
#
function sht_usage() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
methods=$(sht_methods)
methods=$(echo $methods | tr ' ' '|')
cat <<-!
usage: $0 ($methods)
$0 manages a SAP HANA Instance as an HA resource.
The 'start' operation starts the HANA instance or bring the "instance" to a WAITING (for primary) status
The 'stop' operation stops the HANA instance
The 'status' operation reports whether the HANA instance is running
The 'monitor' operation reports whether the HANA instance seems to be working in master/slave it also needs to check the system replication status
The 'notify' operation always returns SUCCESS
The 'validate-all' operation reports whether the parameters are valid
The 'methods' operation reports on the methods $0 supports
The 'reload' operation allows to change parameters like HANA_CALL_TIMEOUT without forcing a recover of all instances
!
return $rc
}
#
# function: sht_meta_data - print resource agent meta-data for cluster
# params: -
# globals: -
#
function sht_meta_data() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="SAPHanaTopology">
<version>$SAPHanaTopologyVersion</version>
<shortdesc lang="en">Analyzes SAP HANA System Replication Topology.</shortdesc>
<longdesc lang="en">This RA analyzes the SAP HANA topology and "sends" all findings via the node status attributes to
all nodes in the cluster. These attributes are taken by the SAPHana RA to control the SAP Hana Databases.
In addition it starts and monitors the local saphostagent.
1. Interface to monitor a HANA system: landscapeHostConfiguration.py
landscapeHostConfiguration.py has some detailed output about HANA system status
and node roles. For our monitor the overall status is relevant. This overall
status is reported by the returncode of the script:
0: Internal Fatal
1: ERROR
2: WARNING
3: INFO (maybe a switch of the resource running)
4: OK
The SAPHanaTopology resource agent will interpret returncodes 1 as NOT-RUNNING (or 1 failure) and returncodes 2+3+4 as RUNNING.
SAPHanaTopology scans the output table of landscapeHostConfiguration.py to identify the roles of the cluster node. Roles means configured and current role of the nameserver as well as the indexserver.
2. Interface is hdbnsutil
The interface hdbnsutil is used to check the "topology" of the system replication as well as the current configuration
(primary/secondary) of a SAP HANA database instance. A second task of the interface is the posibility to run a
system replication takeover (sr_takeover) or to register a former primary to a newer one (sr_register).
3. saphostctrl
The interface saphostctrl uses the function ListInstances to figure out the virtual host name of the
SAP HANA instance. This is the hostname used during the HANA installation.
</longdesc>
<parameters>
<parameter name="SID" unique="0" required="1">
<longdesc lang="en">The SAP System Identifier (SID)</longdesc>
<shortdesc lang="en">The SAP System Identifier (SID)</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="InstanceNumber" unique="0" required="1">
<longdesc lang="en">The SAP Instance Number</longdesc>
<shortdesc lang="en">The SAP Instance Number</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="HANA_CALL_TIMEOUT" unique="0" required="0">
<shortdesc lang="en">Define timeout how long a call to HANA to receive information can take.</shortdesc>
<longdesc lang="en">Define timeout how long a call to HANA to receive information can take. This could be eg landscapeHostConfiguration.py.
There are some specific calls to HANA which have their own timeout values. For example the takeover command does not timeout (inf).
If the timeout is reached, the return code will be 124. If you increase the timeouts for HANA calls you should also adjust the operation timeouts
of your cluster resources.
</longdesc>
<content type="string" default="60" />
</parameter>
<parameter name="DIR_EXECUTABLE" unique="0" required="0">
<longdesc lang="en">Path to the SAP Hana Instance executable directory. If not set the RA tries /usr/sap/\$SID/\$InstanceName/exe.
While InstanceName is the string of "HDB" and \$InstanceNumber for SAP Hana databases.
</longdesc>
<shortdesc lang="en">Path to the SAP Hana Instance executable directory.</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="SAPHanaFilter" unique="0" required="0">
<shortdesc lang="en">OUTDATED</shortdesc>
<longdesc lang="en">OUTDATED</longdesc>
<content type="string" default="" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="600" />
<action name="stop" timeout="300" />
<action name="status" timeout="60" />
<action name="monitor" depth="0" timeout="60" interval="600" />
<action name="validate-all" timeout="5" />
<action name="meta-data" timeout="5" />
<action name="methods" timeout="5" />
<action name="reload" timeout="5" />
</actions>
</resource-agent>
END
return $rc
}
#
# function: get_hana_attribute
# params: NODE ATTR [STORE]
# globals: -
#
function get_hana_attribute()
{
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
local attr_node=$1
local attr_name=$2
local attr_store=${3:-reboot} # DONE: PRIO5 get this (optional) from parameter
local attr_default=${4:-}
local dstr
dstr=$(date)
case "$attr_store" in
reboot | forever )
echo "$dstr: SAPHanaTopology: crm_attribute -N ${attr_node} -G -n \"$attr_name\" -l $attr_store -q" >> $log_attr_file
crm_attribute -N ${attr_node} -G -n "$attr_name" -l $attr_store -q -d "$attr_default" 2>>$log_attr_file; rc=$?
;;
props )
echo "$dstr: SAPHanaTopology: crm_attribute -G -n \"$attr_name\" -t crm_config -q" >> $log_attr_file
crm_attribute -G -n "$attr_name" -t crm_config -q -d "$attr_default" 2>>$log_attr_file; rc=$?
;;
esac
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: set_hana_attribute - set the multi-state status of a node
# params: NODE VALUE ATTR [STORE]
# globals: -
#
function set_hana_attribute()
{
super_ocf_log info "FLOW $FUNCNAME ($*)"
local attr_node=$1
local attr_value=$2
local attr_name=$3
local attr_store=${4:-reboot} # DONE: PRIO5 get this (optional) from parameter
local attr_default=${5:-}
local rc=1
local attr_old=""
local dstr
dstr=$(date)
attr_old=$(get_hana_attribute $attr_node $attr_name $attr_store $attr_default); get_rc=$?
if [ "$attr_old" != "$attr_value" ]; then
super_ocf_log debug "DBG: SET attribute $attr_name for node ${attr_node} to ${attr_value} former ($attr_old) get_rc=$get_rc "
case "$attr_store" in
reboot | forever )
echo "$dstr: SAPHanaTopology: crm_attribute -N $attr_node -v $attr_value -n \"$attr_name\" -l $attr_store" >> $log_attr_file
crm_attribute -N $attr_node -v $attr_value -n "$attr_name" -l $attr_store 2>>$log_attr_file; rc=$?
;;
props )
echo "$dstr: SAPHanaTopology: crm_attribute -v $attr_value -n \"$attr_name\" -t crm_config -s SAPHanaSR" >> $log_attr_file
crm_attribute -v $attr_value -n "$attr_name" -t crm_config -s SAPHanaSR 2>>$log_attr_file; rc=$?
;;
esac
else
super_ocf_log debug "DBG: LET attribute $attr_name for node ${attr_node} still be ${attr_value}"
rc=0
fi
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: sht_methods - report supported cluster methods
# params: -
# globals: -
# methods: What methods/operations do we support?
#
function sht_methods() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
cat <<-!
start
stop
status
monitor
notify
validate-all
methods
meta-data
usage
admin-setup
reload
!
return $rc
}
#
# function: dequote - filter: remove quotes (") from stdin
# params: -
# globals: -
function dequote()
{
local rc=0; tr -d '"'; return $rc
}
# function: version: cpmpare two HANA version strings
function ver_lt() {
ocf_version_cmp $1 $2
test $? -eq 0 && return 0 || return 1
}
function ver_le() {
ocf_version_cmp $1 $2
test $? -eq 0 -o $? -eq 1 && return 0 || return 1
}
function ver_gt() {
ocf_version_cmp $1 $2
test $? -eq 2 && return 0 || return 1
}
function ver_ge() {
ocf_version_cmp $1 $2
test $? -eq 2 -o $? -eq 1 && return 0 || return 1
}
#
# function: version: cpmpare two HANA version strings
#
function version() {
if [ $# -eq 3 ]; then
case "$2" in
LE | le | "<=" ) ver_le $1 $3;;
LT | lt | "<" ) ver_lt $1 $3;;
GE | ge | ">=" ) ver_ge $1 $3;;
GT | gt | ">" ) ver_gt $1 $3;;
* ) return 1;
esac
elif [ $# -ge 5 ]; then
version $1 $2 $3 && shift 2 && version $*
else
return 1;
fi
}
#
# function: is_clone - report, if resource is configured as a clone (also master/slave)
# params: -
# globals: OCF_*(r)
# descript: is_clone : find out if we are configured to run in a Master/Slave configuration
# rc: 0: it is a clone
# 1: it is not a clone
# Special EXIT of RA, if clone is missconfigured
#
function is_clone() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
#
# is a clone config?
#
if [ -n "$OCF_RESKEY_CRM_meta_clone_max" ] \
&& [ "$OCF_RESKEY_CRM_meta_clone_max" -gt 0 ]; then
#
# yes it is a clone config - check, if its configured well
#
if [ "$OCF_RESKEY_CRM_meta_clone_node_max" -ne 1 ] ; then
super_ocf_log err "ACT: Clone options misconfigured. (expect: clone_node_max=1)"
exit $OCF_ERR_CONFIGURED
fi
rc=0;
else
rc=1;
fi
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: HANA_CALL
# params: timeout-in-seconds cmd-line
# globals: sid(r), SID(r), InstanceName(r)
#
function HANA_CALL()
{
#
# TODO: PRIO 5: remove 'su - ${sidadm} later, when SAP HANA resoled issue with
# root-user-called hdbnsutil -sr_state (which creates root-owned shared memory file in /var/lib/hdb/SID/shmgrp)
# would hdbnsutil -sr_stateConfiguration also create such a shared memory file?
# TODO: PRIO 5: Maybe make "su" optional by a parameter
local timeOut=0
local onTimeOut=""
local rc=0
local use_su=1 # Default to be changed later (see TODO above)
local pre_cmd=""
local cmd=""
local pre_script=""
local output=""
while [ $# -gt 0 ]; do
case "$1" in
--timeout ) timeOut=$2; shift;;
--use-su ) use_su=1;;
--on-timeout ) onTimeOut="$2"; shift;;
--cmd ) shift; cmd="$*"; break;;
esac
shift
done
if [ $use_su -eq 1 ]; then
pre_cmd="su - ${sid}adm -c"
pre_script="true"
else
# as root user we need the library path to the SAP kernel to be able to call sapcontrol
# check, if we already added DIR_EXECUTABLE at the beginning of LD_LIBRARY_PATH
if [ "${LD_LIBRARY_PATH%%*:}" != "$DIR_EXECUTABLE" ]
then
MY_LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
fi
pre_cmd="bash -c"
pre_script="LD_LIBRARY_PATH=$MY_LD_LIBRARY_PATH; export LD_LIBRARY_PATH"
fi
case $timeOut in
0 | inf )
output=$($pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $cmd"); rc=$?
;;
* )
output=$(timeout $timeOut $pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $cmd"); rc=$?
#
# on timeout ...
#
if [ $rc -eq 124 ]; then
super_ocf_log warn "HANA_CALL timed out after $timeOut seconds running command '$cmd'"
fi
if [ $rc -eq 124 -a -n "$onTimeOut" ]; then
local second_output=""
second_output=$($pre_cmd "$pre_script; /usr/sap/$SID/$InstanceName/HDBSettings.sh $onTimeOut");
fi
;;
esac
super_ocf_log debug "DBG: HANA_CALL '$cmd' rc=$rc output=$output"
echo "$output"
return $rc;
}
#
# function: sht_init - initialize variables for the resource agent
# params: -
# globals: OCF_*(r), SID(w), sid(rw), sidadm(w), InstanceName(w), InstanceNr(w),
# globals: meta_notify_master_uname(w), HANA_SR_TOLOPOGY(w), sr_name(w)
# globals: ATTR_NAME_HANA_SYNC_STATUS(w), ATTR_NAME_HANA_PRIMARY_AT(w), ATTR_NAME_HANA_CLONE_STATE(w)
# globals: DIR_EXECUTABLE(w), SAPSTARTSRV(w), SAPCONTROL(w), DIR_PROFILE(w), SAPSTARTPROFILE(w), LD_LIBRARY_PATH(w), PATH(w), nodelist(w)
# globals: NODENAME(w), hdbver(w)
# sht_init : Define global variables with default values, if optional parameters are not set
#
#
function sht_init() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local myInstanceName=""
local rc=$OCF_SUCCESS
local hdbANSWER=""
local siteID
local siteNAME
local chkMethod=""
HOSTEXECNAME=saphostexec
USRSAP=/usr/sap
SAPSERVICE_PATH=${USRSAP}/sapservices
SAPHOSTCTRL_PATH=${USRSAP}/hostctrl/exe
HOSTEXEC_PATH=${SAPHOSTCTRL_PATH}/${HOSTEXECNAME}
HOSTEXEC_PROFILE_PATH=${SAPHOSTCTRL_PATH}/host_profile
NODENAME=$(crm_node -n)
SID=$OCF_RESKEY_SID
InstanceNr=$OCF_RESKEY_InstanceNumber
myInstanceName="${SID}_HDB${InstanceNr}"
InstanceName="HDB${InstanceNr}"
super_ocf_log debug "DBG2: Used new method to get SID ($SID) and InstanceNr ($InstanceNr)"
sid=$(echo "$SID" | tr [:upper:] [:lower:])
sidadm="${sid}adm"
ocf_env=$(env | grep 'OCF_RESKEY_CRM')
super_ocf_log debug "DBG3: OCF: $ocf_env"
ATTR_NAME_HANA_SYNC_STATUS=("hana_${sid}_sync_state" "reboot") # SOK, SFAIL, UNKNOWN?
ATTR_NAME_HANA_PRIMARY_AT=("hana_${sid}_primary_at" "reboot") # Not really used
ATTR_NAME_HANA_CLONE_STATE=("hana_${sid}_clone_state" "reboot") # UKNOWN?, DEMOTED, PROMOTED
ATTR_NAME_HANA_REMOTEHOST=("hana_${sid}_remoteHost" "forever")
ATTR_NAME_HANA_SITE=("hana_${sid}_site" "forever")
ATTR_NAME_HANA_ROLES=("hana_${sid}_roles" "reboot")
ATTR_NAME_HANA_SRMODE=("hana_${sid}_srmode" "forever")
ATTR_NAME_HANA_VHOST=("hana_${sid}_vhost" "forever")
ATTR_NAME_HANA_STATUS=("hana_${sid}_status" "reboot")
ATTR_NAME_HANA_VERSION=("hana_${sid}_version" "reboot")
#
# new "central" attributes
#
ATTR_NAME_HANA_FILTER=("hana_${sid}_glob_filter" "props" "ra-act-dec-lpa")
#
# SITE based attributes
#
ATTR_NAME_HANA_SEC_SYNC_SRHOOK=("hana_${sid}_site_sec_sync_state" "props") # SOK, SFAIL
# optional OCF parameters, we try to guess which directories are correct
SAPHanaFilter=$(get_hana_attribute "X" "${ATTR_NAME_HANA_FILTER[@]}")
if [ -z "$OCF_RESKEY_DIR_EXECUTABLE" ]
then
DIR_EXECUTABLE="/usr/sap/$SID/$InstanceName/exe"
else
DIR_EXECUTABLE="$OCF_RESKEY_DIR_EXECUTABLE"
fi
if [ -z "$DIR_EXECUTABLE" ]; then
super_ocf_log err "DEC: Can not determine DIR_EXECUTABLE. Please set this parameter. -> OCF_ERR_CONFIGURED"
rc=$OCF_ERR_CONFIGURED
fi
if [ -z "$OCF_RESKEY_DIR_PROFILE" ]
then
DIR_PROFILE="/usr/sap/$SID/SYS/profile"
else
DIR_PROFILE="$OCF_RESKEY_DIR_PROFILE"
fi
#PATH=${PATH}:${DIR_EXECUTABLE}
#
# figure-out all needed values from system replication status with ONE call
# we need: mode=primary|sync|syncmem|...; site name=<site>; mapping/<me>=<site>/<node> (multiple lines)
case $(crm_attribute --type crm_config --name cluster-infrastructure -q) in
*corosync* ) nodelist=$(crm_node -l | awk '{ print $2 }');;
*openais* ) nodelist=$(crm_node -l | awk '/member/ {print $2}');;
*cman* ) nodelist=$(crm_node -l);;
esac
#
# get HANA version
#
local ges_ver
ges_ver=$(HANA_CALL --timeout 10 --cmd "HDB version" | tr -d " " | awk -F: '$1 == "version" {print $2}')
hdbver=${ges_ver%.*.*}
#
# since rev 111.00 we should use a new hdbnsutil option to get the -sr_state
# since rev 112.03 the old option is changed and we should use -sr_stateConfiguration where ever possible
#
hdbState="hdbnsutil -sr_state"
hdbMap="hdbnsutil -sr_state"
if version "$hdbver" ">=" "1.00.111"; then
hdbState="hdbnsutil -sr_stateConfiguration"
hdbMap="hdbnsutil -sr_stateHostMapping"
fi
#### SAP-CALL
# hdbnsutil was a bit unstable in some tests so we recall the tool, if it fails to report the srmode
for chkMethod in hU hU hU gP ; do
# DONE: Limit the runtime of hdbnsutil.
# DONE: Use getParameter.py if we get no answer
# SAP_CALL
#super_ocf_log debug "DBG2: hdbANSWER=$hdbANSWER"
#srmode=$(echo "$hdbANSWER" | awk -F= '/mode/ {print $2}')
case "$chkMethod" in
gP ) # call getParameter (gP)
local gpKeys=""
gpKeys=$(echo --key=global.ini/system_replication/{mode,site_name,site_id})
hdbANSWER=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --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} }')
srmode=$(echo "$hdbANSWER" | awk -F= '$1=="mode" {print $2}')
super_ocf_log info "ACT: hdbnsutil not answering - using global.ini as fallback - srmode=$srmode"
;;
hU | * ) # call hdbnsUtil (hU) ( also for unknown chkMethod )
# DONE: PRIO1: Begginning from SAP HANA rev 112.03 -sr_state is not longer supported
hdbANSWER=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "$hdbState --sapcontrol=1" 2>/dev/null)
srmode=$(echo "$hdbANSWER" | awk -F= '$1=="mode" {print $2}')
;;
esac
case "$srmode" in
primary | syncmem | sync | async | none )
# we can leave the loop as we already got a result
break
;;
* )
# lets pause a bit to give hdbnsutil a chance to answer next time
sleep 2
;;
esac
done
# TODO PRIO3: Implement a file lookup, if we did not get a result
siteID=$(echo "$hdbANSWER" | awk -F= '/site.id/ {print $2}') # allow 'site_id' AND 'site id'
siteNAME=$(echo "$hdbANSWER" | awk -F= '/site.name/ {print $2}')
site=$siteNAME
srmode=$(echo "$hdbANSWER" | awk -F= '$1=="mode" {print $2}')
#
# for rev >= 111 we use the new mapping query
#
if version "$hdbver" ">=" "1.00.111"; then
hdbANSWER=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "$hdbMap --sapcontrol=1" 2>/dev/null)
fi
MAPPING=$(echo "$hdbANSWER" | awk -F[=/] '$1 == "mapping" && $3 != site { print $4 }' site=$site)
super_ocf_log debug "DBG: site=$site, mode=$srmode, MAPPING=$MAPPING"
if [ -n "$MAPPING" ]; then
# we have a mapping from HANA, lets use it
#
# filter all non-cluster mappings
#
local hanaVHost=""
local n1=""
hanaRemoteHost=""
for n1 in $nodelist; do
hanaVHost=$(get_hana_attribute ${n1} ${ATTR_NAME_HANA_VHOST[@]})
for n2 in $MAPPING; do
if [ "$hanaVHost" == "$n2" ]; then
hanaRemoteHost="$hanaVHost"
fi;
done;
done
super_ocf_log info "DEC: site=$site, mode=$srmode, MAPPING=$MAPPING, hanaRemoteHost=$hanaRemoteHost"
super_ocf_log debug "DBG: site=$site, mode=$srmode, MAPPING=$MAPPING, hanaRemoteHost=$hanaRemoteHost"
else
# HANA DID NOT TOLD THE MAPPING, LETS TRY TO USE THE SITE ATTRIBUTES
local n1=""
local hanaSite=""
for n1 in $nodelist; do
# TODO: PRIO9 - For multi tier with more than 2 chain/star members IN the cluster we might need to be
# able to catch more than one remoteHost
# currently having more than 2 HANA in a chain/star members IN the cluster is not allowed, the third must be external
if [ "$NODENAME" != "$n1" ]; then
hanaSite=$(get_hana_attribute ${n1} ${ATTR_NAME_HANA_SITE[@]})
#
# only, if a hanaSite is found use that node - this allows majority makers
#
if [ -n "$hanaSite" ]; then
hanaRemoteHost=$(get_hana_attribute ${n1} ${ATTR_NAME_HANA_VHOST[@]})
#
# only if vhost is NOT set use the nodename instead
#
if [ -z "$hanaRemoteHost" ]; then
hanaRemoteHost="$n1"
fi
fi
fi
done
super_ocf_log info "DEC: site=$site, mode=$srmode, hanaRemoteHost=$hanaRemoteHost - found by remote site ($hanaSite)"
fi
super_ocf_log info "FLOW $FUNCNAME rc=$OCF_SUCCESS"
return $OCF_SUCCESS
}
#
# function: check_for_primary - check if local SAP HANA is configured as primary
# params: -
# globals: srmode(r), HANA_STATE_PRIMARY(r), HANA_STATE_SECONDARY(r), HANA_STATE_DEFECT(r), HANA_STATE_STANDALONE(r)
#
function check_for_primary() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
super_ocf_log debug "DBG: check_for_primary: srmode=$srmode"
case "$srmode" in
primary )
super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_PRIMARY"
rc=$HANA_STATE_PRIMARY;;
syncmem | sync | async )
super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_SECONDARY"
rc=$HANA_STATE_SECONDARY;;
none ) # have seen that mode on second side BEFEORE we registered it as replica
super_ocf_log info "FLOW $FUNCNAME rc=HANA_STATE_STANDALONE"
rc=$HANA_STATE_STANDALONE;;
* )
dump=$( echo $srmode | hexdump -C );
super_ocf_log err "ACT: check_for_primary: we didn't expect srmode to be: DUMP: <$dump>"
rc=$HANA_STATE_DEFECT
esac;
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: start_saphostagent
# params: -
# globals: HOSTEXEC_PATH(r), HOSTEXEC_PROFILE_PATH(r)
#
function start_saphostagent()
{
### SAP-CALL
if [ -x "${HOSTEXEC_PATH}" ]; then
${HOSTEXEC_PATH} pf=${HOSTEXEC_PROFILE_PATH}
fi
return 0
}
#
# function: stop_saphostagent
# params: -
# globals: HOSTEXEC_PATH(r)
#
function stop_saphostagent()
{
### SAP-CALL
if [ -x "${HOSTEXEC_PATH}" ]; then
${HOSTEXEC_PATH} -stop
fi
}
#
# function: check_saphostagent
# params: -
# globals:
#
function check_saphostagent()
{
local rc=1
# TODO: PRIO3: should the path been removed like "saphostexec" instead of "/usr/sap/hostctrl/exe/saphostexec"
# or should we use ${HOSTEXEC_PATH} instead?
pgrep -f /usr/sap/hostctrl/exe/saphostexec; rc=$?
return $rc
}
#
#############################################################################
#
# function: sht_start - start a hana instance
# params: -
# globals: OCF_*
# sht_start : Start the SAP HANA instance
#
function sht_start() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=$OCF_NOT_RUNNING
local output=""
local loopcount=0
# TODO: PRIO3: move the string "$HA_RSCTMP/SAPHana/SAPTopologyON" to a variable
# TODO: PRIO3: move the file to the clusters tmp directory?
mkdir -p $HA_RSCTMP/SAPHana
if [ -f $HA_RSCTMP/SAPHana/SAPTopologyON ]; then
rm $HA_RSCTMP/SAPHana/SAPTopologyON
fi
touch $HA_RSCTMP/SAPHana/SAPTopologyON.${SID}
if ! check_saphostagent; then
start_saphostagent
fi
rc=$OCF_SUCCESS
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: sht_stop - stop a hana instance
# params: -
# globals: OCF_*(r), SAPCONTROL(r), SID(r), InstanceName(r)
# sht_stop: Stop the SAP HANA Topology Resource
#
function sht_stop() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local output=""
local rc=0
if [ -f $HA_RSCTMP/SAPHana/SAPTopologyON ]; then
rm $HA_RSCTMP/SAPHana/SAPTopologyON
fi
rm $HA_RSCTMP/SAPHana/SAPTopologyON.${SID}
rc=$OCF_SUCCESS
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: sht_monitor - monitor a hana topology instance
# params: --
# globals: OCF_*(r), SAPCONTROL(r), InstanveNr(r)
# sht_monitor: Can the given SAP instance do anything useful?
#
function sht_monitor() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
# check for old status file
if [ -f $HA_RSCTMP/SAPHana/SAPTopologyON ]; then
rm $HA_RSCTMP/SAPHana/SAPTopologyON
touch $HA_RSCTMP/SAPHana/SAPTopologyON.${SID}
fi
if [ -f $HA_RSCTMP/SAPHana/SAPTopologyON.${SID} ]; then
rc=$OCF_SUCCESS
else
rc=$OCF_NOT_RUNNING
fi
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: sht_status - get status of a hana instance (os tools only)
# params: -
# globals: SID(r), InstanceName(r), OCF_*(r), sidarm(r)
# sht_status: Lightweight check of SAP instance only with OS tools
#
function sht_status() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
sht_monitor; rc=$?
return $rc
}
#
# function: sht_validate - validation of (some) variables/parameters
# params: -
# globals: OCF_*(r), SID(r), InstanceName(r), InstanceNr(r),
# sht_validate: Check the symantic of the input parameters
#
function sht_validate() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=$OCF_SUCCESS
if [ $(echo "$SID" | grep -c '^[A-Z][A-Z0-9][A-Z0-9]$') -ne 1 ]
then
super_ocf_log err "ACT: Parsing instance profile name: '$SID' is not a valid SID!"
rc=$OCF_ERR_ARGS
fi
if [ $(echo "$InstanceNr" | grep -c '^[0-9][0-9]$') -ne 1 ]
then
super_ocf_log err "ACT: Parsing instance profile name: '$InstanceNr' is not a valid instance number!"
rc=$OCF_ERR_ARGS
fi
super_ocf_log info "FLOW $FUNCNAME rc=$rc"
return $rc
}
#
# function: sht_start_clone - start a hana clone instance
# params: -
# globals: OCF_*(r),
# sht_start_clone
#
function sht_start_clone() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=$OCF_NOT_RUNNING
sht_start; rc=$?
return $rc
}
#
# function: sht_stop_clone - stop a hana clone instance
# params: -
# globals: NODENAME(r), HANA_STATE_*, ATTR_NAME_*
# sht_stop_clone
#
function sht_stop_clone() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
local rc=0
check_for_primary; primary_status=$?
if [ $primary_status -eq $HANA_STATE_PRIMARY ]; then
hanaPrim="P"
elif [ $primary_status -eq $HANA_STATE_SECONDARY ]; then
hanaPrim="S"
elif [ $primary_status -eq $HANA_STATE_STANDALONE ]; then
hanaPrim="N"
else
hanaPrim="-"
fi
set_hana_attribute "${NODENAME}" "1:$hanaPrim:-:-:-:-" ${ATTR_NAME_HANA_ROLES[@]}
sht_stop; rc=$?
return $rc
}
#
# function: sht_monitor_clone - monitor a hana clone instance
# params: -
# globals: OCF_*, SID, InstanceNr, InstanceName, MAPPING(r)
# sht_monitor_clone
#
function sht_monitor_clone() {
super_ocf_log info "FLOW $FUNCNAME ($*)"
#
local rc=$OCF_ERR_GENERIC
local promoted=0
local init_attribute=0
if ocf_is_probe; then
super_ocf_log debug "DBG: PROBE ONLY"
sht_monitor; rc=$?
local hana_version=$(HANA_CALL --timeout 10 --cmd "HDB version" \
| awk -F':' '$1==" version" {print $2}; ' | tr -d '[:space:]')
if [[ -n $hana_version ]]; then
set_hana_attribute "${NODENAME}" "$hana_version" ${ATTR_NAME_HANA_VERSION[@]}
fi
else
super_ocf_log debug "DBG: REGULAR MONITOR"
if ! check_saphostagent; then
start_saphostagent
fi
#
# First check, if we are PRIMARY or SECONDARY
#
super_ocf_log debug "DBG: HANA SID $SID"
super_ocf_log debug "DBG: HANA InstanceName $InstanceName"
super_ocf_log debug "DBG: HANA InstanceNr $InstanceNr"
check_for_primary; primary_status=$?
if [ $primary_status -eq $HANA_STATE_PRIMARY ]; then
hanaPrim="P"
super_ocf_log debug "DBG: HANA IS PRIMARY"
sht_monitor; rc=$?
else
if [ $primary_status -eq $HANA_STATE_SECONDARY ]; then
hanaPrim="S"
super_ocf_log debug "DBG: HANA IS SECONDARY"
sht_monitor; rc=$?
elif [ $primary_status -eq $HANA_STATE_STANDALONE ]; then
hanaPrim="N"
super_ocf_log debug "DBG: HANA IS STANDALONE"
sht_monitor; rc=$?
else
# bsc#1027098 Do not mark HANA instance as failed, if "only" the HANA state could not be detected
hanaPrim=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_ROLES[@]} | awk -F: '{ print $2}')
if [ "$hanaPrim" = "" ]; then
hanaPrim="-"
fi
super_ocf_log warn "ACT: sht_monitor_clone: HANA_STATE_DEFECT (primary/secondary state could not be detected at this point of time)"
sht_monitor; rc=$?
fi
fi
# DONE: PRIO1: ASK: Is the output format of ListInstances fix? Could we take that as an API?
# try to catch: Inst Info : LNX - 42 - lv9041 - 740, patch 36, changelist 1444691
# We rely on the following format: SID is word#4, SYSNR is word#6, vHost is word#8
#### SAP-CALL
vName=$(/usr/sap/hostctrl/exe/saphostctrl -function ListInstances \
| awk '$4 == SID && $6 == SYSNR { print $8 }' SID=$SID SYSNR=$InstanceNr 2>/dev/null )
# super_ocf_log debug "DBG: ListInstances: $(/usr/sap/hostctrl/exe/saphostctrl -function ListInstances)"
if [ -n "$vName" ]; then
set_hana_attribute ${NODENAME} "$vName" ${ATTR_NAME_HANA_VHOST[@]}
else
vName=$(get_hana_attribute ${NODENAME} ${ATTR_NAME_HANA_VHOST[@]})
fi
#site=$(get_site_name)
#### SAP-CALL
# SAP_CALL
#hanaANSWER=$(su - $sidadm -c "python exe/python_support/landscapeHostConfiguration.py" 2>/dev/null); hanalrc="$?"
#
# since rev 09x SAP has added the --sapcontrol option for the landscapeHostConfiguration interface
# we begin to use --sapcontrol with rev 100
# since rev 120 we need to use the --sapcontrol, because SAP changed the tool output
#
setRole=true
if version "$hdbver" ">=" "1.00.100"; then
hanaANSWER=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "landscapeHostConfiguration.py --sapcontrol=1" 2>/dev/null); hanalrc="$?"
# retry command, if a timeout occured
if [ "$hanalrc" -ge 124 ]; then
super_ocf_log warn "HANA_CALL timed out after $HANA_CALL_TIMEOUT seconds running command 'landscapeHostConfiguration.py --sapcontrol=1'. Retrying..."
hanaANSWER=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "landscapeHostConfiguration.py --sapcontrol=1" 2>/dev/null); hanalrc="$?"
# if the second try again run into a timeout, log an error and do not set hanarole but keep the previous settings.
if [ "$hanalrc" -ge 124 ]; then
super_ocf_log err "HANA_CALL Operation timeout after $HANA_CALL_TIMEOUT seconds running command 'landscapeHostConfiguration.py --sapcontrol=1'."
setRole=false
fi
fi
# TODO: PRIO9: Do we need to check the lines: 'SAPCONTROL-OK: <begin>' and 'SAPCONTROL-OK: <end>'?
hanarole=$(echo "$hanaANSWER" | tr -d ' ' | \
awk -F= '$1 == "nameServerConfigRole" {f1=$2}
$1 == "nameServerActualRole" {f2=$2}
$1 == "indexServerConfigRole" {f3=$2}
$1 == "indexServerActualRole" {f4=$2}
END { printf "%s:%s:%s:%s\n", f1, f2, f3,f4 }')
else
#
# old code for backward compatability
#
hanaANSWER=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "landscapeHostConfiguration.py" 2>/dev/null); hanalrc="$?"
# retry command, if a timeout occured
if [ "$hanalrc" -ge 124 ]; then
super_ocf_log warn "HANA_CALL timed out after $HANA_CALL_TIMEOUT seconds running command 'landscapeHostConfiguration.py'. Retrying..."
hanaANSWER=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "landscapeHostConfiguration.py" 2>/dev/null); hanalrc="$?"
# if the second try again run into a timeout, log an error and do not set hanarole but keep the previous settings.
if [ "$hanalrc" -ge 124 ]; then
super_ocf_log err "HANA_CALL Operation timeout after $HANA_CALL_TIMEOUT seconds running command 'landscapeHostConfiguration.py'."
setRole=false
fi
fi
hanarole=$(echo "$hanaANSWER" | tr -d ' ' | awk -F'|' '$2 == host { printf "%s:%s:%s:%s\n",$10,$11,$12,$13 } ' host=${vName})
fi
#if [ -z "$MAPPING" ]; then
# super_ocf_log info "ACT: Did not find remote Host at this moment"
#fi
# FH TODO PRIO3: TRY TO GET RID OF "ATTR_NAME_HANA_REMOTEHOST"
if [ -n "$hanaRemoteHost" ]; then
set_hana_attribute ${NODENAME} "$hanaRemoteHost" ${ATTR_NAME_HANA_REMOTEHOST[@]}
fi
if $setRole; then
set_hana_attribute ${NODENAME} "$hanalrc:$hanaPrim:$hanarole" ${ATTR_NAME_HANA_ROLES[@]}
fi
if [ -n "$site" ]; then
set_hana_attribute ${NODENAME} "$site" ${ATTR_NAME_HANA_SITE[@]}
fi
case "$hanaPrim" in