ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DLSInfo.py
Revision: 1.9
Committed: Thu Jun 1 11:11:17 2006 UTC (18 years, 11 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_2_1, CRAB_1_2_0, CRAB_1_2_0_pre9, CRAB_1_2_0_pre8, CRAB_1_2_0_pre7
Branch point for: CRAB_BOSS4_v1, CRAB_BOSS4
Changes since 1.8: +6 -2 lines
Log Message:
mods to use different DLS-LFC endpoints for old EDM and new EDM data

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.7 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 afanfani 1.6
34    
35 afanfani 1.1 class DLSError:
36 slacapra 1.5 def __init__(self, fileblocks):
37     print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
38     pass
39 afanfani 1.1
40 afanfani 1.4
41     class DLSNoReplicas(exceptions.Exception):
42 slacapra 1.5 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 afanfani 1.4
55 afanfani 1.6
56 afanfani 1.1 ##############################################################################
57     # Class to extract info from DLS
58     ##############################################################################
59    
60     class DLSInfo:
61 afanfani 1.9 def __init__(self, type, jobtype):
62 afanfani 1.6 if type=="DLS_TYPE_DLI":
63 afanfani 1.9 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 afanfani 1.6 try:
68     import xml.dom.ext.reader
69     except:
70     crabdir=os.getenv('CRABDIR')
71     ## Let the user set up PyXML by hand
72 afanfani 1.8 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 afanfani 1.6 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 afanfani 1.9 common.logger.debug(5,"DLS interface: %s Server %s"%(type,endpoint))
87 afanfani 1.6 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 afanfani 1.1
94     # ####################################
95 afanfani 1.6 def getReplicas(self,fileblocks):
96 slacapra 1.5 """
97     query DLS to get replicas
98     """
99     ##
100 afanfani 1.6 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 afanfani 1.4
114 slacapra 1.5 return ListSites