source: DCWoRMS/branches/coolemall/src/example/globalplugin/GridFCFSRandomPlugin.java @ 1449

Revision 1449, 2.3 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.globalplugin;
2
3import java.util.List;
4import java.util.Random;
5
6import schedframe.events.scheduling.SchedulingEvent;
7import schedframe.scheduling.SchedulerDescription;
8import schedframe.scheduling.manager.resources.ResourceManager;
9import schedframe.scheduling.manager.tasks.JobRegistry;
10import schedframe.scheduling.plan.SchedulingPlanInterface;
11import schedframe.scheduling.plan.impl.Allocation;
12import schedframe.scheduling.plan.impl.ScheduledTask;
13import schedframe.scheduling.plan.impl.SchedulingPlan;
14import schedframe.scheduling.plugin.Module;
15import schedframe.scheduling.plugin.ModuleList;
16import schedframe.scheduling.plugin.grid.ResourceDiscovery;
17import schedframe.scheduling.queue.TaskQueue;
18import schedframe.scheduling.queue.TaskQueueList;
19import schedframe.scheduling.tasks.TaskInterface;
20import schedframe.scheduling.tasks.WorkloadUnit;
21
22public class GridFCFSRandomPlugin extends BaseGlobalPlugin {
23
24        private Random rand;
25       
26        public GridFCFSRandomPlugin() {
27                rand = new Random(5);
28        }
29       
30        public SchedulingPlanInterface<?> schedule(SchedulingEvent event,
31                        TaskQueueList queues,
32                        JobRegistry jobRegistry,
33                        ResourceManager resourceManager, ModuleList modules)  {
34               
35                ResourceDiscovery resources = null;
36                for(int i = 0; i < modules.size(); i++){
37                        Module m = modules.get(i);
38                        switch(m.getType()){
39                                case RESOURCE_DISCOVERY: resources = (ResourceDiscovery) m;
40                                        break;
41                        }
42                }
43               
44                SchedulingPlan plan = new SchedulingPlan();
45               
46                TaskQueue q = queues.get(0);
47                int size = q.size();
48               
49                // order of the resources on this list is not determined
50                List<SchedulerDescription> availableResources = resources.getResources(null);
51                int resourceIdx = -1;
52               
53                for(int i = 0; i < size; i++) {
54
55                        TaskInterface<?> task = q.remove(0);
56                       
57                        resourceIdx = rand.nextInt(availableResources.size());
58                        SchedulerDescription sd = availableResources.get(resourceIdx);
59                       
60                        Allocation allocation = new Allocation();
61                        allocation.setProcessesCount(1);
62                        allocation.setProviderName(sd.getProvider().getProviderId());
63                       
64                        ScheduledTask scheduledTask = new ScheduledTask(task);
65                        scheduledTask.setTaskId(task.getId());
66                        scheduledTask.setJobId(task.getJobId());
67                        scheduledTask.addAllocation(allocation);               
68                       
69                        plan.addTask(scheduledTask);
70
71                }
72                return plan;
73               
74        }
75
76}
Note: See TracBrowser for help on using the repository browser.