-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrails_lib.sh
1349 lines (1249 loc) · 52.5 KB
/
mrails_lib.sh
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
CONF_FILE="/home/oracle/webhdfs/mrails.conf"
if [ -f "$CONF_FILE" ]
then
. "$CONF_FILE"
else
echo "${CONF_FILE} does not exist or is not a file"
return 1
fi
if [ -f "$WEBHDFS_LIB" ]
then
. "$WEBHDFS_LIB"
else
echo "${v_name} can not library ${WEBHDFS_LIB} error-exiting"
return 1
fi
[ -z "$UPLOADTIME_LIMIT" ] && UPLOADTIME_LIMIT="120"
#================================================================
# Misc
usage() {
printf "%s\n" "
initdb - Create tables in local sqlite-db, for datacollection metadata;
get_attribute - Get attribute value of given datacollection;
upload_to_storage - Upload data from csv-liked file to storage; Set of attributes, which are needed for processing
of a given csv-file named here as a datacollection, or datasource attributes;
Techinaclly thouse ds-attributes is a bundle of rows in sqlite-tables;
See get_attribute, set_attribute: routines for managing attributes;
check_attributes - Auxiliary routine, used in upload_to_storage as a checker of various attributes,
needed for processing of data from csv-liked file;
set_attribute - Set attribute
upload_awrto_storage - Upload awr-data to hdfs;
check_awr_attributes - Used in upload_awrto_storage as a checker of various attributes which're necessery for this process;
upload_atopto_storage - Upload atop-data to hdfs;
check_atop_attributes - Used in upload_atopto_storage as a checker of various attributes which're necessery for this process;
"
}
delete_aux_files() {
#deleting temporary files, see definitions in $CONF_FILE
[ -f "$SPOOL_FILE" ] && rm -f "$SPOOL_FILE"
[ -f "$TEMP_FILE" ] && rm -f "$TEMP_FILE"
[ -f "$HOME/.cookie_$$" ] && rm -f "$HOME/.cookie_$$"
}
#== Metric data level processing ===========================================================================================
get_attribute() {
local v_module="get_attribute"
local v_dcname=""
local v_dcid=""
local v_atname=""
local v_atvalue=""
local rc v_count v_x v_y v_fsize="0"
while [ "$1" != "" ]
do
case "$1" in
"-h"|"--help")
printf "%s\n" "
-h|--help - This help
-d|--dcname - Name of datacollection, which attribute(s) you want to get out; Mandatory;
-a|--atname - Name of attribute of which value you want ot get; Optional;
If not set: all available pairs of attribute's name-value, of given dc, will be showed;"
return 0
;;
"-d"|"--dcname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -d|--dcname option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_dcname="$2"
shift 2
;;
"-a"|"--atname")
v_atname="$2"
shift 2
;;
*)
log_info "${LAYER_NAME}.${v_module} ${1} is not an option; Please use -h|--help to see reference"; return 1
;;
esac
done
if [ -z "$v_dcname" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -d|--dcname option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
rc=$(echo "select count(*) from datasets where dataset_name='${v_dcname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ "$rc" -ne "1" ]
then
log_info "${LAYER_NAME}.${v_module} datacollection ${v_dcname} not registered"
return 1
fi
v_dcid=$(echo "select id from datasets where dataset_name='${v_dcname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ -z "$v_atname" ]
then
"$SQLITE" "$SQLITEDB" << __EOF__ 2>/dev/null | column -s "|" -t
select attr_name, attr_value from datasets_attributes where ds_id=${v_dcid} order by attr_name;
select
.exit
__EOF__
else
rc=$(echo "select count(*) from datasets_attributes where ds_id='${v_dcid}' and attr_name='${v_atname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ "$rc" -eq "1" ]
then
v_atvalue=$(echo "select attr_value from datasets_attributes where ds_id='${v_dcid}' and attr_name='${v_atname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null)
echo -n "$v_atvalue"
return 0
elif [ "$rc" -gt "1" ]
then
log_info "${LAYER_NAME}.${v_module} attr ${v_atname} for dataset ${v_dcname} (id: ${v_dcid}) registered too many times: ${rc})"
return 1
else
log_info "${LAYER_NAME}.${v_module} attr ${v_atname} for dataset ${v_dcname} (id: ${v_dcid}) not found"
return 1
fi
fi
return 0
}
set_attribute() {
local v_module="set_attribute"
local v_dcname=""
local v_atname=""
local v_atvalue=""
local v_dcid v_attrid rc
while [ "$1" != "" ]
do
case "$1" in
"-h"|"--help")
printf "%s\n" "
-h|--help - This help
-d|--dcname - Name of datacollection, which attribute(s) you want to get out; Mandatory;
-a|--atname - Name of attribute of which value you want ot get; Mandatory;
-v|--value - Value for attribute; Mandatory"
return 0
;;
"-d"|"--dcname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -d|--dcname option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_dcname="$2"
shift 2
;;
"-a"|"--atname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -a|--atname option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_atname="$2"
shift 2
;;
"-v"|"--value")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -v|--value option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_atvalue="$2"
shift 2
;;
*)
log_info "${LAYER_NAME}.${v_module} ${1} is not an option; Please use -h|--help to see reference"; return 1
;;
esac
done
if [ -z "$v_atvalue" -o -z "$v_atname" -o -z "$v_dcname" ]
then
log_info "${LAYER_NAME}.${v_module} You didn't set mandatory arguments for this routine;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_dcid=$(echo "select id from datasets where dataset_name='${v_dcname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ -z "$v_dcid" ]
then
log_info "${LAYER_NAME}.${v_module} there is no data-collection with name '${v_dcname}'"
return 1
else
cat /dev/null > "$SPOOL_FILE"; v_attrid=""
v_attrid=$(echo "select id from datasets_attributes where ds_id=${v_dcid} and attr_name='${v_atname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ -z "$v_attrid" ]
then
#log_info "${LAYER_NAME}.${v_module} insert into datasets_attributes(attr_name, attr_value, ds_id) values('${v_atname}', '${v_atvalue}', ${v_dcid});"
echo "insert into datasets_attributes(attr_name, attr_value, ds_id) values('${v_atname}', '${v_atvalue}', ${v_dcid});" | "$SQLITE" "$SQLITEDB" 1>"$SPOOL_FILE" 2>&1
rc="$?"
else
#log_info "${LAYER_NAME}.${v_module} update datasets_attributes set attr_value='${v_atvalue}' where ds_id=${v_dcid} and id=${v_attrid};"
echo "update datasets_attributes set attr_value='${v_atvalue}' where ds_id=${v_dcid} and id=${v_attrid};" | "$SQLITE" "$SQLITEDB" 1>"$SPOOL_FILE" 2>&1
rc="$?"
fi
if [ "$rc" -eq "0" ]
then
log_info "${LAYER_NAME}.${v_module} ok: ${v_atname}=${v_atvalue} setted for ${v_dcname}"
else
log_info "${LAYER_NAME}.${v_module} can not set ${v_atname}=${v_atvalue} for ${v_dcname}"
log_info "$SPOOL_FILE" "logfile"
fi
return "$rc"
fi
return 0
}
check_awr_attributes() {
local v_module="check_awr_attributes"
local v_dcname=""
local rc v_x v_dcid v_y v_key v_value
while [ "$1" != "" ]
do
case "$1" in
"-h"|"--help")
printf "%s\n" "-h|--help - This help
-d|--dcname - Name of datacollection, which attribute(s) you want to get out; Mandatory;
--------------------------------------------------------------------------------------------
Checks:
1 - Datacollection with name, given through -d|--dcname, is;
2 - Oracle directory: is
3 - Path, which set as oracle-directory's path: is,
it's directory and it's writable
and has enough free-space for awr-dump file;
"
return 0
;;
"-d"|"--dcname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -d|--dcname option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_dcname="$2"
shift 2
;;
*)
log_info "${v_module} ${1} is not an option; use -h|--help;"
return 1
;;
esac
done
if [ -z "$v_dcname" ]
then
log_info "${LAYER_NAME}.${v_module} you have to set value for -d|--dcname option; See -h|--help"; return 1
fi
v_dcid=$(echo "select id from datasets where dataset_name='${v_dcname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ -z "$v_dcid" ]
then
log_info "${LAYER_NAME}.${v_module} there is no data-collection with name '${v_dcname}'"
return 1
fi
get_attribute -d "$v_dcname">"$SPOOL_FILE"
[ "$?" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not obtain set of attributes for data-collection with name: ${v_dcname};";
return 1
}
declare -A v_attrset
while read line
do
v_key=$(echo ${line} | awk '{printf "%s", $1}')
v_value=$(echo ${line} | awk '{printf "%s", $2}')
#printf "%s\t%s\n" "$v_key" "$v_value"
v_attrset["$v_key"]="$v_value"
done<"$SPOOL_FILE"
v_x=${v_attrset["free_space"]}
if [ -z "$v_x" ]
then
log_info "${LAYER_NAME}.${v_module} you should set value for free_space conf-parameter, in bytes"
log_info "${LAYER_NAME}.${v_module} it's requirement for amount of free space for awr-dump file"
return 1
fi
v_x=${v_attrset["oradir"]}
if [ -z "$v_x" ]
then
log_info "${LAYER_NAME}.${v_module} oracle-drectory object name, for dumping awr-data to file, is not definted;"
return 1
fi
$ORACLE_HOME/bin/sqlplus -S / as sysdba << __EOFF__ 1>"$SPOOL_FILE" 2>/dev/null
set head off
set echo off
set newp none
set feedback off
set linesize 1024
whenever sqlerror exit failure
select DIRECTORY_PATH from sys.dba_directories where DIRECTORY_NAME='${v_x}';
exit
__EOFF__
rc="$?"
if [ "$rc" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} can not ask database about fs-path associated with oracle-dir: ${v_x}"
return 1
fi
v_x=$(cat $SPOOL_FILE | tr -d [:cntrl:])
log_info "${LAYER_NAME}.${v_module} fs-path, assigned with ${v_attrset["oradir"]} is: ${v_x}"
if [ ! -d "$v_x" -a -w "$v_x" ]
then
log_info "${LAYER_NAME}.${v_module} ${v_x} is not a directory and|or is not writable;"
return 1
fi
v_y=$(df -P -B 1 "/opt/rias/spool/dba/awr/" | tail -n 1 | awk '{printf "%d", $4;}')
if [ "$v_y" -lt "${v_attrset["free_space"]}" ]
then
log_info "${LAYER_NAME}.${v_module} according to configuration-limit free_space (${v_attrset["free_space"]}): there isn't enought free space, in ${v_x} for making awr-dump file there"
return 1
fi
return 0
#end of check_awr_attributes
}
check_attributes() {
local v_module="check_attributes"
local v_dcname=""
local rc v_x v_dcid v_key v_value
while [ "$1" != "" ]
do
case "$1" in
"-h"|"--help")
printf "%s\n" "
-h|--help - This help
-d|--dcname - Name of datacollection, which attribute(s) you want to get out; Mandatory;
--------------------------------------------------------------------------------------------
Checks:
1 - key-column number: is set and it's digit
2 - hdfs_file_sizelimit: is set and it's digit
3 - column_count: is set and it's a digit;
actual number of column in datafile is equal to column_count value
4 - column_separator: is set
5 - datafile_path: is set and it refers to a readable file"
return 0
;;
"-d"|"--dcname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -d|--dcname option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_dcname="$2"
shift 2
;;
*)
log_info "${v_module} ${1} is not an option; use -h|--help"
return 1
;;
esac
done
if [ -z "$v_dcname" ]
then
log_info "${LAYER_NAME}.${v_module} you have to set value for -d|--dcname option; See -h|--help"; return 1
fi
v_dcid=$(echo "select id from datasets where dataset_name='${v_dcname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ -z "$v_dcid" ]
then
log_info "${LAYER_NAME}.${v_module} there is no data-collection with name '${v_dcname}'"
return 1
fi
get_attribute -d "$v_dcname">"$SPOOL_FILE"
[ "$?" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not obtain set of attributes for data-collection with name: ${v_dcname};";
return 1
}
declare -A v_attrset
while read line
do
v_key=$(echo ${line} | awk '{printf "%s", $1}')
v_value=$(echo ${line} | awk '{printf "%s", $2}')
#printf "%s\t%s\n" "$v_key" "$v_value"
v_attrset["$v_key"]="$v_value"
done<"$SPOOL_FILE"
## get in into separate routine
if [ -z "${v_attrset["hdfs_filesize_limit"]}" ]
then
log_info "${LAYER_NAME}.${v_module} hdfs_file_sizelimit attribute is undefined"
return 1
fi
if [[ ! "${v_attrset["hdfs_filesize_limit"]}" =~ [0-9]+ ]]
then
log_info "${LAYER_NAME}.${v_module} hdfs_file_sizelimit attribute is not a digit"
return 1
fi
##if [ "${v_attrset["hdfs_file_sizelimit"]}" -lt "1048576" -o "${v_attrset["hdfs_file_sizelimit"]}" -gt "10737418240" ]
##then
## log_info "${LAYER_NAME}.${v_module} value of hdfs_file_sizelimit attribute is too smaill, or too big"; return 1
##fi
if [ -z "${v_attrset["datafile_path"]}" ]
then
log_info "${LAYER_NAME}.${v_module} attribute 'datafile_path' is not defined for data-collection ${v_dcname}"
return 1
fi
if [ ! -f "${v_attrset["datafile_path"]}" -a -r "${v_attrset["datafile_path"]}" ]
then
log_info "${LAYER_NAME}.${v_module} local datafile ${v_attrset["datafile_path"]} not exist and|or not readable";
return 1
fi
##column_separator
if [ -z "${v_attrset["column_separator"]}" ]
then
log_info "${LAYER_NAME}.${v_module} column_separator is not set"
return 1
fi
##column count
if [ -z "${v_attrset["column_count"]}" ]
then
log_info "${LAYER_NAME}.${v_module} column count is not set"
return 1
fi
if [[ ! "${v_attrset["column_count"]}" =~ [0-9]+ ]]
then
log_info "${LAYER_NAME}.${v_module} column count should be a digit"
return 1
fi
v_x=$( head -n 10 ${v_attrset["datafile_path"]} | awk -F "${v_attrset["column_separator"]}" '{print NF;}' | sort -u | tr -d [:cntrl:] )
if [[ ! "$v_x" =~ [0-9]+ ]]
then
log_info "${LAYER_NAME}.${v_module} can not find out number of column for ${v_attrset["datafile_path"]} with settet sep-char: ${v_attrset["column_separator"]}"
return 1
fi
if [ "$v_x" -ne ${v_attrset["column_count"]} ]
then
log_info "${LAYER_NAME}.${v_module} actual number of filed is: ${v_x}; It's not equal setted number of filed: ${v_attrset["column_count"]}"
return 1
fi
## key-column is
if [ -z ${v_attrset["key_column_number"]} ]
then
log_info "${LAYER_NAME}.${v_module} key-column for dataset-rows is not set"
return 1
fi
if [[ ! "${v_attrset["key_column_number"]}" =~ [0-9]+ ]]
then
log_info "${LAYER_NAME}.${v_module} value of key_column_number attribute is not a digit"
return 1
fi
return 0
}
upload_awrto_storage() {
local v_module="upload_awrto_storage"
local v_dcname=""
local v_x v_y v_k v_z v_key v_value v_hdfsfileis v_path
local v_minsnapid v_maxsnapid v_last_snapid_inhdfs v_dbid v_hdfsdbid
while [ "$1" != "" ]
do
case "$1" in
"-h"|"--help")
printf "%s\n" "
-h|--help - This help
-d|--dcname - Name of data-collection, by which this program shuld have to obtain various necessary attribytes for data processing"
return 0
;;
"-d"|"--dcname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} you have to set value for -d|--dcname option; See -h|--help"; return 1
fi
v_dcname="$2"
shift 2
;;
*)
log_info "${v_module} ${1} is not an option; Use -h|--help"
return 1
;;
esac
done
if [ -z "$v_dcname" ]
then
log_info "${LAYER_NAME}.${v_module} you have to set value for -d|--dcname option; See -h|--help"; return 1
fi
log_info "${LAYER_NAME}.${v_module} ok, data-collection name is: ${v_dcname}"
check_awr_attributes -d "$v_dcname"
if [ "$?" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} something wrong with work with attributes and|or with attrs itself, of data-collection with name: ${v_dcname};"
return 1
fi
get_attribute -d "$v_dcname">"$SPOOL_FILE"
declare -A v_attrset
while read line
do
v_key=$(echo ${line} | awk '{printf "%s", $1}')
v_value=$(echo ${line} | awk '{printf "%s", $2}')
#printf "%s\t%s\n" "$v_key" "$v_value"
v_attrset["$v_key"]="$v_value"
done<"$SPOOL_FILE"
#check: if hdfs-file exist; If file is then try to get max snap_id from it's xattr; If hdfs-file is but it isn't possible to obtain xattr from it: it's fail
cat /dev/null > "$SPOOL_FILE"
v_hdfsfileis="" #it means: no, hdfs-file - doesn't exist
v_y="${v_attrset["hdfs_flagfile"]}"
itemstatus -n "$v_y" 1>"$SPOOL_FILE" 2>&1
rc="$?"
if [ "$rc" -eq "0" ]
then
#Ok we defenetly get info about hdfs-item from hdfs; Let's see: what it is
v_x=$(cat "$SPOOL_FILE" | egrep "^type:" | awk '{printf "%s", $2;}' | tr [:lower:] [:upper:])
if [ "$v_x" == "FILE" ]
then
log_info "${LAYER_NAME}.${v_module} hdfs-side available and file ${v_y} is there"
v_hdfsfileis="y"
else
#Well, it's not a file; Directory, symlinc, something else but not a file; Well nothing else but erroro-ending
log_info "${LAYER_NAME}.${v_module} hdfs-side is available but ${v_y} is not a file, it's: ${v_x};"
return 1
fi
else
#well may be hdfs is not reachable; Or may be it said something about error; Let us see: what is it
v_x=$(cat "$SPOOL_FILE" | wc -l)
if [ "$v_x" -gt "0" ]
then
#cat "$SPOOL_FILE"
cat "$SPOOL_FILE" | grep -q "FileNotFoundExceptionFile" 1>/dev/null 2>&1
if [ "$?" -eq "0" ]
then
v_hdfsfileis="n" #So it means that hdfs is reachable and it said that asked file: is absent;
else
log_info "${LAYER_NAME}.${v_module} hdfs returned error on itemstatus req for: ${v_y}"
log_info "$SPOOL_FILE" "logfile"
return 1
fi
else
log_info "${LAYER_NAME}.${v_module} hdfs is not reachable right now; error-exiting"; return 1
fi
fi
v_last_snapid_inhdfs=""
v_hdfsdbid=""
if [ "$v_hdfsfileis" == "y" ]
then
v_last_snapid_inhdfs=$(getxattr -n "${v_attrset["hdfs_flagfile"]}" -a "user.max_keyvalue" | egrep "^user.max_keyvalue.*" | awk '{printf "%s", $2;}')
v_last_snapid_inhdfs=${v_last_snapid_inhdfs#\"}; v_last_snapid_inhdfs=${v_last_snapid_inhdfs%\"}
log_info "${LAYER_NAME}.${v_module} last_snapid_inhdfs value obtained as: ${v_last_snapid_inhdfs}"
if [ "$v_last_snapid_inhdfs" == "none" ]
then
log_info "${LAYER_NAME}.${v_module} v_last_snapid_inhdfs is none, ok set it to 0"
v_last_snapid_inhdfs="0"
fi
if [[ ! "$v_last_snapid_inhdfs" =~ [0-9]+ ]]
then
log_info "${LAYER_NAME}.${v_module} and it isn't a digit"
return 1
fi
v_hdfsdbid=$(getxattr -n "${v_attrset["hdfs_flagfile"]}" -a "user.dbid" | egrep "^user.dbid.*" | awk '{printf "%s", $2;}')
v_hdfsdbid=${v_hdfsdbid#\"}; v_hdfsdbid=${v_hdfsdbid%\"}
log_info "${LAYER_NAME}.${v_module} v_hdfsdbid obtained as: ${v_hdfsdbid}"
if [ "$v_hdfsdbid" == "none" ]
then
log_info "${LAYER_NAME}.${v_module} v_hdfsdbid is none, ok set it to 0"
v_hdfsdbid="0"
fi
if [[ ! "$v_hdfsdbid" =~ [0-9]+ ]]
then
log_info "${LAYER_NAME}.${v_module} v_hdfsdbid is not a digit"
return 1
fi
else
log_info "${LAYER_NAME}.${v_module} hdfs flag-file ${v_attrset["hdfs_flagfile"]} doesn't exist, set v_last_snapid_inhdfs to 0"
v_last_snapid_inhdfs="0"
log_info "${LAYER_NAME}.${v_module} set v_hdfsdbid to 0"
v_hdfsdbid="0"
fi
if [ "$v_hdfsfileis" == "y" -a -z "$v_last_snapid_inhdfs" ]
then
log_info "${LAYER_NAME}.${v_module} can not obtain max awr-snap_id from the last awr-dump as hdfs-file"
return 1
fi
v_dbid=""
cat /dev/null > "$SPOOL_FILE"
$ORACLE_HOME/bin/sqlplus -S / as sysdba << __EOF__ 1>"$SPOOL_FILE" 2>&1
set head off
set echo off
set newp none
set feedback off
set linesize 1024
whenever sqlerror exit failure
select dbid from v\$database;
exit
__EOF__
rc="$?"
if [ "$rc" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} can not obtain dbid from database;"
log_info "$SPOOL_FILE" "logfile"
return 1
fi
v_dbid=$(cat $SPOOL_FILE | awk '{printf "%d", $1;}' | tr -d [:cntrl:] | tr -d [:space:])
log_info "${LAYER_NAME}.${v_module} dbid of database is: ${v_dbid}"
# export awr-data to dumpfile; Probably from hdfs-found snap_id; save min|max snap_id of exported awr-data to variable v_minkey v_maxkey
cat /dev/null > "$SPOOL_FILE"
v_x=""
if [ "$v_dbid" -ne "$v_hdfsdbid" ]
then
log_info "${LAYER_NAME}.${v_module} current dbid is not equal dbid obtained from hdfs: dbid to which most resent uploaded to he hdfs awr-data is related;"
v_last_snapid_inhdfs="0"
fi
[ ! -z "$v_last_snapid_inhdfs" ] && v_x="AND s.snap_id>=${v_last_snapid_inhdfs}"
$ORACLE_HOME/bin/sqlplus -S / as sysdba << __EOF__ 1>"$SPOOL_FILE" 2>&1
set head off
set echo off
set newp none
set feedback off
set linesize 1024
whenever sqlerror exit failure
SELECT Min(s.snap_id)||' '||Max(s.snap_id) AS col
FROM sys.dba_hist_snapshot s
WHERE s.dbid=(select d.dbid from sys.v_\$database d) ${v_x}
AND s.begin_interval_time>(SELECT i.startup_time FROM sys.v_\$instance i)
;
exit
__EOF__
rc="$?"
if [ "$rc" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} can not obtain min|max snap_id from datatase to awr-export"
log_info "$SPOOL_FILE" "logfile"
return 1
fi
v_minsnapid=$(cat $SPOOL_FILE | awk '{printf "%d", $1;}' | tr -d [:cntrl:])
v_maxsnapid=$(cat $SPOOL_FILE | awk '{printf "%d", $2;}' | tr -d [:cntrl:])
log_info "${LAYER_NAME}.${v_module} minsnapid: ${v_minsnapid}; maxsnapid: ${v_maxsnapid}"
if [[ ! "$v_minsnapid" =~ [0-9]+ ]] || [[ ! "$v_maxsnapid" =~ [0-9]+ ]]
then
log_info "${LAYER_NAME}.${v_module} minsnapid and|or maxsnapid is not a digit"
return 1
fi
v_x=${v_attrset["oradir"]}
$ORACLE_HOME/bin/sqlplus -S / as sysdba << __EOFF__ 1>"$SPOOL_FILE" 2>/dev/null
set head off
set echo off
set newp none
set feedback off
set linesize 1024
whenever sqlerror exit failure
select DIRECTORY_PATH from sys.dba_directories where DIRECTORY_NAME='${v_x}';
exit
__EOFF__
rc="$?"
if [ "$rc" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} can not ask database about fs-path associated with oracle-dir: ${v_x}"
return 1
fi
v_path=$(cat $SPOOL_FILE | tr -d [:cntrl:])
find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
#v_x=${v_attrset["dump_name"]}"_"${v_minsnapid}"_"${v_maxsnapid}
v_x=${v_dbid}"_"${v_minsnapid}"_"${v_maxsnapid}
v_path=${v_path%\/}"/"${v_x}
v_path=${v_path}".dmp"
log_info "${LAYER_NAME}.${v_module} exporting awr-data to ${v_path}"
$ORACLE_HOME/bin/sqlplus -S "/ as sysdba" << __EOFF__ 1>$SPOOL_FILE 2>&1
set verify off
set newp none
whenever sqlerror exit failure
column v_dbid new_value v_dbid noprint;
select dbid as v_dbid from v\$database;
define dbid = "&&v_dbid"
define num_days = ""
define begin_snap = ${v_minsnapid}
define end_snap = ${v_maxsnapid}
define directory_name = "${v_attrset["oradir"]}"
define file_name = "${v_x}"
define
@$ORACLE_HOME/rdbms/admin/awrextr.sql
exit;
__EOFF__
rc="$?"
if [ "$rc" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} can not export awr-data to file"
return 1
fi
log_info "${LAYER_NAME}.${v_module} export-log: "
log_info "$SPOOL_FILE" "logfile"
if [ -f "$v_path" ]
then
log_info "${LAYER_NAME}.${v_module} gzipping ${v_path}"
gzip -6 "$v_path"
v_path=${v_path}".gz"
else
log_info "${LAYER_NAME}.${v_module} hmmm,.. awr-dump file supposed to be prepared as ${v_path}; but it isn't"
return 1
fi
if [ "$v_hdfsfileis" == "n" ]
then
log_info "${LAYER_NAME}.${v_module} try to create flag-file ${v_attrset["hdfs_flagfile"]}"
cat /dev/null > $SPOOL_FILE
createfile -n "${v_attrset["hdfs_flagfile"]}" -l "$SPOOL_FILE" -m 10 1>/dev/null 2>&1; rc="$?"
if [ "$rc" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} can not create flag file ${v_attrset["hdfs_flagfile"]}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return 1
fi
setxattr -n ${v_attrset["hdfs_flagfile"]} -a "user.min_keyvalue" -v "$v_minsnapid" -f "create"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.min_keyvalue attr for ${v_attrset["hdfs_flagfile"]}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return "$v_z"
}
setxattr -n ${v_attrset["hdfs_flagfile"]} -a "user.max_keyvalue" -v "none" -f "create"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.max_keyvalue attr for ${v_attrset["hdfs_flagfile"]}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return 1
}
setxattr -n ${v_attrset["hdfs_flagfile"]} -a "user.recent_filename" -v "none" -f "create"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.max_keyvalue attr for ${v_attrset["hdfs_flagfile"]}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return 1
}
setxattr -n ${v_attrset["hdfs_flagfile"]} -a "user.dbid" -v "none" -f "create"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.max_keyvalue attr for ${v_attrset["hdfs_flagfile"]}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return 1
}
log_info "${LAYER_NAME}.${v_module} flag-file ${v_attrset["hdfs_flagfile"]} created, it's xattrs setted"
else
log_info "${LAYER_NAME}.${v_module} flag-file already is"
fi
#create new hdfs-file from the newly generated awr-dump file
log_info "${LAYER_NAME}.${v_module} ok let's upload local-file ${v_path} to hdfs-dir ${v_attrset["hdfs_folder"]}"
v_y=${v_attrset["hdfs_folder"]}
v_y=${v_y%\/}"/"$(basename "$v_path")
log_info "${LAYER_NAME}.${v_module} hdfs-file name is: ${v_y}"
createfile -n "$v_y" -l "${v_path}" -m "$UPLOADTIME_LIMIT" 1>/dev/null 2>&1; rc="$?"
if [ "$rc" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} can not create hdfs file"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return 1
fi
v_x="${v_attrset["hdfs_flagfile"]}"
setxattr -n "$v_x" -a "user.min_keyvalue" -v "$v_minsnapid" -f "replace"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.min_keyvalue to ${v_minsnapid} for ${v_x}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return "$v_z"
}
setxattr -n "$v_x" -a "user.max_keyvalue" -v "$v_maxsnapid" -f "replace"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.max_keyvalue to ${v_maxsnapid} for ${v_x}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return "$v_z"
}
setxattr -n "$v_x" -a "user.dbid" -v "$v_dbid" -f "replace"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.dbid to ${v_dbid} for ${v_x}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return "$v_z"
}
v_k=$(getxattr -n "${v_x}" -a "user.recent_filename" | egrep "^user.recent_filename.*" | awk '{printf "%s", $2;}')
v_k=${v_k#\"}; v_k=${v_k%\"}
setxattr -n "$v_k" -a "user.next_file" -v "$v_y" -f "create" 1>/dev/null 2>&1
setxattr -n "$v_y" -a "user.prev_file" -v "$v_k" -f "create" 1>/dev/null 2>&1
setxattr -n "$v_x" -a "user.recent_filename" -v "$v_y" -f "replace"; v_z="$?"
[ "$v_z" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not set user.max_keyvalue to ${v_maxsnapid} for ${v_x}"
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return "$v_z"
}
v_path=$(dirname "$v_path"); find ${v_path} -type f -name "${v_attrset["dump_name"]}*" -delete
return 0
#end of upload_awrto_storage
}
check_atop_attributes() {
local v_module="check_atop_attributes"
local v_dcname=""
local rc v_x v_dcid v_key v_value
while [ "$1" != "" ]
do
case "$1" in
"-h"|"--help")
printf "%s\n" "
-h|--help - This help
-d|--dcname - Name of datacollection, which attribute(s) you want to get out; Mandatory;
--------------------------------------------------------------------------------------------
Checks:"
return 0
;;
"-d"|"--dcname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} You have to set value for -d|--dcname option;"
log_info "${LAYER_NAME}.${v_module} Please use -h|--help to see reference"
return 1
fi
v_dcname="$2"
shift 2
;;
*)
log_info "${v_module} ${1} is not an option; use -h|--help"
return 1
;;
esac
done
if [ -z "$v_dcname" ]
then
log_info "${LAYER_NAME}.${v_module} you have to set value for -d|--dcname option; See -h|--help"; return 1
fi
v_dcid=$(echo "select id from datasets where dataset_name='${v_dcname}';" | "$SQLITE" "$SQLITEDB" 2>/dev/null | tr -d [:cntrl:] | tr -d [:space:])
if [ -z "$v_dcid" ]
then
log_info "${LAYER_NAME}.${v_module} there is no data-collection with name '${v_dcname}'"
return 1
fi
get_attribute -d "$v_dcname">"$SPOOL_FILE"
[ "$?" -ne "0" ] && {
log_info "${LAYER_NAME}.${v_module} can not obtain set of attributes for data-collection with name: ${v_dcname};";
return 1
}
declare -A v_attrset
while read line
do
v_key=$(echo ${line} | awk '{printf "%s", $1}')
v_value=$(echo ${line} | awk '{printf "%s", $2}')
#printf "%s\t%s\n" "$v_key" "$v_value"
v_attrset["$v_key"]="$v_value"
done<"$SPOOL_FILE"
if [ ! -d "${v_attrset["atoplog_dir"]}" ]
then
log_info "${LAYER_NAME}.${v_module} by configuration ${v_attrset["atoplog_dir"]} should be a local-dir with atop-log;"
log_info "${LAYER_NAME}.${v_module} But ${v_attrset["atoplog_dir"]} is not a dir and|or doesn't exist"
return 1
fi
if [ ! -r "${v_attrset["atoplog_dir"]}" ]
then
log_info "${LAYER_NAME}.${v_module} you don't have read-permission to directory ${v_attrset["atoplog_dir"]}, which is supposed to be atop-log dir"
return 1
fi
return 0
#end of check_atop_attributes
}
upload_atopto_storage() {
local v_module="upload_atopto_storage"
local v_hdfsfileis v_x v_y v_key v_value v_path rc v_dcname=""
while [ "$1" != "" ]
do
case "$1" in
"-h"|"--help")
printf "%s\n" "
-h|--help - This help
-d|--dcname - Name of data-collection, by which this program shuld have to obtain various necessary attribytes for data processing"
return 0
;;
"-d"|"--dcname")
if [ -z "$2" ]
then
log_info "${LAYER_NAME}.${v_module} you have to set value for -d|--dcname option; See -h|--help"; return 1
fi
v_dcname="$2"
shift 2
;;
*)
log_info "${v_module} ${1} is not an option; Use -h|--help;"
return 1
;;
esac
done
if [ -z "$v_dcname" ]
then
log_info "${LAYER_NAME}.${v_module} you have to set value for -d|--dcname option; See -h|--help"; return 1
fi
log_info "${LAYER_NAME}.${v_module} ok, data-collection name is: ${v_dcname}"
check_atop_attributes -d "$v_dcname"
if [ "$?" -ne "0" ]
then
log_info "${LAYER_NAME}.${v_module} something wrong with work with attributes and|or with attrs itself, of data-collection with name: ${v_dcname};"
return 1
fi
get_attribute -d "$v_dcname">"$SPOOL_FILE"
declare -A v_attrset
while read line
do
v_key=$(echo ${line} | awk '{printf "%s", $1}')
v_value=$(echo ${line} | awk '{printf "%s", $2}')
#printf "%s\t%s\n" "$v_key" "$v_value"
v_attrset["$v_key"]="$v_value"
done<"$SPOOL_FILE"
#check: if hdfs-file exist; If file is then try to get max snap_id from it's xattr; If hdfs-file is but it isn't possible to obtain xattr from it: it's fail
cat /dev/null > "$SPOOL_FILE"
v_hdfsfileis="" #it means: no, hdfs-file - doesn't exist
v_y="${v_attrset["hdfs_flagfile"]}"
itemstatus -n "$v_y" 1>"$SPOOL_FILE" 2>&1
rc="$?"
if [ "$rc" -eq "0" ]
then
#Ok we defenetly get info about hdfs-item from hdfs; Let's see: what it is
v_x=$(cat "$SPOOL_FILE" | egrep "^type:" | awk '{printf "%s", $2;}' | tr [:lower:] [:upper:])
if [ "$v_x" == "FILE" ]
then
log_info "${LAYER_NAME}.${v_module} hdfs-side available and file ${v_y} is there"
v_hdfsfileis="y"
else
#Well, it's not a file; Directory, symlinc, something else but not a file; Well nothing else but erroro-ending
log_info "${LAYER_NAME}.${v_module} hdfs-side is available but ${v_y} is not a file, it's: ${v_x};"
return 1
fi
else
#well may be hdfs is not reachable; Or may be it said something about error; Let us see: what is it
v_x=$(cat "$SPOOL_FILE" | wc -l)
if [ "$v_x" -gt "0" ]
then
#cat "$SPOOL_FILE"
cat "$SPOOL_FILE" | grep -q "FileNotFoundExceptionFile" 1>/dev/null 2>&1
if [ "$?" -eq "0" ]
then
v_hdfsfileis="n" #So it means that hdfs is reachable and it said that asked file: is absent;
else
log_info "${LAYER_NAME}.${v_module} hdfs returned error on itemstatus req for: ${v_y}"
log_info "$SPOOL_FILE" "logfile"
return 1
fi
else
log_info "${LAYER_NAME}.${v_module} hdfs is not reachable right now; error-exiting"; return 1
fi
fi
v_last_snapid_inhdfs=""
if [ "$v_hdfsfileis" == "y" ]
then
v_last_snapid_inhdfs=$(getxattr -n "${v_attrset["hdfs_flagfile"]}" -a "user.max_keyvalue" | egrep "^user.max_keyvalue.*" | awk '{printf "%s", $2;}')
v_last_snapid_inhdfs=${v_last_snapid_inhdfs#\"}; v_last_snapid_inhdfs=${v_last_snapid_inhdfs%\"}
log_info "${LAYER_NAME}.${v_module} last_snapid_inhdfs value obtained as: ${v_last_snapid_inhdfs}"
if [ "$v_last_snapid_inhdfs" == "none" ]
then
log_info "${LAYER_NAME}.${v_module} v_last_snapid_inhdfs is none, ok set it to 0"
v_last_snapid_inhdfs="0"