CMS 3D CMS Logo

Functions | Variables

crabWrap Namespace Reference

Functions

def checkStatus
def computeSummaryCRAB251
def computeSummaryCRAB260
def convertStatus
def crabAction
def crabActionCRAB251
def crabCreate
def crabStatus
def crabSubmit
def crabWatch
def getOutput
def initCrabEnvironment
def run
def summaryServer
def summaryStandAlone

Variables

 computeSummary = computeSummaryCRAB260
 project = None
float threshold = 95.0

Function Documentation

def crabWrap::checkStatus (   project,
  threshold = 95.0 
)

Definition at line 205 of file crabWrap.py.

00206                                           :
00207 
00208     status = crabStatus(project)
00209  
00210     print "Percentage of jobs per status:"
00211     maxLength = max( [len(x) for x in status] )
00212     for item in status:
00213         print "%*s: %.0f%%" % (maxLength,item,status[item])
00214 
00215 
00216     statusNew = convertStatus(status)
00217        
00218     print "Relative percentage finished: %.0f%%" % statusNew['Finished']
00219     print "Relative percentage failed  : %.0f%%" % statusNew['Failed']
00220     print "Relative percentage running : %.0f%%" % statusNew['Running']
00221 
00222     finished = False
00223     # Condition for stopping
00224     #if fracFailed > 50.0: raise RuntimeError,'Too many jobs have failed (%.0f%%).' % fracFailed
00225 
00226     # Condition for considering it finished
00227     if statusNew['Finished'] >= threshold: finished = True 
00228 
00229     return finished

def crabWrap::computeSummaryCRAB251 (   up_task)

Definition at line 38 of file crabWrap.py.

00039                                   :
00040     "Computes jobs summary for given task" 
00041  
00042     taskId = str(up_task['name'])
00043     task_unique_name = str(up_task['name'])
00044     ended = None
00045 
00046     summary = {}
00047     nJobs = 0
00048     for job in up_task.jobs :
00049         id = str(job.runningJob['jobId'])
00050         jobStatus =  str(job.runningJob['statusScheduler'])
00051         dest = str(job.runningJob['destination']).split(':')[0]
00052         exe_exit_code = str(job.runningJob['applicationReturnCode'])
00053         job_exit_code = str(job.runningJob['wrapperReturnCode'])
00054         ended = str(job['standardInput'])  
00055         printline=''
00056         if dest == 'None' :  dest = ''
00057         if exe_exit_code == 'None' :  exe_exit_code = ''
00058         if job_exit_code == 'None' :  job_exit_code = ''
00059         #printline+="%-6s %-18s %-36s %-13s %-16s %-4s" % (id,jobStatus,dest,exe_exit_code,job_exit_code,ended)
00060         #print printline
00061         if summary.has_key(jobStatus): summary[jobStatus] += 1
00062         else: summary[jobStatus] = 1 
00063         nJobs += 1
00064 
00065     for item in summary: summary[item] = 100.*summary[item]/nJobs 
00066 
00067     return summary

def crabWrap::computeSummaryCRAB260 (   up_task)
Computes jobs summary for given task

Definition at line 5 of file crabWrap.py.

00006                                   :
00007     """
00008     Computes jobs summary for given task
00009     """
00010     taskId = str(up_task['name'])
00011     task_unique_name = str(up_task['name'])
00012     ended = None
00013 
00014     summary = {}
00015     nJobs = 0
00016     for job in up_task.jobs :
00017         id = str(job.runningJob['jobId'])
00018         jobStatus =  str(job.runningJob['statusScheduler'])
00019         jobState =  str(job.runningJob['state'])
00020         dest = str(job.runningJob['destination']).split(':')[0]
00021         exe_exit_code = str(job.runningJob['applicationReturnCode'])
00022         job_exit_code = str(job.runningJob['wrapperReturnCode'])
00023         ended = str(job['closed'])  
00024         printline=''
00025         if dest == 'None' :  dest = ''
00026         if exe_exit_code == 'None' :  exe_exit_code = ''
00027         if job_exit_code == 'None' :  job_exit_code = ''
00028         if job.runningJob['state'] == 'SubRequested' : jobStatus = 'Submitting'
00029         if job.runningJob['state'] == 'Terminated': jobStatus = 'Done'
00030         
00031         if summary.has_key(jobStatus): summary[jobStatus] += 1
00032         else: summary[jobStatus] = 1 
00033         nJobs += 1
00034 
00035     for item in summary: summary[item] = 100.*summary[item]/nJobs 
00036 
00037     return summary

def crabWrap::convertStatus (   status)
doneStatus = ['Done','Done (success)','Cleared','Retrieved']
failedStatus = ['Aborted','Done (failed)','Killed','Cancelled']
ignoreStatus = ['Created']

Definition at line 174 of file crabWrap.py.

