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.5 by slacapra, Tue Mar 28 11:25:39 2006 UTC vs.
Revision 1.6 by afanfani, Thu May 18 18:46:22 2006 UTC

# Line 5 | Line 5 | from crab_exceptions import *
5   from crab_util import *
6   import common
7  
8 + import dlsApi
9 + import dlsClient
10 + from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
11 +
12 +
13   class DLSError:
14      def __init__(self, fileblocks):
15          print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
# Line 25 | Line 30 | class DLSNoReplicas(exceptions.Exception
30          """ Return exception error. """
31          return "%s" % (self.args)
32  
33 +
34   ##############################################################################
35   # Class to extract info from DLS
36   ##############################################################################
37  
38   class DLSInfo:
39 <    def __init__(self, fileblocks):
40 <        self.fileblocks = fileblocks
41 <        self.DLSclient_ = 'dls-get-se '
42 <        self.DLSServer_ = 'lxgate10.cern.ch'
43 <        self.DLSServerPort_ = '18081'
44 <        #self.DLSServerPort_ = '18080
45 <
46 <        out=commands.getstatusoutput('which '+self.DLSclient_)
47 <        if out[0]>0:
48 <            msg="ERROR no DLS CLI available in $PATH : %s"%self.DLSclient_
49 <            raise CrabException(msg)
39 >    def __init__(self, type):
40 >        if type=="DLS_TYPE_DLI":
41 >           endpoint="lfc-cms-test.cern.ch/grid/cms/DLS/LFCProto"
42 >           try:
43 >             import xml.dom.ext.reader
44 >           except:
45 >             crabdir=os.getenv('CRABDIR')
46 > ## Let the user set up PyXML by hand
47 >             msg="Need to setup the PyXML python module. Do the following:\n"
48 >             msg+="  cd %s/DLSAPI\n"%crabdir
49 >             msg+="  ./InstallPyXML.sh"
50 >             raise CrabException(msg)
51 >
52 >        elif type=="DLS_TYPE_MYSQL":
53 >           endpoint="lxgate10.cern.ch:18081"
54 >        else:
55 >           msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type
56 >           raise CrabException(msg)
57 >
58 >        try:
59 >          self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint)
60 >        except dlsApi.DlsApiError, inst:
61 >          msg = "Error when binding the DLS interface: %s  Server %s"%(str(inst),self.DLSServer_)
62 >          #print msg
63 >          raise CrabException(msg)
64  
65   # ####################################
66 <    def getReplicas(self):
66 >    def getReplicas(self,fileblocks):
67          """
68          query DLS to get replicas
69          """
70          ##
71 <        cmd = self.DLSclient_+" --port "+self.DLSServerPort_+" --host "+self.DLSServer_+" --datablock "+self.fileblocks
72 <        #print cmd
73 <        sites = runCommand(cmd)
74 <        sites=string.strip(sites)
75 <        if len(sites)<=0:
76 <            raise DLSNoReplicas(self.fileblocks)
71 >        try:
72 >          entryList=self.api.getLocations([fileblocks])
73 >        except dlsApi.DlsApiError, inst:
74 >          msg = "Error in the DLS query: %s." % str(inst)
75 >          #print msg
76 >          raise DLSNoReplicas(fileblocks)
77 >
78 >        ListSites=[]
79 >        for entry in entryList:
80 >         for loc in entry.locations:
81 >           ListSites.append(str(loc.host))
82 >        if len(ListSites)<=0:
83 >          raise DLSNoReplicas(fileblocks)
84  
58        ListSites=string.split(string.strip(sites),'\n')
85          return ListSites        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines