ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DLSInfo.py
Revision: 1.6
Committed: Thu May 18 18:46:22 2006 UTC (18 years, 11 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: post_cmssw_integration_20060527, pre_cmssw_integration_20060527
Changes since 1.5: +45 -19 lines
Log Message:
mods to use new DBS and DLS API

File Contents

# User Rev Content
1 afanfani 1.1 #!/usr/bin/env python
2     import sys, os, commands,string, re
3 afanfani 1.4 import exceptions
4     from crab_exceptions import *
5 afanfani 1.1 from crab_util import *
6     import common
7    
8 afanfani 1.6 import dlsApi
9     import dlsClient
10     from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
11    
12    
13 afanfani 1.1 class DLSError:
14 slacapra 1.5 def __init__(self, fileblocks):
15     print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
16     pass
17 afanfani 1.1
18 afanfani 1.4
19     class DLSNoReplicas(exceptions.Exception):
20 slacapra 1.5 def __init__(self, FileBlock):
21     args ="No replicas exists for fileblock: "+FileBlock+"\n"
22     exceptions.Exception.__init__(self, args)
23     pass
24    
25     def getClassName(self):
26     """ Return class name. """
27     return "%s" % (self.__class__.__name__)
28    
29     def getErrorMessage(self):
30     """ Return exception error. """
31     return "%s" % (self.args)
32 afanfani 1.4
33 afanfani 1.6
34 afanfani 1.1 ##############################################################################
35     # Class to extract info from DLS
36     ##############################################################################
37    
38     class DLSInfo:
39 afanfani 1.6 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 afanfani 1.1
65     # ####################################
66 afanfani 1.6 def getReplicas(self,fileblocks):
67 slacapra 1.5 """
68     query DLS to get replicas
69     """
70     ##
71 afanfani 1.6 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 afanfani 1.4
85 slacapra 1.5 return ListSites