ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DataLocation.py
Revision: 1.6
Committed: Thu May 18 18:46:22 2006 UTC (18 years, 11 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: pre_cmssw_integration_20060527
Changes since 1.5: +5 -2 lines
Log Message:
mods to use new DBS and DLS API

File Contents

# User Rev Content
1 afanfani 1.1 #!/usr/bin/env python2
2     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     self.SelectedSites = [] # DLS output: list of sites hosting all the needed fileblocks
30     # retireved using method getSites
31    
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     self.reCEBlackList.append(re.compile( bad ))
44    
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     self.reCEWhiteList.append(re.compile( good ))
57    
58    
59 afanfani 1.1 # #######################################################################
60     def fetchDLSInfo(self):
61     """
62     Contact DLS
63     """
64     countblock=0
65     Sites = []
66     allblockSites = []
67    
68 afanfani 1.6 DLS_type="DLS_TYPE_MYSQL"
69     #DLS_type="DLS_TYPE_DLI"
70    
71 afanfani 1.1 ## find the replicas for each block
72     for fileblocks in self.Listfileblocks:
73 slacapra 1.5 #print fileblocks
74     for afileblock in fileblocks:
75     countblock=countblock+1
76     dbspath=string.split(afileblock,'#')[0]
77     (null,ds,tier,ow)=string.split(dbspath,'/')
78     datablock=ow+"/"+ds
79     #
80 afanfani 1.6 dls=DLSInfo(DLS_type)
81 slacapra 1.5 try:
82 afanfani 1.6 replicas=dls.getReplicas(datablock)
83 slacapra 1.5 except DLSNoReplicas, ex:
84     raise DataLocationError(ex.getErrorMessage())
85     except:
86     raise DataLocationError('')
87 afanfani 1.1
88 slacapra 1.5 for replica in replicas:
89     Sites.append(replica)
90 afanfani 1.1
91     ## select only sites that contains _all_ the fileblocks
92     allblockSites=self.SelectSites(countblock,Sites)
93     #for as in allblockSites:
94     # print " site is "+as
95 afanfani 1.4 ## select sites that are not in a BlackList , if any
96     self.SelectedNotBlackSites=self.checkBlackList(allblockSites)
97     ## select sites there are in the white list , if any
98     self.SelectedSites=self.checkWhiteList(self.SelectedNotBlackSites)
99 afanfani 1.1
100     # #######################################################################
101     def getSites(self):
102     """
103 slacapra 1.5 get the sites hosting all the needed data
104 afanfani 1.1 """
105     return self.SelectedSites
106    
107     # #######################################################################
108     def SelectSites(self, countblock, Sites ):
109     """
110 slacapra 1.5 select only sites that contains _all_ the fileblocks
111 afanfani 1.1 """
112     goodSites=[]
113     for aSite in Sites :
114 slacapra 1.5 if ( Sites.count(aSite)==countblock ) :
115     goodSites.append(aSite)
116 afanfani 1.1
117     return self.uniquelist(goodSites)
118    
119     # #######################################################################
120     def checkBlackList(self, Sites):
121     """
122 afanfani 1.4 select sites that are not excluded by the user (via CE black list)
123 afanfani 1.1 """
124     goodSites = []
125     for aSite in Sites:
126     good=1
127     for re in self.reCEBlackList:
128     if re.search(aSite):
129     common.logger.message('CE in black list, skipping site '+aSite)
130     good=0
131     pass
132     if good: goodSites.append(aSite)
133     if len(goodSites) == 0:
134     common.logger.debug(3,"No selected Sites")
135     return goodSites
136    
137 afanfani 1.4 # #######################################################################
138     def checkWhiteList(self, Sites):
139     """
140     select sites that are defined by the user (via CE white list)
141     """
142     if len(self.reCEWhiteList)==0: return Sites
143     goodSites = []
144     for aSite in Sites:
145     good=0
146     for re in self.reCEWhiteList:
147     if re.search(aSite):
148     common.logger.message('CE in white list, adding site '+aSite)
149     good=1
150     pass
151     if good: goodSites.append(aSite)
152     if len(goodSites) == 0:
153     common.logger.debug(3,"No selected Sites")
154     return goodSites
155    
156 afanfani 1.1 #######################################################################
157     def uniquelist(self, old):
158     """
159 slacapra 1.5 remove duplicates from a list
160 afanfani 1.1 """
161     nd={}
162     for e in old:
163     nd[e]=0
164     return nd.keys()
165 slacapra 1.5