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.4 by afanfani, Sun Jan 29 01:46:08 2006 UTC vs.
Revision 1.9 by afanfani, Thu Jun 1 11:11:17 2006 UTC

# Line 5 | Line 5 | 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)
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_ = 'dls-get-se '
64 <          self.DLSServer_ = 'lxgate10.cern.ch'
65 <          self.DLSServerPort_ = '18081'
66 <          #self.DLSServerPort_ = '18080'
67 <          
68 <          out=commands.getstatusoutput('which '+self.DLSclient_)
69 <          if out[0]>0:
70 <             msg="ERROR no DLS CLI available in $PATH : %s"%self.DLSclient_
61 >    def __init__(self, type, jobtype):
62 >        if type=="DLS_TYPE_DLI":
63 >           if jobtype.count('orca')>0:
64 >             endpoint="lfc-cms-test.cern.ch/grid/cms/DLS/LFCProto"
65 >           else:  
66 >             endpoint="lfc-cms-test.cern.ch/grid/cms/DLS/LFC"
67 >           try:
68 >             import xml.dom.ext.reader
69 >           except:
70 >             crabdir=os.getenv('CRABDIR')
71 > ## Let the user set up PyXML by hand
72 >             msg="There is no setup of PyXML python module required by DLS (DLI). Do the following:\n"
73 >             msg+=" - check that in  %s/configure  the function configureDLSAPI is not commented \n"%crabdir
74 >             msg+=" - uncomment it and re-run the configuration :"
75 >             msg+="\n    cd %s\n"%crabdir
76 >             msg+="     ./configure\n"
77 >             msg+="     source crab.(c)sh\n"
78               raise CrabException(msg)
79  
80 +        elif type=="DLS_TYPE_MYSQL":
81 +           endpoint="lxgate10.cern.ch:18081"
82 +        else:
83 +           msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type
84 +           raise CrabException(msg)
85 +
86 +        common.logger.debug(5,"DLS interface: %s Server %s"%(type,endpoint))      
87 +        try:
88 +          self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint)
89 +        except dlsApi.DlsApiError, inst:
90 +          msg = "Error when binding the DLS interface: %s  Server %s"%(str(inst),self.DLSServer_)
91 +          #print msg
92 +          raise CrabException(msg)
93 +
94   # ####################################
95 <     def getReplicas(self):
96 <         """
97 <          query DLS to get replicas
98 <         """
99 <         ##
100 <         cmd = self.DLSclient_+" --port "+self.DLSServerPort_+" --host "+self.DLSServer_+" --datablock "+self.fileblocks
101 <         #print cmd
102 <         sites = runCommand(cmd)
103 <         sites=string.strip(sites)
104 <         if len(sites)<=0:
105 <           raise DLSNoReplicas(self.fileblocks)
95 >    def getReplicas(self,fileblocks):
96 >        """
97 >        query DLS to get replicas
98 >        """
99 >        ##
100 >        try:
101 >          entryList=self.api.getLocations([fileblocks])
102 >        except dlsApi.DlsApiError, inst:
103 >          msg = "Error in the DLS query: %s." % str(inst)
104 >          #print msg
105 >          raise DLSNoReplicas(fileblocks)
106 >
107 >        ListSites=[]
108 >        for entry in entryList:
109 >         for loc in entry.locations:
110 >           ListSites.append(str(loc.host))
111 >        if len(ListSites)<=0:
112 >          raise DLSNoReplicas(fileblocks)
113  
114 <         ListSites=string.split(string.strip(sites),'\n')
59 <         return ListSites        
114 >        return ListSites        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines