source: xssim/branches/tpiontek/src/simulator/AbstractGridBroker.java @ 104

Revision 104, 10.1 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package simulator;
2
3import eduni.simjava.Sim_event;
4import eduni.simjava.Sim_system;
5import gridsim.GridSimTags;
6import gridsim.gssim.AbstractAdvanceReservation;
7import gridsim.gssim.GssimConstants;
8import gridsim.gssim.GssimTags;
9import schedframe.scheduling.events.SchedulingEventType;
10import schedframe.scheduling.plan.impl.SchedulingPlan;
11import schedframe.scheduling.plugin.SchedulingPluginConfiguration;
12import schedframe.scheduling.plugin.grid.GlobalSchedulingPlugin;
13import schedframe.scheduling.plugin.grid.ModuleList;
14import schedframe.scheduling.plugin.grid.ModuleListImpl;
15import simulator.lists.ExecutablesList;
16import simulator.utils.InstanceFactory;
17import test.rewolucja.CommunicationInterface;
18import gssim.schedframe.scheduling.AbstractExecutable;
19import gssim.schedframe.scheduling.plugin.grid.GridResourceDiscovery;
20import gridsim.net.Link;
21
22import java.util.HashSet;
23import java.util.List;
24import java.util.Map;
25import java.util.Properties;
26import java.util.Set;
27
28import org.apache.commons.logging.Log;
29import org.apache.commons.logging.LogFactory;
30
31
32/**
33 * This class models an interface to the grid scheduler (the plug-in). It is an entity that:
34 * <ul>
35 *  <li> passes the received jobs (created by users) to the plug-in, </li>
36 *  <li> collects the current resources' descriptions and gives it to the plug-in, </li>
37 *  <li> sends the scheduled tasks to the resources, </li>
38 *  <li> gives back the finished tasks to the plug-in, </li>
39 *  <li> sends back the return information to the users. </li>
40 * </ul>
41 * 
42 * @author Stanislaw Szczepanowski
43 *
44 */
45public abstract class AbstractGridBroker extends AbstractAdvanceReservation implements CommunicationInterface{
46       
47        protected Set<Integer> otherGridSchedulersIDs;
48        protected ModuleList moduleList;
49
50        /**
51         * The plug-in that has been passed to this interface entity
52         */
53        protected GlobalSchedulingPlugin<SchedulingPlan> gridSchedulerPlugin;
54       
55        private static Log log = LogFactory.getLog(AbstractGridBroker.class);
56       
57       
58        /**
59         * @param name the name of this entity
60         * @param gridSchedulerPluginName the name and package prefix of the plug-in that is to be used (this should be given in the main method of the simulator)
61         * @throws Exception if the plug-in name is wrong
62         */
63        public AbstractGridBroker(String name, String gridSchedulerPluginName) throws Exception {
64                super(name, GssimConstants.DEFAULT_BAUD_RATE);
65               
66                //make use of plug-in interface
67                gridSchedulerPlugin = (GlobalSchedulingPlugin) InstanceFactory.createInstance(
68                                                                                                                        gridSchedulerPluginName,
69                                                                                                                        GlobalSchedulingPlugin.class);
70                if(gridSchedulerPlugin == null){
71                        throw new Exception("Can not create grid scheduling plugin instance");
72                }
73               
74                Properties prop = new Properties();
75                prop.put("plugin.name", name);
76                prop.put("plugin.utils.timeoperations", "gssim.scheduling.plugin.local.GssimTimeOperations");
77                gridSchedulerPlugin.init(prop);
78                this.otherGridSchedulersIDs = new HashSet<Integer>();
79               
80                this.moduleList = new ModuleListImpl(2);
81                this.moduleList.add(new GridResourceDiscovery(this));
82               
83                if(log.isDebugEnabled())
84                        log.debug(name + ": Creating a broker interface object");
85        }
86
87        /**
88         * @param name the name of this entity
89         * @param gridSchedulerPluginName the name and package prefix of the plug-in that is to be used (this should be given in the main method of the simulator)
90         * @param link the connection between entity and router
91         * @throws Exception if the plug-in name is wrong
92         */
93        public AbstractGridBroker(String name, Link link, String gridSchedulerPluginName) throws Exception {
94                super(name, link);
95               
96                //make use of plug-in interface
97                gridSchedulerPlugin = (GlobalSchedulingPlugin) InstanceFactory.createInstance(
98                                                                                                                        gridSchedulerPluginName,
99                                                                                                                        GlobalSchedulingPlugin.class);
100               
101                if(gridSchedulerPlugin == null){
102                        throw new Exception("Can not create grid scheduling plugin instance");
103                }
104               
105                Properties prop = new Properties();
106                prop.put("plugin.name", name);
107                prop.put("plugin.utils.timeoperations", "gssim.scheduling.plugin.local.GssimTimeOperations");
108                gridSchedulerPlugin.init(prop);
109                this.otherGridSchedulersIDs = new HashSet<Integer>();
110               
111                this.moduleList = new ModuleListImpl(2);
112                this.moduleList.add(new GridResourceDiscovery(this));
113               
114                if(log.isDebugEnabled())
115                        log.debug(name + ": Creating a broker interface object");
116        }
117       
118        public void body() {
119                if(log.isDebugEnabled())
120                        log.debug("Grid scheduler interface "+name+" entity has started");
121               
122                SchedulingPluginConfiguration config = gridSchedulerPlugin.getConfiguration();
123                if(config != null){
124                        Map<SchedulingEventType, Object> events = config.getServedEvents();
125                        Object obj = events.get(SchedulingEventType.TIMER);
126                        if(obj != null){
127                                int delay = (Integer) obj;
128                                send(this.me, delay, GssimTags.TIMER);
129                        }
130                }
131               
132                Sim_event ev = new Sim_event();
133               
134                boolean run = true;
135
136/*              List<?> arResources = GridSim.getAdvancedReservationList();
137                Iterator<?> itr = arResources.iterator();
138                while(itr.hasNext()){
139                        Integer dest = (Integer) itr.next();
140                        send(dest, GridSimTags.SCHEDULE_NOW, GssimTags.RETURN_RESERVATIONS, new Integer(this.me));
141                }
142*/             
143                sim_get_next(ev);
144
145                while(Sim_system.running() && run) {
146                        switch (ev.get_tag()) {
147                        case GridSimTags.END_OF_SIMULATION:
148                                run = false;
149                                break;
150                        case GridSimTags.GRIDLET_SUBMIT:
151                               
152                                if(!pluginSupportsEvent(GridSimTags.GRIDLET_SUBMIT)){
153                                        log.error("Plugin " + this.gridSchedulerPlugin.getClass() + " does not provide support for TASK_ARRIVED event.\n" +
154                                                        "Check plugin configuration or use default one.");
155                                        break;
156                                }
157                               
158                                List<?> jobsList = prepareJobDescription(ev);
159                               
160                                //all the tasks are supposed to turn back to this entity (broker interface)
161                                int submittedJobsCount = jobsList.size();
162                               
163                                //give the task to the broker
164                                scheduleJob(jobsList, null, null, moduleList, null, null, null, null, null);
165                               
166                                //informs the Sim_system statistics about the completion of an event (multiplied by the number of jobs
167                                //sent to this broker) - this influences the "Throughput" metric in statistics.
168                                for (int i = 0; i < submittedJobsCount; ++i) {
169                                        sim_completed(ev);
170                                }
171                                break;
172                               
173                        case GridSimTags.INFOPKT_RETURN:
174                                //do nothing
175                                break;
176                               
177                        case GridSimTags.GRIDLET_RETURN:
178                                AbstractExecutable simpleGridlet = (AbstractExecutable) ev.get_data();
179                                notifyReturnedGridlet(simpleGridlet);
180                                break;
181                        case GridSimTags.GRIDLET_CANCEL:
182                                AbstractExecutable taskGridlet = (AbstractExecutable) ev.get_data();
183                                if(pluginSupportsEvent(GridSimTags.GRIDLET_CANCEL))
184                                        notifyCanceledGridlet(taskGridlet);
185                                break;
186                        case GssimTags.TIMER:
187                               
188                                if(pluginSupportsEvent(GssimTags.TIMER))
189                                        scheduleCyclic();
190                               
191                                config = gridSchedulerPlugin.getConfiguration();
192                                if(config != null){
193                                        Map<SchedulingEventType, Object> events = config.getServedEvents();
194                                        Object obj = events.get(SchedulingEventType.TIMER);
195                                        if(obj != null){
196                                                int delay = (Integer) obj;
197                                                send(this.me, delay, GssimTags.TIMER);
198                                        }
199                                }
200                               
201                                break;
202                        }
203                       
204                        //sim_get_next(notGRMSTags, ev);
205                        sim_get_next(ev);
206                }
207               
208                //shut down all the entities, including GridStatistics entity since
209        // we used it to record certain events.
210        shutdownGridStatisticsEntity();
211        shutdownUserEntity();
212        terminateIOEntities();
213       
214        if(log.isDebugEnabled())
215                log.debug("Grid scheduler "+name+" interface ends");
216        }
217       
218        public void addOtherGridSchedulerID(int id){
219                this.otherGridSchedulersIDs.add(id);
220        }
221
222        /**
223         * This method is used to retrieve the the list of identifiers of grid resources, that this broker instance can contact to.
224         * This method should be overwritten in subclasses, if a broker instance sees only a subset of all available grid resources.
225         *
226         * @return the list of identifiers of grid resources, that this broker instance can contact to
227         */
228        public List<Integer> getMyGridResources() {
229                return getGridResourceList();
230        }
231       
232        protected boolean pluginSupportsEvent(int eventType){
233                SchedulingPluginConfiguration config = this.gridSchedulerPlugin.getConfiguration();
234                if(config == null)
235                        return false;
236               
237                Map<SchedulingEventType, Object> servedEvent = config.getServedEvents();
238                if(servedEvent == null)
239                        return false;
240               
241               
242                switch(eventType){
243               
244                        case GssimTags.TIMER:
245                                return servedEvent.containsKey(SchedulingEventType.TIMER);
246
247                        case GssimTags.GRIDLET_SUBMIT:
248                                        return servedEvent.containsKey(SchedulingEventType.TASK_ARRIVED);
249                        case GssimTags.GRIDLET_CANCEL:
250                                        return servedEvent.containsKey(SchedulingEventType.TASK_CANCELED);
251                        case GssimTags.GRIDLET_RESUME:
252                                        return servedEvent.containsKey(SchedulingEventType.TASK_ARRIVED);
253
254                        case GssimTags.GRIDRESOURCE_FAILURE:
255                                        return servedEvent.containsKey(SchedulingEventType.RESOURCE_FAILED);
256
257
258                        default: return false;
259                }
260        }
261       
262        /**
263         * The entry point to the plug-in.<br>
264         * Invokes the plug-in with the provided information.
265         *
266         * @param gridletList the list of jobs that have come from users
267         * @param jobDescription (JD) Job description (resource requirements, information needed to run a job-e.g. environmental variables, data needed)
268         * @param userPreferences (UP) User preferences
269         * @param reservationRequest (RR) Reservation request
270         * @param resources (RP) Resource parameters (static and dynamic)
271         * @param reservationOffers (RO) Reservation offers
272         * @param predictedTimes (PT) Predicted times
273         * @param jobSet (JQ) Job set(queue)
274         * @param jobRegistry (JR) Job registry (information about already executed (and being executed) jobs)
275         * @param brokerConfiguration (BC) Broker configuration
276         */
277        public abstract void scheduleJob(List<?> gridletList,
278                                                                                        String userPreferences,
279                                                                                        String reservationRequest,
280                                                                                        ModuleList moduleList,
281                                                                                        String reservationOffers,
282                                                                                        String predictedTimes,
283                                                                                        String jobSet,
284                                                                                        String jobRegistry,
285                                                                                        String brokerConfiguration);
286       
287        public abstract void scheduleCyclic();
288       
289        public abstract void notifyReturnedGridlet(AbstractExecutable simpleGridlet);
290       
291        public abstract void notifyCanceledGridlet(AbstractExecutable taskGridlet);
292       
293        public abstract ExecutablesList getExecutables();
294       
295        protected abstract List<?> prepareJobDescription(Sim_event ev);
296       
297}
Note: See TracBrowser for help on using the repository browser.