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.1 by afanfani, Mon Nov 7 23:20:21 2005 UTC vs.
Revision 1.12 by gutsche, Fri Sep 22 14:47:33 2006 UTC

# Line 1 | Line 1
1   #!/usr/bin/env python
2   import sys, os, commands,string, re
3 + import exceptions
4 + from crab_exceptions import *
5   from crab_util import *
6   import common
7  
8 + try:
9 +    import dlsApi
10 +    import dlsClient
11 +    from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
12 + except:
13 +    try:
14 +        Crabpydir=commands.getoutput('which crab')
15 +        Topdir=string.replace(Crabpydir,'/python/crab','')
16 +        sys.path.append(Topdir+'/DLSAPI')
17 +        import dlsApi
18 +        import dlsClient
19 +        from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
20 +    except:
21 +        msg="ERROR no DLS API available"
22 +        raise CrabException(msg)
23 +                                                                                            
24 + ## for python 2.2 add the pyexpat.so to PYTHONPATH
25 + pythonV=sys.version.split(' ')[0]
26 + if pythonV.find('2.2') >= 0 :
27 + Crabpydir=commands.getoutput('which crab')
28 + Topdir=string.replace(Crabpydir,'/python/crab','')
29 + extradir=Topdir+'/DLSAPI/extra'
30 + if sys.path.count(extradir) <= 0:
31 +   if os.path.exists(extradir):
32 +    sys.path.insert(0, extradir)
33 +
34 +
35   class DLSError:
36 <  def __init__(self, fileblocks):
37 <    print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
38 <    pass
36 >    def __init__(self, fileblocks):
37 >        print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
38 >        pass
39 >
40 >
41 > class DLSNoReplicas(exceptions.Exception):
42 >    def __init__(self, FileBlock):
43 >        args ="No replicas exists for fileblock: "+FileBlock+"\n"
44 >        exceptions.Exception.__init__(self, args)
45 >        pass
46 >
47 >    def getClassName(self):
48 >        """ Return class name. """
49 >        return "%s" % (self.__class__.__name__)
50 >
51 >    def getErrorMessage(self):
52 >        """ Return exception error. """
53 >        return "%s" % (self.args)
54 >
55  
56   ##############################################################################
57   # Class to extract info from DLS
58   ##############################################################################
59  
60   class DLSInfo:
61 <     def __init__(self, fileblocks):
62 <          self.fileblocks = fileblocks
63 <          self.DLSclient_ = 'DLSAPI/dls-get-se '
64 <          self.DLSServer_ = 'cmsbogw.bo.infn.it'
61 >    def __init__(self, type, cfg_params):
62 >        self.cfg_params = cfg_params
63 >        jobtype = self.cfg_params['CRAB.jobtype']
64 >        ##SL I don't like all this hardcoded and jobtype dependent info put here
65 >        if type=="DLS_TYPE_DLI":
66 >            if jobtype.count('orca')>0:
67 >                endpoint="lfc-cms-test.cern.ch/grid/cms/DLS/LFCProto"
68 >            else:  
69 >                try:
70 >                    endpoint=self.cfg_params['CMSSW.dls_endpoint']
71 >                except KeyError:
72 >                    endpoint="prod-lfc-cms-central.cern.ch/grid/cms/DLS/LFC"
73 >
74 >            try:
75 >                import xml.dom.ext.reader
76 >            except:
77 >                crabdir=os.getenv('CRABDIR')
78 > ## Let the  user set up PyXML by hand
79 >                msg="There is no setup of PyXML python module required by DLS (DLI). Do the following:\n"
80 >                msg+=" - check that in  %s/configure  the function configureDLSAPI is not commented \n"%crabdir
81 >                msg+=" - uncomment it and re-run the configuration :"
82 >                msg+="\n    cd %s\n"%crabdir
83 >                msg+="     ./configure\n"
84 >                msg+="     source crab.(c)sh\n"
85 >                raise CrabException(msg)
86 >
87 >        elif type=="DLS_TYPE_MYSQL":
88 >            if jobtype.count('orca')>0:
89 >                endpoint="lfc-cms-test.cern.ch/grid/cms/DLS/LFCProto"
90 >            else:  
91 >                try:
92 >                    endpoint=self.cfg_params['CMSSW.dls_endpoint']
93 >                except KeyError:
94 >                    endpoint="lxgate10.cern.ch:18081"
95 >        else:
96 >            msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type
97 >            raise CrabException(msg)
98  
99 +        common.logger.debug(5,"DLS interface: %s Server %s"%(type,endpoint))      
100 +        try:
101 +            self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint)
102 +        except dlsApi.DlsApiError, inst:
103 +            msg = "Error when binding the DLS interface: %s  Server %s"%(str(inst),self.DLSServer_)
104 +            #print msg
105 +            raise CrabException(msg)
106 +
107   # ####################################
108 <     def getReplicas(self):
109 <         """
110 <          query DLS to get replicas
111 <         """
112 <         ##
113 <         cmd = self.DLSclient_+" --host "+self.DLSServer_+" --datablock "+self.fileblocks
114 <         #print cmd
115 <         sites = runCommand(cmd)
116 <         ListSites=string.split(sites,'\n')
117 <         return ListSites        
108 >    def getReplicas(self,fileblocks):
109 >        """
110 >        query DLS to get replicas
111 >        """
112 >        ##
113 >        try:
114 >            entryList=self.api.getLocations([fileblocks])
115 >        except dlsApi.DlsApiError, inst:
116 >            msg = "Error in the DLS query: %s." % str(inst)
117 >            #print msg
118 >            raise DLSNoReplicas(fileblocks)
119 >
120 >        ListSites=[]
121 >        for entry in entryList:
122 >            for loc in entry.locations:
123 >                ListSites.append(str(loc.host))
124 >        if len(ListSites)<=0:
125 >            raise DLSNoReplicas(fileblocks)
126 >
127 >        return ListSites        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines