ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DLSInfo.py
Revision: 1.22
Committed: Mon Sep 8 09:47:47 2008 UTC (16 years, 7 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_DLS_PHED
Changes since 1.21: +0 -2 lines
Log Message:
removed print and duobled line

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 slacapra 1.14 import dlsApi
9     import dlsClient
10     from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
11 afanfani 1.7
12 afanfani 1.1 class DLSError:
13 slacapra 1.5 def __init__(self, fileblocks):
14     print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
15     pass
16 afanfani 1.1
17 afanfani 1.4
18     class DLSNoReplicas(exceptions.Exception):
19 slacapra 1.5 def __init__(self, FileBlock):
20 spiga 1.15 self.args ="No replicas exists for fileblock: "+FileBlock+"\n"
21 slacapra 1.14 exceptions.Exception.__init__(self, self.args)
22 slacapra 1.5 pass
23    
24     def getClassName(self):
25     """ Return class name. """
26     return "%s" % (self.__class__.__name__)
27    
28     def getErrorMessage(self):
29     """ Return exception error. """
30     return "%s" % (self.args)
31 afanfani 1.4
32 afanfani 1.6
33 afanfani 1.1 ##############################################################################
34     # Class to extract info from DLS
35     ##############################################################################
36    
37     class DLSInfo:
38 mkirn 1.11 def __init__(self, type, cfg_params):
39     self.cfg_params = cfg_params
40 slacapra 1.18 if type=="DLS_TYPE_DBS":
41 gutsche 1.17 # use dbs_url as dls_endpoint if dls_type is dbs
42 gutsche 1.16 try:
43 gutsche 1.17 endpoint=self.cfg_params['CMSSW.dbs_url']
44 gutsche 1.16 except KeyError:
45     endpoint="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
46 spiga 1.21 elif type=="DLS_TYPE_PHEDEX":
47     try:
48     endpoint=self.cfg_params['CMSSW.dls_phedex_url']
49     except KeyError:
50     endpoint='http://cmsweb.cern.ch/phedex/datasvc/xml/prod/'
51 afanfani 1.6 else:
52 gutsche 1.10 msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type
53     raise CrabException(msg)
54 afanfani 1.6
55 afanfani 1.9 common.logger.debug(5,"DLS interface: %s Server %s"%(type,endpoint))
56 afanfani 1.6 try:
57 gutsche 1.10 self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint)
58 afanfani 1.6 except dlsApi.DlsApiError, inst:
59 slacapra 1.14 msg = "Error when binding the DLS interface: %s Server %s"%(str(inst),endpoint)
60 gutsche 1.10 #print msg
61     raise CrabException(msg)
62    
63 afanfani 1.1 # ####################################
64 afanfani 1.6 def getReplicas(self,fileblocks):
65 slacapra 1.5 """
66     query DLS to get replicas
67     """
68     ##
69 afanfani 1.6 try:
70 gutsche 1.10 entryList=self.api.getLocations([fileblocks])
71 afanfani 1.6 except dlsApi.DlsApiError, inst:
72 slacapra 1.14 #msg = "Error in the DLS query: %s." % str(inst)
73 gutsche 1.10 #print msg
74     raise DLSNoReplicas(fileblocks)
75 afanfani 1.6
76     ListSites=[]
77     for entry in entryList:
78 gutsche 1.10 for loc in entry.locations:
79     ListSites.append(str(loc.host))
80 afanfani 1.6 if len(ListSites)<=0:
81 gutsche 1.10 raise DLSNoReplicas(fileblocks)
82 afanfani 1.4
83 slacapra 1.5 return ListSites