ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DLSInfo.py
Revision: 1.4
Committed: Sun Jan 29 01:46:08 2006 UTC (19 years, 3 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_0_7, CRAB_1_0_7_pre1, CRAB_1_0_6, CRAB_1_0_5
Changes since 1.3: +28 -1 lines
Log Message:
improvements to deal with error conditions ( i.e. dataset not existing, invalid datatie .... etc with changed DBS 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     class DLSError:
9     def __init__(self, fileblocks):
10     print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
11     pass
12    
13 afanfani 1.4
14     class DLSNoReplicas(exceptions.Exception):
15     def __init__(self, FileBlock):
16     args ="No replicas exists for fileblock: "+FileBlock+"\n"
17     exceptions.Exception.__init__(self, args)
18     pass
19    
20     def getClassName(self):
21     """ Return class name. """
22     return "%s" % (self.__class__.__name__)
23    
24     def getErrorMessage(self):
25     """ Return exception error. """
26     return "%s" % (self.args)
27    
28 afanfani 1.1 ##############################################################################
29     # Class to extract info from DLS
30     ##############################################################################
31    
32     class DLSInfo:
33     def __init__(self, fileblocks):
34     self.fileblocks = fileblocks
35 afanfani 1.4 self.DLSclient_ = 'dls-get-se '
36 afanfani 1.3 self.DLSServer_ = 'lxgate10.cern.ch'
37     self.DLSServerPort_ = '18081'
38     #self.DLSServerPort_ = '18080'
39 afanfani 1.4
40     out=commands.getstatusoutput('which '+self.DLSclient_)
41     if out[0]>0:
42     msg="ERROR no DLS CLI available in $PATH : %s"%self.DLSclient_
43     raise CrabException(msg)
44 afanfani 1.1
45     # ####################################
46     def getReplicas(self):
47     """
48     query DLS to get replicas
49     """
50 afanfani 1.3 ##
51     cmd = self.DLSclient_+" --port "+self.DLSServerPort_+" --host "+self.DLSServer_+" --datablock "+self.fileblocks
52 afanfani 1.4 #print cmd
53 afanfani 1.1 sites = runCommand(cmd)
54 afanfani 1.4 sites=string.strip(sites)
55     if len(sites)<=0:
56     raise DLSNoReplicas(self.fileblocks)
57    
58 afanfani 1.2 ListSites=string.split(string.strip(sites),'\n')
59 afanfani 1.1 return ListSites