Changeset 539 for DCWoRMS/trunk/build/classes/schedframe/scheduling/policy/AbstractManagementSystem.java
- Timestamp:
- 10/31/12 13:52:06 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DCWoRMS/trunk/build/classes/schedframe/scheduling/policy/AbstractManagementSystem.java
r477 r539 8 8 import org.joda.time.DateTimeUtilsExt; 9 9 10 import dcworms.schedframe.scheduling.ExecTask; 11 import dcworms.schedframe.scheduling.Executable; 12 import dcworms.schedframe.scheduling.queues.AbstractStatsSupportingQueue; 13 10 14 import schedframe.PluginConfiguration; 11 15 import schedframe.events.scheduling.SchedulingEventType; 12 import schedframe.resources.units.StandardResourceUnitName;13 16 import schedframe.scheduling.Scheduler; 14 17 import schedframe.scheduling.WorkloadUnitHandler; … … 16 19 import schedframe.scheduling.manager.resources.ResourceManager; 17 20 import schedframe.scheduling.manager.resources.ResourceManagerFactory; 21 import schedframe.scheduling.manager.tasks.JobRegistry; 18 22 import schedframe.scheduling.manager.tasks.JobRegistryImpl; 19 import schedframe.scheduling.manager.tasks.JobRegistry;20 23 import schedframe.scheduling.plan.AllocationInterface; 21 24 import schedframe.scheduling.plan.SchedulingPlanInterface; … … 27 30 import schedframe.scheduling.queue.TaskQueueList; 28 31 import schedframe.scheduling.tasks.Job; 32 import schedframe.scheduling.tasks.TaskInterface; 29 33 import schedframe.scheduling.tasks.WorkloadUnit; 30 import simulator. WormsConstants;34 import simulator.DCWormsConstants; 31 35 import eduni.simjava.Sim_event; 32 36 import gridsim.GridSim; 33 37 import gridsim.GridSimTags; 34 import gridsim.Gridlet;35 38 import 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; 39 import gridsim.dcworms.DCWormsTags; 40 40 41 41 public abstract class AbstractManagementSystem { … … 45 45 protected String name; 46 46 47 protected TaskQueueList queues; 47 48 protected ResourceManager resourceManager; 48 49 protected TaskQueueList queues;50 49 protected JobRegistryImpl jobRegistry; 50 protected ModuleList moduleList; 51 51 52 protected SchedulingPlugin schedulingPlugin; 52 53 53 protected ExecutionTimeEstimationPlugin execTimeEstimationPlugin; 54 54 55 protected ModuleList moduleList; 56 57 protected JobRegistryImpl jobRegistry; 55 protected Scheduler scheduler; 58 56 59 57 … … 67 65 } 68 66 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 69 80 public void processEvent(Sim_event ev) { 70 81 processOtherEvent(ev); … … 81 92 } 82 93 94 83 95 public String getName() { 84 96 return name; 85 }86 87 public PluginConfiguration getSchedulingPluginConfiguration() {88 return schedulingPlugin.getConfiguration();89 97 } 90 98 … … 106 114 return jobRegistry; 107 115 } 116 117 public Scheduler getScheduler() { 118 return scheduler; 119 } 120 121 public PluginConfiguration getSchedulingPluginConfiguration() { 122 return schedulingPlugin.getConfiguration(); 123 } 108 124 109 125 public boolean pluginSupportsEvent(int eventType){ … … 111 127 } 112 128 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 123 141 //POPRAWIC (ale co? bo teraz chyba jest ok) 124 protected void submit WorkloadUnit(WorkloadUnit<?> wu, AllocationInterfaceallocation) {142 protected void submitTask(TaskInterface<?> task, AllocationInterface<?> allocation) { 125 143 String providerName = allocation.getProviderName(); 126 144 if (providerName == null) { 127 145 return; 128 146 } 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) { 167 152 168 153 Executable exec = (Executable) wu; 169 154 if(scheduler.getParent() == null) 170 155 { 171 Job job = jobRegistry.get (exec.getJobId());156 Job job = jobRegistry.getJob(exec.getJobId()); 172 157 173 158 if(job.isFinished()){ 174 159 scheduler.send(job.getSenderId(), GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_RETURN, job); 175 160 return true; 176 }else return true; 161 } 162 else return true; 177 163 } 178 164 … … 183 169 184 170 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 }*/191 171 192 172 long delay = 0; … … 201 181 } 202 182 203 scheduler.sendInternal(Long.valueOf(delay).doubleValue(), WormsTags.TASK_READY_FOR_EXECUTION,183 scheduler.sendInternal(Long.valueOf(delay).doubleValue(), DCWormsTags.TASK_READY_FOR_EXECUTION, 204 184 exec); 205 185 } … … 213 193 if (obj != null) { 214 194 int delay = (Integer) obj; 215 scheduler.sendInternal(delay, WormsTags.TIMER, null);195 scheduler.sendInternal(delay, DCWormsTags.TIMER, null); 216 196 } 217 197 } … … 219 199 } 220 200 221 protected boolean removeFromQueue( WorkloadUnit<?> wu) {201 protected boolean removeFromQueue(TaskInterface<?> task) { 222 202 for(TaskQueue queue : queues){ 223 if(queue.contains( wu)){224 queue.remove( wu);203 if(queue.contains(task)){ 204 queue.remove(task); 225 205 return true; 226 206 } … … 228 208 return false; 229 209 } 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 }261 210 262 211 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); 263 218 264 219 }
Note: See TracChangeset
for help on using the changeset viewer.