5 |
|
from WorkSpace import * |
6 |
|
from urlparse import urlparse |
7 |
|
from LFNBaseName import * |
8 |
+ |
from crab_util import getUserName |
9 |
|
|
10 |
|
class PhEDExDatasvcInfo: |
11 |
|
def __init__( self , cfg_params=None, config=None ): |
14 |
|
self.datasvc_url="https://cmsweb.cern.ch/phedex/datasvc/xml/prod" |
15 |
|
|
16 |
|
self.FacOps_savannah = 'https://savannah.cern.ch/support/?func=additem&group=cmscompinfrasup' |
17 |
< |
stage_out_faq='https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabHowTo#Stageout_and_publication' |
17 |
> |
self.stage_out_faq='https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabHowTo#Stageout_and_publication' |
18 |
|
self.dataPub_faq = 'https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrabForPublication' |
19 |
|
|
20 |
|
self.usePhedex = True |
59 |
|
#check if using "private" Storage |
60 |
|
if not self.node : |
61 |
|
msg = 'Please specify the storage_element name in your crab.cfg section [USER].\n' |
62 |
< |
msg +='\tFor further information please visit : %s'%stage_out_faq |
62 |
> |
msg +='\tFor further information please visit : %s'%self.stage_out_faq |
63 |
|
raise CrabException(msg) |
64 |
|
if (self.node.find('T1_') + self.node.find('T2_')+self.node.find('T3_')) == -3: self.usePhedex = False |
65 |
|
|
66 |
|
if not self.usePhedex and ( self.user_remote_dir == '' or self.user_se_path == '' ): |
67 |
|
msg = 'You are asking to stage out without using CMS Storage Name convention. In this case you \n' |
68 |
|
msg += '\t must specify both user_remote_dir and storage_path in the crab.cfg section [USER].\n ' |
69 |
< |
msg += '\t For further information please visit : \n\t%s'%stage_out_faq |
69 |
> |
msg += '\t For further information please visit : \n\t%s'%self.stage_out_faq |
70 |
|
raise CrabException(msg) |
71 |
|
|
72 |
|
self.forced_path = '/store/user/' |
73 |
< |
if self.sched in ['CAF','LSF']: |
74 |
< |
self.protocol = 'direct' |
75 |
< |
self.SE = {'CAF':'caf.cern.ch', 'LSF':''} |
73 |
> |
if self.sched in ['CAF','LSF','PBS']: |
74 |
> |
self.srm_version = 'direct' |
75 |
> |
self.SE = {'CAF':'caf.cern.ch', 'LSF':'', 'PBS':''} |
76 |
|
if self.sched == 'CAF': self.forced_path = '/store/caf/user/' |
77 |
|
|
78 |
|
if not self.usePhedex: |
87 |
|
|
88 |
|
#extract the PFN for the given node,LFN,protocol |
89 |
|
endpoint = self.getStageoutPFN() |
89 |
– |
### FEDE added a check for the final / |
90 |
|
if ( endpoint[-1] != '/' ) : endpoint = endpoint + '/' |
91 |
– |
###################################### |
91 |
|
|
92 |
|
#extract SE name an SE_PATH (needed for publication) |
93 |
|
SE, SE_PATH, User = self.splitEndpoint(endpoint) |
100 |
|
''' |
101 |
|
SE = '' |
102 |
|
SE_PATH = '' |
103 |
< |
USER = '' |
103 |
> |
USER = getUserName() |
104 |
|
if self.usePhedex: |
105 |
|
if self.protocol == 'direct': |
106 |
|
query=endpoint |
108 |
|
SE = self.SE[self.sched] |
109 |
|
else: |
110 |
|
url = 'http://'+endpoint.split('://')[1] |
112 |
– |
# python > 2.4 |
113 |
– |
# SE = urlparse(url).hostname |
111 |
|
scheme, host, path, params, query, fragment = urlparse(url) |
112 |
< |
SE = host.split(':')[0] |
112 |
> |
SE = self.getAuthoritativeSE() |
113 |
|
SE_PATH = endpoint.split(host)[1] |
117 |
– |
USER = (query.split('user')[1]).split('/')[1] |
114 |
|
else: |
115 |
< |
#### to test ##### |
115 |
> |
#### to test ##### |
116 |
|
# url = 'http://'+endpoint.split('://')[1] |
117 |
|
# scheme, host, path, params, query, fragment = urlparse(url) |
118 |
|
# SE = host.split(':')[0] |
119 |
|
# SE_PATH = endpoint.split(host)[1] |
120 |
|
SE = self.node |
121 |
|
SE_PATH = self.user_se_path + self.user_remote_dir |
122 |
< |
try: |
123 |
< |
USER = (self.lfn.split('user')[1]).split('/')[1] |
124 |
< |
except: |
125 |
< |
pass |
126 |
< |
|
122 |
> |
if self.lfn.find('group') != -1: |
123 |
> |
try: |
124 |
> |
USER = (self.lfn.split('group')[1]).split('/')[1] |
125 |
> |
except: |
126 |
> |
pass |
127 |
|
return SE, SE_PATH, USER |
132 |
– |
|
128 |
|
|
129 |
|
def getLFN(self): |
130 |
|
""" |
158 |
|
else: |
159 |
|
if self.sched in ['CAF','LSF']: l_User=True |
160 |
|
lfn = LFNBase(self.forced_path,self.user_remote_dir) |
161 |
+ |
if ( lfn[-1] != '/' ) : lfn = lfn + '/' |
162 |
|
return lfn |
163 |
|
|
164 |
|
def computePrimaryDataset(self): |
171 |
|
primarydataset = self.publish_data_name |
172 |
|
return primarydataset |
173 |
|
|
174 |
< |
def lfn2pfn(self): |
174 |
> |
def domPhedex(self,params,datasvc_baseUrl): |
175 |
|
""" |
176 |
|
PhEDEx Data Service lfn2pfn call |
177 |
|
|
178 |
< |
input: LFN,node name,protocol |
178 |
> |
input: params,datasvc_baseUrl |
179 |
|
returns: DOM object with the content of the PhEDEx Data Service call |
180 |
|
""" |
185 |
– |
params = {'node' : self.node , 'lfn': self.lfn , 'protocol': self.protocol} |
181 |
|
params = urllib.urlencode(params) |
187 |
– |
datasvc_lfn2pfn="%s/lfn2pfn"%self.datasvc_url |
182 |
|
try: |
183 |
< |
urlresults = urllib.urlopen(datasvc_lfn2pfn, params) |
183 |
> |
urlresults = urllib.urlopen(datasvc_baseUrl, params) |
184 |
|
urlresults = parse(urlresults) |
185 |
|
except IOError: |
186 |
< |
msg="Unable to access PhEDEx Data Service at %s"%datasvc_lfn2pfn |
186 |
> |
msg="Unable to access PhEDEx Data Service at %s"%datasvc_baseUrl |
187 |
|
raise CrabException(msg) |
188 |
|
except: |
189 |
|
urlresults = None |
227 |
|
returns: PFN |
228 |
|
""" |
229 |
|
if self.usePhedex: |
230 |
+ |
params = {'node' : self.node , 'lfn': self.lfn , 'protocol': self.protocol} |
231 |
+ |
datasvc_lfn2pfn="%s/lfn2pfn"%self.datasvc_url |
232 |
|
fullurl="%s/lfn2pfn?node=%s&lfn=%s&protocol=%s"%(self.datasvc_url,self.node,self.lfn,self.protocol) |
233 |
< |
domlfn2pfn = self.lfn2pfn() |
233 |
> |
domlfn2pfn = self.domPhedex(params,datasvc_lfn2pfn) |
234 |
|
if not domlfn2pfn : |
235 |
|
msg="Unable to get info from %s"%fullurl |
236 |
|
raise CrabException(msg) |
249 |
|
msg+=' OriginalSubmission: stageout path is not retrieved from %s \n'%fullurl |
250 |
|
raise CrabException(msg) |
251 |
|
else: |
252 |
< |
if self.sched in ['CAF','LSF'] : |
252 |
> |
if self.sched in ['CAF','LSF','PBS'] : |
253 |
|
stageoutpfn = self.user_se_path+self.lfn |
254 |
|
else: |
255 |
|
stageoutpfn = 'srm://'+self.node+':'+self.user_port+self.user_se_path+self.lfn |
256 |
|
|
257 |
+ |
if ( stageoutpfn[-1] != '/' ) : stageoutpfn = stageoutpfn + '/' |
258 |
|
return stageoutpfn |
259 |
|
|
260 |
+ |
def getAuthoritativeSE(self): |
261 |
+ |
""" |
262 |
+ |
input: node name |
263 |
+ |
returns: AuthoritativeSE |
264 |
+ |
""" |
265 |
+ |
params = {'node' : self.node } |
266 |
+ |
datasvc_nodes="%s/nodes"%self.datasvc_url |
267 |
+ |
fullurl="%s/nodes/?node=%s"%(self.datasvc_url,self.node) |
268 |
+ |
domnodes = self.domPhedex(params,datasvc_nodes) |
269 |
+ |
|
270 |
+ |
if not domnodes : |
271 |
+ |
msg="Unable to get info from %s"%fullurl |
272 |
+ |
raise CrabException(msg) |
273 |
+ |
|
274 |
+ |
errormsg = self.parse_error(domnodes) |
275 |
+ |
if errormsg: |
276 |
+ |
msg="Error extracting info from %s due to: %s"%(fullurl,errormsg) |
277 |
+ |
raise CrabException(msg) |
278 |
+ |
result = domnodes.getElementsByTagName('phedex') |
279 |
+ |
if not result: |
280 |
+ |
return [] |
281 |
+ |
result = result[0] |
282 |
+ |
se = None |
283 |
+ |
node = result.getElementsByTagName('node') |
284 |
+ |
for m in node: |
285 |
+ |
se=m.getAttribute("se") |
286 |
+ |
if se: |
287 |
+ |
return se |
288 |
|
|
289 |
|
|
290 |
|
if __name__ == '__main__': |