ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Boss.py
Revision: 1.27
Committed: Sat Apr 26 09:08:29 2008 UTC (17 years ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.26: +1 -1 lines
Log Message:
pass corect arguments to submit blite  api..very strange that it worked before...

File Contents

# User Rev Content
1 slacapra 1.1 from crab_logger import Logger
2     from crab_exceptions import *
3     from crab_util import *
4     import common
5     import os, time, shutil
6 spiga 1.17 import traceback
7 slacapra 1.1
8 spiga 1.4 from ProdCommon.BossLite.API.BossLiteAPI import BossLiteAPI
9    
10    
11     from ProdCommon.BossLite.DbObjects.Job import Job
12     from ProdCommon.BossLite.DbObjects.Task import Task
13     from ProdCommon.BossLite.DbObjects.RunningJob import RunningJob
14    
15 spiga 1.17 from ProdCommon.BossLite.Common.Exceptions import SchedulerError
16 spiga 1.4 from ProdCommon.BossLite.API.BossLiteAPISched import BossLiteAPISched
17 slacapra 1.1
18     class Boss:
19     def __init__(self):
20 spiga 1.4
21 slacapra 1.21 self.session=None
22 slacapra 1.1 return
23 ewv 1.14
24 slacapra 1.21 def __del__(self):
25     """ destroy instance """
26     del self.session
27    
28 ewv 1.14 def configure(self,cfg_params):
29 spiga 1.9 self.cfg_params = cfg_params
30     self.schedulerName = self.cfg_params.get("CRAB.scheduler",'') # this should match with the bosslite requirements
31     self.rb_param_file=''
32     if (cfg_params.has_key('EDG.rb')):
33     self.rb_param_file=common.scheduler.rb_configure(cfg_params.get("EDG.rb"))
34 ewv 1.14 self.wms_service=cfg_params.get("EDG.wms_service",'')
35    
36 spiga 1.4
37 spiga 1.8 ## Add here the map for others Schedulers (LSF/CAF/CondorG)
38 ewv 1.14 SchedMap = {'glite':'SchedulerGLiteAPI',
39 spiga 1.9 'glitecoll':'SchedulerGLiteAPI',\
40 ewv 1.23 'condor_g':'SchedulerCondorG',\
41     'glidein':'SchedulerGlidein',\
42 slacapra 1.21 'lsf':'SchedulerLsf',\
43     'caf':'SchedulerLsf'
44 ewv 1.23 }
45    
46 spiga 1.16 self.schedulerConfig = {
47 spiga 1.9 'name' : SchedMap[self.schedulerName], \
48     'service' : self.wms_service, \
49 ewv 1.14 'config' : self.rb_param_file
50 slacapra 1.7 }
51 slacapra 1.21
52     self.session=None
53 slacapra 1.1 return
54    
55 ewv 1.23 def schedSession(self):
56     '''
57 spiga 1.17 Istantiate BossLiteApi session
58 ewv 1.23 '''
59 slacapra 1.21 if not self.session:
60 ewv 1.23 try:
61 slacapra 1.21 self.session = BossLiteAPISched( common.bossSession, self.schedulerConfig)
62     except Exception, e :
63     common.logger.debug(3, "Istantiate SchedSession: " +str(traceback.format_exc()))
64     raise CrabException('Scheduler Session: '+str(e))
65     return self.session
66 spiga 1.17
67 ewv 1.14 def declare(self, nj):
68 slacapra 1.1 """
69     BOSS declaration of jobs
70     """
71 spiga 1.4 index = nj - 1
72     job = common.job_list[index]
73     jbt = job.type()
74     base = jbt.name()
75    
76 spiga 1.24 wrapper = os.path.basename(str(common._db.queryTask('scriptName')))
77 spiga 1.8 listField=[]
78 ewv 1.14 listID=[]
79 spiga 1.8 task=common._db.getTask()
80 spiga 1.4 for id in range(nj):
81     parameters={}
82     jobs=[]
83 ewv 1.14 out=[]
84 spiga 1.8 stdout = base +'_'+ str(id+1)+'.stdout'
85     stderr = base +'_'+ str(id+1)+'.stderr'
86 spiga 1.4 jobs.append(id)
87 spiga 1.8 out=task.jobs[id]['outputFiles']
88 spiga 1.16 # out.append(stdout)
89     # out.append(stderr)
90 spiga 1.18 # out.append('.BrokerInfo')
91 spiga 1.19 ## To be better understood if it is needed
92     out.append('crab_fjr_'+str(id+1)+'.xml')
93 ewv 1.14 parameters['outputFiles']=out
94 spiga 1.8 parameters['executable']=wrapper
95 spiga 1.4 parameters['standardOutput'] = stdout
96     parameters['standardError'] = stderr
97 spiga 1.8 listField.append(parameters)
98 ewv 1.14 listID.append(id+1)
99 spiga 1.8 common._db.updateJob_( listID, listField)
100 slacapra 1.1
101 ewv 1.14 return
102 slacapra 1.1
103 spiga 1.10 def listMatch(self, tags, dest, whiteL, blackL ):
104 slacapra 1.1 """
105     Check the compatibility of available resources
106     """
107 spiga 1.17 try:
108 afanfani 1.26 sites = self.schedSession().lcgInfo(tags, seList=dest, blacklist=blackL, whitelist=whiteL)
109 spiga 1.17 except SchedulerError, err :
110     common.logger.message("Warning: List Match operation failed with message: " +str(err))
111     common.logger.debug(3, "List Match failed: " +str(traceback.format_exc()))
112    
113 slacapra 1.25 return sites
114 ewv 1.14
115 spiga 1.8 def submit(self, jobsList,req):
116 slacapra 1.1 """
117     Submit BOSS function.
118     Submit one job. nj -- job number.
119     """
120 spiga 1.11 task = common._db.getTask(jobsList)
121 ewv 1.23 try:
122 spiga 1.27 self.schedSession().submit( task['id'],jobsList,req )
123 spiga 1.17 except SchedulerError, err :
124 spiga 1.20 common.logger.message("Submit: " +str(err))
125     common.logger.debug(3, "Submit: " +str(traceback.format_exc()))
126     raise CrabException('Submit: '+str(err))
127 ewv 1.14
128     return
129 spiga 1.10
130     def queryEverything(self,taskid):
131     """
132 spiga 1.15 Query needed info of all jobs with specified taskid
133 spiga 1.10 """
134    
135 spiga 1.17 try:
136 slacapra 1.21 statusRes = self.schedSession().query( str(taskid))
137 spiga 1.17 except SchedulerError, err :
138     common.logger.message("Status Query : " +str(err))
139     common.logger.debug(3, "Status Query : " +str(traceback.format_exc()))
140     raise CrabException('Status Query : '+str(err))
141    
142 spiga 1.15 return statusRes
143 slacapra 1.1
144 spiga 1.15 def getOutput(self,taskId,jobRange, outdir):
145 slacapra 1.1 """
146 spiga 1.15 Retrieve output of all jobs with specified taskid
147 slacapra 1.1 """
148 ewv 1.23 try:
149 slacapra 1.21 self.schedSession().getOutput( taskId, jobRange, outdir )
150 spiga 1.17 except SchedulerError, err :
151     common.logger.message("GetOutput : " +str(err))
152     common.logger.debug(3, "GetOutput : " +str(traceback.format_exc()))
153     raise CrabException('GetOutput : '+str(err))
154 ewv 1.23
155 slacapra 1.1 return
156    
157 slacapra 1.21 def cancel(self,list):
158 slacapra 1.1 """
159 slacapra 1.21 Cancel the job with id from a list
160 slacapra 1.1 """
161 slacapra 1.21 task = common._db.getTask(list)
162 ewv 1.23 try:
163 slacapra 1.21 self.schedSession().kill( task, list)
164     except SchedulerError, err :
165     common.logger.message("Kill: " +str(err))
166     common.logger.debug(3, "Kill: " +str(traceback.format_exc()))
167     raise CrabException('Kill: '+str(err))
168 slacapra 1.1 return
169    
170 spiga 1.22 def LoggingInfo(self,list_id,outfile):
171     """
172     query the logging info with id from a list and
173 ewv 1.23 retourn the reults
174     """
175     try:
176 spiga 1.22 self.schedSession().postMortem(1,list_id,outfile)
177     except SchedulerError, err :
178     common.logger.message("logginginfo: " +str(err))
179     common.logger.debug(3, "logginginfo: " +str(traceback.format_exc()))
180     raise CrabException('logginginfo: '+str(err))
181     return
182    
183 slacapra 1.1 def setFlag( self, list, index ):
184     if len( list ) > (index + 1):
185     if list[index + 1] == ( list[index] + 1 ):
186     return -2
187     return -1
188     return list[ len(list) - 1 ]
189    
190     def prepString( self, list ):
191     s = ""
192     flag = 0
193     for i in range( len( list ) ):
194     if flag == 0:
195     s = str( list[i] )
196     flag = self.setFlag( list, i )
197     elif flag == -1:
198     s = s + "," + str( list[i] )
199     flag = self.setFlag( list, i )
200     elif flag == -2:
201     flag = self.setFlag( list, i )
202     if flag == -1:
203     s = s + ":" + str( list[i] )
204     if flag > 0:
205     s = s + ":" + str( list[i] )
206     return s