source: DCWoRMS/trunk/src/example/globalplugin/GridFCFSRandomPlugin.java @ 478

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