Ignore:
Timestamp:
10/31/12 13:52:06 (12 years ago)
Author:
wojtekp
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/trunk/build/classes/schedframe/scheduling/policy/AbstractManagementSystem.java

    r477 r539  
    88import org.joda.time.DateTimeUtilsExt; 
    99 
     10import dcworms.schedframe.scheduling.ExecTask; 
     11import dcworms.schedframe.scheduling.Executable; 
     12import dcworms.schedframe.scheduling.queues.AbstractStatsSupportingQueue; 
     13 
    1014import schedframe.PluginConfiguration; 
    1115import schedframe.events.scheduling.SchedulingEventType; 
    12 import schedframe.resources.units.StandardResourceUnitName; 
    1316import schedframe.scheduling.Scheduler; 
    1417import schedframe.scheduling.WorkloadUnitHandler; 
     
    1619import schedframe.scheduling.manager.resources.ResourceManager; 
    1720import schedframe.scheduling.manager.resources.ResourceManagerFactory; 
     21import schedframe.scheduling.manager.tasks.JobRegistry; 
    1822import schedframe.scheduling.manager.tasks.JobRegistryImpl; 
    19 import schedframe.scheduling.manager.tasks.JobRegistry; 
    2023import schedframe.scheduling.plan.AllocationInterface; 
    2124import schedframe.scheduling.plan.SchedulingPlanInterface; 
     
    2730import schedframe.scheduling.queue.TaskQueueList; 
    2831import schedframe.scheduling.tasks.Job; 
     32import schedframe.scheduling.tasks.TaskInterface; 
    2933import schedframe.scheduling.tasks.WorkloadUnit; 
    30 import simulator.WormsConstants; 
     34import simulator.DCWormsConstants; 
    3135import eduni.simjava.Sim_event; 
    3236import gridsim.GridSim; 
    3337import gridsim.GridSimTags; 
    34 import gridsim.Gridlet; 
    3538import gridsim.IO_data; 
    36 import gridsim.gssim.WormsTags; 
    37 import gssim.schedframe.scheduling.ExecTask; 
    38 import gssim.schedframe.scheduling.Executable; 
    39 import gssim.schedframe.scheduling.queues.AbstractStatsSupportingQueue; 
     39import gridsim.dcworms.DCWormsTags; 
    4040 
    4141public abstract class AbstractManagementSystem { 
     
    4545        protected String name; 
    4646 
     47        protected TaskQueueList queues; 
    4748        protected ResourceManager resourceManager; 
    48  
    49         protected TaskQueueList queues; 
    50  
     49        protected JobRegistryImpl jobRegistry; 
     50        protected ModuleList moduleList; 
     51         
    5152        protected SchedulingPlugin schedulingPlugin; 
    52  
    5353        protected ExecutionTimeEstimationPlugin execTimeEstimationPlugin; 
    5454 
    55         protected ModuleList moduleList; 
    56          
    57         protected JobRegistryImpl jobRegistry; 
     55        protected Scheduler scheduler; 
    5856         
    5957 
     
    6765        } 
    6866         
     67        public void init(Scheduler sched, ManagedResources managedResources) { 
     68                scheduler = sched; 
     69                resourceManager = ResourceManagerFactory.createResourceManager(scheduler, managedResources); 
     70                scheduler.set_stat(DCWormsConstants.getResourcesStatisticsObject(queues.size())); 
     71                for(int i = 0; i < queues.size(); i++){ 
     72                        TaskQueue q = queues.get(i); 
     73                        if(q instanceof AbstractStatsSupportingQueue<?>){ 
     74                                AbstractStatsSupportingQueue<?> queue = (AbstractStatsSupportingQueue<?>) q; 
     75                                queue.setStats(scheduler.get_stat(), DCWormsConstants.TASKS_QUEUE_LENGTH_MEASURE_NAME + "_" + Integer.toString(i)); 
     76                        } 
     77                } 
     78        } 
     79         
    6980        public void processEvent(Sim_event ev) { 
    7081                processOtherEvent(ev); 
     
    8192        } 
    8293         
     94         
    8395        public String getName() { 
    8496                return name; 
    85         } 
    86  
    87         public PluginConfiguration getSchedulingPluginConfiguration() { 
    88                 return schedulingPlugin.getConfiguration(); 
    8997        } 
    9098         
     
    106114                return jobRegistry; 
    107115        } 
     116         
     117        public Scheduler getScheduler() { 
     118                return scheduler; 
     119        } 
     120         
     121        public PluginConfiguration getSchedulingPluginConfiguration() { 
     122                return schedulingPlugin.getConfiguration(); 
     123        } 
    108124 
    109125        public boolean pluginSupportsEvent(int eventType){ 
     
    111127        } 
    112128 
    113         public abstract void notifySubmittedWorkloadUnit(WorkloadUnit<?> wu, boolean ack); 
    114  
    115         public abstract void notifyCanceledWorkloadUnit(WorkloadUnit<?> wu); 
    116  
    117         public abstract void notifyReturnedWorkloadUnit(WorkloadUnit<?> wu); 
    118  
    119         protected abstract void executeSchedulingPlan(SchedulingPlanInterface decision); 
    120  
    121  
    122  
     129        public TaskQueueList getQueues(){ 
     130                return queues; 
     131        } 
     132         
     133        public Map<String, Integer> getQueuesSize() { 
     134                Map<String, Integer> queue_size = new HashMap<String, Integer>(); 
     135                for (TaskQueue queue : queues) { 
     136                        queue_size.put(queue.getName(), queue.size()); 
     137                } 
     138                return queue_size; 
     139        } 
     140         
    123141        //POPRAWIC  (ale co? bo teraz chyba jest ok) 
    124         protected void submitWorkloadUnit(WorkloadUnit<?> wu, AllocationInterface allocation) { 
     142        protected void submitTask(TaskInterface<?> task, AllocationInterface<?> allocation) { 
    125143                String providerName = allocation.getProviderName(); 
    126144                if (providerName == null) { 
    127145                        return; 
    128146                } 
    129                 //Executable exec = (Executable) wu; 
    130                 removeFromQueue(wu); 
    131                 scheduler.send(providerName, GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_SUBMIT, wu);  
    132         } 
    133          
    134         protected boolean sendCanceledWorkloadUnit(int tag, Executable task, int executableId, int destId) { 
    135                  
    136                 if (tag != GridSimTags.GRIDLET_CANCEL) { 
    137                         return false; 
    138                 } 
    139  
    140                 long taskSize = 0; 
    141                 if (task != null) { 
    142                         taskSize = task.getGridletOutputSize(); 
    143                 } 
    144  
    145                 // if no Gridlet found, then create a new Gridlet but set its status 
    146                 // to FAILED. Then, most importantly, set the resource parameters 
    147                 // because the user will search/filter based on a resource ID. 
    148                 else if (task == null) { 
    149                         try { 
    150                                 taskSize = 100; 
    151                                 task = jobRegistry.getTaskExecutable(executableId); 
    152                                 task.setGridletStatus(Gridlet.FAILED); 
    153                                 int cost = resourceManager.getSharedResourceUnits().get(StandardResourceUnitName.COST) != null ? resourceManager 
    154                                                 .getSharedResourceUnits().get(StandardResourceUnitName.COST).get(0).getAmount() 
    155                                                 : 1; 
    156                                 task.setResourceParameter(scheduler.get_id(), cost); 
    157                         } catch (Exception e) { 
    158                                 // empty ... 
    159                         } 
    160                 } 
    161                 scheduler.send(scheduler.getOutputPort(), GridSimTags.SCHEDULE_NOW, tag,  new IO_data(task, taskSize, destId)); 
    162  
    163                 return true; 
    164         } 
    165  
    166         protected boolean sendFinishedWorkloadUnit(WorkloadUnit<?> wu) { 
     147                removeFromQueue(task); 
     148                scheduler.send(providerName, GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_SUBMIT, task);        
     149        } 
     150 
     151        protected boolean sendFinishedWorkloadUnit(WorkloadUnit wu) { 
    167152                 
    168153                Executable exec = (Executable) wu; 
    169154                if(scheduler.getParent() == null) 
    170155                { 
    171                         Job job = jobRegistry.get(exec.getJobId()); 
     156                        Job job = jobRegistry.getJob(exec.getJobId()); 
    172157 
    173158                        if(job.isFinished()){ 
    174159                                scheduler.send(job.getSenderId(), GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_RETURN, job); 
    175160                                return true; 
    176                         }else return true; 
     161                        } 
     162                        else return true; 
    177163                } 
    178164         
     
    183169 
    184170        protected void sendExecutableReadyEvent(ExecTask exec) { 
    185  
    186                 /*if (wu instanceof JobInterface) { 
    187                         scheduler.sendInternal(Long.valueOf(0).doubleValue(), GssimTags.TASK_READY_FOR_EXECUTION, 
    188                                         wu); 
    189                         return; 
    190                 }*/ 
    191171 
    192172                long delay = 0; 
     
    201181                } 
    202182 
    203                 scheduler.sendInternal(Long.valueOf(delay).doubleValue(), WormsTags.TASK_READY_FOR_EXECUTION, 
     183                scheduler.sendInternal(Long.valueOf(delay).doubleValue(), DCWormsTags.TASK_READY_FOR_EXECUTION, 
    204184                                exec); 
    205185        } 
     
    213193                                if (obj != null) { 
    214194                                        int delay = (Integer) obj; 
    215                                         scheduler.sendInternal(delay, WormsTags.TIMER, null); 
     195                                        scheduler.sendInternal(delay, DCWormsTags.TIMER, null); 
    216196                                } 
    217197                        } 
     
    219199        } 
    220200         
    221         protected boolean removeFromQueue(WorkloadUnit<?> wu) { 
     201        protected boolean removeFromQueue(TaskInterface<?> task) { 
    222202                for(TaskQueue queue : queues){ 
    223                         if(queue.contains(wu)){ 
    224                                 queue.remove(wu); 
     203                        if(queue.contains(task)){ 
     204                                queue.remove(task); 
    225205                                return true; 
    226206                        } 
     
    228208                return false; 
    229209        } 
    230  
    231         public TaskQueueList getAccessQueues(){ 
    232                 return queues; 
    233         } 
    234          
    235         public Map<String, Integer> getQueuesSize() { 
    236                 Map<String, Integer> queue_size = new HashMap<String, Integer>(); 
    237                 for (TaskQueue queue : queues) { 
    238                         queue_size.put(queue.getName(), queue.size()); 
    239                 } 
    240                 return queue_size; 
    241         } 
    242  
    243         public void init(Scheduler sched, ManagedResources managedResources) { 
    244                 scheduler = sched; 
    245                 resourceManager = ResourceManagerFactory.createResourceManager(scheduler, managedResources); 
    246                 scheduler.set_stat(WormsConstants.getResourcesStatisticsObject(queues.size())); 
    247                 for(int i = 0; i < queues.size(); i++){ 
    248                         TaskQueue q = queues.get(i); 
    249                         if(q instanceof AbstractStatsSupportingQueue<?>){ 
    250                                 AbstractStatsSupportingQueue<?> queue = (AbstractStatsSupportingQueue<?>) q; 
    251                                 queue.setStats(scheduler.get_stat(), WormsConstants.TASKS_QUEUE_LENGTH_MEASURE_NAME + "_" + Integer.toString(i)); 
    252                         } 
    253                 } 
    254         } 
    255  
    256         protected Scheduler scheduler; 
    257  
    258         public Scheduler getScheduler() { 
    259                 return scheduler; 
    260         } 
    261210         
    262211        public abstract WorkloadUnitHandler getWorkloadUnitHandler(); 
     212         
     213        public abstract void notifySubmittedWorkloadUnit(WorkloadUnit wu, boolean ack); 
     214 
     215        public abstract void notifyReturnedWorkloadUnit(WorkloadUnit wu); 
     216 
     217        protected abstract void executeSchedulingPlan(SchedulingPlanInterface<?> decision); 
    263218 
    264219} 
Note: See TracChangeset for help on using the changeset viewer.