2 |
|
import urllib |
3 |
|
from xml.dom.minidom import parse |
4 |
|
from crab_exceptions import * |
5 |
– |
from crab_logger import Logger |
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 ): |
11 |
> |
def __init__( self , cfg_params=None, config=None ): |
12 |
|
|
13 |
|
## PhEDEx Data Service URL |
14 |
< |
url="https://cmsweb.cern.ch/phedex/datasvc/xml/prod" |
15 |
< |
self.datasvc_url = cfg_params.get("USER.datasvc_url",url) |
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 |
+ |
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 |
21 |
+ |
self.sched = common.scheduler.name().upper() |
22 |
+ |
|
23 |
+ |
if config!=None: |
24 |
+ |
self.checkConfig(config) |
25 |
+ |
else: |
26 |
+ |
self.checkCfgConfig(cfg_params) |
27 |
+ |
|
28 |
+ |
self.protocol = self.srm_version |
29 |
+ |
|
30 |
+ |
|
31 |
+ |
def checkConfig(self,config): |
32 |
+ |
""" |
33 |
+ |
""" |
34 |
+ |
self.srm_version = config.get("srm_version",'srmv2') |
35 |
+ |
self.node = config.get('storage_element',None) |
36 |
+ |
self.lfn='/store/' |
37 |
|
|
38 |
+ |
def checkCfgConfig(self,cfg_params): |
39 |
+ |
""" |
40 |
+ |
""" |
41 |
+ |
self.datasvc_url = cfg_params.get("USER.datasvc_url",self.datasvc_url) |
42 |
|
self.srm_version = cfg_params.get("USER.srm_version",'srmv2') |
43 |
|
self.node = cfg_params.get('USER.storage_element',None) |
44 |
< |
|
44 |
> |
|
45 |
|
self.publish_data = cfg_params.get("USER.publish_data",0) |
46 |
|
self.usenamespace = cfg_params.get("USER.usenamespace",0) |
47 |
< |
self.user_remote_dir = cfg_params.get("USER.remote_dir",'') |
47 |
> |
self.user_remote_dir = cfg_params.get("USER.user_remote_dir",'') |
48 |
|
if self.user_remote_dir: |
49 |
|
if ( self.user_remote_dir[-1] != '/' ) : self.user_remote_dir = self.user_remote_dir + '/' |
50 |
< |
|
50 |
> |
|
51 |
|
self.datasetpath = cfg_params.get("CMSSW.datasetpath") |
52 |
|
self.publish_data_name = cfg_params.get('USER.publish_data_name','') |
53 |
|
|
32 |
– |
self.user_lfn = cfg_params.get("USER.lfn",'') |
33 |
– |
if self.user_lfn: |
34 |
– |
if ( self.user_lfn[-1] != '/' ) : self.user_lfn = self.user_lfn + '/' |
35 |
– |
|
54 |
|
self.user_port = cfg_params.get("USER.storage_port",'8443') |
55 |
|
self.user_se_path = cfg_params.get("USER.storage_path",'') |
56 |
|
if self.user_se_path: |
57 |
|
if ( self.user_se_path[-1] != '/' ) : self.user_se_path = self.user_se_path + '/' |
58 |
|
|
41 |
– |
|
59 |
|
#check if using "private" Storage |
60 |
< |
self.usePhedex = True |
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'%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 |
< |
if not self.usePhedex and ( self.user_lfn == '' or self.user_se_path == '' ): |
66 |
< |
msg = 'You are asking to stage out without using CMS Storage Name convention. In this case you \n' |
67 |
< |
msg += ' must specify both lfn and storage_path in the crab.cfg section [USER].\n ' |
68 |
< |
msg += ' For further information please visit: ADD_TWIKI_LINK' |
65 |
> |
|
66 |
> |
if not self.usePhedex and ( self.user_remote_dir == '' or self.user_se_path == '' ): |
67 |
> |
##### remove |
68 |
> |
####### FEDE FOR BUG 73010 ############ |
69 |
> |
print "--------->>>> self = ", self |
70 |
> |
task = common._db.getTask() |
71 |
> |
print "task = ", task |
72 |
> |
print "common.work_space = ", common.work_space._top_dir |
73 |
> |
print "removing common.work_space" |
74 |
> |
add = '\n' |
75 |
> |
import shutil |
76 |
> |
try: |
77 |
> |
shutil.rmtree(common.work_space._top_dir) |
78 |
> |
except OSError: |
79 |
> |
add += '\t Warning: problems removing the dir ' + common.work_space._top_dir + ' \n' |
80 |
> |
add += '\t Please remove it by hand' |
81 |
> |
#common.work_space.delete() |
82 |
> |
|
83 |
> |
msg = 'Error: you are asking to stage out without using CMS Storage Name convention. In this case you \n' |
84 |
> |
msg += '\t must specify both user_remote_dir and storage_path in the crab.cfg section [USER].\n ' |
85 |
> |
msg += '\t Otherwise this task can not be correctly created. \n' |
86 |
> |
msg += '\t For further information please visit : \n\t%s'%self.stage_out_faq |
87 |
> |
msg += add |
88 |
|
raise CrabException(msg) |
89 |
< |
self.sched = common.scheduler.name().upper() |
51 |
< |
self.protocol = self.srm_version |
52 |
< |
if self.sched in ['CAF','LSF']:self.protocol = 'direct' |
89 |
> |
######################################### |
90 |
|
|
91 |
+ |
self.forced_path = '/store/user/' |
92 |
+ |
if self.sched in ['CAF','LSF','PBS']: |
93 |
+ |
self.srm_version = 'direct' |
94 |
+ |
self.SE = {'CAF':'caf.cern.ch', 'LSF':'', 'PBS':''} |
95 |
+ |
if self.sched == 'CAF': self.forced_path = '/store/caf/user/' |
96 |
+ |
|
97 |
+ |
if not self.usePhedex: |
98 |
+ |
self.forced_path = self.user_remote_dir |
99 |
|
return |
100 |
|
|
101 |
|
def getEndpoint(self): |
106 |
|
|
107 |
|
#extract the PFN for the given node,LFN,protocol |
108 |
|
endpoint = self.getStageoutPFN() |
109 |
+ |
if ( endpoint[-1] != '/' ) : endpoint = endpoint + '/' |
110 |
|
|
111 |
|
#extract SE name an SE_PATH (needed for publication) |
112 |
|
SE, SE_PATH, User = self.splitEndpoint(endpoint) |
119 |
|
''' |
120 |
|
SE = '' |
121 |
|
SE_PATH = '' |
122 |
< |
USER = '' |
122 |
> |
USER = getUserName() |
123 |
|
if self.usePhedex: |
124 |
|
if self.protocol == 'direct': |
125 |
|
query=endpoint |
126 |
|
SE_PATH = endpoint |
127 |
< |
### FEDE added SE ### |
82 |
< |
SE = self.sched |
127 |
> |
SE = self.SE[self.sched] |
128 |
|
else: |
129 |
|
url = 'http://'+endpoint.split('://')[1] |
85 |
– |
# python > 2.4 |
86 |
– |
# SE = urlparse(url).hostname |
130 |
|
scheme, host, path, params, query, fragment = urlparse(url) |
131 |
< |
SE = host.split(':')[0] |
131 |
> |
SE = self.getAuthoritativeSE() |
132 |
|
SE_PATH = endpoint.split(host)[1] |
90 |
– |
USER = (query.split('user')[1]).split('/')[1] |
133 |
|
else: |
134 |
+ |
#### to test ##### |
135 |
+ |
# url = 'http://'+endpoint.split('://')[1] |
136 |
+ |
# scheme, host, path, params, query, fragment = urlparse(url) |
137 |
+ |
# SE = host.split(':')[0] |
138 |
+ |
# SE_PATH = endpoint.split(host)[1] |
139 |
|
SE = self.node |
140 |
< |
SE_PATH = self.user_se_path + self.user_lfn |
141 |
< |
try: |
142 |
< |
USER = (self.lfn.split('user')[1]).split('/')[1] |
143 |
< |
except: |
144 |
< |
pass |
145 |
< |
|
140 |
> |
SE_PATH = self.user_se_path + self.user_remote_dir |
141 |
> |
if self.lfn.find('group') != -1: |
142 |
> |
try: |
143 |
> |
USER = (self.lfn.split('group')[1]).split('/')[1] |
144 |
> |
except: |
145 |
> |
pass |
146 |
|
return SE, SE_PATH, USER |
100 |
– |
|
147 |
|
|
148 |
|
def getLFN(self): |
149 |
|
""" |
156 |
|
## check if storage_name is a T2 (siteDB query) |
157 |
|
## if yes :match self.user_lfn with LFNBaseName... |
158 |
|
## if NOT : raise (you are using a T2. It's not allowed stage out into self.user_path+self.user_lfn) |
159 |
< |
lfn = self.user_lfn |
159 |
> |
lfn = self.user_remote_dir |
160 |
|
return lfn |
161 |
|
if self.publish_data_name == '' and int(self.publish_data) == 1: |
162 |
< |
msg = "Eeror. The [USER] section does not have 'publish_data_name'" |
162 |
> |
msg = "Error. The [USER] section does not have 'publish_data_name'\n" |
163 |
> |
msg += '\tFor further information please visit : \n\t%s'%self.dataPub_faq |
164 |
|
raise CrabException(msg) |
165 |
|
if self.publish_data_name == '' and int(self.usenamespace) == 1: |
166 |
|
self.publish_data_name = "DefaultDataset" |
167 |
< |
if int(self.publish_data) == 1 or int(self.usenamespace) == 1: |
167 |
> |
if int(self.publish_data) == 1: |
168 |
> |
if self.sched in ['CAF']: l_User=True |
169 |
> |
primaryDataset = self.computePrimaryDataset() |
170 |
> |
### added the case lfn = LFNBase(self.forced_path, primaryDataset, self.publish_data_name, publish=True) |
171 |
> |
### for the publication in order to be able to check the lfn length |
172 |
> |
lfn = LFNBase(self.forced_path, primaryDataset, self.publish_data_name, publish=True) + '/${PSETHASH}/' |
173 |
> |
elif int(self.usenamespace) == 1: |
174 |
|
if self.sched in ['CAF']: l_User=True |
175 |
|
primaryDataset = self.computePrimaryDataset() |
176 |
< |
lfn = LFNBase(primaryDataset,self.publish_data_name,LocalUser=l_User) + '/${PSETHASH}/' |
176 |
> |
lfn = LFNBase(self.forced_path, primaryDataset, self.publish_data_name) + '/${PSETHASH}/' |
177 |
|
else: |
178 |
|
if self.sched in ['CAF','LSF']: l_User=True |
179 |
< |
lfn = LFNBase(self.user_remote_dir,LocalUser=l_User) |
179 |
> |
lfn = LFNBase(self.forced_path,self.user_remote_dir) |
180 |
> |
if ( lfn[-1] != '/' ) : lfn = lfn + '/' |
181 |
|
return lfn |
182 |
|
|
183 |
|
def computePrimaryDataset(self): |
190 |
|
primarydataset = self.publish_data_name |
191 |
|
return primarydataset |
192 |
|
|
193 |
< |
def lfn2pfn(self): |
193 |
> |
def domPhedex(self,params,datasvc_baseUrl): |
194 |
|
""" |
195 |
|
PhEDEx Data Service lfn2pfn call |
196 |
|
|
197 |
< |
input: LFN,node name,protocol |
197 |
> |
input: params,datasvc_baseUrl |
198 |
|
returns: DOM object with the content of the PhEDEx Data Service call |
199 |
|
""" |
146 |
– |
params = {'node' : self.node , 'lfn': self.lfn , 'protocol': self.protocol} |
200 |
|
params = urllib.urlencode(params) |
148 |
– |
datasvc_lfn2pfn="%s/lfn2pfn"%self.datasvc_url |
149 |
– |
urlresults = urllib.urlopen(datasvc_lfn2pfn, params) |
201 |
|
try: |
202 |
+ |
urlresults = urllib.urlopen(datasvc_baseUrl, params) |
203 |
|
urlresults = parse(urlresults) |
204 |
+ |
except IOError: |
205 |
+ |
msg="Unable to access PhEDEx Data Service at %s"%datasvc_baseUrl |
206 |
+ |
raise CrabException(msg) |
207 |
|
except: |
208 |
|
urlresults = None |
209 |
|
|
246 |
|
returns: PFN |
247 |
|
""" |
248 |
|
if self.usePhedex: |
249 |
+ |
params = {'node' : self.node , 'lfn': self.lfn , 'protocol': self.protocol} |
250 |
+ |
datasvc_lfn2pfn="%s/lfn2pfn"%self.datasvc_url |
251 |
|
fullurl="%s/lfn2pfn?node=%s&lfn=%s&protocol=%s"%(self.datasvc_url,self.node,self.lfn,self.protocol) |
252 |
< |
domlfn2pfn = self.lfn2pfn() |
252 |
> |
domlfn2pfn = self.domPhedex(params,datasvc_lfn2pfn) |
253 |
|
if not domlfn2pfn : |
254 |
|
msg="Unable to get info from %s"%fullurl |
255 |
|
raise CrabException(msg) |
268 |
|
msg+=' OriginalSubmission: stageout path is not retrieved from %s \n'%fullurl |
269 |
|
raise CrabException(msg) |
270 |
|
else: |
271 |
< |
stageoutpfn = 'srm://'+self.node+':'self.user_port+self.user_se_path+self.lfn |
271 |
> |
if self.sched in ['CAF','LSF','PBS'] : |
272 |
> |
stageoutpfn = self.user_se_path+self.lfn |
273 |
> |
else: |
274 |
> |
stageoutpfn = 'srm://'+self.node+':'+self.user_port+self.user_se_path+self.lfn |
275 |
|
|
276 |
+ |
if ( stageoutpfn[-1] != '/' ) : stageoutpfn = stageoutpfn + '/' |
277 |
|
return stageoutpfn |
278 |
|
|
279 |
+ |
def getAuthoritativeSE(self): |
280 |
+ |
""" |
281 |
+ |
input: node name |
282 |
+ |
returns: AuthoritativeSE |
283 |
+ |
""" |
284 |
+ |
params = {'node' : self.node } |
285 |
+ |
datasvc_nodes="%s/nodes"%self.datasvc_url |
286 |
+ |
fullurl="%s/nodes/?node=%s"%(self.datasvc_url,self.node) |
287 |
+ |
domnodes = self.domPhedex(params,datasvc_nodes) |
288 |
+ |
|
289 |
+ |
if not domnodes : |
290 |
+ |
msg="Unable to get info from %s"%fullurl |
291 |
+ |
raise CrabException(msg) |
292 |
+ |
|
293 |
+ |
errormsg = self.parse_error(domnodes) |
294 |
+ |
if errormsg: |
295 |
+ |
msg="Error extracting info from %s due to: %s"%(fullurl,errormsg) |
296 |
+ |
raise CrabException(msg) |
297 |
+ |
result = domnodes.getElementsByTagName('phedex') |
298 |
+ |
if not result: |
299 |
+ |
return [] |
300 |
+ |
result = result[0] |
301 |
+ |
se = None |
302 |
+ |
node = result.getElementsByTagName('node') |
303 |
+ |
for m in node: |
304 |
+ |
se=m.getAttribute("se") |
305 |
+ |
if se: |
306 |
+ |
return se |
307 |
|
|
308 |
|
|
309 |
|
if __name__ == '__main__': |