-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_SGEJobStatusUpdate.sh
executable file
·487 lines (407 loc) · 17.8 KB
/
run_SGEJobStatusUpdate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/bin/bash
#***************************************************************************************
# brief:
# --check that whether all submitted SGE jobs have been completed
# --usage: ./run_SGEJobStatusUpdate.sh ${SGEJobSubmittedLogFile}
# ${SGEJobsFinishFlagFile}
#
#
#date: 04/26/2015 Created
#***************************************************************************************
runUsage()
{
echo ""
echo -e "\033[31m usage: usage: ./run_SGEJobStatusUpdate.sh \${SGEJobSubmittedLogFile} \033[0m"
echo -e "\033[31m usage: usage: \${SGEJobsFinishFlagFile} \033[0m"
echo -e "\033[32m when all SGE test jobs have been completd, \${SGEJobsFinishFlagFile} will be generated! \033[0m"
echo ""
}
runInitial()
{
declare -a aSubmittedSGEJobIDList
declare -a aSubmittedSGEJobNameList
declare -a aSubmittedSGEJobYUVNameList
declare -a aSubmittedSGEJobSubCasesIndexList
declare -a aCurrentSGEQueueJobIDList
declare -a aRunningJobIDList
declare -a aWaitingJobIDList
declare -a aCompletedJobIDList
declare -a aFailedJobIDList
declare -a aFailedJobNameList
declare -a aFailedJobUnpassedCasesNumList
declare -a aSucceedJobIDList
declare -a aSucceedJobNameList
declare -a aSucceedJobPassedCasesNumList
declare -a aUnRunCaseJobIDList
declare -a aUnRunCaseJobNameList
declare -a aUnknownReasonFailedJobIDList
declare -a aUnknownReasonFailedJobNameList
declare -a aFailedJobTestDirList
declare -a aSucceedJobTestDirList
declare -a aUnRunCaseJobTestDirList
let "SubmittedJobNum = 0"
let "CurrentSGEQueueJobNum = 0"
let "NonCompletedJobNum=0"
let "RunningJobNum=0"
let "WaitingJobNum=0"
let "CompletedJobNum=0"
let "SucceedJobNum=0"
let "FailedJobNum=0"
let "UnRunCasesJobNum=0"
let "UnKnownReasonFailedJobNum=0"
FaildJobInfoLog="FailedJobInfo.txt"
if [ -e ${FaildJobInfoLog} ]
then
./Scripts/run_SafeDelete.sh ${FaildJobInfoLog}
fi
CurrentDir=`pwd`
TestSpace="${CurrentDir}/AllTestData"
SucceedJobsInfo="${CurrentDir}/SucceedJobsDetailInfo.txt"
FailedJobsInfo="${CurrentDir}/FailedJobsDetailInfo.txt"
UnRunCasesJobsInfo="${CurrentDir}/UnRunCasesJobsDetailInfo.txt"
UnknownReasonJobsInfo="${CurrentDir}/UnknownReasonJobsDetailInfo.txt"
date
DateInfo=`date`
echo "${DateInfo}">${SucceedJobsInfo}
echo "${DateInfo}">${FailedJobsInfo}
echo "${DateInfo}">${UnRunCasesJobsInfo}
echo "${DateInfo}">${UnknownReasonJobsInfo}
}
runParseJobsInfo()
{
aSubmittedSGEJobIDList=(`./Scripts/run_ParseSGEJobIDs.sh ${SGEJobSubmittedLogFile}`)
aSubmittedSGEJobNameList=(`./Scripts/run_ParseSGEJobNames.sh ${SGEJobSubmittedLogFile}`)
#list info include ID and status
#e.g.:aCurrentSGEQueueJobIDList=(501 r 502 r 503 w 504 qw)
aCurrentSGEQueueJobIDList=(`./Scripts/run_ParseRunningSGEJobIDsAndStatus.sh IDAndStatus`)
let "SubmittedJobNum = ${#aSubmittedSGEJobIDList[@]}"
let "CurrentSGEQueueJobNum = ${#aCurrentSGEQueueJobIDList[@]}/2"
}
runParseJobsDetailInfo()
{
# job name looks like as below:
# ----MSHD_320x192_12fps.yuv_SubCaseIndex_22
for((i=0;i<${SubmittedJobNum};i++))
do
vTempJobName=${aSubmittedSGEJobNameList[$i]}
vTempYUVName=`echo ${vTempJobName} | awk 'BEGIN {FS="----"} {print $1}' `
vTempYUVName=`echo ${vTempYUVName} | awk 'BEGIN {FS=".yuv"} {print $1}' `
vTempYUVName="${vTempYUVName}.yuv"
vTempSubCasesIndex=`echo ${vTempJobName} | awk 'BEGIN {FS="SubCaseIndex_"} {print $2}' `
vTempSubCasesIndex="SubCaseIndex_${vTempSubCasesIndex}"
aSubmittedSGEJobYUVNameList[$i]=${vTempYUVName}
aSubmittedSGEJobSubCasesIndexList[$i]=${vTempSubCasesIndex}
done
}
runOutputParseInfo()
{
echo -e "\033[32m Total submitted job num is ${SubmittedJobNum} \033[0m"
echo -e "\033[32m Current job num in queue(SVC+SCC) is ${CurrentSGEQueueJobNum} \033[0m"
echo ""
echo -e "\033[32m Submitted jobs' ID is ${aSubmittedSGEJobIDList[@]} \033[0m"
echo ""
echo -e "\033[32m Current queue's job ID is ${aCurrentSGEQueueJobIDList[@]} \033[0m"
echo ""
echo -e "\033[32m Submitted jobs' name is ${aSubmittedSGEJobNameList[@]} \033[0m"
echo ""
}
#comparison between current runnig SGE job list and the submitted job list
#to check that whether all submitted jobs are not in current running list
runSGEJobStatusCheck()
{
for((i=0;i<${SubmittedJobNum};i++))
do
SubmitId=${aSubmittedSGEJobIDList[$i]}
let "JonRunningFlag=0"
for((j=0;j<${CurrentSGEQueueJobNum};j++))
do
#e.g.:aCurrentSGEQueueJobIDList=(501 r 502 r 503 w 504 qw), so need to j*2; r means running, qw means queue wait
let "QueueIDIndex = j*2"
let "QueueStatusIndex = QueueIDIndex+1"
CurrentSGEQueueJobID=${aCurrentSGEQueueJobIDList[${QueueIDIndex}]}
CurrentSGEQueueJobStatus=${aCurrentSGEQueueJobIDList[${QueueStatusIndex}]}
if [ ${SubmitId} -eq ${CurrentSGEQueueJobID} ]
then
if [ "${CurrentSGEQueueJobStatus}" = "r" ]
then
let "JonRunningFlag=1"
else # job is under waiting status
let "JonRunningFlag=2"
fi
break
fi
done
#job is still running
if [ ${JonRunningFlag} -eq 1 ]
then
echo -e "\033[31m Job ${SubmitId} is still running \033[0m"
echo -e "\033[31m Job info is:----${aSubmittedSGEJobNameList[$i]} \033[0m"
aRunningJobIDList[${RunningJobNum}]=${SubmitId}
let "NonCompletedJobNum++"
let "RunningJobNum ++"
#job is still waiting
elif [ ${JonRunningFlag} -eq 2 ]
then
echo -e "\033[31m Job ${SubmitId} is still waiting \033[0m"
echo -e "\033[31m Job info is:----${aSubmittedSGEJobNameList[$i]} \033[0m"
aWaitingJobIDList[${WaitingJobNum}]=${SubmitId}
let "NonCompletedJobNum++"
let "WaitingJobNum ++"
else
echo -e "\033[32m Job ${SubmitId} has been finished! \033[0m"
echo -e "\033[32m Job info is:----${aSubmittedSGEJobNameList[$i]} \033[0m"
aCompletedJobIDList[${CompletedJobNum}]=${SubmitId}
let "CompletedJobNum++"
fi
done
}
runUpdateSGEJobPassedStatus()
{
#aOptionList=(FailedJobID FailedJobName FailedJobUnPassedNum SucceedJobID SucceedJobName SucceedJobPassedNum)
aFailedJobIDList=(`./Scripts/run_ParseSGEJobPassStatus.sh FailedJobID `)
aFailedJobNameList=(`./Scripts/run_ParseSGEJobPassStatus.sh FailedJobName `)
aFailedJobUnpassedCasesNumList=(`./Scripts/run_ParseSGEJobPassStatus.sh FailedJobUnpassedNum `)
aSucceedJobIDList=(`./Scripts/run_ParseSGEJobPassStatus.sh SucceedJobID `)
aSucceedJobNameList=(`./Scripts/run_ParseSGEJobPassStatus.sh SucceedJobName `)
aSucceedJobPassedCasesNumList=(`./Scripts/run_ParseSGEJobPassStatus.sh SucceedJobPassedNum `)
aUnRunCaseJobIDList=(`./Scripts/run_ParseSGEJobPassStatus.sh UnRunCaseJobID `)
aUnRunCaseJobNameList=(`./Scripts/run_ParseSGEJobPassStatus.sh UnRunCaseJobName `)
aFailedJobTestDirList=(`./Scripts/run_ParseSGEJobPassStatus.sh FailedJobTestDir `)
aSucceedJobTestDirList=(`./Scripts/run_ParseSGEJobPassStatus.sh SucceedJobTestDir `)
aUnRunCaseJobTestDirList=(`./Scripts/run_ParseSGEJobPassStatus.sh UnRunCaseJobTestDir `)
let "FailedJobNum=${#aFailedJobIDList[@]}"
let "SucceedJobNum=${#aSucceedJobIDList[@]}"
let "UnRunCasesJobNum=${#aUnRunCaseJobIDList[@]}"
let "DetectedJobNum= ${FailedJobNum} + ${SucceedJobNum} + ${UnRunCasesJobNum}"
let "UnKnownReasonFailedJobNum=${CompletedJobNum} - ${DetectedJobNum}"
if [ ! ${UnKnownReasonFailedJobNum} -eq 0 ]
then
runGetUnknownReasonFailedJobInfo
fi
}
runGetUnknownReasonFailedJobInfo()
{
declare -a DetectedJobList
DetectedJobList=( ${aRunningJobIDList[@]} ${aWaitingJobIDList[@]} ${aFailedJobIDList[@]} ${aSucceedJobIDList[@]} ${aUnRunCaseJobIDList[@]} )
let "DetectedJobNum =${#DetectedJobList[@]}"
echo DetectedJobNum is ${DetectedJobNum}
echo DetectedJobList is ${DetectedJobList[@]}
echo UnKnownReasonFailedJobNum is ${UnKnownReasonFailedJobNum}
let "UnKnownJobIndex=0"
for((i=0;i<${SubmittedJobNum}; i++))
do
let "SubmittedJobID = ${aSubmittedSGEJobIDList[$i]}"
let "DetectedFlag=0"
for ((j=0;j<${DetectedJobNum};j++))
do
let "DetectedJobID = ${DetectedJobList[$j]}"
if [ "${SubmittedJobID}" = "${DetectedJobID}" ]
then
let "DetectedFlag=1"
fi
done
if [ ${DetectedFlag} -eq 0 ]
then
aUnknownReasonFailedJobIDList[${UnKnownJobIndex}]=${SubmittedJobID}
aUnknownReasonFailedJobNameList[${UnKnownJobIndex}]=${aSubmittedSGEJobNameList[$i]}
let "UnKnownJobIndex ++"
fi
done
}
runOutputJobDetailInfoFile()
{
for((i=0;i<${SubmittedJobNum}; i++))
do
let "SubmittedJobID = ${aSubmittedSGEJobIDList[$i]}"
vSubCasesIndex="${aSubmittedSGEJobSubCasesIndexList[$i]}"
vTestDir="${TestSpace}/${aSubmittedSGEJobYUVNameList[$i]}"
## for unknown reason jobs' info
for ((j=0;j<${UnKnownReasonFailedJobNum};j++))
do
let "DetectedJobID = ${aUnknownReasonFailedJobIDList[$j]}"
if [ "${SubmittedJobID}" = "${DetectedJobID}" ]
then
echo "${SubmittedJobID} ${vSubCasesIndex} ${vTestDir} ">>${UnknownReasonJobsInfo}
fi
done
## for failed jobs' info
for ((j=0;j<${FailedJobNum};j++))
do
let "DetectedJobID = ${aFailedJobIDList[$j]}"
if [ "${SubmittedJobID}" = "${DetectedJobID}" ]
then
echo "${SubmittedJobID} ${vSubCasesIndex} ${vTestDir} ">>${FailedJobsInfo}
echo " ----Test dir is: ${aFailedJobTestDirList}">>${FailedJobsInfo}
fi
done
## for succeed jobs' info
for ((j=0;j<${SucceedJobNum};j++))
do
let "DetectedJobID = ${aSucceedJobIDList[$j]}"
if [ "${SubmittedJobID}" = "${DetectedJobID}" ]
then
echo "${SubmittedJobID} ${vSubCasesIndex} ${vTestDir} ">>${SucceedJobsInfo}
echo " ----Test dir is: ${aSucceedJobTestDirList}">>${SucceedJobsInfo}
fi
done
## for un-run-cases jobs' info
for ((j=0;j<${UnRunCasesJobNum};j++))
do
let "DetectedJobID = ${aUnRunCaseJobIDList[$j]}"
if [ "${SubmittedJobID}" = "${DetectedJobID}" ]
then
echo "${SubmittedJobID} ${vSubCasesIndex} ${vTestDir} ">>${UnRunCasesJobsInfo}
echo " ----Test dir is: ${aUnRunCaseJobTestDirList}">>${UnRunCasesJobsInfo}
fi
done
done
}
runOutputStatusSummary()
{
if [ ${NonCompletedJobNum} -eq 0 ]
then
echo -e "\033[32m ****************************************************** \033[0m"
echo -e "\033[32m All submitted SGE jobs have completed all test \033[0m"
echo -e "\033[32m ****************************************************** \033[0m"
echo ""
echo ""
echo -e "\033[32m ******************************************************************** \033[0m"
echo -e "\033[32m Completed jobs test cases status info \033[0m"
echo -e "\033[32m ******************************************************************** \033[0m"
echo ""
echo -e "\033[32m Succeed job num is ${SucceedJobNum} \033[0m"
echo ""
echo -e "\033[32m Succeed job ID is ${aSucceedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[31m Failed job num is ${FailedJobNum} \033[0m"
echo ""
echo -e "\033[31m Failed job ID is ${aFailedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[31m Failed job un-passed num list is ${aFailedJobUnpassedCasesNumList[@]} \033[0m"
echo ""
echo -e "\033[34m no case run job num(e.g. YUV not found) is ${UnRunCasesJobNum} \033[0m"
echo ""
echo -e "\033[34m no case run job ID is ${aUnRunCaseJobIDList[@]} \033[0m"
echo ""
echo -e "\033[35m Unknown reason failed job num is ${UnKnownReasonFailedJobNum} \033[0m"
echo ""
echo -e "\033[35m Unknown reason failed job ID is ${aUnknownReasonFailedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[32m ********************************************************************* \033[0m"
echo ""
return 0
else
echo -e "\033[31m ****************************************************** \033[0m"
echo -e "\033[31m Not all submitted SGE jobs have completed yet \033[0m"
echo -e "\033[31m ****************************************************** \033[0m"
echo ""
echo -e "\033[32m Total submitted job num is ${SubmittedJobNum} \033[0m"
echo -e "\033[32m Completed job num is ${CompletedJobNum} \033[0m"
echo -e "\033[31m Non completed job num is ${NonCompletedJobNum} \033[0m"
echo -e "\033[31m --Running job num is ${RunningJobNum} \033[0m"
echo -e "\033[33m --Waiting job num is ${WaitingJobNum} \033[0m"
echo ""
echo -e "\033[31m ****************************************************** \033[0m"
echo -e "\033[31m ****************************************************** \033[0m"
echo ""
echo -e "\033[32m Completed job ID is ${aCompletedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[31m Running job ID is ${aRunningJobIDList[@]} \033[0m"
echo ""
echo -e "\033[33m Waiting job ID is ${aWaitingJobIDList[@]} \033[0m"
echo ""
echo -e "\033[31m ****************************************************** \033[0m"
echo ""
echo -e "\033[32m ******************************************************************** \033[0m"
echo -e "\033[32m Completed jobs passed status info \033[0m"
echo -e "\033[32m ******************************************************************** \033[0m"
echo ""
echo -e "\033[32m Succeed job num is ${#aSucceedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[32m Succeed job ID is ${aSucceedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[31m Failed job num is ${#aFailedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[31m Failed job ID is ${aFailedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[31m Failed job un-passed num list is ${aFailedJobUnpassedCasesNumList[@]} \033[0m"
echo ""
echo -e "\033[34m no case run job num(e.g. YUV not found) is ${UnRunCasesJobNum} \033[0m"
echo ""
echo -e "\033[34m no case run job ID is ${aUnRunCaseJobIDList[@]} \033[0m"
echo ""
echo -e "\033[35m Unknown reason failed job num is ${UnKnownReasonFailedJobNum} \033[0m"
echo ""
echo -e "\033[35m Unknown reason failed job ID is ${aUnknownReasonFailedJobIDList[@]} \033[0m"
echo ""
echo -e "\033[33m ********************************************************************* \033[0m"
echo ""
return 1
fi
}
runVaildateCheck()
{
if [ ! -e ${SGEJobSubmittedLogFile} ]
then
echo ""
echo -e "\033[31m SGEJobSubmittedLogFile ${SGEJobSubmittedLogFile} does not exist! \033[0m"
echo -e "\033[31m Please double check!\033[0m"
echo -e "\033[32m --Submit SGE jobs before you detect the SGE jobs status! \033[0m"
echo -e "\033[32m --or check the the SGE submitted log file!\033[0m"
echo ""
touch ${SGEJobSubmittedLogFile}
return 1
fi
if [ ! -s ${SGEJobSubmittedLogFile} ]
then
echo ""
echo -e "\033[31m SGEJobSubmittedLogFile ${SGEJobSubmittedLogFile} does not exist! \033[0m"
echo -e "\033[31m Please double check!\033[0m"
echo -e "\033[32m --Submit SGE jobs before you detect the SGE jobs status! \033[0m"
echo -e "\033[32m --or check the the SGE submitted log file!\033[0m"
echo ""
touch ${SGEJobSubmittedLogFile}
return 1
fi
if [ -e ${SGEJobsFinishFlagFile} ]
then
./Scripts/run_SafeDelete.sh ${SGEJobsFinishFlagFile}
fi
}
runMain()
{
runVaildateCheck
if [ ! $? -eq 0 ]
then
return 0
fi
runInitial
runParseJobsInfo
runParseJobsDetailInfo
runOutputParseInfo
runSGEJobStatusCheck
runUpdateSGEJobPassedStatus
runOutputJobDetailInfoFile
runOutputStatusSummary
if [ $? -eq 0 ]
then
touch ${SGEJobsFinishFlagFile}
fi
[ ! ${FailedJobNum} -eq 0 ] || [ ! ${UnKnownReasonFailedJobNum} -eq 0 ] && touch ${FaildJobInfoLog}
return 0
}
SGEJobSubmittedLogFile=$1
SGEJobsFinishFlagFile=$2
if [ ! $# -eq 2 ]
then
runUsage
exit 1
fi
echo ""
echo "*********************************************************"
echo " call bash file is $0"
echo " input parameters is:"
echo " $0 $@"
echo "*********************************************************"
echo ""
runMain ${SGEJobSubmittedLogFile} ${SGEJobsFinishFlagFile}