1 |
afanfani |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
|
3 |
|
|
import urllib
|
4 |
|
|
from xml.dom.minidom import parse
|
5 |
|
|
from crab_exceptions import *
|
6 |
|
|
|
7 |
|
|
class PhEDExDatasvcInfo:
|
8 |
|
|
"""
|
9 |
|
|
provides information from PhEDEx Data Service
|
10 |
|
|
"""
|
11 |
afanfani |
1.2 |
## PhEDEx Data Service URL
|
12 |
|
|
#datasvc_url="https://cmsweb.cern.ch/phedex/test/datasvc/xml/prod"
|
13 |
|
|
datasvc_url="https://cmsweb.cern.ch/phedex/datasvc/xml/prod"
|
14 |
|
|
|
15 |
afanfani |
1.1 |
def lfn2pfn(self,node,lfn,protocol):
|
16 |
|
|
"""
|
17 |
|
|
PhEDEx Data Service lfn2pfn call
|
18 |
|
|
|
19 |
|
|
input: LFN,node name,protocol
|
20 |
|
|
returns: DOM object with the content of the PhEDEx Data Service call
|
21 |
|
|
"""
|
22 |
|
|
params = {'node' : node , 'lfn': lfn , 'protocol': protocol}
|
23 |
|
|
params = urllib.urlencode(params)
|
24 |
|
|
#print params
|
25 |
|
|
datasvc_lfn2pfn="%s/lfn2pfn"%self.datasvc_url
|
26 |
|
|
urlresults = urllib.urlopen(datasvc_lfn2pfn, params)
|
27 |
|
|
try:
|
28 |
|
|
urlresults = parse(urlresults)
|
29 |
|
|
except:
|
30 |
|
|
urlresults = None
|
31 |
|
|
return urlresults
|
32 |
|
|
|
33 |
|
|
def parse_error(self,urlresults):
|
34 |
|
|
"""
|
35 |
|
|
look for errors in the DOM object returned by PhEDEx Data Service call
|
36 |
|
|
"""
|
37 |
|
|
errormsg = None
|
38 |
|
|
errors=urlresults.getElementsByTagName('error')
|
39 |
|
|
for error in errors:
|
40 |
|
|
errormsg=error.childNodes[0].data
|
41 |
|
|
if len(error.childNodes)>1:
|
42 |
|
|
errormsg+=error.childNodes[1].data
|
43 |
|
|
return errormsg
|
44 |
|
|
|
45 |
|
|
def parse_lfn2pfn(self,urlresults):
|
46 |
|
|
"""
|
47 |
|
|
Parse the content of the result of lfn2pfn PhEDEx Data Service call
|
48 |
|
|
|
49 |
|
|
input: DOM object with the content of the lfn2pfn call
|
50 |
|
|
returns: PFN
|
51 |
|
|
"""
|
52 |
|
|
result = urlresults.getElementsByTagName('phedex')
|
53 |
|
|
if not result:
|
54 |
|
|
return []
|
55 |
|
|
result = result[0]
|
56 |
|
|
pfn = None
|
57 |
|
|
mapping = result.getElementsByTagName('mapping')
|
58 |
|
|
for m in mapping:
|
59 |
|
|
pfn=m.getAttribute("pfn")
|
60 |
|
|
if pfn:
|
61 |
|
|
return pfn
|
62 |
|
|
|
63 |
|
|
def getStageoutPFN(self,node,lfn,protocol):
|
64 |
|
|
"""
|
65 |
|
|
input: LFN,node name,protocol
|
66 |
|
|
returns: PFN
|
67 |
|
|
"""
|
68 |
|
|
fullurl="%s/lfn2pfn?node=%s&lfn=%s&protocol=%s"%(self.datasvc_url,node,lfn,protocol)
|
69 |
|
|
domlfn2pfn = self.lfn2pfn(node,lfn,protocol)
|
70 |
|
|
if not domlfn2pfn :
|
71 |
|
|
msg="Unable to get info from %s"%fullurl
|
72 |
|
|
raise CrabException(msg)
|
73 |
|
|
|
74 |
|
|
errormsg = self.parse_error(domlfn2pfn)
|
75 |
|
|
if errormsg:
|
76 |
|
|
msg="Error extracting info from %s due to: %s"%(fullurl,errormsg)
|
77 |
|
|
raise CrabException(msg)
|
78 |
|
|
|
79 |
|
|
stageoutpfn = self.parse_lfn2pfn(domlfn2pfn)
|
80 |
|
|
if not stageoutpfn:
|
81 |
|
|
msg="Unable to get stageout path (PFN) from %s"%fullurl
|
82 |
|
|
raise CrabException(msg)
|
83 |
|
|
return stageoutpfn
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
if __name__ == '__main__' :
|
87 |
|
|
"""
|
88 |
|
|
"""
|
89 |
|
|
from crab_logger import Logger
|
90 |
|
|
from WorkSpace import *
|
91 |
|
|
continue_dir="/home/fanfani/CRAB"
|
92 |
|
|
cfg_params={'USER.logdir' : continue_dir }
|
93 |
|
|
common.work_space = WorkSpace(continue_dir, cfg_params)
|
94 |
|
|
log = Logger()
|
95 |
|
|
common.logger = log
|
96 |
|
|
|
97 |
|
|
from LFNBaseName import *
|
98 |
|
|
# test values
|
99 |
|
|
lfn = LFNBase("datasetstring")
|
100 |
|
|
node='T2_IT_Bari'
|
101 |
|
|
protocol="srmv2"
|
102 |
|
|
|
103 |
|
|
#create an instance of the PhEDExDatasvcInfo object
|
104 |
|
|
dsvc = PhEDExDatasvcInfo()
|
105 |
|
|
#extract the PFN for the given node,LFN,protocol
|
106 |
|
|
print "Stageout to %s"%dsvc.getStageoutPFN(node,lfn,protocol)
|
107 |
|
|
|