ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Submitter.py
Revision: 1.17
Committed: Tue Oct 4 16:47:53 2005 UTC (19 years, 7 months ago) by corvo
Content type: text/x-python
Branch: MAIN
Changes since 1.16: +61 -57 lines
Log Message:
Bug fix

File Contents

# User Rev Content
1 nsmirnov 1.1 from Actor import *
2 nsmirnov 1.6 from crab_util import *
3 nsmirnov 1.2 import common
4 corvo 1.9 from ApmonIf import ApmonIf
5 spiga 1.10 import Statistic
6 nsmirnov 1.1
7     class Submitter(Actor):
8 nsmirnov 1.4 def __init__(self, cfg_params, nj_list):
9 nsmirnov 1.1 self.cfg_params = cfg_params
10 nsmirnov 1.4 self.nj_list = nj_list
11 spiga 1.10 #############################################
12     fileCODE1 = open(common.work_space.logDir()+"/.code","r")
13     array = fileCODE1.read().split('::')
14     self.ID1 = array[0]
15     self.NJC = array[1]
16     self.dataset = array[2]
17     self.owner = array[3]
18     fileCODE1.close()
19    
20 nsmirnov 1.1 return
21    
22     def run(self):
23 nsmirnov 1.2 """
24     The main method of the class.
25     """
26     common.logger.debug(5, "Submitter::run() called")
27 corvo 1.9 # Add an instance of ApmonIf to send relevant parameters to ML
28     mon = ApmonIf()
29 slacapra 1.7 firstJob=self.nj_list[0]
30     match = common.scheduler.listMatch(firstJob)
31 slacapra 1.8 if match:
32     common.logger.message("Found compatible resources "+str(match))
33     else:
34     raise CrabException("No compatible resources found!")
35 fanzago 1.16 #########
36 nsmirnov 1.2 # Loop over jobs
37 nsmirnov 1.6 njs = 0
38 corvo 1.15 try:
39 corvo 1.17 for nj in self.nj_list:
40     st = common.jobDB.status(nj)
41     #print "nj = ", nj
42     #print "st = ", st
43     if st != 'C' and st != 'K' and st != 'A' and st != 'RC':
44     long_st = crabJobStatusToString(st)
45     #msg = "Job # %d is not submitted: status %s"%(nj+1, long_st)
46     #common.logger.message(msg)
47     continue
48    
49     common.logger.message("Submitting job # "+`(nj+1)`)
50     print "submitting job!"
51     jid = common.scheduler.submit(nj)
52    
53     common.jobDB.setStatus(nj, 'S')
54     common.jobDB.setJobId(nj, jid)
55     njs += 1
56    
57     ############################################
58    
59     destination = common.scheduler.queryDest(jid).split(":")[0]
60     ID3 = jid.split("/")[3]
61     broker = jid.split("/")[2].split(":")[0]
62     if st == 'C':
63     resFlag = 0
64     elif st == 'RC':
65     resFlag = 2
66     else:
67     resFlag = 0
68     pass
69    
70     Statistic.notify('submit',resFlag,'-----',self.dataset,self.owner,destination,broker,ID3,self.ID1,self.NJC)
71    
72     # List of parameters to be sent to ML monitor system
73     user = os.getlogin()
74     taskId = os.getlogin()+'_'+string.split(common.work_space.topDir(),'/')[-2]
75     jobId = str(nj)
76     sid = jid
77     try:
78     application = os.path.basename(os.environ['SCRAMRT_LOCALRT'])
79     except KeyError:
80     application = os.path.basename(os.environ['LOCALRT'])
81    
82     nevtJob = common.jobDB.maxEvents(nj)
83     exe = self.cfg_params['USER.executable']
84     tool = common.prog_name
85     scheduler = self.cfg_params['CRAB.scheduler']
86     taskType = 'analysis'
87     vo = 'cms'
88     dataset = self.cfg_params['USER.dataset']
89     owner = self.cfg_params['USER.owner']
90     rb = sid.split(':')[1]
91     rb = rb.replace('//', '')
92     params = {'taskId': taskId, 'jobId': jobId, 'sid': sid, 'application': application, \
93     'exe': exe, 'nevtJob': nevtJob, 'tool': tool, 'scheduler': scheduler, \
94     'user': user, 'taskType': taskType, 'vo': vo, 'dataset': dataset, 'owner': owner, 'broker': rb}
95     mon.fillDict(params)
96     mon.sendToML()
97     except:
98     common.jobDB.save()
99     common.jobDB.save()
100 corvo 1.15
101 nsmirnov 1.6 msg = '\nTotal of %d jobs submitted'%njs
102     if njs != len(self.nj_list) :
103     msg += ' (from %d requested).'%(len(self.nj_list))
104     pass
105     else:
106     msg += '.'
107     pass
108 nsmirnov 1.2 common.logger.message(msg)
109 nsmirnov 1.1 return
110