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
|