@@ -171,6 +171,9 @@ def doStashCpSingle(sourceFile, destination, debug=False):
171171
172172 else :
173173 logging .debug ("CVMFS File does not exist" )
174+
175+ if not check_for_xrootd ():
176+ return download_with_http (sourceFile , destination , debug )
174177
175178 # If the cache is not specified by the command line, then look for the closest
176179 if not nearest_cache :
@@ -265,6 +268,100 @@ def doStashCpSingle(sourceFile, destination, debug=False):
265268 return 1
266269 return 0
267270
271+ def check_for_xrootd ():
272+ """
273+ Check if xrootd is installed by checking if the xrdcp command returns a reasonable output
274+ """
275+ # xrdcp output the version on stderr, what?!?
276+ check_command = "xrdcp -V 2>&1"
277+ logging .debug ("Running the command to check of xrdcp existance: %s" , check_command )
278+ command_object = subprocess .Popen ([check_command ], stdout = subprocess .PIPE , shell = True )
279+ xrdcp_version = command_object .communicate ()[0 ]
280+ if command_object .returncode == 0 :
281+ logging .debug ("xrdcp version: %s" , xrdcp_version )
282+ return xrdcp_version
283+ else :
284+ logging .debug ("xrdcp command returned exit code: %i" , command_object .returncode )
285+ return False
286+
287+
288+ def download_with_http (source , destination , debug ):
289+ """
290+ Download from the nearest cache with HTTP
291+ """
292+ global nearest_cache
293+ logging .debug ("Downloading with HTTP" )
294+
295+ payload = {}
296+ payload ['filename' ] = source
297+ sitename = os .environ .setdefault ("OSG_SITE_NAME" , "siteNotFound" )
298+ payload ['sitename' ] = sitename
299+ payload .update (parse_job_ad ())
300+ # Calculate the starting time
301+ start = int (time .time ()* 1000 )
302+
303+ if not nearest_cache :
304+ nearest_cache = get_best_stashcache ()
305+
306+ # Parse the nearest_cache url, make sure it uses http
307+ # Should really use urlparse, but python3 and python2 urlparse imports are
308+ # very different
309+ if nearest_cache .startswith ('root://' ):
310+ nearest_cache = nearest_cache .replace ('root://' , 'http://' )
311+
312+ # Append port 8000, which is just a convention for now, not set in stone
313+ nearest_cache += ":8000"
314+
315+ # Ok, now run the curl command:
316+ if debug :
317+ output_mode = "-v"
318+ else :
319+ output_mode = "-s"
320+
321+ # The command will cd into destination directory and then run curl
322+ if os .path .isdir (destination ):
323+ destination += "/"
324+ dest_dir , dest_filename = os .path .split (destination )
325+ if not dest_dir :
326+ dest_dir = "."
327+
328+ if dest_filename :
329+ download_output = "-o %s" % dest_filename
330+ final_destination = destination
331+ else :
332+ download_output = "-O"
333+ final_destination = os .path .join (dest_dir , os .path .basename (source ))
334+ curl_command = "cd %s; curl %s --connect-timeout 30 --speed-limit 1024 %s --fail %s%s" % (dest_dir , output_mode , download_output , nearest_cache , source )
335+ logging .debug ("About to run curl command: %s" , curl_command )
336+ command_object = subprocess .Popen ([curl_command ], shell = True )
337+ command_object .wait ()
338+
339+ end = int (time .time ()* 1000 )
340+ if command_object .returncode == 0 :
341+ dlSz = os .stat (final_destination ).st_size
342+ filesize = dlSz
343+ status = 'Success'
344+ payload ['download_size' ]= dlSz
345+ payload ['filesize' ] = filesize
346+ else :
347+ status = 'Failure'
348+ dltime = end - start
349+ destSpace = 1
350+ payload ['timestamp' ]= end
351+ payload ['host' ]= nearest_cache
352+ payload ['download_time' ]= dltime
353+ payload ['destination_space' ]= destSpace
354+ payload ['status' ]= status
355+ payload ['tries' ]= 1
356+ payload ['start1' ]= start
357+ payload ['end1' ]= end
358+ payload ['cache' ]= nearest_cache
359+ es_send (payload )
360+ if command_object .returncode == 0 :
361+ return 0
362+ else :
363+ return 1
364+
268365
269366def parse_job_ad ():
270367 """
0 commit comments