Skip to content

Commit 8055b77

Browse files
committed
Adding initial writeback support
1 parent 22dca8b commit 8055b77

1 file changed

Lines changed: 39 additions & 4 deletions

File tree

bin/stashcp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,40 @@ from urlparse import urlparse
1717

1818
main_redirector = "root://redirector.osgstorage.org"
1919
stash_origin = "root://stash.osgconnect.net"
20+
writeback_host = "http://stash-xrd.osgconnect.net:1094"
2021

2122
TIMEOUT = 300
2223
DIFF = TIMEOUT * 10
2324

25+
def doWriteBack(source, destination):
26+
"""
27+
Do a write back to Stash using SciTokens
28+
29+
:param str source: The location of the local file
30+
:param str destination: The location of the remote file
31+
"""
32+
33+
# Get the scitoken content
34+
if 'KRB5CCNAME' in os.environ:
35+
scitoken_file = os.environ['KRB5CCNAME']
36+
else:
37+
logging.error("Unable to find SciToken file, environment variable \"KRB5CCNAME\" not found.")
38+
return 1
39+
40+
with open(scitoken_file, 'r') as scitoken_obj:
41+
scitoken_contents = scitoken_obj.read().strip()
42+
43+
command = "curl -X PUT --fail --upload-file %s -H \"Authorization: Bearer %s\" %s%s" % (source, scitoken_contents, writeback_host, destination)
44+
print command
45+
46+
curl=subprocess.Popen([command ],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
47+
(stdout, stderr) = curl.communicate()
48+
curl_exit=curl.returncode
49+
if curl_exit != 0:
50+
print stdout
51+
print stderr
52+
return curl_exit
53+
2454

2555
def doStashCpSingle(sourceFile, destination, cache, debug=False):
2656

@@ -38,8 +68,13 @@ def doStashCpSingle(sourceFile, destination, cache, debug=False):
3868
payload['sitename'] = sitename
3969
payload.update(parse_job_ad())
4070

71+
# Check if this is a source
72+
if os.path.exists(sourceFile):
73+
# Source file exists, must be a writeback
74+
return doWriteBack(sourceFile, destination)
75+
4176
# Calculate the starting time
42-
start1 = int(time.time()*1000)
77+
start1 = int(time.time()*1000)
4378

4479
# First, check if the file is available in CVMFS
4580
# Really, we don't need to check for close caches before this, but oh well
@@ -371,9 +406,9 @@ def main():
371406
else:
372407
cache = get_best_stashcache()
373408

374-
if not source.startswith('/'):
375-
logging.warning("DEPRECIATED: The source path does not begin with a '/', but it is required. This functionality will be removed in an upcoming release")
376-
source = "/" + source
409+
#if not source.startswith('/'):
410+
# logging.warning("DEPRECIATED: The source path does not begin with a '/', but it is required. This functionality will be removed in an upcoming release")
411+
# source = "/" + source
377412

378413

379414
if not args.recursive:

0 commit comments

Comments
 (0)