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 |
|
|
class StatusServer(Status):
|
14 |
|
|
|
15 |
|
|
def __init__(self, *args):
|
16 |
|
|
self.cfg_params = args[0]
|
17 |
|
|
self.server_name = None
|
18 |
farinafa |
1.25 |
self.server_port = None
|
19 |
|
|
self.srvCfg = {}
|
20 |
|
|
try:
|
21 |
|
|
self.srvCfg = ServerConfig(self.cfg_params['CRAB.server_name']).config()
|
22 |
farinafa |
1.24 |
|
23 |
farinafa |
1.25 |
self.server_name = str(self.srvCfg['serverName'])
|
24 |
|
|
self.server_port = int(self.srvCfg['serverPort'])
|
25 |
spiga |
1.3 |
except KeyError:
|
26 |
farinafa |
1.24 |
msg = 'No server selected or port specified.'
|
27 |
|
|
msg = msg + 'Please specify a server in the crab cfg file'
|
28 |
|
|
raise CrabException(msg)
|
29 |
mcinquil |
1.2 |
|
30 |
farinafa |
1.27 |
# proxy management
|
31 |
|
|
self.proxy = None # common._db.queryTask('proxy')
|
32 |
|
|
if 'X509_USER_PROXY' in os.environ:
|
33 |
|
|
self.proxy = os.environ['X509_USER_PROXY']
|
34 |
|
|
else:
|
35 |
|
|
status, self.proxy = commands.getstatusoutput('ls /tmp/x509up_u`id -u`')
|
36 |
|
|
self.proxy = proxy.strip()
|
37 |
|
|
return
|
38 |
|
|
|
39 |
farinafa |
1.24 |
# all the behaviors are inherited from the direct status. Only some mimimal modifications
|
40 |
|
|
# are needed in order to extract data from status XML and to align back DB information
|
41 |
|
|
# Fabio
|
42 |
|
|
|
43 |
|
|
def compute(self):
|
44 |
farinafa |
1.27 |
common.scheduler.checkProxy()
|
45 |
|
|
printOutList = self.resynchClientSide()
|
46 |
|
|
if 'machine_readable_status' in self.cfg_params:
|
47 |
|
|
self.machineReadableReport(self.cfg_params['machine_readable_status'])
|
48 |
farinafa |
1.24 |
else:
|
49 |
farinafa |
1.27 |
self.detailedReport(printOutList)
|
50 |
|
|
pass
|
51 |
spiga |
1.1 |
|
52 |
farinafa |
1.27 |
# aling back data on client
|
53 |
|
|
def resynchClientSide(self):
|
54 |
farinafa |
1.24 |
task = common._db.getTask()
|
55 |
spiga |
1.1 |
|
56 |
farinafa |
1.24 |
# communicator allocation
|
57 |
|
|
common.logger.message("Checking the status of all jobs: please wait")
|
58 |
farinafa |
1.27 |
csCommunicator = ServerCommunicator(self.server_name, self.server_port, self.cfg_params, self.proxy)
|
59 |
farinafa |
1.24 |
reportXML = csCommunicator.getStatus( str(task['name']) )
|
60 |
|
|
del csCommunicator
|
61 |
|
|
|
62 |
|
|
# align back data and print
|
63 |
|
|
reportList = minidom.parseString(reportXML).getElementsByTagName('Job')
|
64 |
|
|
toPrint=[]
|
65 |
|
|
for job in task.jobs:
|
66 |
farinafa |
1.26 |
if not job.runningJob:
|
67 |
|
|
raise CrabException( "Missing running object for job %s"%str(job['id']) )
|
68 |
farinafa |
1.27 |
|
69 |
farinafa |
1.24 |
id = str(job.runningJob['id'])
|
70 |
farinafa |
1.25 |
# TODO linear search, probably it can be optized with binary search
|
71 |
farinafa |
1.24 |
rForJ = None
|
72 |
|
|
for r in reportList:
|
73 |
farinafa |
1.26 |
if r.getAttribute('id') in [ id, 'all']:
|
74 |
farinafa |
1.24 |
rForJ = r
|
75 |
|
|
break
|
76 |
|
|
|
77 |
farinafa |
1.27 |
# Data alignment
|
78 |
farinafa |
1.24 |
job.runningJob['statusScheduler'] = str( rForJ.getAttribute('status') )
|
79 |
|
|
jobStatus = str(job.runningJob['statusScheduler'])
|
80 |
farinafa |
1.27 |
|
81 |
|
|
job.runningJob['destination'] = str( rForJ.getAttribute('site') )
|
82 |
farinafa |
1.24 |
dest = str(job.runningJob['destination']).split(':')[0]
|
83 |
|
|
|
84 |
|
|
job.runningJob['applicationReturnCode'] = str( rForJ.getAttribute('exe_exit') )
|
85 |
|
|
exe_exit_code = str(job.runningJob['applicationReturnCode'])
|
86 |
|
|
|
87 |
|
|
job.runningJob['wrapperReturnCode'] = str( rForJ.getAttribute('job_exit') )
|
88 |
|
|
job_exit_code = str(job.runningJob['wrapperReturnCode'])
|
89 |
farinafa |
1.27 |
|
90 |
|
|
if str( rForJ.getAttribute('resubmit') ).isdigit():
|
91 |
farinafa |
1.26 |
job['submissionNumber'] = int(rForJ.getAttribute('resubmit'))
|
92 |
farinafa |
1.24 |
# TODO cleared='0' field, how should it be handled/mapped in BL? #Fabio
|
93 |
|
|
common.bossSession.updateDB( task )
|
94 |
|
|
|
95 |
|
|
printline=''
|
96 |
|
|
if dest == 'None' : dest = ''
|
97 |
|
|
if exe_exit_code == 'None' : exe_exit_code = ''
|
98 |
|
|
if job_exit_code == 'None' : job_exit_code = ''
|
99 |
|
|
printline+="%-8s %-18s %-40s %-13s %-15s" % (id,jobStatus,dest,exe_exit_code,job_exit_code)
|
100 |
|
|
toPrint.append(printline)
|
101 |
spiga |
1.1 |
|
102 |
farinafa |
1.27 |
return toPrint
|
103 |
|
|
|
104 |
|
|
# Print status to file.
|
105 |
|
|
# To support automatic stress tests a-la JobRobot or similar tools
|
106 |
|
|
#
|
107 |
|
|
def machineReadableReport(self, fileName):
|
108 |
|
|
task = common._db.getTask()
|
109 |
|
|
taskXML = common._db.serializeTask(task)
|
110 |
|
|
common.logger.debug(5, taskXML)
|
111 |
|
|
f = open(fileName, 'w')
|
112 |
|
|
f.write(taskXML)
|
113 |
|
|
f.close()
|
114 |
farinafa |
1.24 |
pass
|
115 |
spiga |
1.1 |
|
116 |
mcinquil |
1.2 |
|