source: xssim/src/example/gridplugin/GridFCFSRandomPlugin.java @ 104

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