@@ -15,26 +15,16 @@ import shutil
1515import logging
1616from urlparse import urlparse
1717
18-
18+ main_redirector = "root://redirector.osgstorage.org"
19+ stash_origin = "root://stash.osgconnect.net"
1920
2021TIMEOUT = 300
2122DIFF = TIMEOUT * 10
2223
2324
2425def doStashCpSingle (sourceFile , destination , cache , debug = False ):
2526
26- logging .debug ("Checking size of file." )
27- (xrdfs_stdout , xrdfs_stderr ) = subprocess .Popen (["xrdfs" , "root://stash.osgconnect.net" , "stat" , sourceFile ], stdout = subprocess .PIPE ).communicate ()
28- xrdcp_version = subprocess .Popen (['echo $(xrdcp -V 2>&1)' ], stdout = subprocess .PIPE , shell = True ).communicate ()[0 ][:- 1 ]
29- try :
30- fileSize = int (re .findall (r"Size: \d+" , xrdfs_stdout )[0 ].split (": " )[1 ])
31- except Exception as e :
32- sys .stderr .write ("Unable to find size of file\n " )
33- print str (xrdfs_stdout )
34- sys .stderr .write (str (xrdfs_stderr ))
35- sys .stderr .write ("\n " )
36- return 1
37- logging .debug ("Size of the file %s is %s" , sourceFile , str (fileSize ))
27+
3828 #cache=get_best_stashcache()
3929 logging .debug ("Using Cache %s" , cache )
4030
@@ -44,8 +34,7 @@ def doStashCpSingle(sourceFile, destination, cache, debug=False):
4434 filename = destination + '/' + sourceFile .split ('/' )[- 1 ]
4535
4636 payload = {}
47- payload ['xrdcp_version' ] = xrdcp_version
48- payload ['filesize' ] = fileSize
37+
4938 payload ['filename' ] = sourceFile
5039 payload ['sitename' ] = sitename
5140 payload .update (parse_job_ad ())
@@ -66,12 +55,14 @@ def doStashCpSingle(sourceFile, destination, cache, debug=False):
6655 logging .debug ("Succesfully copied file from CVMFS!" )
6756 end1 = int (time .time ()* 1000 )
6857 dlSz = os .stat (destination ).st_size
58+ filesize = os .stat (cvmfs_file ).st_size
6959 dltime = end1 - start1
7060 destSpace = 1
7161 status = 'Success'
7262 payload ['timestamp' ]= end1
7363 payload ['host' ]= "CVMFS"
7464 payload ['download_size' ]= dlSz
65+ payload ['filesize' ] = filesize
7566 payload ['download_time' ]= dltime
7667 payload ['destination_space' ]= destSpace
7768 payload ['status' ]= status
@@ -89,6 +80,23 @@ def doStashCpSingle(sourceFile, destination, cache, debug=False):
8980 else :
9081 logging .debug ("CVMFS File does not exist" )
9182
83+ # Now check the size of the file with xrootd
84+ logging .debug ("Checking size of file." )
85+ (xrdfs_stdout , xrdfs_stderr ) = subprocess .Popen (["xrdfs" , main_redirector , "stat" , sourceFile ], stdout = subprocess .PIPE ).communicate ()
86+ xrdcp_version = subprocess .Popen (['echo $(xrdcp -V 2>&1)' ], stdout = subprocess .PIPE , shell = True ).communicate ()[0 ][:- 1 ]
87+ try :
88+ fileSize = int (re .findall (r"Size: \d+" , xrdfs_stdout )[0 ].split (": " )[1 ])
89+ except Exception as e :
90+ sys .stderr .write ("Unable to find size of file\n " )
91+ print str (xrdfs_stdout )
92+ sys .stderr .write (str (xrdfs_stderr ))
93+ sys .stderr .write ("\n " )
94+ return 1
95+ logging .debug ("Size of the file %s is %s" , sourceFile , str (fileSize ))
96+
97+ payload ['xrdcp_version' ] = xrdcp_version
98+ payload ['filesize' ] = fileSize
99+
92100 end1 = int (time .time ()* 1000 )
93101 payload ['end1' ]= end1
94102 payload ['start1' ]= start1
@@ -123,8 +131,8 @@ def doStashCpSingle(sourceFile, destination, cache, debug=False):
123131 es_send (payload )
124132
125133 else : #pull from origin
126- logging .warning ("XrdCP from cache failed on %s, pulling from origin " , cache )
127- cache = "root://stash.osgconnect.net"
134+ logging .warning ("XrdCP from cache failed on %s, pulling from main redirector " , cache )
135+ cache = main_redirector
128136 start3 = int (time .time ()* 1000 )
129137 xrd_exit = timed_transfer (filename = sourceFile , debug = debug , cache = cache , destination = destination )
130138 end3 = int (time .time ()* 1000 )
@@ -179,9 +187,9 @@ def parse_job_ad():
179187 return temp_list
180188
181189def dostashcpdirectory (sourceDir , destination , cache , debug = False ):
182- sourceItems = subprocess .Popen (["xrdfs" , "root://stash.osgconnect.net" , "ls" , sourceDir ], stdout = subprocess .PIPE ).communicate ()[0 ].split ()
190+ sourceItems = subprocess .Popen (["xrdfs" , stash_origin , "ls" , sourceDir ], stdout = subprocess .PIPE ).communicate ()[0 ].split ()
183191 for remote_file in sourceItems :
184- command2 = 'xrdfs root://stash.osgconnect.net stat ' + remote_file + ' | grep "IsDir" | wc -l'
192+ command2 = 'xrdfs ' + stash_origin + ' stat '+ remote_file + ' | grep "IsDir" | wc -l'
185193 isdir = subprocess .Popen ([command2 ],stdout = subprocess .PIPE ,shell = True ).communicate ()[0 ].split ()[0 ]
186194 if isdir != '0' :
187195 result = dostashcpdirectory (remote_file , destination , cache , debug )
0 commit comments