source: DCWoRMS/trunk/src/schedframe/scheduling/tasks/SubmittedTask.java @ 477

Revision 477, 7.5 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.scheduling.tasks;
2
3import gridsim.GridSim;
4import gridsim.Gridlet;
5import gridsim.ResGridlet;
6import gssim.schedframe.scheduling.ExecTask;
7import gssim.schedframe.scheduling.Executable;
8
9import java.util.List;
10
11import org.apache.commons.lang.ArrayUtils;
12import org.joda.time.DateTime;
13import org.joda.time.DateTimeUtilsExt;
14import org.joda.time.ReadableDuration;
15
16import schedframe.resources.computing.ComputingResource;
17import schedframe.resources.units.ProcessingElements;
18import schedframe.resources.units.StandardResourceUnitName;
19import schedframe.scheduling.ResourceHistoryItem;
20import schedframe.scheduling.UsedResourceList;
21import schedframe.scheduling.WorkloadUnitHandler;
22import schedframe.scheduling.manager.tasks.JobRegistryImpl;
23import schedframe.scheduling.tasks.requirements.ResourceParameterName;
24
25/**
26 *
27 * @author Marcin Krystek
28 *
29 */
30public 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
234        @Override
235        public boolean isFinished() {
236                // TODO Auto-generated method stub
237                return false;
238        }
239       
240        /*public void addToResPath(String resName){
241                task.addToResPath(resName);
242        }
243       
244        public String getResPath(){
245                return task.getResPath();
246        }*/
247       
248        public void visitResource(String resName){
249                task.visitResource(resName);
250        }
251       
252        public List<String> getVisitedResources(){
253                return task.getVisitedResources();
254        }
255       
256        public boolean isRegistered() {
257                return task.isRegistered();
258        }
259
260        public void register(JobRegistryImpl jobRegistry) {
261                task.register(jobRegistry);
262                //jobRegistry.addTask(this);
263        }
264       
265        @Override
266        public void accept(WorkloadUnitHandler wuh) {
267                wuh.handleSubmittedTask(this);
268        }
269}
Note: See TracBrowser for help on using the repository browser.