Changeset 1362 for DCWoRMS/branches


Ignore:
Timestamp:
06/03/14 15:12:11 (11 years ago)
Author:
wojtekp
Message:
 
Location:
DCWoRMS/branches/coolemall/src
Files:
1 added
1 deleted
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/dcworms/schedframe/scheduling/ExecTask.java

    r1207 r1362  
    11package dcworms.schedframe.scheduling; 
    22 
    3 import java.util.List; 
     3import java.util.LinkedList; 
    44 
     5import schedframe.scheduling.ExecutionHistoryItem; 
     6import schedframe.scheduling.ResourceHistoryItem; 
    57import schedframe.scheduling.tasks.TaskInterface; 
    68import schedframe.scheduling.tasks.phases.ResourceConsumption; 
    7 import schedframe.scheduling.tasks.phases.ResourceConsumptionProfile; 
     9import schedframe.scheduling.tasks.phases.ExecutionProfile; 
    810import schedframe.scheduling.tasks.requirements.ResourceParameterName; 
    911 
     
    1214        public boolean expectSpecificResource(ResourceParameterName resourceName);       
    1315        public Object getExpectedSpecificResource(ResourceParameterName resourceName); 
    14  
    15         public void trackResource(String resName); 
    16         public List<String> getVisitedResources(); 
    1716         
    18         public ResourceConsumptionProfile getResourceConsumptionProfile(); 
     17        public LinkedList<ExecutionHistoryItem> getExecHistory(); 
     18        public LinkedList<ResourceHistoryItem> getAllocatedResources(); 
     19         
     20        public ExecutionProfile getResourceConsumptionProfile(); 
    1921        public ResourceConsumption getCurrentResourceConsumption(); 
     22         
     23    public String getSchedulerName(); 
    2024} 
  • DCWoRMS/branches/coolemall/src/dcworms/schedframe/scheduling/Executable.java

    r1315 r1362  
    55import gridsim.dcworms.DCWormsTags; 
    66 
    7 import java.util.ArrayList; 
    87import java.util.HashMap; 
    98import java.util.LinkedList; 
     
    1110import java.util.Map; 
    1211 
    13 import org.apache.commons.lang.ArrayUtils; 
    1412import org.joda.time.DateTime; 
    1513import org.joda.time.DateTimeUtilsExt; 
     
    2523import schedframe.resources.units.ProcessingElements; 
    2624import schedframe.resources.units.StandardResourceUnitName; 
     25import schedframe.scheduling.ExecutionHistoryItem; 
    2726import schedframe.scheduling.ResourceHistoryItem; 
    28 import schedframe.scheduling.UsedResourcesList; 
    2927import schedframe.scheduling.WorkloadUnitHandler; 
    3028import schedframe.scheduling.manager.tasks.JobRegistryImpl; 
     
    3331import schedframe.scheduling.tasks.Task; 
    3432import schedframe.scheduling.tasks.phases.ResourceConsumption; 
    35 import schedframe.scheduling.tasks.phases.ResourceConsumptionProfile; 
     33import schedframe.scheduling.tasks.phases.ExecutionProfile; 
    3634import schedframe.scheduling.tasks.requirements.ResourceParameterName; 
    3735 
     
    5351         
    5452        protected int estimatedDuration; 
    55         //TO DO remove and benefit from visitedResources 
    5653        protected String schedName; 
    57         protected UsedResourcesList usedResources; 
    58         //TO DO consider removing 
    59         protected List<String> visitedResources; 
    6054 
    6155        protected double submissionTime; 
    6256    protected double arrivalTime; 
    63         protected double execStartTime ; 
     57        protected double execStartTime; 
    6458    protected double totalCompletionTime;  
    6559        protected double finishTime;  
    6660         
    67         private ResourceConsumptionProfile resourceConsumptionProfile; 
     61    private boolean firstTime = true; 
     62        protected double execStartTimeFirst; 
     63         
     64        protected ExecutionProfile execProfile; 
     65         
     66        protected LinkedList<ExecutionHistoryItem> execHistory;; 
     67        protected LinkedList<ResourceHistoryItem> allocatedResources; 
    6868         
    6969        public Executable(Task t){ 
    7070                this.task = t; 
    7171                this.status = DCWormsTags.CREATED; 
    72                  
    73                 this.usedResources = new UsedResourcesList(); 
    74                 this.visitedResources = new ArrayList<String>(); 
     72 
     73                this.allocatedResources = new LinkedList<ResourceHistoryItem>(); 
     74                this.execHistory = new LinkedList<ExecutionHistoryItem>(); 
    7575                init(); 
    7676        } 
     
    8181                this.processesSetId = procesesSet.getId();  
    8282                 
    83                 this.usedResources = new UsedResourcesList(); 
    84                 this.visitedResources = new ArrayList<String>(); 
     83                this.allocatedResources = new LinkedList<ResourceHistoryItem>(); 
     84                this.execHistory = new LinkedList<ExecutionHistoryItem>(); 
    8585                init(); 
    8686        } 
     
    8888        protected void init() { 
    8989                double currentTime = DateTimeUtilsExt.currentTimeMillis() / 1000; 
     90                this.arrivalTime = currentTime; 
    9091                this.submissionTime =  currentTime; 
    9192        this.totalCompletionTime = 0.0; 
     
    168169        } 
    169170 
    170         if (newStatus < DCWormsTags.CREATED || newStatus > DCWormsTags.NEW_EXEC_PHASE) { 
     171        if (newStatus < DCWormsTags.CREATED || newStatus > DCWormsTags.FAILED) { 
    171172            throw new Exception("Executable.setStatuts() : Error - " + 
    172                     "Invalid integer range for Execiutable status."); 
     173                    "Invalid integer range for Executable status."); 
    173174        } 
    174175 
     
    189190        } 
    190191                 
    191                 if(newStatus == DCWormsTags.SUBMITTED){ 
     192                /*if(newStatus == DCWormsTags.SUBMITTED){ 
    192193                         arrivalTime = GridSim.clock(); 
    193                 } 
    194  
    195         if (prevStatus == DCWormsTags.INEXEC) { 
    196             if (status == DCWormsTags.CANCELED || status == DCWormsTags.PAUSED || 
    197                 status == DCWormsTags.SUCCESS) { 
     194                }*/ 
     195 
     196        if ((prevStatus == DCWormsTags.INEXEC) && (status == DCWormsTags.CANCELED || status == DCWormsTags.PAUSED || 
     197                status == DCWormsTags.SUCCESS)){ 
    198198                totalCompletionTime += (currentTime -  execStartTime); 
     199                execStartTime = execStartTimeFirst; 
     200        } 
     201 
     202        /*if (prevStatus == DCWormsTags.RESUMED && status == DCWormsTags.SUCCESS) { 
     203            totalCompletionTime += (currentTime -  execStartTime); 
     204        }*/ 
     205 
     206        if(prevStatus == DCWormsTags.PAUSED && status == DCWormsTags.RESUMED){ 
     207                 
     208        } 
     209        if (status == DCWormsTags.INEXEC) { 
     210                 
     211                execStartTime = currentTime; 
     212            if (firstTime){ 
     213                execStartTimeFirst = currentTime; 
     214                firstTime = false; 
    199215            } 
    200216        } 
    201  
    202         if (prevStatus == DCWormsTags.RESUMED && status == DCWormsTags.SUCCESS) { 
    203             totalCompletionTime += (currentTime -  execStartTime); 
    204         } 
    205  
    206         if (status == DCWormsTags.INEXEC || 
    207             (prevStatus == DCWormsTags.PAUSED && status == DCWormsTags.RESUMED) ) { 
    208                 execStartTime = currentTime; 
    209                  
    210                 ProcessingElements pes = (ProcessingElements) getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
    211                 for (ComputingResource resource : pes) { 
    212  
    213                                 LinkedList<ComputingResource> toExamine = new LinkedList<ComputingResource>(); 
    214                                 toExamine.push(resource); 
    215  
    216                                 while (!toExamine.isEmpty()) { 
    217                                         ComputingResource compResource = toExamine.pop(); 
    218                                         List<ComputingResource> resources = compResource.getChildren(); 
    219                                         int numberOfRes = resources.size(); 
    220                                         for (int i = 0; i < numberOfRes; i++) { 
    221                                                 ComputingResource resourceChild = resources.get(i); 
    222                                                 trackResource(resourceChild.getFullName()); 
    223                                                 toExamine.addLast(resourceChild); 
    224                                         } 
    225                                 } 
    226  
    227                          
    228                         trackResource(resource.getFullName()); 
    229                          
    230                         ComputingResource parent = resource.getParent(); 
    231                                 List<String> visitedResource = getVisitedResources(); 
    232                                 String [] visitedResourcesArray = visitedResource.toArray(new String[visitedResource.size()]); 
    233                         while (parent != null && !ArrayUtils.contains(visitedResourcesArray, parent.getFullName())) { 
    234                                 trackResource(parent.getFullName()); 
    235                                 parent = parent.getParent(); 
    236                         } 
    237                 } 
    238         } 
    239217         
    240         if(status == DCWormsTags.NEW_EXEC_PHASE){ 
    241                 if(prevStatus == DCWormsTags.INEXEC){ 
    242                         status = DCWormsTags.INEXEC; 
    243                         setCompletionPercentage(0); 
    244                         resourceConsumptionProfile.setCurrentPhase(resourceConsumptionProfile.getCurrentPhase() + 1); 
    245                          
    246                         DateTime currentDateTime = new DateTime(); 
    247                          
    248                         if(getUsedResources().getLast().getTimeStamp().getMillis() == currentDateTime.getMillis()){ 
    249                                 return; 
    250                         } 
    251                         ResourceHistoryItem resHistItem = new ResourceHistoryItem(getUsedResources().getLast().getResourceUnits(), currentDateTime); 
    252                         resHistItem.setCompletionPercentage(0); 
    253                         addUsedResources(resHistItem); 
    254                 } 
    255         } 
     218        if(status == DCWormsTags.NEW_EXEC_PHASE && prevStatus == DCWormsTags.INEXEC){ 
     219                status = DCWormsTags.INEXEC; 
     220                completionPercentage = 0; 
     221                execProfile.setCurrentPhase(execProfile.getCurrentPhase() + 1); 
     222        } 
     223 
    256224        } 
    257225         
     
    295263        } 
    296264 
    297         public void addUsedResources(ResourceHistoryItem usedResources){ 
    298                 this.usedResources.add(usedResources); 
    299         } 
    300          
    301         public UsedResourcesList getUsedResources(){ 
    302                 return this.usedResources; 
    303         } 
    304          
    305265    public void setSchedulerName(int resourceId){ 
    306266        this.schedName = GridSim.getEntityName(resourceId); 
    307267    } 
     268     
     269    public void setSchedulerName(String resourceId){ 
     270        this.schedName = resourceId; 
     271    } 
    308272 
    309273    public String getSchedulerName(){ 
     
    326290                task.register(jobRegistry); 
    327291        } 
    328          
    329         public void trackResource(String resName){ 
    330                 visitedResources.add(resName); 
    331         } 
    332          
    333         public List<String> getVisitedResources(){ 
    334                 return visitedResources; 
    335         } 
    336          
     292 
    337293        public ReadableDuration getExpectedDuration() throws NoSuchFieldException { 
    338294                return task.getExpectedDuration(); 
     
    410366        }*/ 
    411367         
    412         public ResourceConsumptionProfile getResourceConsumptionProfile(){ 
    413                 return resourceConsumptionProfile; 
     368        public ExecutionProfile getResourceConsumptionProfile(){ 
     369                return execProfile; 
    414370        } 
    415371 
    416372        public ResourceConsumption getCurrentResourceConsumption(){ 
    417                 return resourceConsumptionProfile.getCurrentResourceConsumption(); 
     373                return execProfile.getCurrentResourceConsumption(); 
    418374        } 
    419375         
     
    437393                        } 
    438394                        resourceConsumptionList.add(resConsumption); 
    439                 }else{ 
     395                } else { 
    440396                        boolean found = false; 
    441397                        if(resourceType != null){ 
     
    473429                 
    474430                usefulWork = (usefulWork != -1) ? usefulWork : this.getLength(); 
    475                 this.resourceConsumptionProfile = new ResourceConsumptionProfile(resourceConsumptionList); 
    476                 this.resourceConsumptionProfile.setUsefulWork(usefulWork); 
     431                this.execProfile = new ExecutionProfile(resourceConsumptionList); 
     432                this.execProfile.setUsefulWork(usefulWork); 
    477433 
    478434        } 
     
    480436        private boolean loadResourceConsumptionProfile(){ 
    481437 
    482                 PEUnit peUnit = (PEUnit)getUsedResources().getLast().getResourceUnits() 
     438                PEUnit peUnit = (PEUnit)getAllocatedResources().getLast().getResourceUnits() 
    483439                                .get(StandardResourceUnitName.PE); 
    484440                if(peUnit instanceof ProcessingElements){ 
     
    513469                 
    514470        } 
     471 
     472        public LinkedList<ExecutionHistoryItem> getExecHistory() { 
     473                return execHistory; 
     474        } 
     475 
     476        public void addExecHistory(ExecutionHistoryItem execHistoryItem) { 
     477                this.execHistory.add(execHistoryItem); 
     478        } 
     479 
     480        public LinkedList<ResourceHistoryItem> getAllocatedResources() { 
     481                return allocatedResources; 
     482        } 
     483 
     484        public void addAllocatedResources(ResourceHistoryItem allocatedResourcesItem) { 
     485                this.allocatedResources.add(allocatedResourcesItem); 
     486        } 
    515487} 
  • DCWoRMS/branches/coolemall/src/gridsim/dcworms/DCWormsTags.java

    r1316 r1362  
    3737         
    3838        public static final int POWER_LIMIT_EXCEEDED = DCWORMSBASE + 8; 
     39         
     40        public static final int TASK_PAUSE = DCWORMSBASE + 9; 
     41         
     42        public static final int TASK_RESUME = DCWORMSBASE + 10; 
     43         
     44        public static final int TASK_MOVE = DCWORMSBASE + 11; 
    3945 
    4046         
     
    4854 
    4955    public static final int INEXEC = 4; 
     56     
     57    public static final int NEW_EXEC_PHASE = 5; 
     58     
     59    public static final int PAUSED = 6; 
    5060 
    51     public static final int SUCCESS = 5; 
     61    public static final int RESUMED = 7; 
     62     
     63    public static final int SUCCESS = 8; 
    5264 
    53     public static final int FAILED = 6; 
     65    public static final int CANCELED = 9; 
    5466 
    55     public static final int CANCELED = 7; 
    56  
    57     public static final int PAUSED = 8; 
    58  
    59     public static final int RESUMED = 9; 
    60  
    61     public static final int NEW_EXEC_PHASE = 10; 
    62  
     67    public static final int FAILED = 10; 
    6368} 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/ResourceHistoryItem.java

    r1317 r1362  
    11package schedframe.scheduling; 
    22 
     3import java.util.HashSet; 
    34import java.util.Map; 
    4  
    5 import org.joda.time.DateTime; 
     5import java.util.Set; 
    66 
    77import schedframe.resources.units.ResourceUnit; 
    88import schedframe.resources.units.ResourceUnitName; 
    99 
    10 //TODO - change name 
    1110public class ResourceHistoryItem { 
    1211 
    1312        protected Map<ResourceUnitName, ResourceUnit> usedResources; 
    14         protected DateTime timeStamp; 
    15         protected double completionPercentage; 
    16          
    17         /** 
    18          *  
    19          * @param map hash map of resource units, which should be remembered 
    20          * @param time the moment in time when this resource configuration was created   
    21          */ 
    22         public ResourceHistoryItem(Map<ResourceUnitName, ResourceUnit> map, DateTime time){ 
    23                 this.usedResources = map; 
    24                 this.timeStamp = time; 
     13        protected Set<String> visitedResources; 
     14 
     15        public ResourceHistoryItem(Map<ResourceUnitName, ResourceUnit> usedResources){ 
     16                this.usedResources = usedResources; 
     17                this.visitedResources = new HashSet<String>(); 
    2518        } 
    2619         
     
    2922        } 
    3023         
    31         public DateTime getTimeStamp(){ 
    32                 return timeStamp; 
     24        public void trackResource(String resName){ 
     25                visitedResources.add(resName); 
    3326        } 
    34  
    35         public double getCompletionPercentage() { 
    36                 return completionPercentage; 
    37         } 
    38  
    39         public void setCompletionPercentage(double completionPercentage) { 
    40                 this.completionPercentage = completionPercentage; 
     27         
     28        public Set<String> getVisitedResources(){ 
     29                return visitedResources; 
    4130        } 
    4231         
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/Scheduler.java

    r970 r1362  
    136136                                break; 
    137137                        } 
    138                          
    139138                        // process the received event 
    140139                        processRequest(ev); 
     
    147146 
    148147                case GridSimTags.GRIDLET_SUBMIT: 
    149                         processWorkloadUnitSubmit(ev, false); 
    150                         break; 
    151  
    152                 case GridSimTags.GRIDLET_SUBMIT_ACK: 
    153                         processWorkloadUnitSubmit(ev, true); 
    154                         break; 
     148                        processWorkloadUnitSubmit(ev); 
     149                        break; 
     150 
    155151 
    156152                case GridSimTags.GRIDLET_RETURN: 
     
    187183        } 
    188184 
    189         protected void processWorkloadUnitSubmit(Sim_event ev, boolean ack) { 
     185        protected void processWorkloadUnitSubmit(Sim_event ev) { 
    190186                WorkloadUnit job = (WorkloadUnit) ev.get_data(); 
    191                 managementSystem.notifySubmittedWorkloadUnit(job, ack); 
     187                managementSystem.notifySubmittedWorkloadUnit(job); 
    192188        } 
    193189         
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/manager/tasks/AbstractJobRegistry.java

    r1151 r1362  
    22 
    33 
     4import gridsim.dcworms.DCWormsTags; 
     5 
    46import java.util.ArrayList; 
    57import java.util.List; 
     8import java.util.Map; 
    69import java.util.concurrent.ConcurrentHashMap; 
    710 
     11import schedframe.resources.units.ResourceUnit; 
     12import schedframe.resources.units.ResourceUnitName; 
    813import schedframe.scheduling.tasks.Job; 
    914import schedframe.scheduling.tasks.JobInterface; 
    1015import schedframe.scheduling.tasks.Task; 
    1116import schedframe.scheduling.tasks.TaskInterface; 
     17import simulator.DataCenterWorkloadSimulator; 
     18import dcworms.schedframe.scheduling.ExecTask; 
    1219 
    1320 
    1421public abstract class AbstractJobRegistry /*extends ConcurrentHashMap<String, Job>*/ implements JobRegistry, Cloneable{ 
    1522         
    16         private static final long serialVersionUID = 8409060063583755824L; 
    17  
    1823         
    1924        protected static final ConcurrentHashMap<String, JobInterface<?>> jobs = new ConcurrentHashMap<String, JobInterface<?>>(); 
     
    7984        } 
    8085 
     86        @Override 
     87        public boolean pauseTask(String jobId, String taskId) { 
     88                ExecTask execTask = getTask(jobId, taskId); 
     89                if (execTask == null) { 
     90                        return false; 
     91                }else{ 
     92                        String[] ids = new String[2]; 
     93                        ids[0] = new String(jobId); 
     94                        ids[1] = new String(taskId); 
     95                        DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.TASK_PAUSE, ids); 
     96                        return true; 
     97                } 
     98        } 
     99 
     100        public boolean resumeTask(String jobId, String taskId) { 
     101                ExecTask execTask = getTask(jobId, taskId); 
     102                if (execTask == null) { 
     103                        return false; 
     104                }else{ 
     105                        String[] ids = new String[2]; 
     106                        ids[0] = new String(jobId); 
     107                        ids[1] = new String(taskId); 
     108                        DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.TASK_RESUME, ids); 
     109                        return true;     
     110                } 
     111        } 
     112 
     113        public boolean migrateTask(String jobId, String taskId, Map<ResourceUnitName, ResourceUnit> choosenResources) { 
     114                ExecTask execTask = getTask(jobId, taskId); 
     115                if (execTask == null) { 
     116                        return false; 
     117                }else{ 
     118                        Object[] data = new Object[3]; 
     119                        data[0] = new String(jobId); 
     120                        data[1] = new String(taskId); 
     121                        data[2] = choosenResources; 
     122                        DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.TASK_MOVE, data); 
     123                        return true;     
     124                } 
     125        } 
     126 
     127        public boolean migrateTask(String jobId, String taskId, String nodeName) { 
     128                // TODO Auto-generated method stub 
     129                return false; 
     130        } 
     131         
    81132} 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/manager/tasks/JobRegistry.java

    r1151 r1362  
    33 
    44import java.util.List; 
     5import java.util.Map; 
    56 
    67import dcworms.schedframe.scheduling.ExecTask; 
    78 
    89import schedframe.ExecutablesList; 
     10import schedframe.resources.units.ResourceUnit; 
     11import schedframe.resources.units.ResourceUnitName; 
    912import schedframe.scheduling.tasks.JobInterface; 
    1013import schedframe.scheduling.tasks.TaskInterface; 
     
    2730 
    2831         
    29         public List<ExecTask> getTasks(int status) ; 
     32        public List<ExecTask> getTasks(int status); 
    3033 
    31         public List<ExecTask> getQueuedTasks() ; 
     34        public List<ExecTask> getQueuedTasks(); 
    3235         
    33         public List<ExecTask> getRunningTasks() ; 
     36        public List<ExecTask> getRunningTasks(); 
    3437         
    35         public List<ExecTask> getReadyTasks() ; 
     38        public List<ExecTask> getReadyTasks(); 
    3639         
    3740        public List<ExecTask> getFinishedTasks(); 
     
    3942         
    4043        public List<? extends TaskInterface<?>> getAvailableTasks(List<JobInterface<?>> jobsList); 
     44         
     45         
     46        public boolean pauseTask(String jobId, String taskId); 
     47         
     48        public boolean resumeTask(String jobId, String taskId); 
     49         
     50        public boolean migrateTask(String jobId, String taskId, Map<ResourceUnitName, ResourceUnit> choosenResources); 
     51         
     52        public boolean migrateTask(String jobId, String taskId, String nodeName); 
     53         
    4154 
    4255} 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/manager/tasks/JobRegistryImpl.java

    r1151 r1362  
    55import java.util.ArrayList; 
    66import java.util.List; 
    7  
    8 import org.apache.commons.lang.ArrayUtils; 
     7import java.util.Set; 
     8 
    99import org.apache.commons.logging.Log; 
    1010import org.apache.commons.logging.LogFactory; 
     
    2121 
    2222public class JobRegistryImpl extends AbstractJobRegistry { 
    23          
    24         private static final long serialVersionUID = 8030555906990767342L; 
    2523 
    2624        private static Log log = LogFactory.getLog(JobRegistryImpl.class); 
     
    5553                        for (ExecTask task: executables) { 
    5654                                if (task.getStatus() == status) { 
    57                                         List<String> visitedResource = task.getVisitedResources(); 
    58                                         if(ArrayUtils.contains(visitedResource.toArray(new String[visitedResource.size()]), context)) { 
     55                                        Set<String> visitedResource = task.getAllocatedResources().getLast().getVisitedResources(); 
     56                                        for(String res: visitedResource){ 
     57                                                if(res.contains(context)){ 
     58                                                        taskList.add(task); 
     59                                                        break; 
     60                                                } 
     61                                        } 
     62                                        if(task.getSchedulerName().contains(context)) { 
    5963                                                taskList.add(task); 
    6064                                        } 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/AbstractManagementSystem.java

    r579 r1362  
    212212        public abstract WorkloadUnitHandler getWorkloadUnitHandler(); 
    213213         
    214         public abstract void notifySubmittedWorkloadUnit(WorkloadUnit wu, boolean ack); 
     214        public abstract void notifySubmittedWorkloadUnit(WorkloadUnit wu); 
    215215 
    216216        public abstract void notifyReturnedWorkloadUnit(WorkloadUnit wu); 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/global/GlobalManagementSystem.java

    r1357 r1362  
    7171        } 
    7272         
    73         public void notifySubmittedWorkloadUnit(WorkloadUnit wu, boolean ack) { 
     73        public void notifySubmittedWorkloadUnit(WorkloadUnit wu) { 
    7474                if (!pluginSupportsEvent(GridSimTags.GRIDLET_SUBMIT)) { 
    7575                        log.error("Plugin " + schedulingPlugin.getClass() 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java

    r1357 r1362  
    11package schedframe.scheduling.policy.local; 
    2  
    3 import dcworms.schedframe.scheduling.ExecTask; 
    4 import dcworms.schedframe.scheduling.Executable; 
    5 import eduni.simjava.Sim_event; 
    6 import eduni.simjava.Sim_system; 
    7 import gridsim.dcworms.DCWormsTags; 
    8 import gridsim.dcworms.filter.ExecTaskFilter; 
    92 
    103import java.util.ArrayList; 
    114import java.util.HashMap; 
    125import java.util.Iterator; 
     6import java.util.LinkedList; 
    137import java.util.List; 
    148import java.util.Map; 
    15  
    16 import org.apache.commons.lang.ArrayUtils; 
     9import java.util.Set; 
     10 
    1711import org.apache.commons.logging.Log; 
    1812import org.apache.commons.logging.LogFactory; 
     
    3832import schedframe.resources.units.ResourceUnitName; 
    3933import schedframe.resources.units.StandardResourceUnitName; 
     34import schedframe.scheduling.ExecutionHistoryItem; 
    4035import schedframe.scheduling.ResourceHistoryItem; 
    4136import schedframe.scheduling.Scheduler; 
    4237import schedframe.scheduling.TaskList; 
    4338import schedframe.scheduling.TaskListImpl; 
    44 import schedframe.scheduling.UsedResourcesList; 
    4539import schedframe.scheduling.WorkloadUnitHandler; 
    4640import schedframe.scheduling.manager.resources.LocalResourceManager; 
     
    6458import simulator.stats.GSSAccumulator; 
    6559import simulator.utils.DoubleMath; 
     60import dcworms.schedframe.scheduling.ExecTask; 
     61import dcworms.schedframe.scheduling.Executable; 
     62import eduni.simjava.Sim_event; 
     63import eduni.simjava.Sim_system; 
     64import gridsim.dcworms.DCWormsTags; 
     65import gridsim.dcworms.filter.ExecTaskFilter; 
    6666 
    6767public class LocalManagementSystem extends AbstractManagementSystem { 
     
    127127                                finalizeExecutable(execTask); 
    128128                                sendFinishedWorkloadUnit(execTask); 
    129                                 log.debug(execTask.getJobId() + "_" + execTask.getId() + " finished execution on " + new DateTime()); 
    130                                 log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad()); 
    131129                                if (pluginSupportsEvent(tag)) { 
    132130                                        SchedulingEvent event = new TaskFinishedEvent(execTask.getJobId(), execTask.getId()); 
     
    164162                        break; 
    165163                         
     164                case DCWormsTags.TASK_PAUSE:{ 
     165                        String[] ids = (String[]) ev.get_data(); 
     166                        execTask = jobRegistry.getTask(ids[0], ids[1]); 
     167                        taskPause(execTask); 
     168                        if (pluginSupportsEvent(tag)) { 
     169                                SchedulingEvent event = new SchedulingEvent(SchedulingEventType.TASK_PAUSED); 
     170                                SchedulingPlanInterface<?> decision = schedulingPlugin.schedule(event, 
     171                                                queues, getJobRegistry(), getResourceManager(), moduleList); 
     172                                executeSchedulingPlan(decision); 
     173                        } 
     174                } 
     175                break; 
     176                 
     177                case DCWormsTags.TASK_RESUME:{ 
     178                        String[] ids = (String[]) ev.get_data(); 
     179                        execTask = jobRegistry.getTask(ids[0], ids[1]); 
     180                        taskResume(execTask, execTask.getAllocatedResources().getLast().getResourceUnits()); 
     181                        if (pluginSupportsEvent(tag)) { 
     182                                SchedulingEvent event = new StartTaskExecutionEvent(ids[0], ids[1]); 
     183                                SchedulingPlanInterface<?> decision = schedulingPlugin.schedule(event, 
     184                                                queues, getJobRegistry(), getResourceManager(), moduleList); 
     185                                executeSchedulingPlan(decision); 
     186                        } 
     187                } 
     188                break; 
     189                         
     190                case DCWormsTags.TASK_MOVE:{ 
     191                        Object[] data = (Object[]) ev.get_data(); 
     192                        execTask = jobRegistry.getTask((String)data[0], (String)data[1]); 
     193                        taskMove(execTask, (Map<ResourceUnitName, ResourceUnit>)data[2]); 
     194                        if (pluginSupportsEvent(tag)) { 
     195                                SchedulingEvent event = new StartTaskExecutionEvent((String)data[0], (String)data[1]); 
     196                                SchedulingPlanInterface<?> decision = schedulingPlugin.schedule(event, 
     197                                                queues, getJobRegistry(), getResourceManager(), moduleList); 
     198                                executeSchedulingPlan(decision); 
     199                        } 
     200                } 
     201                break; 
    166202                         
    167203                case DCWormsTags.TASK_EXECUTION_CHANGED: 
    168204                        execTask = (ExecTask) ev.get_data(); 
    169                         updateTaskExecution(execTask, SchedulingEventType.RESOURCE_STATE_CHANGED); 
     205                        updateTaskExecutionPhase(execTask, SchedulingEventType.RESOURCE_STATE_CHANGED); 
    170206                        break; 
    171                          
     207 
    172208                case DCWormsTags.UPDATE_PROCESSING: 
    173                         updateProcessingTimes(ev); 
     209                        updateProcessingTimes(); 
    174210                        break; 
    175211                         
     
    177213                        if (pluginSupportsEvent(tag)) { 
    178214                                SchedulingEvent event = new SchedulingEvent(SchedulingEventType.POWER_LIMIT_EXCEEDED); 
    179                                 schedulingPlugin.schedule(event, 
     215                                SchedulingPlanInterface<?> decision = schedulingPlugin.schedule(event, 
    180216                                                queues,  getJobRegistry(), getResourceManager(), moduleList); 
     217                                executeSchedulingPlan(decision); 
    181218                        } 
    182219                        break; 
     
    184221        } 
    185222 
     223 
     224        public void taskPause(ExecTask execTask) { 
     225                if (execTask == null) { 
     226                        return; 
     227                } else { 
     228                        try { 
     229                                execTask.setStatus(DCWormsTags.PAUSED); 
     230                                 
     231                                Executable exec = (Executable) execTask; 
     232                                Map<ResourceUnitName, ResourceUnit> lastUsed = exec.getAllocatedResources().getLast().getResourceUnits(); 
     233                                getAllocationManager().freeResources(lastUsed); 
     234                                 
     235                                saveExecutionHistory(exec, exec.getCompletionPercentage(), exec.getEstimatedDuration()); 
     236                                 
     237                                ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), -1); 
     238                                scheduler.sim_cancel(filter, null); 
     239                                 
     240                                PEUnit peUnit = (PEUnit)lastUsed.get(StandardResourceUnitName.PE); 
     241                                updateComputingResources(peUnit, EnergyEventType.TASK_FINISHED, exec); 
     242                        } catch (Exception e) { 
     243                                // TODO Auto-generated catch block 
     244                                e.printStackTrace(); 
     245                        } 
     246                }                
     247        } 
     248         
     249        public void taskResume(ExecTask execTask, Map<ResourceUnitName, ResourceUnit> resources) { 
     250                if (execTask == null) { 
     251                        return; 
     252                } else if (execTask.getStatus() == DCWormsTags.PAUSED) { 
     253                        try { 
     254                                execTask.setStatus(DCWormsTags.RESUMED); 
     255                                Executable exec = (Executable) execTask; 
     256 
     257                                boolean status = allocateResources(exec, resources); 
     258                                if(status == false){ 
     259                                        TaskList newTasks = new TaskListImpl(); 
     260                                        newTasks.add(exec); 
     261                                        schedulingPlugin.placeTasksInQueues(newTasks, queues, getResourceManager(), moduleList); 
     262                                        exec.setStatus(DCWormsTags.READY); 
     263                                } else { 
     264                                        runTask(execTask); 
     265                                         
     266                                        PEUnit peUnit = (PEUnit)resources.get(StandardResourceUnitName.PE); 
     267                                        updateComputingResources(peUnit, EnergyEventType.TASK_STARTED, exec); 
     268                                } 
     269 
     270                        } catch (Exception e) { 
     271                                // TODO Auto-generated catch block 
     272                                e.printStackTrace(); 
     273                        } 
     274                }                        
     275        } 
     276         
     277        public void taskMove(ExecTask execTask, Map<ResourceUnitName, ResourceUnit> map) { 
     278                taskPause(execTask); 
     279                taskResume(execTask, map); 
     280        } 
     281         
    186282        public void notifyReturnedWorkloadUnit(WorkloadUnit wu) { 
    187283                if (pluginSupportsEvent(DCWormsTags.TASK_EXECUTION_FINISHED)) { 
     
    229325 
    230326                Executable exec = (Executable)task; 
    231                 boolean allocationStatus = getAllocationManager().allocateResources(choosenResources); 
     327                boolean allocationStatus = allocateResources(exec, choosenResources); 
    232328                if(allocationStatus == false){ 
    233329                        log.info("Task " + task.getJobId() + "_" + task.getId() + " requires more resources than is available at this moment."); 
     
    239335                log.debug(task.getJobId() + "_" + task.getId() + " starts executing on " + new DateTime()); 
    240336 
    241                 //if (phaseDuration < 0.0) 
    242                 //      return; 
    243  
    244                 //exec.setEstimatedDuration(exec.getEstimatedDuration() + phaseDuration); 
    245                 DateTime currentTime = new DateTime(); 
    246                 ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime); 
    247                 resHistItem.setCompletionPercentage(0); 
    248                 exec.addUsedResources(resHistItem); 
    249                  
    250                 try { 
    251                         exec.setStatus(DCWormsTags.INEXEC); 
    252                 } catch (Exception e) { 
    253                         // TODO Auto-generated catch block 
    254                         e.printStackTrace(); 
    255                 } 
     337                runTask(exec); 
    256338                 
    257339                PEUnit peUnit = (PEUnit)choosenResources.get(StandardResourceUnitName.PE); 
    258340                updateComputingResources(peUnit, EnergyEventType.TASK_STARTED, exec); 
    259341                 
    260                 updateTaskExecution(exec, SchedulingEventType.START_TASK_EXECUTION); 
    261                 //scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, exec); 
    262342 
    263343                try { 
     
    269349                } 
    270350 
    271                 log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad()); 
    272                  
    273         } 
    274          
     351                log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad());             
     352        } 
     353         
     354        private void runTask(ExecTask execTask){ 
     355                Executable exec = (Executable) execTask; 
     356                Map<ResourceUnitName, ResourceUnit> resources = exec.getAllocatedResources().getLast().getResourceUnits(); 
     357                 
     358                try { 
     359                        exec.setStatus(DCWormsTags.INEXEC); 
     360                } catch (Exception e) { 
     361                        // TODO Auto-generated catch block 
     362                        e.printStackTrace(); 
     363                } 
     364 
     365                int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.START_TASK_EXECUTION),  
     366                                execTask, resources, exec.getCompletionPercentage())).intValue(); 
     367 
     368                saveExecutionHistory(exec, exec.getCompletionPercentage(), phaseDuration); 
     369                if(exec.getResourceConsumptionProfile().isLast()){ 
     370                        scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_FINISHED, execTask);; 
     371                } else { 
     372                        scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask); 
     373                } 
     374                 
     375                PEUnit peUnit = (PEUnit)resources.get(StandardResourceUnitName.PE); 
     376                updateComputingResources(peUnit, EnergyEventType.TASK_STARTED, exec); 
     377                 
     378        } 
    275379        protected void finalizeExecutable(ExecTask execTask){ 
    276380                 
     
    304408                        } 
    305409                } 
    306                  
    307                 UsedResourcesList lastUsedList = exec.getUsedResources(); 
    308                 Map<ResourceUnitName, ResourceUnit> lastUsed = lastUsedList.getLast() 
    309                                 .getResourceUnits(); 
     410 
     411                Map<ResourceUnitName, ResourceUnit> lastUsed = exec.getAllocatedResources().getLast().getResourceUnits(); 
    310412                getAllocationManager().freeResources(lastUsed); 
     413                 
     414                saveExecutionHistory(exec, 100,0); 
    311415                 
    312416                PEUnit peUnit = (PEUnit)lastUsed.get(StandardResourceUnitName.PE); 
    313417                updateComputingResources(peUnit, EnergyEventType.TASK_FINISHED, exec); 
     418                 
     419                log.debug(execTask.getJobId() + "_" + execTask.getId() + " finished execution on " + new DateTime()); 
     420                log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad()); 
    314421        } 
    315422         
     
    326433                        ExecTask task = iter.next(); 
    327434                        Executable exec = (Executable)task; 
    328  
    329                         if(exec.getUsedResources().size() > 1){ 
    330                                 //System.out.println("--- upadteProgressX: " + Sim_system.sim_clock() ); 
    331                                 //System.out.println("taskId: " + exec.getId() + "; completion percentage: " + exec.getCompletionPercentage() + "; timespan: " + timeSpan + "; estimatedDuration: " +  exec.getEstimatedDuration()); 
    332                                 exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / (exec.getEstimatedDuration()) * (1.0 - exec.getUsedResources().get(exec.getUsedResources().size()-1).getCompletionPercentage()/100.0))); 
    333                                 //System.out.println("newProgress: " + exec.getCompletionPercentage()  );        
    334                         }  
    335                         else { 
    336                                 //System.out.println("--- upadteProgress2: " + Sim_system.sim_clock() ); 
    337                                 //System.out.println("taskId: " + exec.getId() + "; completion percentage: " + exec.getCompletionPercentage() + "; timespan: " + timeSpan + "; estimatedDuration: " +  exec.getEstimatedDuration()); 
    338                                 exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / exec.getEstimatedDuration())); 
    339                                 //System.out.println("newProgress: " + exec.getCompletionPercentage()  );        
    340                         } 
     435                        ExecutionHistoryItem execHistItem = exec.getExecHistory().getLast(); 
     436                        //System.out.println("--- upadteProgressX: " + Sim_system.sim_clock() ); 
     437                        //System.out.println("taskId: " + exec.getId() + "; completion percentage: " + exec.getCompletionPercentage() + "; timespan: " + timeSpan + "; estimatedDuration: " +  execHistItem.getCompletionPercentage()); 
     438                        exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / (execHistItem.getEstimatedDuration()) * (1.0 - execHistItem.getCompletionPercentage()/100.0))); 
     439                        //System.out.println("newProgress: " + exec.getCompletionPercentage()  );        
     440 
    341441                } 
    342442        } 
     
    368468        } 
    369469 
    370         protected void updateProcessingTimes(Sim_event ev) { 
     470        protected void updateProcessingTimes() { 
    371471                for (ExecTask execTask : jobRegistry.getRunningTasks()) { 
    372472                        Executable exec = (Executable)execTask; 
    373473 
    374                         Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits(); 
    375                         double lastTimeStamp = exec.getUsedResources().getLast().getTimeStamp().getMillis()/1000; 
     474 
     475                        Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getAllocatedResources().getLast().getResourceUnits(); 
     476 
    376477                        int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.RESOURCE_STATE_CHANGED),  
    377478                                        execTask, choosenResources, exec.getCompletionPercentage())).intValue(); 
    378479 
    379                         if(DoubleMath.subtract((lastTimeStamp + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration)) == 0.0){ 
     480                        ExecutionHistoryItem execHistItem = exec.getExecHistory().getLast(); 
     481                        double lastTimeStamp = execHistItem.getTimeStamp().getMillis()/1000; 
     482                        if(DoubleMath.subtract((lastTimeStamp + execHistItem.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration)) == 0.0){ 
    380483                                continue; 
    381484                        } 
    382485                        //System.out.println("=== upadteTIme: " + Sim_system.sim_clock() ); 
    383                         //System.out.println("execId: " + exec.getId() +  "; estimatedDuration " + exec.getEstimatedDuration()); 
    384                         //System.out.println("execId: " + exec.getId() + "; difference " + DoubleMath.subtract((lastTimeStamp + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration))); 
     486                        //System.out.println("execId: " + exec.getId() +  "; estimatedDuration " + execHistItem.getEstimatedDuration()); 
     487                        //System.out.println("execId: " + exec.getId() + "; difference " + DoubleMath.subtract((lastTimeStamp + execHistItem.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration))); 
    385488                        //System.out.println("completionPercantage: " + exec.getCompletionPercentage() + "; basic duration: " +exec.getResourceConsumptionProfile().getCurrentResourceConsumption().getDuration() +   "; phaseDuration: " +  phaseDuration); 
    386489 
    387                         exec.setEstimatedDuration(phaseDuration); 
    388                         DateTime currentTime = new DateTime(); 
    389                         ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime); 
    390                         resHistItem.setCompletionPercentage(exec.getCompletionPercentage()); 
    391                         exec.addUsedResources(resHistItem); 
    392                          
    393                         if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){ 
     490                        saveExecutionHistory(exec, exec.getCompletionPercentage(), phaseDuration); 
     491                         
     492                        if(exec.getResourceConsumptionProfile().isLast()){ 
    394493                                ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED); 
    395494                                scheduler.sim_cancel(filter, null); 
     
    407506        }        
    408507 
    409         protected void updateTaskExecution(ExecTask execTask, SchedulingEventType schedEvType) { 
     508        protected void updateTaskExecutionPhase(ExecTask execTask, SchedulingEventType schedEvType) { 
    410509 
    411510                if (execTask.getStatus() == DCWormsTags.INEXEC) { 
     
    415514                                exec.setStatus(DCWormsTags.NEW_EXEC_PHASE); 
    416515                        } catch (Exception e) { 
    417                         } 
    418                          
    419                         Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits(); 
     516                                 
     517                        } 
     518 
     519                        Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getAllocatedResources().getLast().getResourceUnits(); 
    420520 
    421521                        int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(schedEvType),  
    422522                                        execTask, choosenResources, exec.getCompletionPercentage())).intValue(); 
    423  
    424                         exec.setEstimatedDuration(phaseDuration); 
    425                          
    426                         if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){ 
     523                         
     524                        saveExecutionHistory(exec, exec.getCompletionPercentage(), phaseDuration); 
     525                         
     526                        if(exec.getResourceConsumptionProfile().isLast()){ 
    427527                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_FINISHED, execTask); 
    428                                 PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
    429                                 updateComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); 
    430528                        } else { 
    431529                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask); 
    432                                 PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
    433                                 updateComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); 
    434                         } 
     530                        } 
     531                         
     532                        PEUnit peUnit = (PEUnit)exec.getAllocatedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
     533                        updateComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); 
    435534                } 
    436535        }        
     
    501600        } 
    502601         
    503         public void notifySubmittedWorkloadUnit(WorkloadUnit wu, boolean ack) { 
     602        public void notifySubmittedWorkloadUnit(WorkloadUnit wu) { 
    504603                //250314 
    505604                //updateProcessingProgress(); 
     
    562661                        Executable exec = (Executable) task; 
    563662                        jobRegistry.addExecTask(exec); 
    564                          
    565                         exec.trackResource(scheduler.get_name()); 
    566                         Scheduler parentScheduler = scheduler.getParent(); 
    567                         List<String> visitedResource = exec.getVisitedResources(); 
    568                         String [] visitedResourcesArray = visitedResource.toArray(new String[visitedResource.size()]); 
    569                         while (parentScheduler != null && !ArrayUtils.contains(visitedResourcesArray, parentScheduler.get_name())) { 
    570                                 exec.trackResource(parentScheduler.get_name()); 
    571                                 parentScheduler = parentScheduler.getParent(); 
    572                         } 
    573                         exec.setSchedulerName(scheduler.get_id()); 
     663 
     664                        exec.setSchedulerName(scheduler.getFullName()); 
    574665                         
    575666                        TaskList newTasks = new TaskListImpl(); 
     
    596687        } 
    597688         
     689         
     690        public void saveExecutionHistory(Executable exec, double completionPercentage, double estimatedDuration){ 
     691 
     692                ExecutionHistoryItem execHistoryItem = new ExecutionHistoryItem(new DateTime()); 
     693                execHistoryItem.setCompletionPercentage(completionPercentage); 
     694                execHistoryItem.setEstimatedDuration(estimatedDuration); 
     695                execHistoryItem.setResIndex(exec.getAllocatedResources().size() -1); 
     696                execHistoryItem.setStatus(exec.getStatus()); 
     697                exec.addExecHistory(execHistoryItem); 
     698                 
     699                ProcessingElements pes = (ProcessingElements) exec.getAllocatedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
     700                for (ComputingResource resource : pes) { 
     701 
     702                        LinkedList<ComputingResource> toExamine = new LinkedList<ComputingResource>(); 
     703                        toExamine.push(resource); 
     704 
     705                        while (!toExamine.isEmpty()) { 
     706                                ComputingResource compResource = toExamine.pop(); 
     707                                List<ComputingResource> resources = compResource.getChildren(); 
     708                                if(resources.isEmpty()){ 
     709                                        Set<String> visitedResources = exec.getAllocatedResources().getLast().getVisitedResources(); 
     710                                        if(!visitedResources.contains(compResource.getFullName())){ 
     711                                                exec.getAllocatedResources().getLast().trackResource(compResource.getFullName()); 
     712                                        } 
     713                                } else { 
     714                                        for (int i = 0; i < resources.size(); i++) { 
     715                                                ComputingResource resourceChild = resources.get(i); 
     716                                                toExamine.addLast(resourceChild); 
     717                                        } 
     718                                } 
     719                        } 
     720                } 
     721        } 
     722         
     723        public boolean allocateResources(Executable exec, Map<ResourceUnitName, ResourceUnit> choosenResources){ 
     724                boolean allocationStatus = getAllocationManager().allocateResources(choosenResources); 
     725                if(allocationStatus){ 
     726                        ResourceHistoryItem resourceHistoryItem = new ResourceHistoryItem(choosenResources); 
     727                        exec.addAllocatedResources(resourceHistoryItem); 
     728                        return true; 
     729                } 
     730                return false; 
     731        } 
    598732} 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/Task.java

    r1207 r1362  
    11package schedframe.scheduling.tasks; 
     2 
     3import gridsim.dcworms.DCWormsTags; 
    24 
    35import java.io.StringReader; 
     
    439441        public boolean isFinished(){ 
    440442                if(processes == null) 
    441                         return (status > 3 && status <= 6); 
     443                        return (status >= DCWormsTags.SUCCESS && status <= DCWormsTags.FAILED); 
    442444                 
    443445                for(int i = 0; i < processes.size(); i++){ 
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/phases/ExecutionProfile.java

    r1207 r1362  
    33import java.util.LinkedList; 
    44 
    5 public class ResourceConsumptionProfile { 
     5public class ExecutionProfile { 
    66         
    77        protected LinkedList<ResourceConsumption> resourceConsumptionList; 
    88        protected long usefulWork; 
    99        private int currentPhase; 
    10          
    11         public ResourceConsumptionProfile() { 
    12                 this.resourceConsumptionList = new LinkedList<ResourceConsumption>(); 
    13                 this.currentPhase = -1; 
    14         } 
    15          
    16         public ResourceConsumptionProfile(LinkedList<ResourceConsumption> resourceConsumptionList) { 
     10 
     11        public ExecutionProfile(LinkedList<ResourceConsumption> resourceConsumptionList) { 
    1712                this.resourceConsumptionList = resourceConsumptionList; 
    18                 this.currentPhase = -1; 
     13                this.currentPhase = 0; 
    1914        } 
    2015         
     
    2419         
    2520        public ResourceConsumption getCurrentResourceConsumption(){ 
    26                 if(currentPhase < resourceConsumptionList.size()) 
    27                         return resourceConsumptionList.get(currentPhase); 
    28                 else  
    29                         return null; 
     21                return resourceConsumptionList.get(currentPhase); 
    3022        } 
    3123 
     
    4537                this.usefulWork = usefulWork; 
    4638        } 
     39         
     40        public boolean isLast(){ 
     41                if(currentPhase == resourceConsumptionList.size() - 1){ 
     42                        return true; 
     43                } 
     44                return false; 
     45        } 
    4746} 
  • DCWoRMS/branches/coolemall/src/simulator/stats/implementation/DCWormsStatistics.java

    r1357 r1362  
    1616import java.util.HashMap; 
    1717import java.util.HashSet; 
     18import java.util.LinkedList; 
    1819import java.util.List; 
    1920import java.util.Map; 
     
    7879import schedframe.resources.units.ResourceUnitName; 
    7980import schedframe.resources.units.StandardResourceUnitName; 
     81import schedframe.scheduling.ExecutionHistoryItem; 
    8082import schedframe.scheduling.ResourceHistoryItem; 
    8183import schedframe.scheduling.Scheduler; 
     
    104106import eduni.simjava.Sim_stat; 
    105107import example.energy.coolemall.CoolEmAllTestbedMeasurements; 
     108import gridsim.dcworms.DCWormsTags; 
    106109 
    107110public class DCWormsStatistics implements SimulationStatistics { 
     
    407410                } 
    408411                 
    409                 pesStats = gatherPEStats(jr.getTasks()); 
     412                pesStats = gatherPEStatsMulti(jr.getTasks()); 
    410413                peStatsPostProcessing(pesStats); 
    411414                basicResLoad = calculatePELoad(pesStats); 
     
    763766                        Executable exec = (Executable) execTask; 
    764767 
    765                         List<ResourceHistoryItem> resHistItemList = exec.getUsedResources(); 
    766                         if(resHistItemList.size() == 0) 
     768 
     769                        LinkedList<ResourceHistoryItem> resourceHistory = exec.getAllocatedResources(); 
     770                        if(resourceHistory.size() == 0) 
    767771                                continue; 
    768                         Map<ResourceUnitName, ResourceUnit> res = resHistItemList.get(resHistItemList.size() - 1).getResourceUnits(); 
     772                        Map<ResourceUnitName, ResourceUnit> res = exec.getAllocatedResources().getLast().getResourceUnits(); 
    769773                        ResourceUnit resUnit = res.get(StandardResourceUnitName.PE); 
    770774                        //ProcessingElements pes = (ProcessingElements) resUnit ; 
     
    820824                } 
    821825                return basicResStats; 
     826        } 
     827         
     828        private Map<String, List<ResStat>> gatherPEStatsMulti(ExecutablesList executables) { 
     829                 
     830                Map<String, List<ResStat>> basicResStats = new TreeMap<String, List<ResStat>>(new MapPEIdComparator()); 
     831                for (ExecTask execTask:executables) { 
     832                        Executable exec = (Executable) execTask; 
     833 
     834                        LinkedList<ResourceHistoryItem> resourceHistory = exec.getAllocatedResources(); 
     835                        if(resourceHistory.size() == 0) 
     836                                continue; 
     837 
     838                        for(int i = 0; i < resourceHistory .size(); i++){ 
     839                                ResourceHistoryItem resHistItem = resourceHistory.get(i); 
     840                                Map<ResourceUnitName, ResourceUnit> res = resHistItem.getResourceUnits(); 
     841                                ResourceUnit resUnit = res.get(StandardResourceUnitName.PE); 
     842                                //ProcessingElements pes = (ProcessingElements) resUnit ; 
     843                                LinkedList<ExecutionHistoryItem> execHistory = exec.getExecHistory(); 
     844                                long st = -1, et; 
     845                                for(int j = 0; j < execHistory .size(); j++){ 
     846                                        ExecutionHistoryItem execHistItem = execHistory.get(j); 
     847                                        if(execHistItem.getStatus() == DCWormsTags.PAUSED || execHistItem.getResIndex() != i){ 
     848                                                continue; 
     849                                        } 
     850                                        if(st == -1){ 
     851                                                st = execHistItem.getTimeStamp().getMillis(); 
     852                                        } 
     853                                                 
     854                                        if(j < execHistory.size() - 1 && (execHistory.get(j + 1).getResIndex() != execHistItem.getResIndex() || execHistory.get(j + 1).getStatus() == DCWormsTags.PAUSED) || j + 1 == execHistory.size()){ 
     855                                                if(j < execHistory.size() -1 && (execHistory.get(j + 1).getResIndex() != execHistItem.getResIndex() || execHistory.get(j + 1).getStatus() == DCWormsTags.PAUSED)) 
     856                                                        et = execHistory.get(j + 1).getTimeStamp().getMillis();  
     857                                                else et = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC;  
     858                                                if(resUnit instanceof ProcessingElements){ 
     859                                                        ProcessingElements pes = (ProcessingElements) resUnit; 
     860                                                        for(ComputingResource pe: pes){ 
     861                                                                String peName = pe.getFullName(); 
     862                                                                long startDate = st; 
     863                                                                long endDate; 
     864                                                                if(i == resourceHistory.size() - 1){ 
     865                                                                        endDate = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; 
     866                                                                }else { 
     867                                                                        endDate = et; 
     868                                                                } 
     869 
     870                                                                String appID = getAppId(execTask); 
     871                                                                 
     872                                                                ResStat resStat = new ResStat(peName, pe.getType(), startDate, endDate, appID); 
     873                                                                 
     874                                                                List<ResStat> resStats = basicResStats.get(peName); 
     875                                                                if (resStats == null) { 
     876                                                                        resStats = new ArrayList<ResStat>(); 
     877                                                                        resStats.add(resStat); 
     878                                                                        basicResStats.put(peName, resStats); 
     879                                                                } else { 
     880                                                                        resStats.add(resStat); 
     881                                                                } 
     882                                                                 
     883                                                                String uniqueTaskID = getUniqueTaskId(execTask); 
     884 
     885                                                                Set<ComputingResource> peNames = task_processorsMap.get(uniqueTaskID); 
     886                                                                if (peNames == null) { 
     887                                                                        peNames = new HashSet<ComputingResource>(); 
     888                                                                        peNames.add(pe); 
     889                                                                        task_processorsMap.put(uniqueTaskID, peNames); 
     890                                                                } else { 
     891                                                                        peNames.add(pe); 
     892                                                                } 
     893 
     894                                                                try{ 
     895                                                                        double usefulWork = execTask.getResourceConsumptionProfile().getUsefulWork()/pes.size(); 
     896                                                                        usefulWork = ((et - st) / (1000 * getExecutionTime(execTask))) * usefulWork; 
     897                                                                        GSSAccumulator uwAcc; 
     898                                                                        if(metCalc.getMetricsData().containsKey("UW_" + pe.getFullName())){ 
     899                                                                                uwAcc = metCalc.getMetricsData().get("UW_" + pe.getFullName()).get(0); 
     900                                                                                uwAcc.add(usefulWork); 
     901                                                                        } else { 
     902                                                                                uwAcc = new GSSAccumulator(); 
     903                                                                                uwAcc.add(usefulWork); 
     904                                                                                metCalc.addMetricsData("UW_" + pe.getFullName(), uwAcc); 
     905                                                                        } 
     906                                                                }  catch (Exception e){ 
     907                                                                         
     908                                                                } 
     909                                                                 
     910                                                        } 
     911                                                }  
     912                                                st = -1; 
     913                                        } 
     914                                } 
     915                        } 
     916                } 
     917                return basicResStats; 
     918        } 
     919         
     920        private double getExecutionTime(ExecTask execTask) { 
     921                double executionTime = 0; 
     922                long previousTimestamp = 0; 
     923                int previousStatus = DCWormsTags.CREATED; 
     924                for(ExecutionHistoryItem execHistItem: execTask.getExecHistory()){ 
     925                        if(previousStatus == DCWormsTags.INEXEC){ 
     926                                executionTime = executionTime  + (execHistItem.getTimeStamp().getMillis()/1000 - previousTimestamp); 
     927                        }  
     928                        previousTimestamp  = execHistItem.getTimeStamp().getMillis()/1000; 
     929                        previousStatus = execHistItem.getStatus(); 
     930                } 
     931                return executionTime; 
     932                //return task.getFinishTime() - task.getExecStartTime(); 
    822933        } 
    823934         
  • DCWoRMS/branches/coolemall/src/simulator/stats/implementation/TaskStats.java

    r1247 r1362  
    11package simulator.stats.implementation; 
    22 
     3 
     4import gridsim.dcworms.DCWormsTags; 
    35 
    46import java.util.HashSet; 
     
    1113import schedframe.resources.computing.Core; 
    1214import schedframe.resources.computing.Processor; 
     15import schedframe.scheduling.ExecutionHistoryItem; 
    1316import simulator.stats.implementation.out.StatsSerializer; 
    1417import dcworms.schedframe.scheduling.Executable; 
     
    102105 
    103106        public double getExecutionTime() { 
    104                 return task.getFinishTime() - task.getExecStartTime(); 
     107                double executionTime = 0; 
     108                long previousTimestamp = 0;              
     109                int previousStatus = DCWormsTags.CREATED; 
     110                for(ExecutionHistoryItem execHistItem: task.getExecHistory()){ 
     111                        if(previousStatus == DCWormsTags.INEXEC){ 
     112                                executionTime = executionTime  + (execHistItem.getTimeStamp().getMillis()/1000 - previousTimestamp); 
     113                        }  
     114                        previousTimestamp  = execHistItem.getTimeStamp().getMillis()/1000; 
     115                        previousStatus = execHistItem.getStatus(); 
     116                } 
     117                return executionTime; 
     118                //return task.getFinishTime() - task.getExecStartTime(); 
    105119        } 
    106120 
Note: See TracChangeset for help on using the changeset viewer.