ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PhEDExDatasvcInfo.py
Revision: 1.1
Committed: Wed Jun 25 12:03:43 2008 UTC (16 years, 10 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_0_test
Log Message:
*** empty log message ***

File Contents

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