Skip to content

Commit 63837bd

Browse files
committed
Adding initial http support when xrd not available
1 parent 4151ae6 commit 63837bd

3 files changed

Lines changed: 133 additions & 1 deletion

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ env:
1818
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://its-condor-xrootd1.syr.edu"
1919
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://stashcache.grid.uchicago.edu"
2020
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://sc-cache.chtc.wisc.edu"
21+
- BUILD_TYPE=http OS_TYPE=centos OS_VERSION=7
2122

2223

2324
language: python

bin/stashcp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

269366
def parse_job_ad():
270367
"""

bin/stashcp2/tests/setup_tests.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,42 @@
66
el_version=$1
77
cache=$2
88

9+
if [ "${BUILD_TYPE}" = "http" ]; then
10+
# Run the test without a container
11+
# Copy in the .job.ad file:
12+
cp bin/stashcp2/tests/job.ad ./.job.ad
13+
14+
# Test against a file that is known to not exist
15+
set +e
16+
bin/stashcp --cache=$XRD_CACHE /blah/does/not/exist ./
17+
if [ $? -eq 0 ]; then
18+
echo "Failed to exit with non-zero exit status when it should have"
19+
exit 1
20+
fi
21+
set -e
22+
23+
# Try copying with different destintion filename
24+
bin/stashcp --cache=$XRD_CACHE -d /user/dweitzel/public/blast/queries/query1 query.test
25+
26+
result=`md5sum query.test | awk '{print $1;}'`
27+
28+
if [ "$result" != "12bdb9a96cd5e8ca469b727a81593201" ]; then
29+
exit 1
30+
fi
31+
32+
rm -f query.test
33+
34+
# Perform tests
35+
bin/stashcp --cache=$XRD_CACHE -d /user/dweitzel/public/blast/queries/query1 ./
36+
37+
result=`md5sum query1 | awk '{print $1;}'`
38+
39+
if [ "$result" != "12bdb9a96cd5e8ca469b727a81593201" ]; then
40+
exit 1
41+
fi
42+
943
# Run tests in Container
10-
if [ "$el_version" = "6" ]; then
44+
elif [ "$el_version" = "6" ]; then
1145

1246
sudo docker run --privileged --rm=true -v `pwd`:/StashCache:rw centos:centos${OS_VERSION} /bin/bash -c "bash -xe /StashCache/bin/stashcp2/tests/test_inside_docker.sh ${OS_VERSION} ${XRD_CACHE}"
1347

0 commit comments

Comments
 (0)