Referenced by gen::HydjetHadronizer::build_hyjet().

00175                          :
00176     """
00177     doneStatus = ['Done','Done (success)','Cleared','Retrieved']
00178     failedStatus = ['Aborted','Done (failed)','Killed','Cancelled']
00179     ignoreStatus = ['Created']
00180     """
00181     doneStatus = ['SD','E']
00182     failedStatus = ['A','DA','K']
00183     runningStatus = ['R']
00184     ignoreStatus = ['C']
00185     sumDone = 0.0
00186     sumFailed = 0.0
00187     sumRunning = 0.0
00188     sumIgnore = 0.0
00189     for key in status:
00190         if key in doneStatus: sumDone += status[key]
00191         if key in failedStatus: sumFailed += status[key]
00192         if key in runningStatus: sumRunning += status[key]
00193         if key in ignoreStatus: sumIgnore += status[key]
00194 
00195     # frac(done)' = N*frac(done)/(N - N*frac(ignore)) = frac(done)/(1 - frac(ignore))
00196     fracDone = 100.0*sumDone/(100.0 - sumIgnore)
00197     fracFailed = 100.0*sumFailed/(100.0 - sumIgnore)
00198     fracRun = 100.0*sumRunning/(100.0 - sumIgnore)
00199 
00200     result = {'Finished':fracDone,
00201               'Failed':fracFailed,
00202               'Running':fracRun}
00203 
00204     return result 

def crabWrap::crabAction (   options,
  action = None 
)

Definition at line 95 of file crabWrap.py.

00096                                       :
00097 
00098     options = parseOptions(options)
00099 
00100     crab = Crab()
00101     result = None
00102     try:
00103         crab.initialize_(options)
00104         crab.run()
00105         if action: result = action(crab)
00106         del crab
00107         print 'Log file is %s%s.log'%(common.work_space.logDir(),common.prog_name) 
00108     except CrabException, e:
00109         del crab
00110         #print '\n' + common.prog_name + ': ' + str(e) + '\n' 
00111         raise
00112         
00113     if (common.logger): common.logger.delete()
00114 
00115     if result: return result

def crabWrap::crabActionCRAB251 (   options,
  action = None 
)

Definition at line 116 of file crabWrap.py.

00117                                              :
00118 
00119     options = parseOptions(options)
00120 
00121     result = None
00122     try:
00123         crab = Crab(options)
00124         crab.run()
00125         common.apmon.free()
00126         if action: result = action(crab)
00127         del crab
00128         #print 'Log file is %s%s.log'%(common.work_space.logDir(),common.prog_name)  
00129         #print '\n##############################  E N D  ####################################\n'
00130     except CrabException, e:
00131         print '\n' + common.prog_name + ': ' + str(e) + '\n'
00132         pass
00133     pass
00134     #if (common.logger): common.logger.delete()
00135 
00136     if result: return result

def crabWrap::crabCreate (   dir = '.',
  crabCfg_name = 'crab.cfg' 
)

Definition at line 137 of file crabWrap.py.

00138                                                     :
00139 
00140     cwd = os.getcwd()
00141     os.chdir(dir)
00142 
00143     options = ['-create','-cfg',crabCfg_name]
00144 
00145     project = crabAction(options,lambda crab: common.work_space.topDir())
00146 
00147     os.chdir(cwd)
00148 
00149     return project

def crabWrap::crabStatus (   project)

Definition at line 157 of file crabWrap.py.

00158                        :
00159     options = ['-status']
00160     if project:
00161         options.append('-c')
00162         options.append(project)
00163 
00164     def action(crab):
00165         #act = '-status'
00166         #return crab.actions[act].summary()
00167         xml = crab.cfg_params.get("USER.xml_report",'')
00168         return common.work_space.shareDir() + xml
00169         
00170     xmlreport = crabAction(options,action)
00171     status = crabStatusFromReport(xmlreport)
00172  
00173     return status

def crabWrap::crabSubmit (   project)

Definition at line 150 of file crabWrap.py.

00151                        :
00152     options = ['-submit','-c',project]
00153 
00154     crabAction(options)
00155 
00156     return

def crabWrap::crabWatch (   action,
  project = None,
  threshold = 95.0 
)

Definition at line 240 of file crabWrap.py.

00241                                                       :
00242     #for i in range(5):
00243     while True:
00244         if checkStatus(project,threshold): break
00245         time.sleep(180)
00246  
00247     print "Finished..."
00248 
00249     action(project)
00250   
00251     return

def crabWrap::getOutput (   project)

Definition at line 230 of file crabWrap.py.

00231                       :
00232     options = ['-getoutput']
00233     if project:
00234         options.append('-c')
00235         options.append(project)
00236 
00237     crabAction(options)
00238 
00239     return

def crabWrap::initCrabEnvironment ( )

Definition at line 252 of file crabWrap.py.

