8 |
|
import dlsApi |
9 |
|
import dlsClient |
10 |
|
from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry |
11 |
< |
|
12 |
< |
|
11 |
> |
|
12 |
|
class DLSError: |
13 |
|
def __init__(self, fileblocks): |
14 |
|
print '\nERROR accessing DLS for fileblock '+fileblocks+'\n' |
17 |
|
|
18 |
|
class DLSNoReplicas(exceptions.Exception): |
19 |
|
def __init__(self, FileBlock): |
20 |
< |
args ="No replicas exists for fileblock: "+FileBlock+"\n" |
21 |
< |
exceptions.Exception.__init__(self, args) |
20 |
> |
self.args ="No replicas exists for fileblock: %s \n"%str(FileBlock) |
21 |
> |
exceptions.Exception.__init__(self, self.args) |
22 |
|
pass |
23 |
|
|
24 |
|
def getClassName(self): |
35 |
|
############################################################################## |
36 |
|
|
37 |
|
class DLSInfo: |
38 |
< |
def __init__(self, type): |
39 |
< |
if type=="DLS_TYPE_DLI": |
40 |
< |
endpoint="lfc-cms-test.cern.ch/grid/cms/DLS/LFCProto" |
41 |
< |
try: |
42 |
< |
import xml.dom.ext.reader |
43 |
< |
except: |
44 |
< |
crabdir=os.getenv('CRABDIR') |
45 |
< |
## Let the user set up PyXML by hand |
46 |
< |
msg="Need to setup the PyXML python module. Do the following:\n" |
47 |
< |
msg+=" cd %s/DLSAPI\n"%crabdir |
48 |
< |
msg+=" ./InstallPyXML.sh" |
49 |
< |
raise CrabException(msg) |
50 |
< |
|
51 |
< |
elif type=="DLS_TYPE_MYSQL": |
52 |
< |
endpoint="lxgate10.cern.ch:18081" |
38 |
> |
def __init__(self, type, cfg_params): |
39 |
> |
self.cfg_params = cfg_params |
40 |
> |
self.showCAF = False |
41 |
> |
self.showProd = False |
42 |
> |
self.subscribed = False |
43 |
> |
subscribed =int(self.cfg_params.get('CMSSW.subscribed', 0)) |
44 |
> |
if subscribed == 1: self.subscribed = True |
45 |
> |
showProd = int(self.cfg_params.get('CMSSW.show_prod', 0)) |
46 |
> |
if showProd == 1: self.showProd = True |
47 |
> |
|
48 |
> |
phedexURL='http://cmsweb.cern.ch/phedex/datasvc/xml/prod/' |
49 |
> |
global_url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet" |
50 |
> |
caf_url = "http://cmsdbsprod.cern.ch/cms_dbs_caf_analysis_01/servlet/DBSServlet" |
51 |
> |
dbs_url_map = {'glite': global_url, |
52 |
> |
'glite_slc5':global_url,\ |
53 |
> |
'glitecoll':global_url,\ |
54 |
> |
'condor': global_url,\ |
55 |
> |
'condor_g': global_url,\ |
56 |
> |
'glidein': global_url,\ |
57 |
> |
'lsf': global_url,\ |
58 |
> |
'caf': caf_url,\ |
59 |
> |
'sge': global_url,\ |
60 |
> |
'arc': global_url,\ |
61 |
> |
'pbs': global_url |
62 |
> |
} |
63 |
> |
dbs_url_default = dbs_url_map[(common.scheduler.name()).lower()] |
64 |
> |
|
65 |
> |
if type=="DLS_TYPE_DBS": |
66 |
> |
# use dbs_url as dls_endpoint if dls_type is dbs |
67 |
> |
endpoint=self.cfg_params.get('CMSSW.dbs_url', dbs_url_default) |
68 |
> |
elif type=="DLS_TYPE_PHEDEX": |
69 |
> |
endpoint=self.cfg_params.get('CMSSW.dls_phedex_url',phedexURL) |
70 |
> |
if self.cfg_params['CRAB.scheduler'].upper() == 'CAF': self.showCAF = True |
71 |
|
else: |
72 |
< |
msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type |
73 |
< |
raise CrabException(msg) |
72 |
> |
msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type |
73 |
> |
raise CrabException(msg) |
74 |
> |
common.logger.debug("DLS interface: %s Server %s"%(type,endpoint)) |
75 |
> |
try: |
76 |
> |
self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint) |
77 |
> |
except dlsApi.DlsApiError, inst: |
78 |
> |
msg = "Error when binding the DLS interface: %s Server %s"%(str(inst),endpoint) |
79 |
> |
#print msg |
80 |
> |
raise CrabException(msg) |
81 |
|
|
82 |
+ |
def getReplicasBulk(self,fileblocks): |
83 |
+ |
""" |
84 |
+ |
query DLS to get replicas |
85 |
+ |
""" |
86 |
+ |
## |
87 |
|
try: |
88 |
< |
self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint) |
88 |
> |
entryList=self.api.getLocations(fileblocks,longList=True,showCAF=self.showCAF,showProd=self.showProd,subscribed=self.subscribed) |
89 |
|
except dlsApi.DlsApiError, inst: |
90 |
< |
msg = "Error when binding the DLS interface: %s Server %s"%(str(inst),self.DLSServer_) |
91 |
< |
#print msg |
92 |
< |
raise CrabException(msg) |
90 |
> |
raise DLSNoReplicas(fileblocks) |
91 |
> |
results = {} |
92 |
> |
for entry in entryList: |
93 |
> |
ListSites=[] |
94 |
> |
for loc in entry.locations: |
95 |
> |
ListSites.append(str(loc.host)) |
96 |
> |
if len(ListSites)<=0: |
97 |
> |
msg ="No replicas exists for fileblock: %s \n"%str(fileblocks) |
98 |
> |
raise CrabException(msg) |
99 |
> |
results[entry.fileBlock.name]=ListSites |
100 |
|
|
101 |
+ |
return results |
102 |
|
# #################################### |
103 |
|
def getReplicas(self,fileblocks): |
104 |
|
""" |
106 |
|
""" |
107 |
|
## |
108 |
|
try: |
109 |
< |
entryList=self.api.getLocations([fileblocks]) |
109 |
> |
entryList=self.api.getLocations([fileblocks],showCAF=self.showCAF,subscribed=self.subscribed) |
110 |
|
except dlsApi.DlsApiError, inst: |
111 |
< |
msg = "Error in the DLS query: %s." % str(inst) |
75 |
< |
#print msg |
76 |
< |
raise DLSNoReplicas(fileblocks) |
111 |
> |
raise DLSNoReplicas(fileblocks) |
112 |
|
|
113 |
|
ListSites=[] |
114 |
|
for entry in entryList: |
115 |
< |
for loc in entry.locations: |
116 |
< |
ListSites.append(str(loc.host)) |
115 |
> |
for loc in entry.locations: |
116 |
> |
ListSites.append(str(loc.host)) |
117 |
|
if len(ListSites)<=0: |
118 |
< |
raise DLSNoReplicas(fileblocks) |
118 |
> |
raise DLSNoReplicas(fileblocks) |
119 |
|
|
120 |
|
return ListSites |