1 |
spiga |
1.1 |
from Actor import *
|
2 |
|
|
from crab_util import *
|
3 |
|
|
import common
|
4 |
|
|
from ApmonIf import ApmonIf
|
5 |
|
|
import time
|
6 |
|
|
|
7 |
farinafa |
1.24 |
import traceback
|
8 |
|
|
from xml.dom import minidom
|
9 |
|
|
from ServerCommunicator import ServerCommunicator
|
10 |
|
|
from Status import Status
|
11 |
farinafa |
1.25 |
from ServerConfig import *
|
12 |
farinafa |
1.24 |
|
13 |
spiga |
1.35 |
import zlib
|
14 |
|
|
import base64
|
15 |
|
|
|
16 |
farinafa |
1.24 |
class StatusServer(Status):
|
17 |
|
|
|
18 |
|
|
def __init__(self, *args):
|
19 |
|
|
self.cfg_params = args[0]
|
20 |
|
|
self.server_name = None
|
21 |
farinafa |
1.25 |
self.server_port = None
|
22 |
|
|
self.srvCfg = {}
|
23 |
|
|
try:
|
24 |
|
|
self.srvCfg = ServerConfig(self.cfg_params['CRAB.server_name']).config()
|
25 |
farinafa |
1.24 |
|
26 |
farinafa |
1.25 |
self.server_name = str(self.srvCfg['serverName'])
|
27 |
|
|
self.server_port = int(self.srvCfg['serverPort'])
|
28 |
spiga |
1.3 |
except KeyError:
|
29 |
farinafa |
1.24 |
msg = 'No server selected or port specified.'
|
30 |
|
|
msg = msg + 'Please specify a server in the crab cfg file'
|
31 |
|
|
raise CrabException(msg)
|
32 |
spiga |
1.31 |
|
33 |
spiga |
1.32 |
self.xml = self.cfg_params.get("USER.xml_report",'')
|
34 |
farinafa |
1.27 |
return
|
35 |
|
|
|
36 |
farinafa |
1.24 |
# all the behaviors are inherited from the direct status. Only some mimimal modifications
|
37 |
|
|
# are needed in order to extract data from status XML and to align back DB information
|
38 |
|
|
# Fabio
|
39 |
|
|
|
40 |
spiga |
1.31 |
def query(self):
|
41 |
farinafa |
1.27 |
common.scheduler.checkProxy()
|
42 |
spiga |
1.1 |
|
43 |
spiga |
1.31 |
self.resynchClientSide()
|
44 |
|
|
|
45 |
|
|
upTask = common._db.getTask()
|
46 |
|
|
self.compute(upTask)
|
47 |
|
|
|
48 |
farinafa |
1.27 |
def resynchClientSide(self):
|
49 |
spiga |
1.31 |
"""
|
50 |
|
|
get status from the server and
|
51 |
|
|
aling back data on client
|
52 |
|
|
"""
|
53 |
farinafa |
1.24 |
task = common._db.getTask()
|
54 |
spiga |
1.28 |
# proxy management
|
55 |
|
|
self.proxy = None # common._db.queryTask('proxy')
|
56 |
|
|
if 'X509_USER_PROXY' in os.environ:
|
57 |
|
|
self.proxy = os.environ['X509_USER_PROXY']
|
58 |
|
|
else:
|
59 |
|
|
status, self.proxy = commands.getstatusoutput('ls /tmp/x509up_u`id -u`')
|
60 |
|
|
self.proxy = proxy.strip()
|
61 |
|
|
|
62 |
farinafa |
1.24 |
# communicator allocation
|
63 |
farinafa |
1.27 |
csCommunicator = ServerCommunicator(self.server_name, self.server_port, self.cfg_params, self.proxy)
|
64 |
spiga |
1.35 |
handledXML = csCommunicator.getStatus( str(task['name']) )
|
65 |
farinafa |
1.24 |
del csCommunicator
|
66 |
|
|
|
67 |
|
|
# align back data and print
|
68 |
farinafa |
1.34 |
try:
|
69 |
spiga |
1.35 |
reportXML = zlib.decompress( base64.decodestring(handledXML) )
|
70 |
|
|
except Exception, e:
|
71 |
|
|
print "WARNING: Problem while decompressing fresh status from the server."
|
72 |
|
|
return
|
73 |
|
|
|
74 |
|
|
try:
|
75 |
farinafa |
1.34 |
reportList = minidom.parseString(reportXML.strip()).getElementsByTagName('Job')
|
76 |
|
|
common._db.deserXmlStatus(reportList)
|
77 |
|
|
except Exception, e:
|
78 |
|
|
print "WARNING: Problem while retrieving fresh status from the server."
|
79 |
|
|
return
|
80 |
spiga |
1.35 |
|
81 |
spiga |
1.31 |
return
|
82 |
mcinquil |
1.2 |
|