ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DataLocation.py
Revision: 1.15
Committed: Wed Sep 20 17:29:52 2006 UTC (18 years, 7 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_3_0_pre3
Changes since 1.14: +79 -52 lines
Log Message:
BOSS4 + sub-file splitting + taskDB

File Contents

# User Rev Content
1 gutsche 1.7 #!/usr/bin/env python
2 afanfani 1.1 import sys, os, string, re
3     import urllib, urllister
4     import urllib2
5     import common
6     from DLSInfo import *
7    
8     # ####################################
9 afanfani 1.3 class DataLocationError(exceptions.Exception):
10 slacapra 1.5 def __init__(self, errorMessage):
11     args=errorMessage
12     exceptions.Exception.__init__(self, args)
13     pass
14 afanfani 1.3
15 slacapra 1.5 def getErrorMessage(self):
16     """ Return exception error """
17     return "%s" % (self.args)
18 afanfani 1.1
19     # ####################################
20     # class to extact data location
21     class DataLocation:
22     def __init__(self, Listfileblocks, cfg_params):
23    
24     # Attributes
25     self.Listfileblocks = Listfileblocks # DLS input: list of fileblocks lists
26 slacapra 1.5
27 afanfani 1.1 self.cfg_params = cfg_params
28    
29 slacapra 1.15 self.SelectedSites = {} # DLS output: list of sites hosting fileblocks
30     # retrieved using method getSites
31 afanfani 1.1
32     CEBlackList = []
33     try:
34     tmpBad = string.split(self.cfg_params['EDG.ce_black_list'],',')
35     for tmp in tmpBad:
36     tmp=string.strip(tmp)
37     CEBlackList.append(tmp)
38     except KeyError:
39     pass
40     common.logger.debug(5,'CEBlackList: '+str(CEBlackList))
41     self.reCEBlackList=[]
42     for bad in CEBlackList:
43 slacapra 1.15 self.reCEBlackList.append(re.compile( string.lower(bad) ))
44 afanfani 1.1
45 afanfani 1.4 CEWhiteList = []
46     try:
47     tmpGood = string.split(self.cfg_params['EDG.ce_white_list'],',')
48     for tmp in tmpGood:
49     tmp=string.strip(tmp)
50     CEWhiteList.append(tmp)
51     except KeyError:
52     pass
53     common.logger.debug(5,'CEWhiteList: '+str(CEWhiteList))
54     self.reCEWhiteList=[]
55     for good in CEWhiteList:
56 slacapra 1.15 self.reCEWhiteList.append(re.compile( string.lower(good) ))
57 afanfani 1.4
58 slacapra 1.15 self.osgSitesDictionary = {"Wisconsin":"cmssrm.hep.wisc.edu", \
59     "Purdue":"dcache.rcac.purdue.edu", \
60     "Florida":"ufdcache.phys.ufl.edu", \
61     "Nebraska":"thpc-1.unl.edu", \
62     "Caltech":"cithep59.ultralight.org", \
63     "UCSD":"t2data2.t2.ucsd.edu", \
64     "fnal":"cmssrm.fnal.gov", \
65     "MIT":"se01.cmsaf.mit.edu"}
66 afanfani 1.4
67 afanfani 1.1 # #######################################################################
68     def fetchDLSInfo(self):
69     """
70     Contact DLS
71     """
72     countblock=0
73     Sites = []
74     allblockSites = []
75    
76 afanfani 1.8 try:
77 slacapra 1.15 dlstype=self.cfg_params['CMSSW.dls_type']
78 afanfani 1.8 except KeyError:
79 slacapra 1.15 dlstype='mysql'
80     #DLS_type="DLS_TYPE_MYSQL"
81 afanfani 1.8 DLS_type="DLS_TYPE_%s"%dlstype.upper()
82 afanfani 1.6
83 mkirn 1.11 ## find the replicas for each block
84 slacapra 1.15 blockSites = {}
85     failCount = 0
86 afanfani 1.1 for fileblocks in self.Listfileblocks:
87 slacapra 1.15 countblock=countblock+1
88     #dbspath=string.split(afileblock,'#')[0]
89     #(null,ds,tier,ow)=string.split(dbspath,'/')
90     #datablock=ow+"/"+ds
91     #
92     dls=DLSInfo(DLS_type,self.cfg_params)
93     try:
94     replicas=dls.getReplicas(fileblocks)
95     common.logger.debug(5,"sites are %s"%replicas)
96     replicas = self.checkOSGt2(replicas)
97     replicas = self.checkBlackList(replicas, fileblocks)
98     if len(replicas)!=0:
99     replicas = self.checkWhiteList(replicas, fileblocks)
100     if len(replicas)!=0:
101     blockSites[fileblocks] = replicas
102     except DLSNoReplicas, ex:
103     common.logger.message(str(ex.getErrorMessage()))
104     msg = "Proceeding without this block."
105     common.logger.message("Proceeding without this block.\n")
106     failCount = failCount + 1
107     except:
108     raise DataLocationError('')
109    
110     if countblock == failCount:
111     msg = "All data blocks encountered a DLS error. Quitting."
112     raise DataLocationError(msg)
113    
114     if len(blockSites)==0:
115     msg = 'No sites remaining that host any part of the requested data! Exiting... '
116     raise CrabException(msg)
117    
118     self.SelectedSites = blockSites
119 afanfani 1.1
120     # #######################################################################
121     def getSites(self):
122     """
123 slacapra 1.5 get the sites hosting all the needed data
124 afanfani 1.1 """
125     return self.SelectedSites
126    
127     # #######################################################################
128 slacapra 1.15 def checkBlackList(self, Sites, fileblocks):
129 afanfani 1.1 """
130 afanfani 1.4 select sites that are not excluded by the user (via CE black list)
131 afanfani 1.1 """
132     goodSites = []
133     for aSite in Sites:
134 slacapra 1.15 common.logger.debug(10,'Site '+aSite)
135 afanfani 1.1 good=1
136     for re in self.reCEBlackList:
137 slacapra 1.15 if re.search(string.lower(aSite)):
138 afanfani 1.1 common.logger.message('CE in black list, skipping site '+aSite)
139     good=0
140     pass
141     if good: goodSites.append(aSite)
142     if len(goodSites) == 0:
143 slacapra 1.15 msg = "No sites hosting the block %s after BlackList" % fileblocks
144     common.logger.message(msg)
145     common.logger.message("Proceeding without this block.\n")
146     else:
147     common.logger.debug(5,"Selected sites for block "+str(fileblocks)+" via BlackList are "+str(goodSites)+"\n")
148 afanfani 1.1 return goodSites
149    
150 afanfani 1.4 # #######################################################################
151 slacapra 1.15 def checkWhiteList(self, Sites, fileblocks):
152 afanfani 1.4 """
153     select sites that are defined by the user (via CE white list)
154     """
155     if len(self.reCEWhiteList)==0: return Sites
156     goodSites = []
157     for aSite in Sites:
158     good=0
159     for re in self.reCEWhiteList:
160 slacapra 1.15 if re.search(string.lower(aSite)):
161 afanfani 1.4 common.logger.message('CE in white list, adding site '+aSite)
162     good=1
163     pass
164     if good: goodSites.append(aSite)
165     if len(goodSites) == 0:
166 slacapra 1.15 msg = "No sites hosting the block %s after WhiteList" % fileblocks
167     common.logger.message(msg)
168     common.logger.message("Proceeding without this block.\n")
169     else:
170     common.logger.debug(5,"Selected sites for block "+str(fileblocks)+" via WhiteList are "+str(goodSites)+"\n")
171 afanfani 1.4 return goodSites
172    
173 slacapra 1.15 # #######################################################################
174     def checkOSGt2(self, sites):
175     fixedSites = []
176     osgKeys = self.osgSitesDictionary.keys()
177     for site in sites:
178     fix = 0
179     for osgSite in osgKeys:
180     if string.lower(site) == string.lower(osgSite):
181     fixedSites.append(self.osgSitesDictionary[osgSite])
182     fix = 1
183     if (fix == 0):
184     fixedSites.append(site)
185    
186     return fixedSites
187    
188 afanfani 1.1 #######################################################################
189     def uniquelist(self, old):
190     """
191 slacapra 1.5 remove duplicates from a list
192 afanfani 1.1 """
193     nd={}
194     for e in old:
195     nd[e]=0
196     return nd.keys()