00253                          :
00254     pythonpathenv = os.environ['PYTHONPATH']
00255     pythonpathbegin = pythonpathenv.split(':')[0].rstrip('/')
00256     pythonpathend = pythonpathenv.split(':')[-1].rstrip('/')
00257 
00258     indexBegin = sys.path.index(pythonpathbegin)
00259     if os.environ.has_key('CRABPSETPYTHON'): sys.path.insert( indexBegin, os.environ['CRABPSETPYTHON'] )
00260     if os.environ.has_key('CRABDLSAPIPYTHON'): sys.path.insert( indexBegin, os.environ['CRABDLSAPIPYTHON'] )
00261     if os.environ.has_key('CRABDBSAPIPYTHON'): sys.path.insert( indexBegin, os.environ['CRABDBSAPIPYTHON'] )
00262 
00263     if os.environ['SCRAM_ARCH'].find('32') != -1 and os.environ.has_key('CRABPYSQLITE'):
00264         sys.path.insert( indexBegin, os.environ['CRABPYSQLITE'] )
00265     elif os.environ['SCRAM_ARCH'].find('64') != -1 and os.environ.has_key('CRABPYSQLITE64'):
00266         sys.path.insert( indexBegin, os.environ['CRABPYSQLITE64'] )
00267 
00268     indexEnd = sys.path.index(pythonpathend) + 1
00269     if os.environ.has_key('CRABPYTHON'):
00270         if indexEnd >= len(sys.path): sys.path.append( os.environ['CRABPYTHON'] )
00271         else: sys.path.insert( indexEnd, os.environ['CRABPYTHON'] )
00272 
00273     #print sys.path
00274 
00275     os.environ['LD_LIBRARY_PATH'] = os.environ['GLITE_LOCATION'] + '/lib' + ':' + os.environ['LD_LIBRARY_PATH']
00276     os.environ['VOMS_PROXY_INFO_DONT_VERIFY_AC'] = '1'
00277     #print os.environ['LD_LIBRARY_PATH']
00278     #print os.environ['VOMS_PROXY_INFO_DONT_VERIFY_AC'] 
00279     
00280     """ 
00281     export LD_LIBRARY_PATH=${GLITE_LOCATION}/lib:${LD_LIBRARY_PATH}
00282     export VOMS_PROXY_INFO_DONT_VERIFY_AC=1
00283     """
00284    
00285     ## Get rid of some useless warning
00286     try:
00287         import warnings
00288         warnings.simplefilter("ignore", RuntimeWarning)
00289         # import socket
00290         # socket.setdefaulttimeout(15) # Default timeout in seconds
00291     except ImportError:
00292         pass # too bad, you'll get the warning
00293 
00294     # Remove libraries which over-ride CRAB libs and DBS_CONFIG setting
00295     badPaths = []
00296     if os.environ.has_key('DBSCMD_HOME'): # CMSSW's DBS, remove last bit of path
00297         badPaths.append('/'.join(os.environ['DBSCMD_HOME'].split('/')[:-1]))
00298     if os.environ.has_key('DBS_CLIENT_CONFIG'):
00299         del os.environ['DBS_CLIENT_CONFIG']
00300 
00301     def pathIsGood(checkPath):
00302         """
00303         Filter function for badPaths
00304         """
00305         for badPath in badPaths:
00306             if checkPath.find(badPath) != -1:
00307                 return False
00308         return True
00309 
00310     sys.path = filter(pathIsGood, sys.path)

def crabWrap::run (   project = None,
  threshold = 95.0 
)

Definition at line 311 of file crabWrap.py.

00312                                          :
00313 
00314     crabWatch(getOutput,project,threshold)
00315     
00316     return

def crabWrap::summaryServer (   self)
Returns jobs summary

Definition at line 78 of file crabWrap.py.

00079                        :
00080     """
00081     Returns jobs summary
00082     """
00083     #self.resynchClientSide()
00084         
00085     upTask = common._db.getTask()  
00086     return computeSummary(upTask)
00087 
00088 """
00089 # Add method to Status classes
00090 import Status
00091 import StatusServer
00092 Status.Status.summary = summaryStandAlone
00093 StatusServer.StatusServer.summary = summaryServer
00094 """

def crabWrap::summaryStandAlone (   self)
Returns jobs summary

Definition at line 70 of file crabWrap.py.

00071                            :
00072     """
00073     Returns jobs summary
00074     """
00075     task = common._db.getTask()
00076     upTask = common.scheduler.queryEverything(task['id'])
00077     return computeSummary(upTask)


Variable Documentation

crabWrap::computeSummary = computeSummaryCRAB260

Definition at line 68 of file crabWrap.py.

list crabWrap::project = None

Definition at line 318 of file crabWrap.py.

tuple crabWrap::threshold = 95.0

Definition at line 319 of file crabWrap.py.