-
Notifications
You must be signed in to change notification settings - Fork 0
/
Job.py
97 lines (64 loc) · 2.45 KB
/
Job.py
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
'''
Created on Jan 9, 2015
@author: niuzhaojie
'''
from SchedulableStatus import SchedulableStatus
class Job(object):
'''
classdocs
'''
def __init__(self, jobID, submissionTime):
'''
Constructor
'''
self._jobID = jobID
self._status = SchedulableStatus.WAITING
self._taskList = []
self._taskDict = {}
self._submissionTime = submissionTime
self._startTime = None
self._finishTime = None
def updateStatus(self, status):
self._status = status
def addTask(self, task):
self._taskList.append(task)
self._taskDict[task.getTaskID()] = task
def getResourceVector(self):
return self._taskList[0].getResource().getResourceVector()
def getResource(self):
return self._taskList[0].getResource()
def getJobID(self):
return self._jobID
def getTaskList(self):
return self._taskList
def getSubmissionTime(self):
return self._submissionTime
def setStartTime(self, t):
self._startTime = t
def setFinishTime(self, t):
self._finishTime = t
def getFinishTime(self):
return self._finishTime
def activeAllTasks(self):
for task in self._taskList:
if task.getStatus() == SchedulableStatus.WAITING and len(task.getParents()) == 0:
task.updateStatus(SchedulableStatus.RUNNABLE)
elif task.getStatus() == SchedulableStatus.WAITING and len(task.getParents()) > 0:
task.updateStatus(SchedulableStatus.PENDING)
def getNumofUnFinishedTasks(self):
count = 0
for task in self._taskList:
if task.getStatus() == SchedulableStatus.FINISHING:
count += 1
return count
def allTasksFinished(self):
ret = True
for task in self._taskList:
if task.getStatus() != SchedulableStatus.FINISHING:
ret = False
break
return ret
def updateStatusOfPendingTasks(self):
for task in self._taskList:
if task.getStatus() == SchedulableStatus.PENDING and task.parentsAllFinished():
task.updateStatus(SchedulableStatus.RUNNABLE)