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 |
67 |
> |
####### FEDE FOR BUG 73010 ############ |
68 |
> |
msg = 'Error: you are asking to stage out without using CMS Storage Name convention. In this case you \n' |
69 |
> |
msg += ' must specify both user_remote_dir and storage_path in the crab.cfg section [USER].\n' |
70 |
> |
msg += ' For further information please visit : \n\t%s'%self.stage_out_faq |
71 |
> |
task = common._db.getTask() |
72 |
> |
add = '\n\n' |
73 |
> |
import shutil |
74 |
> |
try: |
75 |
> |
add += ' Task not correctly created: removing the working_dir ' + common.work_space._top_dir + ' \n' |
76 |
> |
shutil.rmtree(common.work_space._top_dir) |
77 |
> |
except OSError: |
78 |
> |
add += ' Warning: problems removing the working_dir ' + common.work_space._top_dir + ' \n' |
79 |
> |
add += ' Please remove it by hand' |
80 |
> |
msg += add |
81 |
|
raise CrabException(msg) |
82 |
|
|
83 |
|
self.forced_path = '/store/user/' |
84 |
< |
if self.sched in ['CAF','LSF']: |
85 |
< |
self.protocol = 'direct' |
86 |
< |
self.SE = {'CAF':'caf.cern.ch', 'LSF':''} |
75 |
< |
if self.sched == 'CAF': self.forced_path = '/store/caf/user/' |
84 |
> |
if self.sched in ['LSF','PBS']: |
85 |
> |
self.srm_version = 'direct' |
86 |
> |
self.SE = {'LSF':'', 'PBS':''} |
87 |
|
|
88 |
+ |
if self.sched == 'CAF': |
89 |
+ |
#### FEDE TEST FOR XROOTD |
90 |
+ |
######### first solution ################ |
91 |
+ |
#eos = cfg_params.get("USER.caf_eos_area", 0) |
92 |
+ |
#if eos == 0: |
93 |
+ |
# self.forced_path = '/store/caf/user/' |
94 |
+ |
#else: |
95 |
+ |
# self.forced_path = '/store/eos/user' |
96 |
+ |
######################################### |
97 |
+ |
######### second solution ############### |
98 |
+ |
self.forced_path = cfg_params.get("USER.caf_lfn", '/store/caf/user') |
99 |
+ |
######################################### |
100 |
+ |
print "--->>> FORCING THE FIRST PART OF LFN WITH ", self.forced_path |
101 |
+ |
self.SE = {'CAF':'caf.cern.ch'} |
102 |
+ |
self.srm_version = 'stageout' |
103 |
+ |
print "--->>> query with 'stageout' " |
104 |
+ |
######################################### |
105 |
+ |
|
106 |
|
if not self.usePhedex: |
107 |
|
self.forced_path = self.user_remote_dir |
108 |
|
return |
115 |
|
|
116 |
|
#extract the PFN for the given node,LFN,protocol |
117 |
|
endpoint = self.getStageoutPFN() |
89 |
– |
### FEDE added a check for the final / |
118 |
|
if ( endpoint[-1] != '/' ) : endpoint = endpoint + '/' |
91 |
– |
###################################### |
119 |
|
|
120 |
|
#extract SE name an SE_PATH (needed for publication) |
121 |
|
SE, SE_PATH, User = self.splitEndpoint(endpoint) |
122 |
|
|
123 |
+ |
#### FEDE FOR XROOTD ##### |
124 |
+ |
#print "in getEndpoint di PhEDExDatasvcInfo.py: " |
125 |
+ |
#print " SE = ", SE |
126 |
+ |
#print " SE_PATH = ", SE_PATH |
127 |
+ |
#print " User = ", User |
128 |
+ |
#print " endpoint = ", endpoint |
129 |
+ |
############################## |
130 |
+ |
|
131 |
|
return endpoint, self.lfn , SE, SE_PATH, User |
132 |
|
|
133 |
|
def splitEndpoint(self, endpoint): |
136 |
|
''' |
137 |
|
SE = '' |
138 |
|
SE_PATH = '' |
139 |
< |
USER = '' |
139 |
> |
USER = getUserName() |
140 |
|
if self.usePhedex: |
141 |
< |
if self.protocol == 'direct': |
142 |
< |
query=endpoint |
108 |
< |
SE_PATH = endpoint |
141 |
> |
### FEDE PER TEST WITH XROOTD |
142 |
> |
if (self.protocol == 'direct' or self.protocol == 'stageout'): |
143 |
|
SE = self.SE[self.sched] |
144 |
+ |
SE_PATH = endpoint |
145 |
+ |
############################# |
146 |
+ |
#print " SE_PATH = ", SE_PATH |
147 |
|
else: |
148 |
|
url = 'http://'+endpoint.split('://')[1] |
112 |
– |
# python > 2.4 |
113 |
– |
# SE = urlparse(url).hostname |
149 |
|
scheme, host, path, params, query, fragment = urlparse(url) |
150 |
< |
SE = host.split(':')[0] |
150 |
> |
SE = self.getAuthoritativeSE() |
151 |
|
SE_PATH = endpoint.split(host)[1] |
117 |
– |
USER = (query.split('user')[1]).split('/')[1] |
152 |
|
else: |
119 |
– |
#### to test ##### |
120 |
– |
# url = 'http://'+endpoint.split('://')[1] |
121 |
– |
# scheme, host, path, params, query, fragment = urlparse(url) |
122 |
– |
# SE = host.split(':')[0] |
123 |
– |
# SE_PATH = endpoint.split(host)[1] |
153 |
|
SE = self.node |
154 |
|
SE_PATH = self.user_se_path + self.user_remote_dir |
155 |
< |
try: |
156 |
< |
USER = (self.lfn.split('user')[1]).split('/')[1] |
157 |
< |
except: |
158 |
< |
pass |
159 |
< |
|
155 |
> |
if self.lfn.find('group') != -1: |
156 |
> |
try: |
157 |
> |
USER = (self.lfn.split('group')[1]).split('/')[1] |
158 |
> |
except: |
159 |
> |
pass |
160 |
|
return SE, SE_PATH, USER |
132 |
– |
|
161 |
|
|
162 |
|
def getLFN(self): |
163 |
|
""" |
191 |
|
else: |
192 |
|
if self.sched in ['CAF','LSF']: l_User=True |
193 |
|
lfn = LFNBase(self.forced_path,self.user_remote_dir) |
194 |
+ |
if ( lfn[-1] != '/' ) : lfn = lfn + '/' |
195 |
|
return lfn |
196 |
|
|
197 |
|
def computePrimaryDataset(self): |
204 |
|
primarydataset = self.publish_data_name |
205 |
|
return primarydataset |
206 |
|
|
207 |
< |
def lfn2pfn(self): |
207 |
> |
def domPhedex(self,params,datasvc_baseUrl): |
208 |
|
""" |
209 |
|
PhEDEx Data Service lfn2pfn call |
210 |
|
|
211 |
< |
input: LFN,node name,protocol |
211 |
> |
input: params,datasvc_baseUrl |
212 |
|
returns: DOM object with the content of the PhEDEx Data Service call |
213 |
|
""" |
185 |
– |
params = {'node' : self.node , 'lfn': self.lfn , 'protocol': self.protocol} |
214 |
|
params = urllib.urlencode(params) |
187 |
– |
datasvc_lfn2pfn="%s/lfn2pfn"%self.datasvc_url |
215 |
|
try: |
216 |
< |
urlresults = urllib.urlopen(datasvc_lfn2pfn, params) |
216 |
> |
urlresults = urllib.urlopen(datasvc_baseUrl, params) |
217 |
|
urlresults = parse(urlresults) |
218 |
|
except IOError: |
219 |
< |
msg="Unable to access PhEDEx Data Service at %s"%datasvc_lfn2pfn |
219 |
> |
msg="Unable to access PhEDEx Data Service at %s"%datasvc_baseUrl |
220 |
|
raise CrabException(msg) |
221 |
|
except: |
222 |
|
urlresults = None |
260 |
|
returns: PFN |
261 |
|
""" |
262 |
|
if self.usePhedex: |
263 |
+ |
params = {'node' : self.node , 'lfn': self.lfn , 'protocol': self.protocol} |
264 |
+ |
datasvc_lfn2pfn="%s/lfn2pfn"%self.datasvc_url |
265 |
|
fullurl="%s/lfn2pfn?node=%s&lfn=%s&protocol=%s"%(self.datasvc_url,self.node,self.lfn,self.protocol) |
266 |
< |
domlfn2pfn = self.lfn2pfn() |
266 |
> |
print "--->>> fullurl = ", fullurl |
267 |
> |
domlfn2pfn = self.domPhedex(params,datasvc_lfn2pfn) |
268 |
|
if not domlfn2pfn : |
269 |
|
msg="Unable to get info from %s"%fullurl |
270 |
|
raise CrabException(msg) |
283 |
|
msg+=' OriginalSubmission: stageout path is not retrieved from %s \n'%fullurl |
284 |
|
raise CrabException(msg) |
285 |
|
else: |
286 |
< |
if self.sched in ['CAF','LSF'] : |
286 |
> |
if self.sched in ['CAF','LSF','PBS'] : |
287 |
|
stageoutpfn = self.user_se_path+self.lfn |
288 |
|
else: |
289 |
|
stageoutpfn = 'srm://'+self.node+':'+self.user_port+self.user_se_path+self.lfn |
290 |
|
|
291 |
+ |
if ( stageoutpfn[-1] != '/' ) : stageoutpfn = stageoutpfn + '/' |
292 |
|
return stageoutpfn |
293 |
|
|
294 |
+ |
def getAuthoritativeSE(self): |
295 |
+ |
""" |
296 |
+ |
input: node name |
297 |
+ |
returns: AuthoritativeSE |
298 |
+ |
""" |
299 |
+ |
params = {'node' : self.node } |
300 |
+ |
datasvc_nodes="%s/nodes"%self.datasvc_url |
301 |
+ |
fullurl="%s/nodes/?node=%s"%(self.datasvc_url,self.node) |
302 |
+ |
domnodes = self.domPhedex(params,datasvc_nodes) |
303 |
+ |
|
304 |
+ |
if not domnodes : |
305 |
+ |
msg="Unable to get info from %s"%fullurl |
306 |
+ |
raise CrabException(msg) |
307 |
+ |
|
308 |
+ |
errormsg = self.parse_error(domnodes) |
309 |
+ |
if errormsg: |
310 |
+ |
msg="Error extracting info from %s due to: %s"%(fullurl,errormsg) |
311 |
+ |
raise CrabException(msg) |
312 |
+ |
result = domnodes.getElementsByTagName('phedex') |
313 |
+ |
if not result: |
314 |
+ |
return [] |
315 |
+ |
result = result[0] |
316 |
+ |
se = None |
317 |
+ |
node = result.getElementsByTagName('node') |
318 |
+ |
for m in node: |
319 |
+ |
se=m.getAttribute("se") |
320 |
+ |
if se: |
321 |
+ |
return se |
322 |
|
|
323 |
|
|
324 |
|
if __name__ == '__main__': |