ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DLSInfo.py
(Generate patch)

Comparing COMP/CRAB/python/DLSInfo.py (file contents):
Revision 1.17 by gutsche, Thu May 24 17:59:26 2007 UTC vs.
Revision 1.29 by spiga, Wed Jan 7 15:24:30 2009 UTC

# Line 9 | Line 9 | import dlsApi
9   import dlsClient
10   from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
11                                                                                              
12 ## for python 2.2 add the pyexpat.so to PYTHONPATH
13 pythonV=sys.version.split(' ')[0]
14 if pythonV.find('2.2') >= 0 :
15    Crabpydir=commands.getoutput('which crab')
16    Topdir=string.replace(Crabpydir,'/python/crab','')
17    extradir=Topdir+'/DLSAPI/extra'
18    if sys.path.count(extradir) <= 0:
19         if os.path.exists(extradir):
20            sys.path.insert(0, extradir)
21
22
12   class DLSError:
13      def __init__(self, fileblocks):
14          print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
# Line 28 | Line 17 | class DLSError:
17  
18   class DLSNoReplicas(exceptions.Exception):
19      def __init__(self, FileBlock):
20 <        self.args ="No replicas exists for fileblock: "+FileBlock+"\n"
20 >        self.args ="No replicas exists for fileblock: %s \n"%str(FileBlock)
21          exceptions.Exception.__init__(self, self.args)
22          pass
23  
# Line 48 | Line 37 | class DLSNoReplicas(exceptions.Exception
37   class DLSInfo:
38      def __init__(self, type, cfg_params):
39          self.cfg_params = cfg_params
40 <        if type=="DLS_TYPE_DLI":
41 <            try:
42 <                endpoint=self.cfg_params['CMSSW.dls_endpoint']
43 <            except KeyError:
44 <                endpoint="prod-lfc-cms-central.cern.ch/grid/cms/DLS/LFC"
56 <
57 <            try:
58 <                import xml.dom.ext.reader
59 <            except:
60 <                crabdir=os.getenv('CRABDIR')
61 < ## Let the  user set up PyXML by hand
62 <                msg="There is no setup of PyXML python module required by DLS (DLI). Do the following:\n"
63 <                msg+=" - check that in  %s/configure  the function configureDLSAPI is not commented \n"%crabdir
64 <                msg+=" - uncomment it and re-run the configuration :"
65 <                msg+="\n    cd %s\n"%crabdir
66 <                msg+="     ./configure\n"
67 <                msg+="     source crab.(c)sh\n"
68 <                raise CrabException(msg)
40 >        self.showCAF = False
41 >        self.showProd = False
42 >
43 >        showProd = int(self.cfg_params.get('CMSSW.show_prod', 0))
44 >        if showProd == 1: self.showProd = True
45  
46 <        elif type=="DLS_TYPE_MYSQL":
47 <            try:
48 <                endpoint=self.cfg_params['CMSSW.dls_endpoint']
49 <            except KeyError:
50 <                endpoint="lxgate10.cern.ch:18081"
51 <        elif type=="DLS_TYPE_DBS":
52 <            #
46 >        phedexURL='http://cmsweb.cern.ch/phedex/datasvc/xml/prod/'
47 >        global_url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
48 >        caf_url = "http://cmsdbsprod.cern.ch/cms_dbs_caf_analysis_01/servlet/DBSServlet"
49 >        dbs_url_map  =   {'glite':    global_url,
50 >                          'glitecoll':global_url,\
51 >                          'condor':   global_url,\
52 >                          'condor_g': global_url,\
53 >                          'glidein':  global_url,\
54 >                          'lsf':      global_url,\
55 >                          'caf':      caf_url,\
56 >                          'sge':      global_url
57 >                          }
58 >        dbs_url_default = dbs_url_map[(common.scheduler.name()).lower()]
59 >
60 >        if type=="DLS_TYPE_DBS":
61              # use dbs_url as dls_endpoint if dls_type is dbs
62 <            #
63 <            try:
64 <                endpoint=self.cfg_params['CMSSW.dbs_url']
65 <            except KeyError:
82 <                endpoint="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
62 >            endpoint=self.cfg_params.get('CMSSW.dbs_url', dbs_url_default)
63 >        elif type=="DLS_TYPE_PHEDEX":
64 >            endpoint=self.cfg_params.get('CMSSW.dls_phedex_url',phedexURL)
65 >            if self.cfg_params['CRAB.scheduler'].upper() == 'CAF':  self.showCAF = True
66          else:
67              msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type
68              raise CrabException(msg)
86
69          common.logger.debug(5,"DLS interface: %s Server %s"%(type,endpoint))      
70          try:
71              self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint)
# Line 91 | Line 73 | class DLSInfo:
73              msg = "Error when binding the DLS interface: %s  Server %s"%(str(inst),endpoint)
74              #print msg
75              raise CrabException(msg)
76 <
76 >
77 >    def getReplicasBulk(self,fileblocks):
78 >        """
79 >        query DLS to get replicas
80 >        """              
81 >        ##
82 >        try:
83 >            entryList=self.api.getLocations(fileblocks,longList=True,showCAF=self.showCAF,showProd=self.showProd)
84 >        except dlsApi.DlsApiError, inst:
85 >            raise DLSNoReplicas(fileblocks)
86 >        results = {}
87 >        for entry in entryList:
88 >            ListSites=[]
89 >            for loc in entry.locations:
90 >                ListSites.append(str(loc.host))
91 >            if len(ListSites)<=0:
92 >                msg ="No replicas exists for fileblock: %s \n"%str(fileblocks)
93 >                raise CrabException(msg)
94 >            results[entry.fileBlock.name]=ListSites
95 >
96 >        return results        
97   # ####################################
98      def getReplicas(self,fileblocks):
99          """
# Line 99 | Line 101 | class DLSInfo:
101          """
102          ##
103          try:
104 <            entryList=self.api.getLocations([fileblocks])
104 >            entryList=self.api.getLocations([fileblocks],showCAF=self.showCAF)
105          except dlsApi.DlsApiError, inst:
104            #msg = "Error in the DLS query: %s." % str(inst)
105            #print msg
106              raise DLSNoReplicas(fileblocks)
107  
108          ListSites=[]

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines