source: xssim/trunk/src/example/gridplugin/GridFCFSRoundRobinPlugin.java @ 164

Revision 164, 3.1 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.LinkedList;
4import java.util.List;
5import java.util.Properties;
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.Queue;
23import test.rewolucja.scheduling.queue.QueueList;
24
25public class GridFCFSRoundRobinPlugin extends BaseGlobalPlugin {
26
27        private LinkedList<String> lastUsedResources = new LinkedList<String>();
28
29        public SchedulingPlanInterfaceNew schedule(SchedulingEvent event,
30                        QueueList queues,
31                        JobRegistryInterface jobRegistry,
32                        ResourceManagerInterface resourceManager, ModuleList modules)  {
33       
34                ResourceDiscovery resources = null;
35                for(int i = 0; i < modules.size(); i++){
36                        Module m = modules.get(i);
37                        switch(m.getType()){
38                                case RESOURCE_DISCOVERY: resources = (ResourceDiscovery) m;
39                                        break;
40                        }
41                }
42               
43                SchedulingPlanNew plan = new SchedulingPlanNew();
44               
45                Queue q = queues.get(0);
46                int size = q.size();
47               
48                // order of the resources on this list is not determined
49                List<ResourceDescription> availableResources = resources.getResources();
50 
51                for(int i = 0; i < size; i++) {
52                        GSSIMJobInterface<?> job = q.remove(0);
53                        TaskInterface<?> task = (TaskInterface<?>)job;
54                       
55                        ResourceDescription rd = availableResources.get(availableResources.size() - 1);
56                        for(ResourceDescription resDesc: availableResources){
57                                if(!lastUsedResources.contains(resDesc.getProvider().getProviderId())){
58                                        if(lastUsedResources.size() + 1 >= availableResources.size()){
59                                                lastUsedResources.poll();
60                                        }
61                                        lastUsedResources.add(resDesc.getProvider().getProviderId());
62                                        rd = resDesc;
63                                        break;
64                                }
65                        }
66               
67                        AllocationNew allocation = new AllocationNew();
68                        allocation.setProcessesCount(1);
69                        allocation.setProviderName(rd.getProvider().getProviderId());
70                       
71                        ScheduledTaskNew scheduledTask = new ScheduledTaskNew(task);
72                        scheduledTask.setTaskId(task.getId());
73                        scheduledTask.setJobId(task.getJobId());
74                        scheduledTask.addAllocation(allocation);               
75                       
76                        plan.addTask(scheduledTask);
77                }
78                return plan;
79        }
80
81       
82        public SchedulingPluginConfiguration getConfiguration() {
83                return DefaultConfiguration.forGridPlugin();
84        }
85
86        public String getName() {
87                return getClass().getName();
88        }
89
90        public void init(Properties properties) {
91                // no extra initialization is expected.
92        }
93
94}
Note: See TracBrowser for help on using the repository browser.