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 |
spiga |
1.36 |
Status.__init__(self, *args)
|
20 |
farinafa |
1.24 |
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 |
farinafa |
1.27 |
return
|
34 |
|
|
|
35 |
spiga |
1.31 |
def query(self):
|
36 |
farinafa |
1.27 |
common.scheduler.checkProxy()
|
37 |
spiga |
1.1 |
|
38 |
spiga |
1.31 |
self.resynchClientSide()
|
39 |
|
|
|
40 |
|
|
upTask = common._db.getTask()
|
41 |
|
|
self.compute(upTask)
|
42 |
|
|
|
43 |
farinafa |
1.27 |
def resynchClientSide(self):
|
44 |
spiga |
1.31 |
"""
|
45 |
|
|
get status from the server and
|
46 |
|
|
aling back data on client
|
47 |
|
|
"""
|
48 |
farinafa |
1.24 |
task = common._db.getTask()
|
49 |
spiga |
1.28 |
# proxy management
|
50 |
|
|
self.proxy = None # common._db.queryTask('proxy')
|
51 |
|
|
if 'X509_USER_PROXY' in os.environ:
|
52 |
|
|
self.proxy = os.environ['X509_USER_PROXY']
|
53 |
|
|
else:
|
54 |
|
|
status, self.proxy = commands.getstatusoutput('ls /tmp/x509up_u`id -u`')
|
55 |
|
|
self.proxy = proxy.strip()
|
56 |
|
|
|
57 |
farinafa |
1.24 |
# communicator allocation
|
58 |
farinafa |
1.27 |
csCommunicator = ServerCommunicator(self.server_name, self.server_port, self.cfg_params, self.proxy)
|
59 |
spiga |
1.35 |
handledXML = csCommunicator.getStatus( str(task['name']) )
|
60 |
farinafa |
1.24 |
del csCommunicator
|
61 |
|
|
|
62 |
|
|
# align back data and print
|
63 |
farinafa |
1.34 |
try:
|
64 |
farinafa |
1.37 |
handledXML += "="*( len(handledXML)%4 )
|
65 |
|
|
reportXML = zlib.decompress( base64.urlsafe_b64decode(handledXML) )
|
66 |
spiga |
1.35 |
except Exception, e:
|
67 |
spiga |
1.36 |
common.logger.debug(1,"WARNING: Problem while decompressing fresh status from the server.")
|
68 |
farinafa |
1.37 |
common.logger.debug(1, traceback.format_exc() )
|
69 |
spiga |
1.35 |
return
|
70 |
|
|
|
71 |
|
|
try:
|
72 |
farinafa |
1.37 |
reportList = minidom.parseString(reportXML).getElementsByTagName('Job')
|
73 |
farinafa |
1.34 |
common._db.deserXmlStatus(reportList)
|
74 |
|
|
except Exception, e:
|
75 |
spiga |
1.36 |
common.logger.debug(1,"WARNING: Problem while retrieving fresh status from the server.")
|
76 |
farinafa |
1.34 |
return
|
77 |
spiga |
1.35 |
|
78 |
spiga |
1.31 |
return
|
79 |
mcinquil |
1.2 |
|