ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Resubmitter.py
(Generate patch)

Comparing COMP/CRAB/python/Resubmitter.py (file contents):
Revision 1.1 by slacapra, Wed Feb 13 18:17:53 2008 UTC vs.
Revision 1.16.2.2 by spiga, Tue Oct 13 13:58:53 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines