1 |
|
from Submitter import Submitter |
2 |
|
import common |
3 |
|
from crab_util import * |
4 |
+ |
from crab_exceptions import * |
5 |
|
|
6 |
|
class Resubmitter(Submitter): |
7 |
< |
def __init__(self, cfg_params, jobs, UseServer=0): |
7 |
> |
def __init__(self, cfg_params, jobs): |
8 |
> |
self.cfg_params = cfg_params |
9 |
> |
|
10 |
|
nj_list = [] |
11 |
< |
for nj in jobs: |
12 |
< |
st = common.jobDB.status(int(nj)-1) |
13 |
< |
if st in ['K','A']: |
14 |
< |
nj_list.append(int(nj)-1) |
15 |
< |
common.jobDB.setStatus(int(nj)-1,'C') |
16 |
< |
elif st == 'Y': |
17 |
< |
common.scheduler.moveOutput(nj) |
18 |
< |
nj_list.append(int(nj)-1) |
19 |
< |
st = common.jobDB.setStatus(int(nj)-1,'RC') |
20 |
< |
elif st in ['C','X']: |
21 |
< |
common.logger.message('Job #'+`int(nj)`+' has status '+crabJobStatusToString(st)+' not yet submitted!!!') |
22 |
< |
pass |
23 |
< |
elif st == 'D': |
24 |
< |
common.logger.message('Job #'+`int(nj)`+' has status '+crabJobStatusToString(st)+' must be retrieved before resubmission') |
11 |
> |
|
12 |
> |
nj_list = self.checkAllowedJob(jobs,nj_list) |
13 |
> |
|
14 |
> |
common.logger.info('Jobs '+str(nj_list)+' will be resubmitted') |
15 |
> |
Submitter.__init__(self, cfg_params, nj_list, 'range') |
16 |
> |
|
17 |
> |
return |
18 |
> |
|
19 |
> |
def checkAllowedJob(self,jobs,nj_list): |
20 |
> |
listRunField=[] |
21 |
> |
|
22 |
> |
task=common._db.getTask(jobs) |
23 |
> |
for job in task.jobs: |
24 |
> |
st = job.runningJob['state'] |
25 |
> |
nj = int(job['jobId']) |
26 |
> |
if st in ['KillSuccess','SubFailed','Cleared','Aborted']: |
27 |
> |
#['K','A','SE','E','DA','NS']: |
28 |
> |
nj_list.append(nj) |
29 |
> |
elif st == 'Created': |
30 |
> |
common.logger.info('Job #'+`nj`+' last action was '+str(job.runningJob['state'])+' not yet submitted: use -submit') |
31 |
> |
elif st in ['Terminated']: |
32 |
> |
common.logger.info('Job #'+`nj`+' last action was '+str(job.runningJob['state'])+' must be retrieved (-get) before resubmission') |
33 |
|
else: |
34 |
< |
common.logger.message('Job #'+`nj`+' has status '+crabJobStatusToString(st)+' must be "killed" before resubmission') |
35 |
< |
pass |
34 |
> |
common.logger.info('Job #'+`nj`+' last action was '+str(job.runningJob['state'])+' actual status is '\ |
35 |
> |
+str(job.runningJob['statusScheduler'])+' must be killed (-kill) before resubmission') |
36 |
> |
if (job.runningJob['state']=='KillRequest'): common.logger.info('\t\tthe previous Kill request is being processed') |
37 |
|
|
38 |
|
|
39 |
< |
if len(nj_list) != 0: |
40 |
< |
nj_list.sort() |
39 |
> |
if len(nj_list) == 0 : |
40 |
> |
msg='No jobs to resubmit' |
41 |
> |
raise CrabException(msg) |
42 |
|
|
43 |
< |
# remove job ids from the submission history file (for the server) # Fabio |
44 |
< |
if (UseServer == 1): |
45 |
< |
file = open(common.work_space.shareDir()+'/submit_directive','r') |
46 |
< |
prev_subms = str(file.readlines()[0]).split('\n')[0] |
47 |
< |
file.close() |
35 |
< |
|
36 |
< |
new_subms = [] |
37 |
< |
if prev_subms != 'all': |
38 |
< |
# remove the jobs in nj_list from the history |
39 |
< |
new_subms = [ j for j in eval(prev_subms) not in nj_list ] |
40 |
< |
|
41 |
< |
file = open(common.work_space.shareDir()+'/submit_directive','w') |
42 |
< |
file.write(str(new_subms)) |
43 |
< |
file.close() |
44 |
< |
pass |
45 |
< |
pass |
46 |
< |
Submitter.__init__(self, cfg_params, nj_list, 'range') |
47 |
< |
pass |
43 |
> |
common._db.updateJob_(nj_list, [{'closed':'N'}]*len(nj_list)) |
44 |
> |
# Get new running instances |
45 |
> |
common._db.newRunJobs(nj_list) |
46 |
> |
|
47 |
> |
return nj_list |