ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DataLocation.py
Revision: 1.10
Committed: Wed Jun 14 22:26:23 2006 UTC (18 years, 10 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_2_0, CRAB_1_2_0_pre9, CRAB_1_2_0_pre8, CRAB_1_2_0_pre7
Branch point for: CRAB_BOSS4_v1, CRAB_BOSS4
Changes since 1.9: +3 -2 lines
Log Message:
default to DLS-DLI for old EDM data

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     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.9
69 afanfani 1.8 try:
70     dlstype=self.cfg_params['ORCA.dls_type']
71     except KeyError:
72 afanfani 1.10 ## default to DLS-DLI:
73     dlstype='dli'
74    
75 afanfani 1.8 DLS_type="DLS_TYPE_%s"%dlstype.upper()
76 afanfani 1.6
77 afanfani 1.1 ## find the replicas for each block
78     for fileblocks in self.Listfileblocks:
79 slacapra 1.5 for afileblock in fileblocks:
80     countblock=countblock+1
81     dbspath=string.split(afileblock,'#')[0]
82     (null,ds,tier,ow)=string.split(dbspath,'/')
83     datablock=ow+"/"+ds
84     #
85 afanfani 1.9 dls=DLSInfo(DLS_type,self.cfg_params['CRAB.jobtype'])
86 slacapra 1.5 try:
87 afanfani 1.6 replicas=dls.getReplicas(datablock)
88 slacapra 1.5 except DLSNoReplicas, ex:
89     raise DataLocationError(ex.getErrorMessage())
90     except:
91     raise DataLocationError('')
92 afanfani 1.1
93 slacapra 1.5 for replica in replicas:
94     Sites.append(replica)
95 afanfani 1.1
96     ## select only sites that contains _all_ the fileblocks
97     allblockSites=self.SelectSites(countblock,Sites)
98     #for as in allblockSites:
99     # print " site is "+as
100 afanfani 1.4 ## select sites that are not in a BlackList , if any
101     self.SelectedNotBlackSites=self.checkBlackList(allblockSites)
102     ## select sites there are in the white list , if any
103     self.SelectedSites=self.checkWhiteList(self.SelectedNotBlackSites)
104 afanfani 1.1
105     # #######################################################################
106     def getSites(self):
107     """
108 slacapra 1.5 get the sites hosting all the needed data
109 afanfani 1.1 """
110     return self.SelectedSites
111    
112     # #######################################################################
113     def SelectSites(self, countblock, Sites ):
114     """
115 slacapra 1.5 select only sites that contains _all_ the fileblocks
116 afanfani 1.1 """
117     goodSites=[]
118     for aSite in Sites :
119 slacapra 1.5 if ( Sites.count(aSite)==countblock ) :
120     goodSites.append(aSite)
121 afanfani 1.1
122     return self.uniquelist(goodSites)
123    
124     # #######################################################################
125     def checkBlackList(self, Sites):
126     """
127 afanfani 1.4 select sites that are not excluded by the user (via CE black list)
128 afanfani 1.1 """
129     goodSites = []
130     for aSite in Sites:
131     good=1
132     for re in self.reCEBlackList:
133     if re.search(aSite):
134     common.logger.message('CE in black list, skipping site '+aSite)
135     good=0
136     pass
137     if good: goodSites.append(aSite)
138     if len(goodSites) == 0:
139     common.logger.debug(3,"No selected Sites")
140     return goodSites
141    
142 afanfani 1.4 # #######################################################################
143     def checkWhiteList(self, Sites):
144     """
145     select sites that are defined by the user (via CE white list)
146     """
147     if len(self.reCEWhiteList)==0: return Sites
148     goodSites = []
149     for aSite in Sites:
150     good=0
151     for re in self.reCEWhiteList:
152     if re.search(aSite):
153     common.logger.message('CE in white list, adding site '+aSite)
154     good=1
155     pass
156     if good: goodSites.append(aSite)
157     if len(goodSites) == 0:
158     common.logger.debug(3,"No selected Sites")
159     return goodSites
160    
161 afanfani 1.1 #######################################################################
162     def uniquelist(self, old):
163     """
164 slacapra 1.5 remove duplicates from a list
165 afanfani 1.1 """
166     nd={}
167     for e in old:
168     nd[e]=0
169     return nd.keys()
170 slacapra 1.5