1 |
corvo |
1.1 |
from Actor import *
|
2 |
mcinquil |
1.8 |
from crab_util import *
|
3 |
farinafa |
1.11 |
import common
|
4 |
|
|
from ApmonIf import ApmonIf
|
5 |
|
|
import time
|
6 |
|
|
|
7 |
|
|
import traceback
|
8 |
|
|
from xml.dom import minidom
|
9 |
|
|
from ServerCommunicator import ServerCommunicator
|
10 |
corvo |
1.1 |
|
11 |
mcinquil |
1.14.4.2 |
from StatusServer import StatusServer
|
12 |
corvo |
1.1 |
|
13 |
mcinquil |
1.14.4.2 |
class KillerServer(Actor, StatusServer):
|
14 |
farinafa |
1.11 |
def __init__(self, cfg_params, range):
|
15 |
corvo |
1.1 |
self.cfg_params = cfg_params
|
16 |
farinafa |
1.2 |
self.range = range
|
17 |
farinafa |
1.11 |
|
18 |
spiga |
1.12 |
# init client server params...
|
19 |
|
|
CliServerParams(self)
|
20 |
farinafa |
1.11 |
|
21 |
corvo |
1.1 |
return
|
22 |
|
|
|
23 |
|
|
def run(self):
|
24 |
|
|
"""
|
25 |
|
|
The main method of the class: kill a complete task
|
26 |
|
|
"""
|
27 |
|
|
common.logger.debug(5, "Killer::run() called")
|
28 |
|
|
|
29 |
mcinquil |
1.14.4.2 |
# get updated status from server #inherited from StatusServer
|
30 |
|
|
self.resynchClientSide()
|
31 |
|
|
|
32 |
spiga |
1.14 |
task = common._db.getTask(self.range)
|
33 |
|
|
toBeKilled = []
|
34 |
|
|
for job in task.jobs:
|
35 |
spiga |
1.14.4.1 |
if job.runningJob['status'] in ['SS','R','SR','SW', 'SU']:
|
36 |
spiga |
1.14 |
toBeKilled.append(job['jobId'])
|
37 |
|
|
else:
|
38 |
|
|
common.logger.message("Not possible to kill Job #"+str(job['jobId'])+" : Status is "+str(job.runningJob['statusScheduler']))
|
39 |
|
|
pass
|
40 |
farinafa |
1.11 |
|
41 |
spiga |
1.14 |
if len(toBeKilled)>0:
|
42 |
|
|
## register proxy ##
|
43 |
|
|
csCommunicator = ServerCommunicator(self.server_name, self.server_port, self.cfg_params)
|
44 |
|
|
|
45 |
|
|
taskuuid = str(common._db.queryTask('name'))
|
46 |
|
|
ret = csCommunicator.killJobs( taskuuid, toBeKilled)
|
47 |
|
|
del csCommunicator
|
48 |
|
|
|
49 |
|
|
if ret != 0:
|
50 |
|
|
msg = "ClientServer ERROR: %d raised during the communication.\n"%ret
|
51 |
|
|
raise CrabException(msg)
|
52 |
|
|
|
53 |
|
|
# update runningjobs status
|
54 |
spiga |
1.14.4.1 |
updList = [{'statusScheduler':'Killing', 'status':'KK'}] * len(toBeKilled)
|
55 |
spiga |
1.14 |
common._db.updateRunJob_(toBeKilled, updList)
|
56 |
|
|
|
57 |
|
|
# printout the command result
|
58 |
spiga |
1.14.4.1 |
common.logger.message("Kill request for %d jobs succesfully sent to the server\n"%len(toBeKilled) )
|
59 |
farinafa |
1.13 |
|
60 |
corvo |
1.1 |
return
|
61 |
|
|
|