1 |
slacapra |
1.1 |
from Actor import *
|
2 |
|
|
import common, crab_util
|
3 |
|
|
import string, os
|
4 |
|
|
|
5 |
|
|
class Status(Actor):
|
6 |
|
|
def __init__(self, cfg_params, nj_list):
|
7 |
|
|
self.cfg_params = cfg_params
|
8 |
|
|
self.nj_list = nj_list
|
9 |
|
|
self.countDone = 0
|
10 |
|
|
self.countReady = 0
|
11 |
|
|
self.countSched = 0
|
12 |
|
|
self.countRun = 0
|
13 |
|
|
self.countCleared = 0
|
14 |
|
|
self.countToTjob = 0
|
15 |
|
|
|
16 |
|
|
Status = crab_util.importName('edg_wl_userinterface_common_LbWrapper', 'Status')
|
17 |
|
|
# Bypass edg-job-status interfacing directly to C++ API
|
18 |
|
|
# Job attribute vector to retrieve status without edg-job-status
|
19 |
|
|
self.level = 0
|
20 |
|
|
# Instance of the Status class provided by LB API
|
21 |
|
|
self.jobStat = Status()
|
22 |
|
|
|
23 |
|
|
self.states = [ "Acl", "cancelReason", "cancelling","ce_node","children", \
|
24 |
|
|
"children_hist","children_num","children_states","condorId","condor_jdl", \
|
25 |
|
|
"cpuTime","destination", "done_code","exit_code","expectFrom", \
|
26 |
|
|
"expectUpdate","globusId","jdl","jobId","jobtype", \
|
27 |
|
|
"lastUpdateTime","localId","location", "matched_jdl","network_server", \
|
28 |
slacapra |
1.5 |
"owner","parent_job", "reason","resubmitted","rsl","seed",\
|
29 |
|
|
"stateEnterTime","stateEnterTimes","subjob_failed", \
|
30 |
slacapra |
1.1 |
"user tags" , "status" , "status_code","hierarchy"]
|
31 |
|
|
self.hstates = {}
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
return
|
35 |
|
|
|
36 |
|
|
def run(self):
|
37 |
|
|
"""
|
38 |
|
|
The main method of the class.
|
39 |
|
|
"""
|
40 |
|
|
common.logger.debug(5, "Status::run() called")
|
41 |
|
|
|
42 |
|
|
common.jobDB.load()
|
43 |
|
|
for nj in self.nj_list:
|
44 |
|
|
st = common.jobDB.status(nj)
|
45 |
|
|
self.countToTjob = self.countToTjob + 1
|
46 |
|
|
jid = common.jobDB.jobId(nj)
|
47 |
|
|
if st == 'S':
|
48 |
slacapra |
1.5 |
result = common.scheduler.queryStatus(jid)
|
49 |
slacapra |
1.1 |
self.processResult_(nj, result)
|
50 |
slacapra |
1.4 |
exit = ''
|
51 |
|
|
if result == 'Done':
|
52 |
slacapra |
1.5 |
exit = common.scheduler.getExitStatus(jid)
|
53 |
slacapra |
1.4 |
pass
|
54 |
|
|
print 'Job %03d:'%(nj+1),jid,result,exit
|
55 |
slacapra |
1.1 |
pass
|
56 |
|
|
else:
|
57 |
slacapra |
1.4 |
exit = ''
|
58 |
|
|
if st == 'D':
|
59 |
slacapra |
1.5 |
exit = common.scheduler.getExitStatus(jid)
|
60 |
slacapra |
1.4 |
pass
|
61 |
|
|
print 'Job %03d:'%(nj+1),jid,crab_util.crabJobStatusToString(st),exit
|
62 |
slacapra |
1.1 |
pass
|
63 |
|
|
pass
|
64 |
|
|
|
65 |
slacapra |
1.2 |
common.jobDB.save()
|
66 |
|
|
|
67 |
slacapra |
1.1 |
self.Report_()
|
68 |
|
|
pass
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
def processResult_(self, nj, result):
|
72 |
|
|
#######################################################################################
|
73 |
slacapra |
1.5 |
# self.hstates['destination'] = self.hstates['destination'].strip()
|
74 |
|
|
# destination = self.hstates['destination'].split(":")[0]
|
75 |
|
|
# self.hstates['jobId'] = self.hstates['jobId'].strip()
|
76 |
|
|
# ID3 = self.hstates['jobId'].split("/")[3]
|
77 |
|
|
# brokTmp = self.hstates['jobId'].split("/")[2]
|
78 |
|
|
# broker = brokTmp.split(":")[0]
|
79 |
|
|
# self.hstates['destination'] = self.hstates['destination'].strip()
|
80 |
|
|
# destination = self.hstates['destination'].split(":")[0]
|
81 |
|
|
# resFlag = 0
|
82 |
slacapra |
1.1 |
#######################################################################################
|
83 |
slacapra |
1.3 |
|
84 |
|
|
### TODO: set relevant status also to DB
|
85 |
|
|
|
86 |
slacapra |
1.1 |
try:
|
87 |
|
|
if result == 'Done':
|
88 |
|
|
self.countDone = self.countDone + 1
|
89 |
|
|
exCode = self.hstates['exit_code']
|
90 |
slacapra |
1.3 |
common.jobDB.setStatus(nj, 'D')
|
91 |
slacapra |
1.1 |
#statistic.notify('checkstatus',resFlag,exCode,dataset,owner,destination,broker,ID3,ID1,NJC)
|
92 |
|
|
elif result == 'Ready':
|
93 |
|
|
self.countReady = self.countReady + 1
|
94 |
|
|
#statistic.notify('checkstatus',resFlag,'-----',dataset,owner,destination,broker,ID3,ID1,NJC)
|
95 |
|
|
elif result == 'Scheduled':
|
96 |
|
|
self.countSched = self.countSched + 1
|
97 |
|
|
#statistic.notify('checkstatus',resFlag,'-----',dataset,owner,destination,broker,ID3,ID1,NJC)
|
98 |
|
|
elif result == 'Running':
|
99 |
|
|
self.countRun = self.countRun + 1
|
100 |
|
|
#statistic.notify('checkstatus',resFlag,'-----',dataset,owner,destination,broker,ID3,ID1,NJC)
|
101 |
|
|
elif result == 'Aborted':
|
102 |
slacapra |
1.2 |
common.jobDB.setStatus(nj, 'A')
|
103 |
slacapra |
1.1 |
#job.saveJobStatus()
|
104 |
|
|
#statistic.notify('checkstatus',resFlag,'abort',dataset,owner,destination,broker,ID3,ID1,NJC)
|
105 |
|
|
pass
|
106 |
|
|
elif result == 'Cancelled':
|
107 |
slacapra |
1.3 |
common.jobDB.setStatus(nj, 'K')
|
108 |
slacapra |
1.1 |
#job.setStatus('K')
|
109 |
|
|
#job.saveJobStatus()
|
110 |
|
|
#statistic.notify('checkstatus',resFlag,'cancel',dataset,owner,destination,broker,ID3,ID1,NJC)
|
111 |
|
|
pass
|
112 |
|
|
elif result == 'Cleared':
|
113 |
|
|
#job.setStatus('P')
|
114 |
|
|
exCode = self.hstates['exit_code']
|
115 |
|
|
#statistic.notify('checkstatus',resFlag,exCode,dataset,owner,destination,broker,ID3,ID1,NJC)
|
116 |
|
|
#job.saveJobStatus()
|
117 |
|
|
self.countCleared = self.countCleared + 1
|
118 |
|
|
except UnboundLocalError:
|
119 |
|
|
common.logger.message('ERROR: UnboundLocalError with ')
|
120 |
|
|
|
121 |
|
|
def Report_(self) :
|
122 |
|
|
|
123 |
|
|
""" Report #jobs for each status """
|
124 |
|
|
|
125 |
|
|
#job_stat = common.job_list.loadStatus()
|
126 |
|
|
|
127 |
|
|
print ''
|
128 |
|
|
print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
|
129 |
|
|
|
130 |
|
|
if (self.countReady != 0):
|
131 |
|
|
print ''
|
132 |
|
|
print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
|
133 |
|
|
if (self.countSched != 0):
|
134 |
|
|
print ''
|
135 |
|
|
print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
|
136 |
|
|
if (self.countRun != 0):
|
137 |
|
|
print ''
|
138 |
|
|
print ">>>>>>>>> %i Jobs Running" % (self.countRun)
|
139 |
|
|
if (self.countCleared != 0):
|
140 |
|
|
print ''
|
141 |
|
|
print ">>>>>>>>> %i Jobs Retrieved (=Cleared)" % (self.countCleared)
|
142 |
|
|
print " You can resubmit them specifying JOB numbers: crab.py -resubmit JOB_number (or range of JOB) -continue"
|
143 |
|
|
print " (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
|
144 |
|
|
# if job_stat[6] or job_stat[7]:
|
145 |
|
|
# print ''
|
146 |
|
|
# print ">>>>>>>>> %i Jobs aborted or killed(=cancelled by user)" % (job_stat[6] + job_stat[7])
|
147 |
|
|
# print " Resubmit them with: crab.py -resubmit -continue to resubmit all"
|
148 |
|
|
# print " or specifying JOB numbers (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
|
149 |
|
|
# print " "
|
150 |
|
|
if (self.countDone != 0):
|
151 |
|
|
print ">>>>>>>>> %i Jobs Done" % (self.countDone)
|
152 |
|
|
print " Retrieve them with: crab.py -getoutput -continue to retrieve all"
|
153 |
|
|
print " or specifying JOB numbers (i.e -getoutput 1-3 => 1 and 2 and 3 or -getoutput 1,3 => 1 and 3)"
|
154 |
|
|
print('\n')
|
155 |
|
|
pass
|
156 |
|
|
|
157 |
|
|
|
158 |
slacapra |
1.5 |
# def getJobStatus_(self, sid, attr):
|
159 |
|
|
# result = ''
|
160 |
|
|
# st = 0
|
161 |
|
|
# self.jobStat.getStatus(sid, self.level)
|
162 |
|
|
# (err, apiMsg) = self.jobStat.get_error()
|
163 |
|
|
# if err:
|
164 |
|
|
# common.logger.message(apiMsg)
|
165 |
|
|
# return None
|
166 |
|
|
# else:
|
167 |
|
|
# for i in range(len(self.states)):
|
168 |
|
|
# #print "states = ", self.states
|
169 |
|
|
# # Fill an hash table with all information retrieved from LB API
|
170 |
|
|
# self.hstates[ self.states[i] ] = self.jobStat.loadStatus(st)[i]
|
171 |
|
|
# result = self.jobStat.loadStatus(st)[ self.states.index(attr) ]
|
172 |
|
|
# return result
|