forked from PanDAWMS/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalSiteMover.py
905 lines (766 loc) · 38.4 KB
/
LocalSiteMover.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
#!/usr/bin/env python
# Copyright European Organization for Nuclear Research (CERN)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Authors:
# - Wen Guan, <[email protected]>, 2014
import os, re
import commands
from time import time
from TimerCommand import TimerCommand
import SiteMover
from futil import *
from PilotErrors import PilotErrors
from pUtil import tolog, readpar, verifySetupCommand, getSiteInformation, extractFilePaths, getExperiment
from FileStateClient import updateFileState
from SiteInformation import SiteInformation
class LocalSiteMover(SiteMover.SiteMover):
""" SiteMover that uses lsm for both get and put """
# no registration is done
copyCommand = "lsm"
realCopyCommand = "lsm-get"
checksum_command = "adler32"
timeout = 3600
__warningStr = '!!WARNING!!2995!! %s'
__spacetoken = '-t %s' # space token descriptor
__localget = '%s lsm-get %s %s %s' # environment, options, lfn, target directory
__localput = '%s lsm-put %s %s %s' # environment, space token (optional), source directory, destination
__localputBAD = '%s lsm-put %s %s %s' # environment, space token (optional), source directory, destination
__localspace = '%s lsm-df %s %s' # environment, space token (optional), storage end-point
__par_filesize = ' --size %s' # filesize in bytes
__par_checksum = ' --checksum %s' # checksum string: "adler32:NNN", "md5:NNN", default is assumed MD5
__timeout = 5400 # seconds
__error = PilotErrors()
__pilotErrorDiag = ''
def __init__(self, setup_path, *args, **kwrds):
self._setup = setup_path.strip()
self.__isSetuped = False
self._defaultSetup = None
def get_timeout(self):
return self.timeout
def log(self, errorLog):
tolog(errorLog)
def getSetup(self):
""" Return the setup string (pacman setup os setup script) for the copy command used by the mover """
_setup_str = ""
self._setup = self._setup.strip()
tolog("self setup: %s" % self._setup)
if self._setup and self._setup != "" and self._setup.strip() != "":
if not self._setup.endswith(";"):
self._setup += ";"
if not "alias" in self._setup:
if "atlasLocalSetup.sh" in self._setup and "--quiet" not in self._setup:
self._setup = self._setup.replace("atlasLocalSetup.sh", "atlasLocalSetup.sh --quiet")
if self._setup.startswith("export") or self._setup.startswith("source"):
_setup_str = "%s" % self._setup
else:
_setup_str = "source %s" % self._setup
else:
_setup_str = self._setup
if _setup_str != "":
tolog("Using setup: %s" % (_setup_str))
return _setup_str
def verifySetupCommand(self, _setupStr):
""" Make sure the setup command exists """
statusRet = 0
outputRet={}
outputRet["errorLog"] = None
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
# remove any '-signs
_setupStr = _setupStr.replace("'", "")
self.log("Will verify: %s" % (_setupStr))
if _setupStr != "" and "source " in _setupStr:
# first extract the file paths from the source command(s)
setupPaths = extractFilePaths(_setupStr)
# only run test if string begins with an "/"
if setupPaths:
# verify that the file paths actually exists
for setupPath in setupPaths:
if "-" in setupPath:
continue
if os.path.exists(setupPath):
self.log("File %s has been verified" % (setupPath))
else:
outputRet["errorLog"] = errorLog = "No such file or directory: %s" % (setupPath)
self.log('!!WARNING!!2991!! %s' % (errorLog))
statusRet = PilotErrors.ERR_NOSUCHFILE
break
else:
# nothing left to test
pass
else:
self.log("Nothing to verify in setup: %s (either empty string or no source command)" % (_setupStr))
return statusRet, outputRet
def verifySetupProxy(self, _setupStr, experiment):
#check do we have a valid proxy
# get the experiment object
thisExperiment = getExperiment(experiment)
status, output = thisExperiment.verifyProxy(envsetup=_setupStr)
return status, output
def verifySetup(self, _setupStr, experiment, proxycheck=True):
statusRet, outputRet = self.verifySetupCommand(_setupStr)
if statusRet != 0:
#self.prepareReport('RFCP_FAIL', self._variables['report'])
outputRet["report"]["clientState"] = "RFCP_FAIL"
return statusRet, outputRet
command = _setupStr
if command != "" and not command.endswith(';'):
command = command + ";"
command += " which " + self.realCopyCommand
status, output = commands.getstatusoutput(command)
self.log("Execute command: %s" % command)
self.log("Status: %s, Output: %s" % (status, output))
if status != 0:
self.log(self.copyCommand +" is not found in envsetup: " + _setupStr)
#self.prepareReport('RFCP_FAIL', self._variables['report'])
outputRet["report"]["clientState"] = "RFCP_FAIL"
outputRet["errorLog"] = output
return status, outputRet
if proxycheck:
status, outputLog = self.verifySetupProxy(_setupStr, experiment)
if status != 0:
outputRet["errorLog"] = outputLog
outputRet["report"]["clientState"] = 'PROXYFAIL'
return status, outputRet
return status, outputRet
def setup(self, experiment):
""" setup env """
if self.__isSetuped:
return 0, None
thisExperiment = getExperiment(experiment)
self.useTracingService = thisExperiment.useTracingService()
_setupStr = self.getSetup()
# get the user proxy if available
envsetupTest = _setupStr.strip()
if envsetupTest != "" and not envsetupTest.endswith(';'):
envsetupTest += ";"
if os.environ.has_key('X509_USER_PROXY'):
envsetupTest += " export X509_USER_PROXY=%s;" % (os.environ['X509_USER_PROXY'])
self.log("to verify site setup: %s " % envsetupTest)
status, output = self.verifySetup(envsetupTest, experiment)
self.log("site setup verifying: status: %s, output: %s" % (status, output["errorLog"]))
if status == 0:
self._setup = envsetupTest
self.__isSetuped = True
return status, output
else:
if self._defaultSetup:
#try to use default setup
self.log("Try to use default envsetup")
envsetupTest = self._defaultSetup.strip()
if envsetupTest != "" and not envsetupTest.endswith(';'):
envsetupTest += ";"
if os.environ.has_key('X509_USER_PROXY'):
envsetupTest += " export X509_USER_PROXY=%s;" % (os.environ['X509_USER_PROXY'])
self.log("verify default setup: %s " % envsetupTest)
status, output = self.verifySetup(envsetupTest, experiment)
self.log("default setup verifying: status: %s, output: %s" % (status, output["errorLog"]))
if status == 0:
self._setup = envsetupTest
self.__isSetuped = True
return status, output
return status, output
def fixStageInPath(self, path):
"""Fix the path"""
if path[:3] == "srm" and '?SFN=' in path:
self.log("Found SFN part in file path: %s" % (path))
elif path[:3] == "srm":
try:
hostname = path.split('/',3)[2]
except Exception as e:
self.log("'!!WARNING!!2999!! Could not extract srm protocol for replacement, keeping path variable as it is: %s (%s)' %\
(path, str(e))")
else:
# srm = 'srm://head01.aglt2.org'
srm = 'srm://' + hostname
# does seopt contain any matching srm's?
sematch = self.getSEMatchFromSEOpt(srm)
if sematch != "":
path = path.replace(srm, sematch)
self.log("Replaced %s with %s (from seopt) in path: %s" % (srm, sematch, path))
else:
se = readpar('se').split(",")[0]
_dummytoken, se = self.extractSE(se)
tolog("Using SE: %s" % (se))
path = path.replace(srm, se)
self.log("Replaced %s with %s (from se) in path: %s" % (srm, se, path))
# add port number from se to getfile if necessary
path = self.addPortToPath(se, path)
return path
def getStageInMode(self, lfn, prodDBlockToken, transferType):
# should the root file be copied or read directly by athena?
status = 0
output={}
output["errorLog"] = None
output["report"] = {}
output["report"]["clientState"] = None
output["transfer_mode"] = None
isRootFileName = self.isRootFileName(lfn)
siteInformation = SiteInformation()
directIn, transfer_mode = siteInformation.getDirectInAccessMode(prodDBlockToken, isRootFileName, transferType)
if transfer_mode:
output["transfer_mode"] = transfer_mode
if directIn:
output["report"]["clientState"] = 'FOUND_ROOT'
output["report"]['relativeStart'] = None
output["report"]['transferStart'] = None
return PilotErrors.ERR_DIRECTIOFILE, output
return 0, output
def stageInFile(self, source, destination, sourceSize, sourceChecksum, guid=None):
"""StageIn the file. should be implementated by different site mover."""
statusRet = 0
outputRet = {}
outputRet["errorLog"] = None
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
# build the parameters
_params = ""
if sourceSize != 0 and sourceSize != "0":
_params += self.__par_filesize % (sourceSize)
if sourceChecksum and sourceChecksum != 'None' and sourceChecksum != 0 and sourceChecksum != "0" and not self.isDummyChecksum(sourceChecksum):
csumtype = self.getChecksumType(sourceChecksum)
# special case for md5sum (command only understands 'md5' and 'adler32', and not 'ad' and 'md5sum')
if csumtype == 'md5sum':
csumtype = 'md5'
_params += self.__par_checksum % ("%s:%s" % (csumtype, sourceChecksum),)
# add the guid option
_params += " --guid %s" % (guid)
self.log("StageIn files started.")
_cmd_str = self.__localget % (self._setup, _params, source, destination)
self.log('Executing command: %s' % (_cmd_str))
s = -1
o = '(not defined)'
t0 = os.times()
outputRet["report"]['relativeStart'] = time()
outputRet["report"]['transferStart'] = time()
try:
timerCommand = TimerCommand(_cmd_str)
s, o = timerCommand.run(timeout=self.timeout)
except Exception, e:
tolog("!!WARNING!!2990!! Exception caught by stageInFile(): %s" % (str(e)))
o = str(e)
t1 = os.times()
t = t1[4] - t0[4]
self.log("Command finished after %f s: %s" % (t, o.replace('\n', ' ')))
if s == 0:
self.log("Stagein succeeded")
else:
self.log("!!WARNING!!2990!! Command failed: %s" % (_cmd_str))
o = o.replace('\n', ' ')
#check_syserr(s, o)
self.log("!!WARNING!!2990!! get_data failed. Status=%s Output=%s" % (s, str(o)))
# remove the local file before any get retry is attempted
_status = self.removeLocal(destination)
if not _status:
self.log("!!WARNING!!1112!! Failed to remove local file, get retry will fail")
status, output = self.errorToReport(o, t, source, stageMethod="stageIN")
return status, output
#outputRet["report"]["clientState"] = "DONE"
return statusRet, outputRet
def verifyStageIN(self, sourceFile, sourceSize, sourceChecksum, destFile):
"""Verify file stagin successfull"""
statusRet = 0
outputRet={}
outputRet["errorLog"] = None
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
outputRet["report"]['validateStart'] = time()
self.log("Verify file Staging: source: %s, sourceSize: %s, sourceChecksum: %s, destFile: %s" % (sourceFile, sourceSize, sourceChecksum, destFile))
if sourceChecksum == 0 and sourceSize ==0:
return statusRet, outputRet
# get the checksum type (md5sum or adler32)
if sourceChecksum != 0 and sourceChecksum != "":
csumtype = self.getChecksumType(sourceChecksum)
else:
csumtype = "default"
self.log("Getting destination file(%s) information." % destFile)
status, output = self.getLocalFileInfo(destFile, checksumType=csumtype)
if status != 0:
self.log("Failed to get local file information")
outputRet["report"]["clientState"] = "FILE_INFO_FAIL"
outputRet["errorLog"] = output["errorLog"]
_status = self.removeLocal(destFile)
self.log("Remove local file.")
if not _status:
self.log("!!WARNING!!1112!! Failed to remove local file, get retry will fail")
return status, outputRet
destSize = output["size"]
destChecksum = output["checksum"]
self.log("Destination file information: file: %s, size: %s, checksum: %s" % (destFile, destSize, destChecksum))
# compare remote and local file size
if long(sourceSize) != 0 and long(destSize) != long(sourceSize):
errorLog = "Remote and local file sizes do not match for %s (%s != %s)" %\
(os.path.basename(sourceFile), str(destSize), str(sourceSize))
self.log("!!WARNING!!2990!! %s" % (errorLog))
outputRet["errorLog"] = errorLog
outputRet["report"]["clientState"] = "WRONG_SIZE"
status = self.removeLocal(destFile)
if not status:
self.log("!!WARNING!!1112!! Failed to remove local file, get retry will fail")
return PilotErrors.ERR_GETWRONGSIZE, outputRet
# compare remote and local file checksum
if sourceChecksum and str(destChecksum) != str(sourceChecksum) and not self.isDummyChecksum(sourceChecksum):
outputRet["errorLog"] = errorLog = "Remote and local checksums (of type %s) do not match for %s (%s != %s)" %\
(csumtype, os.path.basename(sourceFile), destChecksum, sourceChecksum)
self.log("!!WARNING!!2990!! %s" % (errorLog))
# remove the local file before any get retry is attempted
_status = self.removeLocal(destFile)
if not _status:
self.log("!!WARNING!!1112!! Failed to remove local file, get retry will fail")
if csumtype == "adler32":
outputRet["report"]["clientState"] = "AD_MISMATCH"
return PilotErrors.ERR_GETADMISMATCH, outputRet
else:
outputRet["report"]["clientState"] = "MD5_MISMATCH"
return PilotErrors.ERR_GETMD5MISMATCH, outputRet
self.log("Verify staging done.")
outputRet["report"]["clientState"] = "DONE"
return statusRet, outputRet
def stageIn(self, source, destination, sourceSize, sourceChecksum, experiment):
"""Stage in the source file"""
statusRet = 0
outputRet ={}
outputRet["errorLog"] = None
outputRet["report"] = None
status, output = self.setup(experiment)
if status !=0:
statusRet = status
outputRet["errorLog"] = output["errorLog"]
outputRet["report"] = output["report"]
return statusRet, outputRet
source = self.fixStageInPath(source)
status, output = self.stageInFile(source, destination, sourceSize, sourceChecksum)
if status != 0:
statusRet = status
outputRet["errorLog"] = output["errorLog"]
outputRet["report"] = output["report"]
return statusRet, outputRet
#For Local Site Mover, verification is done by lsm. Do checksum again to no checksum in lsm-get
status, output = self.verifyStageIN(source, sourceSize, sourceChecksum, destination)
statusRet = status
outputRet["errorLog"] = output["errorLog"]
outputRet["report"] = output["report"]
return statusRet, outputRet
def getLocalFileInfo(self, fileName, checksumType="default", date=None):
""" Return exit code (0 if OK), file size and checksum of a local file, as well as as date string if requested """
# note that date is mutable
statusRet = 0
outputRet = {}
outputRet["errorLog"] = ""
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
outputRet["size"] = 0
outputRet["checksum"] = ""
outputRet["checksumType"] = checksumType
self.log("Getting local File(%s) info." % fileName)
# does the file exist?
if not os.path.isfile(fileName):
if fileName.find("DBRelease") >= 0 and os.path.exists(os.path.dirname(fileName)):
outputRet["errorLog"] = errorLog = "DBRelease file missing: %s" % (fileNameame)
self.log("!!WARNING!!2999!! %s" % (errorLog))
return PilotErrors.ERR_MISSDBREL, outputRet
else:
outputRet["errorLog"] = errorLog = "No such file or directory: %s" % (fileName)
self.log("!!WARNING!!2999!! %s" % (errorLog))
return PilotErrors.ERR_MISSINGLOCALFILE, outputRet
# get the modification time if needed and store it in the mutable object
if date:
date = SiteMover.getModTime(os.path.dirname(fileName), os.path.basename(fileName))
# get the file size
try:
self.log("Executing getsize() for file: %s" % (fileName))
outputRet["size"] = fsize = str(os.path.getsize(fileName))
except OSError, e:
outputRet["errorLog"] = errorLog = "Could not get file size: %s" % str(e)
tolog("!!WARNING!!2999!! %s" % (errorLog))
return PilotErrors.ERR_FAILEDSIZELOCAL, outputRet
else:
if fsize == "0":
outputRet["errorLog"] = errorLog = "Encountered zero file size for file %s" % (fileName)
self.log("!!WARNING!!2999!! %s" % (errorLog))
return PilotErrors.ERR_ZEROFILESIZE, outputRet
else:
self.log("Got file size: %s" % (fsize))
# get the checksum
if checksumType == "adler32" or checksumType == "default":
self.log("Executing adler32() for file: %s" % (fileName))
outputRet["checksum"] = fchecksum = SiteMover.SiteMover.adler32(fileName)
if fchecksum == '00000001': # "%08x" % 1L
outputRet["errorLog"] = errorLog = "Adler32 failed (returned 1)"
self.log("!!WARNING!!2999!! %s" % (errorLog))
return PilotErrors.ERR_FAILEDADLOCAL, outputRet
else:
self.log("Got adler32 checksum: %s" % (fchecksum))
else:
_cmd = '%s %s' % (CMD_CHECKSUM, fileName)
self.log("Executing command: %s" % (_cmd))
try:
s, o = commands.getstatusoutput(_cmd)
except Exception, e:
s = -1
o = str(e)
self.log("!!WARNING!!2999!! Exception caught in getstatusoutput: %s" % (o))
if s != 0:
o = o.replace('\n', ' ')
check_syserr(s, o)
outputRet["errorLog"] = errorLog = "Error running checksum command (%s): %s" % (CMD_CHECKSUM, o)
self.log("!!WARNING!!2999!! %s" % (errorLog))
return PilotErrors.ERR_FAILEDMD5LOCAL, outputRet
outputRet["checksum"] = fchecksum = o.split()[0]
self.log("Got checksum: %s" % (fchecksum))
return 0, outputRet
def stageOutFile(self, source, destination, sourceSize, sourceChecksum, checksumType, guid, token=None):
"""Stage out the file. Should be implementated by different site mover"""
statusRet = 0
outputRet = {}
outputRet["errorLog"] = None
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
# build the parameters
_params = ""
if token:
# Special case for GROUPDISK (do not remove dst: bit before this stage, needed in several places)
if "dst:" in token:
token = token[len('dst:'):]
tolog("Dropped dst: part of space token descriptor; token=%s" % (token))
if 'DATADISK' in token:
token = "ATLASDATADISK"
else:
token = "ATLASGROUPDISK"
tolog("Space token descriptor reset to: %s" % (token))
_params = self.__spacetoken % (token)
if sourceSize != 0 and sourceSize != "0":
_params += self.__par_filesize % (sourceSize)
if sourceChecksum:
_params += self.__par_checksum % ("%s:%s" % (checksumType, sourceChecksum),)
# add the guid option
_params += " --guid %s" % (guid)
if ".log." in destination:
_cmd_str = self.__localput % (self._setup, _params, source, destination)
else:
_cmd_str = self.__localputBAD % (self._setup, _params, source, destination)
tolog("Executing command: %s" % (_cmd_str))
ec = -1
t0 = os.times()
o = '(not defined)'
outputRet["report"]['relativeStart'] = time()
outputRet["report"]['transferStart'] = time()
try:
timerCommand = TimerCommand(_cmd_str)
ec, o = timerCommand.run(timeout=self.timeout)
except Exception, e:
tolog("!!WARNING!!2999!! gfal-copy threw an exception: %s" % (o))
o = str(e)
outputRet["report"]['validateStart'] = time()
t1 = os.times()
t = t1[4] - t0[4]
tolog("Command finished after %f s" % (t))
tolog("ec = %d, output = %s" % (ec, o.replace("\n"," ")))
if ec != 0:
tolog("!!WARNING!!2990!! Command failed: %s" % (_cmd_str))
#check_syserr(ec, o)
tolog('!!WARNING!!2990!! Stage Out failed: Status=%d Output=%s' % (ec, str(o.replace("\n"," "))))
status, output = self.errorToReport(o, t, source, stageMethod="stageOut")
if status == PilotErrors.ERR_FILEEXIST:
return status, output
# for local site mover, don't remove files
## check if file was partially transferred, if so, remove it
#_ec, removeOutput = self.removeRemoteFile(destination)
#if not _ec :
# self.log("Failed to remove file ") # i.e. do not retry stage-out
return status, output
return statusRet, outputRet
def getRemoteFileChecksum(self, full_surl, checksumType):
""" get checksum with gfal-sum command """
remote_checksum = None
output = None
errorLog = "LocalSiteMover has no function getRemoteFileChecksum"
self.log('!!WARNING!!2999!! %s' % (errorLog))
return remote_checksum
def getRemoteFileSize(self, full_surl):
""" extract checksum and file size from gfal-ls output """
errorLog = "LocalSiteMover has no function getRemoteFileSize"
self.log('!!WARNING!!2999!! %s' % (errorLog))
remote_fsize = None
return remote_fsize
def verifyStageOut(self, sourceFile, sourceSize, sourceChecksum, checksumType, destFile):
"""Verify file stagout successfull"""
statusRet = 0
outputRet = {}
outputRet["errorLog"] = None
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
outputRet["verified"] = False
self.log("verifying stageout")
status, output = self.getRemoteFileInfo(destFile, checksumType)
errorLog = output["errorLog"]
destSize = output["size"]
destChecksum = output["checksum"]
destChecksumType = output["checksumType"]
self.log("Remote checksum: %s" % str(destChecksum))
self.log("Local checksum: %s" % str(sourceChecksum))
if status == 0:
if destChecksum:
if str(sourceChecksum) != str(destChecksum):
outputRet["errorLog"] = errorLog = "Remote and local checksums (of type %s) do not match for %s (%s != %s)" %\
(checksumType, os.path.basename(destFile), destChecksum, sourceChecksum)
self.log("!!WARNING!!1800!! %s" % (errorLog))
if checksumType == "adler32":
outputRet["report"]["clientState"] = 'AD_MISMATCH'
return PilotErrors.ERR_PUTADMISMATCH, outputRet
else:
outputRet["report"]["clientState"] = 'MD5_MISMATCH'
return PilotErrors.ERR_PUTMD5MISMATCH, outputRet
else:
self.log("Remote and local checksums verified")
outputRet["verified"] = verified = True
else:
# if the checksum could not be verified (as is the case for non-dCache sites) test the file size instead
if destSize:
self.log("Local file size: %s" % (sourceSize))
if destSize and destSize != "" and sourceSize != "" and sourceSize:
if sourceSize != destSize:
outputRet["errorLog"] = errorLog = "Remote and local file sizes do not match for %s (%s != %s)" %\
(sourceFile, str(destSize), str(sourceSize))
self.log('!!WARNING!!2999!! %s' % (errorLog))
outputRet['report']["clientState"] = 'FS_MISMATCH'
return PilotErrors.ERR_PUTWRONGSIZE, outputRet
else:
self.log("Remote and local file sizes verified")
outputRet['verified'] = True
else:
self.log("Skipped file size test")
else:
self.log("Failed to get Remote file information: %s" % ())
if outputRet['verified'] != True:
# fail at this point
outputRet["errorLog"] = errorLog = "Neither checksum nor file size could be verified (failing job)"
self.log('!!WARNING!!2999!! %s' % (errorLog))
outputRet['report']["clientState"] = 'NOFILEVERIFICATION'
return PilotErrors.ERR_NOFILEVERIFICATION, outputRet
self.log("verifying stageout done.")
outputRet["report"]["clientState"] = "DONE"
return statusRet, outputRet
def removeRemoteFile(self, full_surl):
errorLog = "LocalSiteMover has no function removeRemoteFile"
self.log('!!WARNING!!2999!! %s' % (errorLog))
return 0, None
def getRemoteFileInfo(self, destFile, checksumType):
""" Get Remote file info. Should be implementated by different site mover"""
status = 0
outputRet = {}
outputRet["errorLog"] = None
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
outputRet["size"] = None
outputRet["checksum"] = None
outputRet["checksumType"] = checksumType
checksum = None
fileSize = None
checksum = self.getRemoteFileChecksum(destFile, checksumType)
if checksum == None:
fileSize = self.getRemoteFileSize(destFile)
outputRet["size"] = fileSize
outputRet["checksum"] = checksum
return status, outputRet
def stageOut(self, source, destination, token, guid, experiment):
"""Stage in the source file"""
statusRet = 0
outputRet ={}
outputRet["errorLog"] = None
outputRet["report"] = None
status, output = self.setup(experiment)
if status !=0:
statusRet = status
outputRet["errorLog"] = output["errorLog"]
outputRet["report"] = output["report"]
return statusRet, outputRet
status, output = self.getLocalFileInfo(source)
if status !=0:
statusRet = status
outputRet["errorLog"] = output["errorLog"]
outputRet["report"] = output["report"]
return statusRet, outputRet
sourceSize = output["size"]
sourceChecksum = output["checksum"]
checksumType = output["checksumType"]
if checksumType == "default":
checksumType = "adler32"
status, output = self.stageOutFile(source, destination, sourceSize, sourceChecksum, checksumType, guid, token)
statusRet = status
outputRet["errorLog"] = output["errorLog"]
outputRet["report"] = output["report"]
outputRet["size"] = sourceSize
outputRet["checksum"] = sourceChecksum
return statusRet, outputRet
# For Local Site Mover, verification is done by lsm
#status, output = self.verifyStageOut(source, sourceSize, sourceChecksum, checksumType, destination)
#statusRet = status
#outputRet["errorLog"] = output["errorLog"]
#outputRet["report"] = output["report"]
#outputRet["size"] = sourceSize
#outputRet["checksum"] = sourceChecksum
#return statusRet, outputRet
def get_data(self, gpfn, lfn, path, fsize=0, fchecksum=0, guid=0, **pdict):
""" copy input file from SE to local dir """
error = PilotErrors()
pilotErrorDiag = ""
# Get input parameters from pdict
jobId = pdict.get('jobId', '')
workDir = pdict.get('workDir', '')
experiment = pdict.get('experiment', '')
transferType = pdict.get('transferType', '')
proxycheck = pdict.get('proxycheck', False)
# try to get the direct reading control variable (False for direct reading mode; file should not be copied)
useCT = pdict.get('usect', True)
prodDBlockToken = pdict.get('access', '')
# get the Rucio tracing report
report = self.getStubTracingReport(pdict['report'], 'local', lfn, guid)
tolog("transferType=%s"%(transferType))
status, output = self.getStageInMode(lfn, prodDBlockToken, transferType)
tolog("output=%s" % str(output))
if output["transfer_mode"]:
updateFileState(lfn, workDir, jobId, mode="transfer_mode", state=output["transfer_mode"], ftype="input")
tolog("updated file state for lfn=%s, workDir=%s, jobId=%s, state=%s"%(lfn, workDir, jobId, output["transfer_mode"]))
if status !=0:
self.prepareReport(output["report"], report)
return status, output["errorLog"]
if path == '': path = './'
fullname = os.path.join(path, lfn)
status, output = self.stageIn(gpfn, fullname, fsize, fchecksum, experiment)
if status == 0:
updateFileState(lfn, workDir, jobId, mode="file_state", state="transferred", ftype="input")
self.prepareReport(output["report"], report)
return status, output["errorLog"]
def put_data(self, source, destination, fsize=0, fchecksum=0, **pdict):
""" copy output file from disk to local SE """
# function is based on dCacheSiteMover put function
error = PilotErrors()
pilotErrorDiag = ""
# Get input parameters from pdict
alt = pdict.get('alt', False)
lfn = pdict.get('lfn', '')
guid = pdict.get('guid', '')
token = pdict.get('token', '')
scope = pdict.get('scope', '')
dsname = pdict.get('dsname', '')
analysisJob = pdict.get('analJob', False)
testLevel = pdict.get('testLevel', '0')
extradirs = pdict.get('extradirs', '')
experiment = pdict.get('experiment', '')
proxycheck = pdict.get('proxycheck', False)
prodSourceLabel = pdict.get('prodSourceLabel', '')
# get the site information object
si = getSiteInformation(experiment)
tolog("put_data received prodSourceLabel=%s" % (prodSourceLabel))
if prodSourceLabel == 'ddm' and analysisJob:
tolog("Treating PanDA Mover job as a production job during stage-out")
analysisJob = False
# get the Rucio tracing report
report = self.getStubTracingReport(pdict['report'], 'local', lfn, guid)
filename = os.path.basename(source)
# get all the proper paths
ec, pilotErrorDiag, tracer_error, dst_gpfn, lfcdir, surl = si.getProperPaths(error, analysisJob, token, prodSourceLabel, dsname, filename, scope=scope, alt=alt, sitemover=self) # quick workaround
if ec != 0:
reportState = {}
reportState["clientState"] = tracer_error
self.prepareReport(reportState, report)
return self.put_data_retfail(ec, pilotErrorDiag)
# get the RSE from ToA
try:
_RSE = self.getRSE(surl=surl)
except Exception, e:
tolog("Warning: Failed to get RSE: %s (can not add this info to tracing report)" % str(e))
else:
report['localSite'], report['remoteSite'] = (_RSE, _RSE)
tolog("RSE: %s" % (_RSE))
if testLevel == "1":
source = "thisisjustatest"
status, output = self.stageOut(source, surl, token, guid, experiment)
if status !=0:
self.prepareReport(output["report"], report)
return self.put_data_retfail(status, output["errorLog"], surl)
reportState = {}
reportState["clientState"] = "DONE"
self.prepareReport(reportState, report)
return 0, pilotErrorDiag, surl, output["size"], output["checksum"], self.arch_type
def errorToReport(self, errorOutput, timeUsed, fileName, stageMethod='stageIN'):
status = 0
outputRet = {}
outputRet["errorLog"] = None
outputRet["report"] = {}
outputRet["report"]["clientState"] = None
if "File exists" in errorOutput or "SRM_FILE_BUSY" in errorOutput:
pilotErrorDiag = "File already exist in the destination."
tolog("!!WARNING!!2990!! %s" % (pilotErrorDiag))
#self.prepareReport('FILE_EXIST', report)
outputRet["report"]["clientState"] = 'FILE_EXIST'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_FILEEXIST, outputRet
elif "Could not establish context" in errorOutput:
pilotErrorDiag = "Could not establish context: Proxy / VO extension of proxy has probably expired"
tolog("!!WARNING!!2990!! %s" % (pilotErrorDiag))
#self.prepareReport('CONTEXT_FAIL', report)
outputRet["report"]["clientState"] = 'CONTEXT_FAIL'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_NOPROXY, outputRet
elif "globus_xio:" in errorOutput:
pilotErrorDiag = "Globus system error: %s" % (errorOuput)
self.log("Globus system error encountered")
#self.prepareReport('GLOBUS_FAIL', report)
outputRet["report"]["clientState"] = 'GLOBUS_FAIL'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_GETGLOBUSSYSERR, outputRet
elif "No space left on device" in errorOutput:
pilotErrorDiag = "No available space left on local disk: %s" % (errorOutput)
tolog("No available space left on local disk")
#self.prepareReport('NO_SPACE', report)
outputRet["report"]["clientState"] = 'NO_SPACE'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_NOLOCALSPACE, outputRet
elif "No such file or directory" in errorOutput:
if "DBRelease" in fileName:
pilotErrorDiag = "Missing DBRelease file: %s" % (fileName)
tolog("!!WARNING!!2990!! %s" % (pilotErrorDiag))
#self.prepareReport('NO_DBREL', report)
outputRet["report"]["clientState"] = 'NO_DBREL'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_MISSDBREL, outputRet
else:
pilotErrorDiag = "No such file or directory: %s" % (fileName)
tolog("!!WARNING!!2990!! %s" % (pilotErrorDiag))
#self.prepareReport('NO_FILE_DIR', report)
outputRet["report"]["clientState"] = 'NO_FILE'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_NOSUCHFILE, outputRet
else:
if timeUsed >= self.timeout:
pilotErrorDiag = "Copy command self timed out after %d s" % (timeUsed)
tolog("!!WARNING!!2990!! %s" % (pilotErrorDiag))
if stageMethod == "stageIN":
#self.prepareReport('GET_TIMEOUT', report)
outputRet["report"]["clientState"] = 'GET_TIMEOUT'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_GETTIMEOUT, outputRet
else:
#self.prepareReport('CP_TIMEOUT', report)
outputRet["report"]["clientState"] = 'CP_TIMEOUT'
outputRet["errorLog"] = pilotErrorDiag
return PilotErrors.ERR_PUTTIMEOUT, outputRet
else:
if len(errorOutput) == 0:
pilotErrorDiag = "Copy command returned error code but no output"
else:
pilotErrorDiag = errorOutput
#self.prepareReport('COPY_ERROR', report)
outputRet["report"]["clientState"] = 'COPY_ERROR'
outputRet["errorLog"] = pilotErrorDiag
if stageMethod == "stageIN":
return PilotErrors.ERR_STAGEINFAILED, outputRet
else:
return PilotErrors.ERR_STAGEOUTFAILED, outputRet