ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Submitter.py
Revision: 1.10
Committed: Tue Aug 30 14:26:10 2005 UTC (19 years, 8 months ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.9: +26 -1 lines
Log Message:
crab-mon

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    
27     common.logger.debug(5, "Submitter::run() called")
28 slacapra 1.7
29 corvo 1.9 # Add an instance of ApmonIf to send relevant parameters to ML
30     mon = ApmonIf()
31 slacapra 1.7 # run a list-match on first job
32     firstJob=self.nj_list[0]
33     match = common.scheduler.listMatch(firstJob)
34 slacapra 1.8 if match:
35     common.logger.message("Found compatible resources "+str(match))
36     else:
37     raise CrabException("No compatible resources found!")
38 nsmirnov 1.2 # Loop over jobs
39    
40 nsmirnov 1.6 njs = 0
41 nsmirnov 1.4 for nj in self.nj_list:
42 nsmirnov 1.2 st = common.jobDB.status(nj)
43 spiga 1.10 if st != 'C' and st != 'K' and st != 'A' and st != 'RC':
44 nsmirnov 1.6 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 nsmirnov 1.2
49 nsmirnov 1.6 common.logger.message("Submitting job # "+`(nj+1)`)
50 nsmirnov 1.2
51     jid = common.scheduler.submit(nj)
52    
53     common.jobDB.setStatus(nj, 'S')
54     common.jobDB.setJobId(nj, jid)
55 nsmirnov 1.6 njs += 1
56 spiga 1.10
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 nsmirnov 1.2 pass
72    
73     ####
74    
75     common.jobDB.save()
76 corvo 1.9
77     # List of parameters to be sent to monitor system
78     user = os.getlogin()
79     taskId = os.getlogin()+'_'+string.split(common.work_space.topDir(),'/')[-2]
80     jobId = str(nj)
81     sid = jid
82     try:
83     application = os.path.basename(os.environ['SCRAMRT_LOCALRT'])
84     except KeyError:
85     application = os.path.basename(os.environ['LOCALRT'])
86     try:
87     nevtJob = self.cfg_params['USER.job_number_of_events']
88     except KeyError:
89     pass
90     exe = self.cfg_params['USER.executable']
91     tool = common.prog_name
92     scheduler = self.cfg_params['CRAB.scheduler']
93     taskType = 'analysis'
94     vo = 'cms'
95     dataset = self.cfg_params['USER.dataset']
96     owner = self.cfg_params['USER.owner']
97     rb = sid.split(':')[1]
98     rb = rb.replace('//', '')
99     params = {'taskId': taskId, 'jobId': jobId, 'sid': sid, 'application': application, \
100     'exe': exe, 'nevtJob': nevtJob, 'tool': tool, 'scheduler': scheduler, \
101     'user': user, 'taskType': taskType, 'vo': vo, 'dataset': dataset, 'owner': owner, 'broker', rb`}
102     for i in params.keys():
103     print "key, value: %s %s" % (i, params[i])
104     mon.fillDict(params)
105     mon.sendToML()
106 nsmirnov 1.2
107 nsmirnov 1.6 msg = '\nTotal of %d jobs submitted'%njs
108     if njs != len(self.nj_list) :
109     msg += ' (from %d requested).'%(len(self.nj_list))
110     pass
111     else:
112     msg += '.'
113     pass
114 nsmirnov 1.2 common.logger.message(msg)
115 nsmirnov 1.1 return
116