-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy patheval_fts.py
executable file
·2637 lines (2509 loc) · 131 KB
/
eval_fts.py
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
#!/data/cmssst/packages/bin/python3.9
# ########################################################################### #
# python script to query the FTS results in ElasticSearch via the grafana
# front-end or read documents from HDFS in MonIT, evaluate link and site
# status, and upload new or changed results to MonIT HDFS. The script
# checks/updates 15 min, 1 hour, 6 hour, and 1 day results, depending on
# the execution time.
#
# 2019-Jun-24 Stephan Lammel
# ########################################################################### #
# 'metadata': {
# 'monit_hdfs_path': "fts15min",
# 'timestamp': 1464871600000
# },
# "data": {
# "name": "T1_US_FNAL" | "cmsdcadisk01.fnal.gov___eoscmsftp.cern.ch",
# "type": "site" | "rse" | "GSIFTP-source" | "WEBDAV-source" |
# "GSIFTP-destination" | "GSIFTP-link",
# "status": "ok" | "warning" | "error" | "unknown"
# "quality": 0.000 | null,
# "detail": "ok: 2 files, 46.7 GB [...]\n
# src_permission: 1 file, 12.1 GB [...]\n
# trn_timeout: 5 files, 64.3 GB [...]\n
# trn-error: 2 files, 34.1 GB [...]"
# "detail": "excluded from the source endpoint evaluation\n
# Transfers: 12 files, 87.5 GBytes ok\n
# Errors: dst_perm: 1, trn_tout: 1, src_err: 2\n
# Links: 6 ok, 2 warning, 1 unknown, 2 bad-source"
# "detail": "Transfers (from/to): 21/3 files, 2.3/10.1 TBytes ok\n
# Errors: src_perm: 3, trn_usr: 1, dst_perm: 1, foreign: 1\n
# Links (from/to): 24/23 ok, 0/1 error, 1/1 bad-endpoint\n
# cmsdcatape01.fnal.gov (from/to): error/ok\n
# cmsdcadisk01.fnal.gov (from/to): ok/ok"
# }
# https://cmsfts3.fnal.gov:8449/fts3/ftsmon/#/18d86488-94d4-11e9-a93b-a0369f23d0c0
# ^job/
# https://fts3.cern.ch:8449/fts3/ftsmon/#/0ba2268e-98d3-11e9-9127-02163e01845e
# ^job/
# https://Imperial-FTS-IPv6:8449/fts3/ftsmon/#/ddba3826-98d0-11e9-9ff9-525400e091e6
# ^fts00.grid.hep.ph.ic.ac.uk ^job/
# https://FTS-MIT:8449/fts3/ftsmon/#/52c192be-9894-11e9-a1d6-001ec9adc410
# ^t3serv019.mit.edu ^job/
import os, sys
import logging
import time, calendar
import math
import socket
import urllib.request, urllib.error
import json
import re
import gzip
#
# setup the Java/HDFS/PATH environment for pydoop to work properly:
os.environ["HADOOP_CONF_DIR"] = "/data/cmssst/packages/etc/hadoop.analytix.conf/hadoop.analytix"
os.environ["JAVA_HOME"] = "/data/cmssst/packages/lib/jvm/java-11-openjdk-11.0.23.0.9-3.el9.x86_64"
os.environ["HADOOP_HOME"] = "/data/cmssst/packages/hadoop/3.3.5-1ba16/x86_64-el9-gcc11-opt"
os.environ["LD_LIBRARY_PATH"] ="/data/cmssst/packages/hadoop/3.3.5-1ba16/x86_64-el9-gcc11-opt/lib/native"
os.environ["PATH"] ="/data/cmssst/packages/hadoop/3.3.5-1ba16/x86_64-el9-gcc11-opt/bin:" + os.environ["PATH"]
import pydoop.hdfs
# ########################################################################### #
#EVFTS_BACKUP_DIR = "./junk"
EVFTS_BACKUP_DIR = "/data/cmssst/MonitoringScripts/fts/failed"
# ########################################################################### #
class FTSmetric:
'CMS Site Support Team FTS metric class'
staticErrorList = []
def __init__(self):
self.mtrc = {}
return
@staticmethod
def interval(metric_name=None):
FTS_METRICS = {'fts15min': 900, 'fts1hour': 3600,
'fts6hour': 21600, 'fts1day': 86400 }
#
if metric_name is None:
return FTS_METRICS
#
try:
return FTS_METRICS[ metric_name ]
except KeyError:
return 0
@staticmethod
def metric_order(metric):
"""function to determine the sort order of FTS metrics"""
SORT_ORDER = {'fts15min': 1, 'fts1hour': 2, 'fts6hour': 3, 'fts1day': 4}
try:
return [ SORT_ORDER[ metric[0] ], metric[1] ]
except KeyError:
return [ 0, metric[1] ]
@staticmethod
def hosts2protolink(source_host=None, destination_host=None, protocol=None):
"""function to compose a link string from source/destination hosts"""
if (( source_host is None ) or ( destination_host is None )):
logging.error("Missing host name(s) to compose link")
return None
#
# in case provided hosts are really endpoints:
source_host = source_host.split("/")[-1].split(":")[0]
destination_host = destination_host.split("/")[-1].split(":")[0]
if ( source_host.count(".") < 2 ):
logging.error("Bad source host name: %s" % source_host)
return None
if ( destination_host.count(".") < 2 ):
logging.error("Bad destination host name: %s" % destination_host)
return None
#
if ( protocol is None ):
logging.error("No protocol name provided, %s___%s" %
(source_host, destination_host))
return None
elif ( protocol.upper() == "SRM" ):
protocol = "GSIFTP"
elif ( protocol.upper() == "DAVS" ):
protocol = "WEBDAV"
elif ( protocol.upper() == "ROOT" ):
protocol = "XROOTD"
# exclude xrootd endpoint for the time beeing
return None
elif (( protocol.upper() != "GSIFTP" ) and
( protocol.upper() != "WEBDAV" )):
logging.error("Unsupported protocol name: %s" % protocol)
return None
#
link = source_host.lower() + "___" + protocol.upper() + "___" + \
destination_host.lower()
#
link = link.replace(" ", "")
linkRegex = re.compile(r"^(([a-z0-9\-]+)\.)+[a-z0-9\-]+___([A-Z]+___)*(([a-z0-9\-]+)\.)+[a-z0-9\-]+$")
if linkRegex.match(link) is None:
logging.error("Bad link name composed: %s" % link)
return None
return link
@staticmethod
def protolink2hosts(link_name=None):
"""function to extract source/destinaton hosts from a link name"""
linkRegex = re.compile(r"^(([a-z0-9\-]+)\.)+[a-z0-9\-]+___([A-Z]+___)*(([a-z0-9\-]+)\.)+[a-z0-9\-]+$")
if link_name is None:
return [None, None, None]
#
matchObj = linkRegex.match(link_name)
if ( matchObj is None ):
logging.error("Bad link name: %s" % link_name)
src = dst = proto = None
elif ( matchObj.group(3) is None ):
src, dst = link_name.split("___")
proto = None
else:
src, proto, dst = link_name.split("___")
#
return [src, dst, proto]
@staticmethod
def protolink2link(protocol_link=None):
"""function to extract source/destinaton hosts from a link name"""
linkRegex = re.compile(r"^(([a-z0-9\-]+)\.)+[a-z0-9\-]+___([A-Z]+___)*(([a-z0-9\-]+)\.)+[a-z0-9\-]+$")
if protocol_link is None:
return None
#
matchObj = linkRegex.match(protocol_link)
if ( matchObj is None ):
logging.error("Bad protocol link name: %s" % protocol_link)
return None
elif ( matchObj.group(3) is None ):
return protocol_link
else:
src, proto, dst = protocol_link.split("___")
return src + "___" + dst
@staticmethod
def classify(error_scope, error_code, error_message, link_name, \
file_size, transfer_activity):
"""function to classify transfer results into counting classes"""
eMsg = error_message
eLwr = error_message.lower()
#
if ( error_code == 0 ):
return "trn_ok"
elif (( file_size >= 21474836480 ) or
( eLwr.find("certificate has expired") >= 0 ) or
( eLwr.find("operation canceled by user") >= 0 ) or
( eLwr.find("path/url invalid") >= 0 ) or
( eLwr.find("file exists and overwrite is not enabled") >= 0 ) or
( eLwr.find("request cancellation was requested") >= 0 )):
return "trn_usr"
elif (( transfer_activity == "ASO" ) and
(( eLwr.find("disk quota exceeded") >= 0 ) or
( eMsg.find("NoFreeSpaceException") >= 0 ) or
( eLwr.find("not enough space") >= 0 ) or
( eLwr.find("no free space") >= 0 ) or
(( eLwr.find("copy failed with mode 3rd push") >= 0 ) and
( eMsg.find("507 status code: 507") >= 0 )) or
( eMsg.find("failed with status code 507") >= 0 ) or
( eMsg.find("Insufficient Storage") >= 0 ))):
return "trn_usr"
elif (( error_scope == "TRANSFER" ) and
(( eLwr.find("no route to host") >= 0 ) or
( eLwr.find("could not open connection to") >= 0 ) or
( eLwr.find("unable to connect") >= 0 ) or
( eLwr.find("failed to connect") >= 0 ) or
( eLwr.find("network is unreachable") >= 0 ))):
return "trn_err"
#
#
elif ( error_scope == "SOURCE" ):
classfcn = "src_err"
elif ( error_scope == "DESTINATION" ):
classfcn = "dst_err"
elif ( error_message[:6] == "SOURCE" ):
classfcn = "src_err"
elif ( error_message[:11] == "DESTINATION" ):
classfcn = "dst_err"
elif (( eMsg.find("SOURCE") > 0 ) and
( eMsg.find("DESTINATION") < 0 )):
classfcn = "src_err"
elif (( eMsg.find("DESTINATION") > 0 ) and
( eMsg.find("SOURCE") < 0 )):
classfcn = "dst_err"
else:
classfcn = "trn_err"
#
#
src_host, dst_host = FTSmetric.protolink2hosts(link_name)[:2]
#
try:
domain = src_host.split(".",1)[-1]
if (( eLwr.find(src_host) >= 0 ) or
( eLwr.find(domain) >= 0 )):
classfcn = "src_err"
else:
ipaddrList = socket.getaddrinfo(src_host, None,
type=socket.SOCK_STREAM)
for tuple in ipaddrList:
if ( tuple[0] == socket.AddressFamily.AF_INET ):
domain = tuple[4][0].rsplit(".", 1)[0] + "."
elif ( tuple[0] == socket.AddressFamily.AF_INET6 ):
domain = tuple[4][0].rsplit(":", 1)[0]
if ( domain[-1] != ":" ):
domain = domain + ":"
else:
continue
ipAddr = tuple[4][0]
if (( eLwr.find(ipAddr) >= 0 ) or
( eLwr.find(domain) >= 0 )):
classfcn = "src_err"
except (TypeError, socket.gaierror, AttributeError):
pass
#
try:
domain = dst_host.split(".",1)[-1]
if (( eLwr.find(dst_host) >= 0 ) or
( eLwr.find(domain) >= 0 )):
if ( classfcn == "src_err" ):
classfcn = "trn_err"
else:
classfcn = "dst_err"
else:
ipaddrList = socket.getaddrinfo(dst_host, None,
type=socket.SOCK_STREAM)
for tuple in ipaddrList:
if ( tuple[0] == socket.AddressFamily.AF_INET ):
domain = tuple[4][0].rsplit(".", 1)[0] + "."
elif ( tuple[0] == socket.AddressFamily.AF_INET6 ):
domain = tuple[4][0].rsplit(":", 1)[0]
if ( domain[-1] != ":" ):
domain = domain + ":"
else:
continue
ipAddr = tuple[4][0]
if (( eLwr.find(ipAddr) >= 0 ) or
( eLwr.find(domain) >= 0 )):
if ( classfcn == "src_err" ):
classfcn = "trn_err"
else:
classfcn = "dst_err"
except (TypeError, socket.gaierror, AttributeError):
pass
#
#
#
#
if ( classfcn == "src_err" ):
# sub-classify source further: _perm, _miss, _err
if (( error_code == 1 ) or
( error_code == 13 )):
return "src_perm"
elif ( error_code == 2 ):
return "src_miss"
elif (( eLwr.find("credential") >= 0 ) or
( eLwr.find("permission denied") >= 0 ) or
( eLwr.find("insufficient user privileges") >= 0 ) or
( eMsg.find("Authorization denied") >= 0 ) or
( eLwr.find("establishing access rights") >= 0 ) or
( eLwr.find("authorization error") >= 0 ) or
( eLwr.find("certificate issued for a diff") >= 0 ) or
( eMsg.find("does not allow setting up correct ACL") >= 0 )):
return "src_perm"
elif (( eLwr.find("no such file or directory") >= 0 ) or
( eLwr.find("file not found") >= 0 ) or
( eLwr.find("file is unavailable") >= 0 ) or
( eLwr.find("file is not online") >= 0 ) or
( eLwr.find("no read pools online") >= 0 ) or
( eLwr.find("file invalidated while queuing") >= 0 )):
return "src_miss"
#
if ( logging.getLogger().level > 25 ):
return classfcn
#
#
#
elif ( classfcn == "trn_err" ):
# sub-classify transfer further: _tout, _err (+ _ok, _usr)
if (( eLwr.find("operation timed out") >= 0 ) or
( eLwr.find("connection timed out") >= 0 ) or
( eLwr.find("idle timeout") >= 0 ) or
( eLwr.find("performance marker timeout") >= 0 ) or
( eLwr.find("timeout expired") >= 0 )):
return "trn_tout"
elif ( eLwr.find("file not found") >= 0 ):
return "src_miss"
elif (( eMsg.find("File exists") >= 0 ) or
( eLwr.find("rm() fail") >= 0 ) or
( eLwr.find("impossible to unlink") >= 0 )):
return "dst_perm"
elif ( eLwr.find("mkdir") >= 0 ):
return "dst_path"
elif (( eLwr.find("disk quota exceeded") >= 0 ) or
( eLwr.find("all pools are full") >= 0 ) or
( eLwr.find("unable to reserve space") >= 0 ) or
( eMsg.find("NoFreeSpaceException") >= 0 ) or
( eLwr.find("no write pools online") >= 0 ) or
( eLwr.find("no space left on device") >= 0 ) or
( eLwr.find("not enough space") >= 0 ) or
( eLwr.find("no free space") >= 0 ) or
( eLwr.find("unable to get quota space") >= 0 ) or
( eLwr.find("status code: 507,") >= 0 ) or
( eMsg.find("Insufficient Storage") >= 0 )):
return "dst_spce"
elif ( eMsg.find("error in write into HDFS") >= 0 ):
return "dst_err"
#
if ( logging.getLogger().level > 25 ):
return classfcn
#
#
#
elif ( classfcn == "dst_err" ):
# sub-classify destination further: _perm, _path, _spce, _err
if (( error_code == 1 ) or
( error_code == 13 ) or
( error_code == 16 ) or
( error_code == 17 ) or
( error_code == 30 )):
return "dst_perm"
elif (( error_code == 2 ) or
( error_code == 19 ) or
( error_code == 20 )):
return "dst_path"
elif (( error_code == 23 ) or
( error_code == 28 ) or
( error_code == 122 )):
return "dst_spce"
elif (( eMsg.find("Operation not permitted") >= 0 ) or
( eMsg.find("Permission denied") >= 0 ) or
( eMsg.find("Device or resource busy") >= 0 ) or
( eMsg.find("File exists") >= 0 ) or
( eMsg.find("Read-only file system") >= 0 ) or
( eMsg.find("Authorization denied") >= 0 ) or
( eLwr.find("authentication failed") >= 0 ) or
( eLwr.find("system error in unlink") >= 0 ) or
( eLwr.find("login incorrect") >= 0 ) or
( eLwr.find("certificate verify failed") >= 0 ) or
( eLwr.find("authentication negotiation") >= 0 ) or
( eLwr.find("commands denied") >= 0 ) or
( eMsg.find("rejected PUT: 403 Forbidden") >= 0 ) or
( eLwr.find("subject alternative names") >= 0 ) or
( eLwr.find("status code: 403,") >= 0 ) or
(( eLwr.find("peers certificate") >= 0 ) and
( eLwr.find("was rejected") >= 0 ))):
return "dst_perm"
elif (( eMsg.find("No such file or directory") >= 0 ) or
( eMsg.find("No such device") >= 0 ) or
( eMsg.find("Not a directory") >= 0 ) or
( eMsg.find("MAKE_PARENT") >= 0 ) or
( eMsg.find("][Mkdir][") >= 0 )):
return "dst_path"
elif (( eMsg.find("File table overflow") >= 0 ) or
( eMsg.find("No space left on device") >= 0 ) or
( eLwr.find("quota exceeded") >= 0 ) or
( eLwr.find("no free space") >= 0 ) or
( eLwr.find("unable to get quota space") >= 0 ) or
( eLwr.find("space management step") >= 0 ) or
( eLwr.find("status code: 507,") >= 0 )):
return "dst_spce"
elif (( eLwr.find("copy failed with mode 3rd push") >= 0 ) and
(( eMsg.find("No valid CRL was found for the CA") >= 0 ) or
( eMsg.find("(category: CRL)") >= 0 ))):
return "src_err"
#
if ( logging.getLogger().level > 25 ):
return classfcn
#
#
#
#
if ( classfcn == "src_err" ):
if (( eLwr.find("communication error") >= 0 ) or
( eLwr.find("connection reset") >= 0 ) or
( eLwr.find("connection closed") >= 0 ) or
( eLwr.find("unable to connect") >= 0 ) or
( eLwr.find("could not connect to") >= 0 ) or
( eLwr.find("timed out") >= 0 ) or
( eLwr.find("timeout") >= 0 ) or
( eLwr.find("problem while connected to") >= 0 ) or
( eLwr.find("incompatible with current file") >= 0 ) or
( eMsg.find("internal HDFS error") >= 0 ) or
( eMsg.find("error in reading from HDFS") >= 0 ) or
( eMsg.find(" 451 End") >= 0 ) or
( eLwr.find("open file for checksumming") >= 0 ) or
( eLwr.find("operation was aborted") >= 0 ) or
( eLwr.find("an end of file occurred") >= 0 ) or
( eLwr.find("commands denied") >= 0 ) or
( eLwr.find("checksum do not match") >= 0 ) or
( eLwr.find("checksum mismatch") >= 0 ) or
( eLwr.find("protocol(s) not supported") >= 0 ) or
( eLwr.find("internal server error") >= 0 ) or
( eMsg.find("Broken pipe") >= 0 ) or
( eMsg.find("Unable to build the TURL") >= 0 ) or
( eMsg.find("TTL exceeded") >= 0 ) or
( eLwr.find("operation canceled") >= 0 ) or
( eLwr.find("input/output error") >= 0 ) or
( eLwr.find("connection limit exceeded") >= 0 ) or
( eLwr.find("local filesystem has problems") >= 0 ) or
( eLwr.find("failed to pin file") >= 0 ) or
( eLwr.find("stale file handle") >= 0 ) or
( eLwr.find("failed to abort transfer") >= 0 ) or
( eLwr.find("error in failed to open checksum") >= 0 ) or
( eLwr.find("error in failed to read checksum") >= 0 ) or
( eMsg.find("SURL is not pinned") >= 0 ) or
( eLwr.find("connection was closed by server") >= 0 ) or
( eMsg.find("SOURCE CHECKSUM") >= 0 ) or
( eMsg.find("Result Invalid read in request") >= 0 ) or
( eMsg.find("Secure connection truncated") >= 0 ) or
( eMsg.find("Unexpected server error: 500") >= 0 )):
return classfcn
elif ( classfcn == "trn_err" ):
if (( eLwr.find("no such file or directory") >= 0 ) or
( eLwr.find("unable to open file") >= 0 ) or
( eLwr.find("login failed") >= 0 ) or
( eLwr.find("login incorrect") >= 0 ) or
( eLwr.find("transfer failed") >= 0 ) or
( eLwr.find("checksum mismatch") >= 0 ) or
( eLwr.find("connection reset") >= 0 ) or
( eLwr.find("connection timed out") >= 0 ) or
( eLwr.find("internal timeout") >= 0 ) or
( eMsg.find("internal HDFS error") >= 0 ) or
( eLwr.find("an end of file occurred") >= 0 ) or
( eLwr.find("protocol family not supported") >= 0 ) or
( eLwr.find("problem while connected to") >= 0 ) or
( eLwr.find("no such file or directory") >= 0 ) or
( eLwr.find("authentication failed") >= 0 ) or
( eLwr.find("upload aborted") >= 0 ) or
( eLwr.find("operation canceled") >= 0 ) or
( eLwr.find("operation was aborted") >= 0 ) or
( eLwr.find("aborting transfer") >= 0 ) or
( eLwr.find("input/output error") >= 0 ) or
( eLwr.find("an unknown error occurred") >= 0 ) or
( eLwr.find("transfer was forcefully killed") >= 0 ) or
( eLwr.find("stream ended before eod") >= 0 ) or
( eLwr.find("file size mismatch") >= 0 ) or
( eLwr.find("internal server error") >= 0 ) or
( eLwr.find("operation not permitted") >= 0 ) or
( eMsg.find("Permission denied") >= 0 ) or
( eMsg.find("Broken pipe") >= 0 ) or
( eMsg.find("Invalid argument") >= 0 ) or
( eMsg.find("SSL handshake problem") >= 0 ) or
( eMsg.find("IPC failed") >= 0 ) or
( eMsg.find(" 501 Port number") >= 0 ) or
( eMsg.find(" 500 Authorization error") >= 0 ) or
( eMsg.find(" 500 End") >= 0 ) or
( eMsg.find(" 530 Login denied") >= 0 ) or
( eMsg.find(" 451 End") >= 0 ) or
( eMsg.find(" 451 Failed to deliver Pool") >= 0 ) or
( eMsg.find(" 451 FTP proxy did not shut") >= 0 ) or
( eMsg.find(" 451 General problem") >= 0 ) or
( eMsg.find(" 451 Post-processing failed") >= 0 ) or
( eMsg.find(" 431 Internal error") >= 0 ) or
( eLwr.find("failed to deliver pnfs") >= 0 ) or
( eLwr.find("block with unknown descriptor") >= 0 ) or
( eLwr.find("certificate verify failed") >= 0 ) or
( eLwr.find("transfer has been aborted") >= 0 ) or
( eLwr.find("transfer cancelled") >= 0 ) or
( eLwr.find("handle not in the proper state") >= 0 ) or
( eLwr.find("error closing xrootd file handle") >= 0 ) or
( eLwr.find("stream was closed") >= 0 ) or
( eLwr.find("failed to open file") >= 0 ) or
( eLwr.find("copy failed with mode 3rd p") >= 0 ) or
( eLwr.find("connection limit exceeded") >= 0 ) or
( eLwr.find("error while searching for end") >= 0 ) or
( eLwr.find("stale file handle") >= 0 ) or
( eLwr.find("could not verify credential") >= 0 ) or
( eLwr.find("redirect limit has been reached") >= 0 ) or
( eLwr.find("operation expired") >= 0 ) or
( eLwr.find("invalid address") >= 0 ) or
( eLwr.find("upload not yet completed") >= 0 ) or
( eLwr.find("cannot allocate memory") >= 0 ) or
( eLwr.find("does not exist") >= 0 ) or
( eMsg.find("Copy failed with mode streamed") >= 0 ) or
( eMsg.find("Transfer forcefully killed") >= 0 )):
return classfcn
elif ( classfcn == "dst_err" ):
if (( eLwr.find("communication error") >= 0 ) or
( eLwr.find("no route to host") >= 0 ) or
( eLwr.find("could not open connection to") >= 0 ) or
( eLwr.find("unable to connect") >= 0 ) or
( eLwr.find("no route to host") >= 0 ) or
( eLwr.find("connection refused") >= 0 ) or
( eLwr.find("connection reset") >= 0 ) or
( eLwr.find("connection closed") >= 0 ) or
( eLwr.find("timed out") >= 0 ) or
( eLwr.find("timeout") >= 0 ) or
( eLwr.find("operation canceled") >= 0 ) or
( eLwr.find("problem while connected to") >= 0 ) or
( eLwr.find("incompatible with current file") >= 0 ) or
( eMsg.find("internal HDFS error") >= 0 ) or
( eMsg.find("error in write into HDFS") >= 0 ) or
( eMsg.find("Failed to close file in HDFS") >= 0 ) or
( eMsg.find(" 500 End") >= 0 ) or
( eMsg.find(" 451 End") >= 0 ) or
( eMsg.find("ERROR: deadlock detected") >= 0 ) or
( eMsg.find(" 451 Failed to deliver Pool") >= 0 ) or
( eLwr.find("unable to open file") >= 0 ) or
( eLwr.find("no data available") >= 0 ) or
( eLwr.find("file size mismatch") >= 0 ) or
( eLwr.find("checksum mismatch") >= 0 ) or
( eLwr.find("internal server error") >= 0 ) or
( eLwr.find("an end of file occurred") >= 0 ) or
( eMsg.find("][SRM_FILE_LIFETIME_EXPIRED]") >= 0 ) or
( eMsg.find("][SRM_INTERNAL_ERROR]") >= 0 ) or
( eMsg.find("][SRM_REQUEST_INPROGRESS]") >= 0 ) or
( eMsg.find("][SRM_ABORTED]") >= 0 ) or
( eMsg.find("][SRM_REQUEST_TIMED_OUT]") >= 0 ) or
( eMsg.find("][SRM_FAILURE]") >= 0 ) or
( eMsg.find("Broken pipe") >= 0 ) or
( eLwr.find("request aborted") >= 0 ) or
( eLwr.find("operation was aborted") >= 0 ) or
( eLwr.find("checksum value required") >= 0 ) or
( eLwr.find("protocol(s) not supported") >= 0 ) or
( eLwr.find("unknown error occurred") >= 0 ) or
( eLwr.find("service unavailable") >= 0 ) or
( eMsg.find("Unable to build the TURL") >= 0 ) or
( eLwr.find("input/output error") >= 0 ) or
( eLwr.find("connection limit exceeded") >= 0 ) or
( eLwr.find("unexpected server error") >= 0 ) or
( eLwr.find("too many queued requests") >= 0 ) or
( eLwr.find("upload not yet completed") >= 0 ) or
( eLwr.find("no such request") >= 0 ) or
( eLwr.find("failed to process") >= 0 ) or
( eLwr.find("unable to write replica") >= 0 ) or
( eLwr.find("handshake_failure; redirections") >= 0 ) or
( eMsg.find("ADLER32 not supported") >= 0 ) or
( eMsg.find("NoHttpResponseException while pushing") >= 0 ) or
( eMsg.find("IllegalStateException while pushing") >= 0 ) or
( eLwr.find("connection was closed by server") >= 0 ) or
( eLwr.find("secure connection truncated") >= 0 ) or
( eMsg.find("OpenSSL SSL_connect") >= 0 ) or
( eMsg.find("Result Invalid read in request") >= 0 ) or
( eMsg.find("Could not connect to server") >= 0 )):
return classfcn
if error_message not in FTSmetric.staticErrorList:
FTSmetric.staticErrorList.append( error_message )
#
logging.log(25, "Unclassified %s error: %s [%d] %s" %
(classfcn[:3], error_scope, error_code, error_message))
#
return classfcn
def fetch(self, metricList):
"""function to retrieve FTS link/site evaluation from MonIT"""
# ############################################################## #
# Retrieve all link/source/destination/site evaluations for the #
# (<metric-name>, <time-bin>) tuples in the provided metricList. #
# ############################################################## #
HDFS_PREFIX = "/project/monitoring/archive/cmssst/raw/ssbmetric/"
oneDay = 24*60*60
now = int( time.time() )
#
if metricList is None:
timeFrst = 0
timeLast = now
else:
t15mFrst = t1hFrst = t6hFrst = t1dFrst = now + oneDay
timeLast = 0
for mtrc in metricList:
if ( mtrc[0] == "fts15min" ):
period = 900
t15mFrst = min(t15mFrst, mtrc[1] * period)
elif ( mtrc[0] == "fts1hour" ):
period = 3600
t1hFrst = min(t1hFrst, mtrc[1] * period)
elif ( mtrc[0] == "fts6hour" ):
period = 21600
t6hFrst = min(t6hFrst, mtrc[1] * period)
elif ( mtrc[0] == "fts1day" ):
period = 86400
t1dFrst = min(t1dFrst, mtrc[1] * period)
else:
continue
timeLast = max(timeLast, ((mtrc[1] + 1) * period ) - 1)
timeFrst = min(t15mFrst, t1hFrst, t6hFrst, t1dFrst)
#
oneDay = 24*60*60
now = int( time.time() )
start15mArea = max( calendar.timegm( time.gmtime(now - (6 * oneDay)) ),
t15mFrst - oneDay)
start1hArea = max( calendar.timegm( time.gmtime(now - (6 * oneDay)) ),
t1hFrst - oneDay)
start6hArea = max( calendar.timegm( time.gmtime(now - (6 * oneDay)) ),
t6hFrst - oneDay)
start1dArea = max( calendar.timegm( time.gmtime(now - (6 * oneDay)) ),
t1dFrst - oneDay)
limitLocalTmpArea = calendar.timegm( time.localtime( now ) ) + oneDay
#
logging.info("Retrieving FTS evaluation docs from MonIT HDFS")
logging.log(15, " between %s and %s" %
(time.strftime("%Y-%m-%d %H:%M", time.gmtime(timeFrst)),
time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(timeLast))))
#
dirList = set()
tis15min = now + oneDay
tis1hour = now + oneDay
tis6hour = now + oneDay
tis1day = now + oneDay
tmp15mFlag = tmp1hFlag = tmp6hFlag = tmp1dFlag = False
for mtrc in metricList:
if ( mtrc[0] == "fts15min" ):
tmp15mFlag = True
dirDay = mtrc[1] * 900
dirList.add( time.strftime("fts15min/%Y/%m/%d",
time.gmtime( dirDay )) )
tis15min = min(tis15min, dirDay)
elif ( mtrc[0] == "fts1hour" ):
tmp1hFlag = True
dirDay = mtrc[1] * 3600
dirList.add( time.strftime("fts1hour/%Y/%m/%d",
time.gmtime( dirDay )) )
tis1hour = min(tis1hour, dirDay)
elif ( mtrc[0] == "fts6hour" ):
tmp6hFlag = True
dirDay = mtrc[1] * 21600
dirList.add( time.strftime("fts6hour/%Y/%m/%d",
time.gmtime( dirDay )) )
tis6hour = min(tis6hour, dirDay)
elif ( mtrc[0] == "fts1day" ):
tmp1dFlag = True
dirDay = mtrc[1] * 86400
dirList.add( time.strftime("fts1day/%Y/%m/%d",
time.gmtime( dirDay )) )
tis1day = min(tis1day, dirDay)
if ( tmp15mFlag ):
for dirDay in range(start15mArea, limitLocalTmpArea, oneDay):
dirList.add( time.strftime("fts15min/%Y/%m/%d.tmp",
time.gmtime( dirDay )) )
if ( tmp1hFlag ):
for dirDay in range(start1hArea, limitLocalTmpArea, oneDay):
dirList.add( time.strftime("fts1hour/%Y/%m/%d.tmp",
time.gmtime( dirDay )) )
if ( tmp6hFlag ):
for dirDay in range(start6hArea, limitLocalTmpArea, oneDay):
dirList.add( time.strftime("fts6hour/%Y/%m/%d.tmp",
time.gmtime( dirDay )) )
if ( tmp1dFlag ):
for dirDay in range(start1dArea, limitLocalTmpArea, oneDay):
dirList.add( time.strftime("fts1day/%Y/%m/%d.tmp",
time.gmtime( dirDay )) )
#
dirList = sorted(dirList)
# connect to HDFS, loop over directories and read FTs eval docs:
# ==============================================================
tmpDict = {}
try:
with pydoop.hdfs.hdfs() as myHDFS:
for subDir in dirList:
logging.debug(" checking HDFS subdirectory %s" % subDir)
if not myHDFS.exists( HDFS_PREFIX + subDir ):
continue
# get list of files in directory:
myList = myHDFS.list_directory( HDFS_PREFIX + subDir )
fileNames = [ d['name'] for d in myList
if (( d['kind'] == "file" ) and
( d['size'] != 0 )) ]
del myList
for fileName in fileNames:
logging.debug(" reading file %s" %
os.path.basename(fileName))
fileHndl = fileObj = None
try:
if ( os.path.splitext(fileName)[-1] == ".gz" ):
fileHndl = myHDFS.open_file(fileName)
fileObj = gzip.GzipFile(fileobj=fileHndl)
else:
fileObj = myHDFS.open_file(fileName)
# read FTS evaluation documents in file:
for myLine in fileObj:
myJson = json.loads(myLine.decode('utf-8'))
try:
if ( "monit_hdfs_path" not
in myJson['metadata'] ):
myJson['metadata']['monit_hdfs_path'] \
= myJson['metadata']['path']
metric = myJson['metadata']['monit_hdfs_path']
if metric not in FTSmetric.interval():
continue
tbin = int( myJson['metadata']['timestamp']
/ ( FTSmetric.interval(metric) * 1000 ))
mKey = (metric, tbin)
if mKey not in metricList:
continue
if 'quality' not in myJson['data']:
myJson['data']['quality'] = None
if 'detail' not in myJson['data']:
myJson['data']['detail'] = None
name = myJson['data']['name']
type = myJson['data']['type']
vrsn = myJson['metadata']['kafka_timestamp']
#
eKey = (name, type)
value = (vrsn, myJson['data'])
#
if mKey not in tmpDict:
tmpDict[mKey] = {}
if eKey in tmpDict[mKey]:
if ( vrsn <= tmpDict[mKey][eKey][0] ):
continue
tmpDict[mKey][eKey] = value
except KeyError:
continue
except json.decoder.JSONDecodeError as excptn:
logging.error("JSON decoding failure, file %s: %s"
% (fileName, str(excptn)))
except FileNotFoundError as excptn:
logging.error("HDFS file not found, %s: %s" %
(fileName, str(excptn)))
except IOError as excptn:
logging.error("IOError accessing HDFS file %s: %s"
% (fileName, str(excptn)))
finally:
if fileObj is not None:
fileObj.close()
if fileHndl is not None:
fileHndl.close()
except Exception as excptn:
logging.error("Failed to fetch documents from MonIT HDFS: %s" %
str(excptn))
# load FTS evaluation information into object:
# ============================================
cnt_docs = 0
cnt_mtrc = len(tmpDict)
for mtrcKey in tmpDict:
self.add1metric(mtrcKey)
for evalKey in tmpDict[mtrcKey]:
cnt_docs += 1
self.add1entry(mtrcKey, tmpDict[mtrcKey][evalKey][1])
del tmpDict
logging.info(" found %d relevant docs for %d (metric,time-bins)" %
(cnt_docs, cnt_mtrc))
#
return
def metrics(self):
"""function to return list of FTS metrics in the object inventory"""
# ############################################################# #
# metrics are returned sorted by metric name (15m/1h/6h/1d) and #
# time-bin #
# ############################################################# #
return sorted( self.mtrc.keys(),
key=lambda m: FTSmetric.metric_order(m) )
def evaluations(self, metric=None):
"""function to return a list of the evaluations for a metric tuple"""
# ################################################################# #
# metric is a tuple of metric-name and time-bin: ("fts1day", 16954) #
# ################################################################# #
if (( metric is None ) and ( len(self.mtrc) == 1 )):
metric = next(iter( self.mtrc.keys() ))
#
return self.mtrc[ metric ]
def links(self, metric=None):
"""function to return a list of links in the metric of the object"""
# ################################################################# #
# metric is a tuple of metric-name and time-bin: ("fts1day", 16954) #
# ################################################################# #
if (( metric is None ) and ( len(self.mtrc) == 1 )):
metric = next(iter( self.mtrc.keys() ))
#
return [ e['name'] for e in self.mtrc[metric] \
if ( e['type'] == "link" ) ]
def sites(self, metric=None):
"""function to return a list of sites in the metric of the object"""
# ################################################################# #
# metric is a tuple of metric-name and time-bin: ("fts1day", 16954) #
# ################################################################# #
if (( metric is None ) and ( len(self.mtrc) == 1 )):
metric = next(iter( self.mtrc.keys() ))
#
return [ e['name'] for e in self.mtrc[metric] \
if ( e['type'] == "site" ) ]
def status(self, metric, name, clss):
"""function to return the status of a link/source/destination/site"""
# ################################################################# #
# metric is a tuple of metric-name and time-bin: ("fts1day", 16954) #
# name is a site (Tn_CC_*), source (*.*.*), destination (*.*.*), or #
# link (*.*.*___*.*.*),(*.*.*___PROTOCOL___*.*.*) name #
# clss is site, source, destination, or link #
# return value is the status of the evaluation or None #
# ###################################################################
if (( metric is None ) and ( len(self.mtrc) == 1 )):
metric = next(iter( self.mtrc.keys() ))
#
for entry in self.mtrc[metric]:
if (( entry['name'] == name ) and ( entry['type'] == clss )):
return entry['status']
#
return "unknown"
def get1entry(self, metric, name, clss):
"""return the entry of a link/source/destination/site evaluation"""
# ################################################################# #
# metric is a tuple of metric-name and time-bin: ("fts1day", 16954) #
# name is a site (Tn_CC_*), source (*.*.*), destination (*.*.*), or #
# link (*.*.*___*.*.*),(*.*.*___PROTOCOL___*.*.*) name #
# clss is site, source, destination, or link #
# return value is the evaluation dictionary {'name':,'status':,...} #
# ###################################################################
if (( metric is None ) and ( len(self.mtrc) == 1 )):
metric = next(iter( self.mtrc.keys() ))
#
for entry in self.mtrc[metric]:
if (( entry['name'] == name ) and ( entry['type'] == clss )):
return entry
#
raise KeyError("No such entry %s / %s in (%s,%d)" % (name, clss,
metric[0], metric[1]))
def add1metric(self, metric, data=None):
"""function to add an additional FTS metric to the object inventory"""
if metric[0] not in FTSmetric.interval():
raise ValueError("metric %s is not a valid FTS metric name" %
str(metric[0]))
#
if metric not in self.mtrc:
if data is not None:
self.mtrc[metric] = data
else:
self.mtrc[metric] = []
elif data is not None:
self.mtrc[metric].extend( data )
return
def add1entry(self, metric, entry):
"""function to add an additional link/site entry to a metric"""
linkRegex = re.compile(r"^(([a-z0-9\-]+)\.)+[a-z0-9\-]+___([A-Z]+___)*(([a-z0-9\-]+)\.)+[a-z0-9\-]+$")
hostRegex = re.compile(r"^(([a-z0-9\-]+)\.)+[a-z0-9\-]+$")
siteRegex = re.compile(r"T\d_[A-Z]{2,2}_\w+")
#
# check entry has mandatory keys:
if (( 'name' not in entry ) or ( 'type' not in entry ) or
( 'status' not in entry )):
raise ValueError("Mandatory keys missing in entry %s" %
str(entry))
#
entry = entry.copy()
if (( entry['type'] == "link" ) or
( entry['type'] == "GSIFTP-link" ) or
( entry['type'] == "WEBDAV-link" ) or
( entry['type'] == "XROOTD-link" )):
if ( linkRegex.match( entry['name'] ) is None ):
raise ValueError("Illegal link name %s" % entry['name'])
entry['name'] = entry['name'].lower()
elif (( entry['type'] == "source" ) or
( entry['type'] == "destination" ) or
( entry['type'] == "GSIFTP-source" ) or
( entry['type'] == "GSIFTP-destination" ) or
( entry['type'] == "WEBDAV-source" ) or
( entry['type'] == "WEBDAV-destination" ) or
( entry['type'] == "XROOTD-source" ) or
( entry['type'] == "XROOTD-destination" )):
if ( hostRegex.match( entry['name'] ) is None ):
raise ValueError("Illegal source/destination name %s" %
entry['name'])
entry['name'] = entry['name'].lower()
elif (( entry['type'] == "rse" ) or
( entry['type'] == "site" )):
if ( siteRegex.match( entry['name'] ) is None ):
raise ValueError("Illegal RSE/site name %s" % entry['name'])
else:
raise ValueError("Illegal type \"%s\" of name \"%s\"" %
(entry['type'], entry['name']))
#
if 'quality' not in entry:
entry['quality'] = None
if 'detail' not in entry:
entry['detail'] = None
elif ( entry['detail'] == "" ):
entry['detail'] = None
#
self.mtrc[metric].append( entry )
#
return
def del1metric(self, metric):
"""function to remove an evaluation metric from the object inventory"""
# ################################################################### #
del self.mtrc[metric]
def del1entry(self, metric, entry):
"""function to remove a link/.../site evaluation entry from a metric"""
# ################################################################### #
self.mtrc[metric].remove( entry )
def compose_json(self):
"""function to extract a FTS-evaluations into a JSON string"""
# ############################################################ #
# compose a JSON string from the FTS evaluations in the object #
# ############################################################ #
jsonString = "["
commaFlag = False
#
for metric in self.metrics():
#
interval = FTSmetric.interval( metric[0] )
timestamp = ( interval * metric[1] ) + int( interval / 2 )
hdrString = (",\n {\n \"producer\": \"cmssst\",\n" +
" \"type\": \"ssbmetric\",\n" +
" \"monit_hdfs_path\": \"%s\",\n" +
" \"timestamp\": %d000,\n" +
" \"type_prefix\": \"raw\",\n" +
" \"data\": {\n") % (metric[0], timestamp)
#
for type in ["link", "GSIFTP-link", "WEBDAV-link", "XROOTD-link",
"source", "destination",
"GSIFTP-source", "GSIFTP-destination",
"WEBDAV-source", "WEBDAV-destination",
"XROOTD-source", "XROOTD-destination",
"rse", "site"]:
tmpDict = {e['name']:e for e in self.mtrc[metric] \
if ( e['type'] == type ) }
logging.log(15, "Composing %d %s for %d" % (len(tmpDict), type,
timestamp))
#
for name in sorted( tmpDict.keys() ):
if commaFlag:
jsonString += hdrString
else:
jsonString += hdrString[1:]
jsonString += ((" \"name\": \"%s\",\n" +