1 | package schedframe.scheduling.tasks; |
---|
2 | |
---|
3 | import gridsim.GridSim; |
---|
4 | import gridsim.Gridlet; |
---|
5 | import gridsim.ResGridlet; |
---|
6 | import gssim.schedframe.scheduling.ExecTask; |
---|
7 | import gssim.schedframe.scheduling.Executable; |
---|
8 | |
---|
9 | import java.util.List; |
---|
10 | |
---|
11 | import org.apache.commons.lang.ArrayUtils; |
---|
12 | import org.joda.time.DateTime; |
---|
13 | import org.joda.time.DateTimeUtilsExt; |
---|
14 | import org.joda.time.ReadableDuration; |
---|
15 | |
---|
16 | import schedframe.resources.computing.ComputingResource; |
---|
17 | import schedframe.resources.units.ProcessingElements; |
---|
18 | import schedframe.resources.units.StandardResourceUnitName; |
---|
19 | import schedframe.scheduling.ResourceHistoryItem; |
---|
20 | import schedframe.scheduling.UsedResourceList; |
---|
21 | import schedframe.scheduling.WorkloadUnitHandler; |
---|
22 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
23 | import schedframe.scheduling.tasks.requirements.ResourceParameterName; |
---|
24 | |
---|
25 | /** |
---|
26 | * |
---|
27 | * @author Marcin Krystek |
---|
28 | * |
---|
29 | */ |
---|
30 | public class SubmittedTask extends ResGridlet implements ExecTask{ |
---|
31 | |
---|
32 | protected Executable task; |
---|
33 | protected int estimatedDuration; |
---|
34 | protected UsedResourceList<ResourceHistoryItem> usedResources; |
---|
35 | //protected List<String> visitedResources; |
---|
36 | |
---|
37 | public SubmittedTask(Executable exec) { |
---|
38 | super(exec); |
---|
39 | task = exec; |
---|
40 | this.usedResources = new UsedResourceList<ResourceHistoryItem>(); |
---|
41 | if(exec.requireReservation()) |
---|
42 | this.reservID_ = Integer.valueOf(exec.getReservationId()); |
---|
43 | //this.visitedResources = new ArrayList<String>(); |
---|
44 | } |
---|
45 | |
---|
46 | public double getCpuCntRequest() throws NoSuchFieldException { |
---|
47 | return task.getCpuCntRequest(); |
---|
48 | } |
---|
49 | |
---|
50 | public DateTime getExecutionEndTime() throws NoSuchFieldException { |
---|
51 | return task.getExecutionEndTime(); |
---|
52 | } |
---|
53 | |
---|
54 | public DateTime getExecutionStartTime() throws NoSuchFieldException { |
---|
55 | return task.getExecutionStartTime(); |
---|
56 | } |
---|
57 | |
---|
58 | public ReadableDuration getExpectedDuration() throws NoSuchFieldException { |
---|
59 | return task.getExpectedDuration(); |
---|
60 | } |
---|
61 | |
---|
62 | public int getEstimatedDuration(){ |
---|
63 | return this.estimatedDuration; |
---|
64 | } |
---|
65 | |
---|
66 | public void setEstimatedDuration(int value){ |
---|
67 | this.estimatedDuration = value; |
---|
68 | } |
---|
69 | |
---|
70 | public String getId() { |
---|
71 | return task.getId(); |
---|
72 | } |
---|
73 | |
---|
74 | public String getJobId() { |
---|
75 | return task.getJobId(); |
---|
76 | } |
---|
77 | |
---|
78 | public long getLength() { |
---|
79 | return task.getLength(); |
---|
80 | } |
---|
81 | |
---|
82 | public double getMemoryRequest() throws NoSuchFieldException { |
---|
83 | return task.getMemoryRequest(); |
---|
84 | } |
---|
85 | |
---|
86 | public double getParameterDoubleValue(ResourceParameterName parameterName) |
---|
87 | throws NoSuchFieldException, IllegalArgumentException { |
---|
88 | return task.getParameterDoubleValue(parameterName); |
---|
89 | } |
---|
90 | |
---|
91 | public String getParameterStringValue(ResourceParameterName parameterName) |
---|
92 | throws NoSuchFieldException, IllegalArgumentException { |
---|
93 | return task.getParameterStringValue(parameterName); |
---|
94 | } |
---|
95 | |
---|
96 | public List<AbstractProcessesGroup> getProcessesGroups() { |
---|
97 | throw new RuntimeException("Not implemented"); |
---|
98 | } |
---|
99 | |
---|
100 | public List<AbstractProcesses> getProcesses(){ |
---|
101 | throw new RuntimeException("Not implemented"); |
---|
102 | } |
---|
103 | |
---|
104 | public List<AbstractProcesses> getProcesses(AbstractProcessesGroup processGroup){ |
---|
105 | throw new RuntimeException("Not implemented"); |
---|
106 | } |
---|
107 | |
---|
108 | public int getStatus() { |
---|
109 | return task.getStatus(); |
---|
110 | } |
---|
111 | |
---|
112 | public DateTime getSubmissionTimeToBroker() { |
---|
113 | return task.getSubmissionTimeToBroker(); |
---|
114 | } |
---|
115 | |
---|
116 | public String getUserDn() { |
---|
117 | return task.getUserDn(); |
---|
118 | } |
---|
119 | |
---|
120 | public void setLength(long length) { |
---|
121 | throw new RuntimeException("Task length should not be changed here."); |
---|
122 | } |
---|
123 | |
---|
124 | public void setStatus(int status) throws Exception { |
---|
125 | task.setStatus(status); |
---|
126 | } |
---|
127 | |
---|
128 | public org.qcg.broker.schemas.resreqs.Task getDescription() { |
---|
129 | return (org.qcg.broker.schemas.resreqs.Task) task.getDescription(); |
---|
130 | } |
---|
131 | |
---|
132 | public String getDocument() throws Exception { |
---|
133 | return task.getDocument(); |
---|
134 | } |
---|
135 | |
---|
136 | public boolean expectSpecificResource(ResourceParameterName resourceName){ |
---|
137 | return task.expectSpecificResource(resourceName); |
---|
138 | } |
---|
139 | |
---|
140 | public Object getExpectedSpecificResource(ResourceParameterName resourceName){ |
---|
141 | return task.getExpectedSpecificResource(resourceName); |
---|
142 | } |
---|
143 | |
---|
144 | public long getWorkloadLogWaitTime() { |
---|
145 | return task.getWorkloadLogWaitTime(); |
---|
146 | } |
---|
147 | |
---|
148 | public void addUsedResources(ResourceHistoryItem usedResources){ |
---|
149 | this.usedResources.add(usedResources); |
---|
150 | } |
---|
151 | |
---|
152 | //public List<Map<ResourceParameterName, ResourceUnit>> getUsedResources(){ |
---|
153 | public UsedResourceList<ResourceHistoryItem> getUsedResources(){ |
---|
154 | return this.usedResources; |
---|
155 | } |
---|
156 | |
---|
157 | public boolean setGridletStatus(int status) |
---|
158 | { |
---|
159 | // gets Gridlet's previous status |
---|
160 | int prevStatus = gridlet_.getGridletStatus(); |
---|
161 | |
---|
162 | // if the status of a Gridlet is the same as last time, then ignore |
---|
163 | if (prevStatus == status) { |
---|
164 | return false; |
---|
165 | } |
---|
166 | |
---|
167 | boolean success = true; |
---|
168 | try |
---|
169 | { |
---|
170 | double clock = GridSim.clock(); // gets the current clock |
---|
171 | long sec = DateTimeUtilsExt.currentTimeMillis() / 1000; // time in seconds |
---|
172 | clock = Long.valueOf(sec).doubleValue(); |
---|
173 | |
---|
174 | // sets Gridlet's current status |
---|
175 | gridlet_.setGridletStatus(status); |
---|
176 | |
---|
177 | // if a previous Gridlet status is INEXEC |
---|
178 | if (prevStatus == Gridlet.INEXEC) |
---|
179 | { |
---|
180 | // and current status is either CANCELED, PAUSED or SUCCESS |
---|
181 | if (status == Gridlet.CANCELED || status == Gridlet.PAUSED || |
---|
182 | status == Gridlet.SUCCESS) |
---|
183 | { |
---|
184 | // then update the Gridlet completion time |
---|
185 | totalCompletionTime_ += (clock - startExecTime_); |
---|
186 | index_ = 0; |
---|
187 | return true; |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | if (prevStatus == Gridlet.RESUMED && status == Gridlet.SUCCESS) |
---|
192 | { |
---|
193 | // then update the Gridlet completion time |
---|
194 | totalCompletionTime_ += (clock - startExecTime_); |
---|
195 | return true; |
---|
196 | } |
---|
197 | |
---|
198 | // if a Gridlet is now in execution |
---|
199 | if (status == Gridlet.INEXEC || |
---|
200 | (prevStatus == Gridlet.PAUSED && status == Gridlet.RESUMED) ) |
---|
201 | { |
---|
202 | |
---|
203 | startExecTime_ = clock; |
---|
204 | gridlet_.setExecStartTime(startExecTime_); |
---|
205 | ProcessingElements pes = (ProcessingElements) getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); |
---|
206 | for (ComputingResource resource : pes) { |
---|
207 | |
---|
208 | visitResource(resource.getName()); |
---|
209 | ComputingResource parent = resource.getParent(); |
---|
210 | |
---|
211 | List<String> visitedResource = getVisitedResources(); |
---|
212 | while (parent != null && !ArrayUtils.contains(visitedResource.toArray(new String[visitedResource.size()]), parent.getName())) { |
---|
213 | visitResource(parent.getName()); |
---|
214 | parent = parent.getParent(); |
---|
215 | } |
---|
216 | } |
---|
217 | } |
---|
218 | } |
---|
219 | catch(Exception e) { |
---|
220 | success = false; |
---|
221 | } |
---|
222 | |
---|
223 | return success; |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | protected void init() { |
---|
228 | super.init(); |
---|
229 | double time = DateTimeUtilsExt.getDateTimeAt(arrivalTime_).getMillis() / 1000; |
---|
230 | this.gridlet_.setSubmissionTime(time); |
---|
231 | } |
---|
232 | |
---|
233 | @Override |
---|
234 | public List<Task> getTask() { |
---|
235 | // TODO Auto-generated method stub |
---|
236 | return null; |
---|
237 | } |
---|
238 | |
---|
239 | @Override |
---|
240 | public TaskInterface<?> getTask(String taskId) throws NoSuchFieldException { |
---|
241 | // TODO Auto-generated method stub |
---|
242 | return null; |
---|
243 | } |
---|
244 | |
---|
245 | @Override |
---|
246 | public int getTaskCount() { |
---|
247 | // TODO Auto-generated method stub |
---|
248 | return 0; |
---|
249 | } |
---|
250 | |
---|
251 | @Override |
---|
252 | public boolean isFinished() { |
---|
253 | // TODO Auto-generated method stub |
---|
254 | return false; |
---|
255 | } |
---|
256 | |
---|
257 | /*public void addToResPath(String resName){ |
---|
258 | task.addToResPath(resName); |
---|
259 | } |
---|
260 | |
---|
261 | public String getResPath(){ |
---|
262 | return task.getResPath(); |
---|
263 | }*/ |
---|
264 | |
---|
265 | public void visitResource(String resName){ |
---|
266 | task.visitResource(resName); |
---|
267 | } |
---|
268 | |
---|
269 | public List<String> getVisitedResources(){ |
---|
270 | return task.getVisitedResources(); |
---|
271 | } |
---|
272 | |
---|
273 | public boolean isRegistered() { |
---|
274 | return task.isRegistered(); |
---|
275 | } |
---|
276 | |
---|
277 | public void register(JobRegistryImpl jobRegistry) { |
---|
278 | task.register(jobRegistry); |
---|
279 | //jobRegistry.addTask(this); |
---|
280 | } |
---|
281 | |
---|
282 | @Override |
---|
283 | public void accept(WorkloadUnitHandler wuh) { |
---|
284 | wuh.handleSubmittedTask(this); |
---|
285 | } |
---|
286 | } |
---|