1 | package test.rewolucja.resources.reader; |
---|
2 | |
---|
3 | |
---|
4 | import gridsim.ResourceCalendar; |
---|
5 | import gridsim.gssim.GssimConstants; |
---|
6 | |
---|
7 | import java.io.File; |
---|
8 | import java.io.FileNotFoundException; |
---|
9 | import java.io.FileReader; |
---|
10 | import java.io.IOException; |
---|
11 | import java.util.LinkedList; |
---|
12 | import java.util.List; |
---|
13 | import java.util.Stack; |
---|
14 | |
---|
15 | import org.exolab.castor.xml.MarshalException; |
---|
16 | import org.exolab.castor.xml.ValidationException; |
---|
17 | import org.qcg.broker.schemas.exception.UnknownParameter; |
---|
18 | |
---|
19 | import org.qcg.broker.schemas.hostparams.HostParameters; |
---|
20 | import org.qcg.broker.schemas.hostparams.wrapper.HostParametersWrapper; |
---|
21 | import org.qcg.broker.schemas.hostparams.wrapper.impl.HostParametersWrapperImpl; |
---|
22 | |
---|
23 | import schedframe.scheduling.plugin.estimation.ExecTimeEstimationPlugin; |
---|
24 | import simulator.ConfigurationOptions; |
---|
25 | import simulator.utils.InstanceFactory; |
---|
26 | import test.rewolucja.resources.ResourceType; |
---|
27 | import test.rewolucja.resources.description.AbstractResourceDescription; |
---|
28 | import test.rewolucja.resources.description.ExecResourceDescription; |
---|
29 | import test.rewolucja.resources.logical.LogicalResource; |
---|
30 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
31 | import test.rewolucja.resources.physical.factory.ResourceFactory; |
---|
32 | import test.rewolucja.resources.reader.test.TempResourceDescriptionReader; |
---|
33 | import test.rewolucja.resources.utils.ResourceController; |
---|
34 | import test.rewolucja.scheduling.implementation.GridBrokerNew; |
---|
35 | import test.rewolucja.scheduling.implementation.LocalManagementSystem; |
---|
36 | import test.rewolucja.scheduling.implementation.ManagementSystem; |
---|
37 | |
---|
38 | public class ResourceReaderNew { |
---|
39 | |
---|
40 | protected String forecastFinishTimePluginName; |
---|
41 | protected String globalSchedulingPluginName; |
---|
42 | protected String localSchedulingPluginName; |
---|
43 | protected String resDescFileName; |
---|
44 | protected String envDescFileName; |
---|
45 | |
---|
46 | protected ResourceCalendar resourceCalendar; |
---|
47 | protected ExecTimeEstimationPlugin execTimeEstimationPlugin; |
---|
48 | |
---|
49 | private List<String> resourceLayers; |
---|
50 | |
---|
51 | |
---|
52 | public ResourceReaderNew(ConfigurationOptions options) throws IOException { |
---|
53 | |
---|
54 | forecastFinishTimePluginName = options.exectimeestimationplugin; |
---|
55 | globalSchedulingPluginName = options.gridSchedulingPluginName; |
---|
56 | localSchedulingPluginName = options.localAllocPolicyPluginName; |
---|
57 | resDescFileName = options.resdescFileName; |
---|
58 | envDescFileName = options.envDescFileName; |
---|
59 | prepareCalendar(); |
---|
60 | } |
---|
61 | |
---|
62 | public ResourceController read() throws MarshalException, ValidationException, FileNotFoundException, |
---|
63 | UnknownParameter { |
---|
64 | |
---|
65 | File file = new File(resDescFileName); |
---|
66 | |
---|
67 | HostParameters resourceDesription = HostParameters.unmarshalHostParameters(new FileReader(file)); |
---|
68 | HostParametersWrapper wrapper = new HostParametersWrapperImpl(); |
---|
69 | wrapper.wrap(resourceDesription); |
---|
70 | org.qcg.broker.schemas.hostparams.ComputingResource compResources[] = null; |
---|
71 | compResources = wrapper.getStandaloneComputingResources(); |
---|
72 | |
---|
73 | TempResourceDescriptionReader resourceDescriptionReader = TempResourceDescriptionReader |
---|
74 | .getConfiguration(envDescFileName); |
---|
75 | System.out.println("started creating environment description"); |
---|
76 | ExecResourceDescription headExecResDesc = createEnvironmentDescription(resourceDescriptionReader, compResources[0]); |
---|
77 | System.out.println("finished creating environment description"); |
---|
78 | |
---|
79 | System.out.println("started creating resources"); |
---|
80 | ComputingResource resource = createResources(headExecResDesc); |
---|
81 | System.out.println("finished creating resource"); |
---|
82 | |
---|
83 | execTimeEstimationPlugin = (ExecTimeEstimationPlugin) InstanceFactory.createInstance( |
---|
84 | forecastFinishTimePluginName, ExecTimeEstimationPlugin.class); |
---|
85 | |
---|
86 | //List<Resource> resources = createResourcesAlternative(resourceDescriptionReader, arc, resourcesDescriptions); |
---|
87 | |
---|
88 | LogicalResource lr = createLogicalResources(resource); |
---|
89 | //LogicalResource lr = createLogicalLayersStructureAlternative(resources); |
---|
90 | ResourceController rc = null; |
---|
91 | try { |
---|
92 | rc = new ResourceController("rc", lr, resource); |
---|
93 | } catch (Exception e) { |
---|
94 | // TODO Auto-generated catch block |
---|
95 | e.printStackTrace(); |
---|
96 | } |
---|
97 | |
---|
98 | return rc; |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | private ExecResourceDescription createEnvironmentDescription(TempResourceDescriptionReader resourceDescriptionReader, |
---|
103 | org.qcg.broker.schemas.hostparams.ComputingResource compResources) { |
---|
104 | |
---|
105 | resourceLayers = resourceDescriptionReader.resources; |
---|
106 | String resLayerName = resourceLayers.get(0); |
---|
107 | |
---|
108 | ExecResourceDescription headExecResDesc = new ExecResourceDescription(null, compResources, resLayerName); |
---|
109 | |
---|
110 | Stack<ExecResourceDescription> toExamine = new Stack<ExecResourceDescription>(); |
---|
111 | toExamine.push(headExecResDesc); |
---|
112 | |
---|
113 | ExecResourceDescription perentResDesc; |
---|
114 | while (!toExamine.isEmpty()) { |
---|
115 | perentResDesc = toExamine.pop(); |
---|
116 | resLayerName = getNextLayer(perentResDesc.getType().toString()); |
---|
117 | if (resLayerName == null) |
---|
118 | continue; |
---|
119 | int resAmount = Integer.parseInt(resourceDescriptionReader.res_amount.get(resLayerName)); |
---|
120 | for (int i = 0; i < resAmount; i++) { |
---|
121 | ExecResourceDescription resDesc = new ExecResourceDescription(perentResDesc, compResources, resLayerName); |
---|
122 | perentResDesc.addChildren(resDesc); |
---|
123 | toExamine.insertElementAt(resDesc, 0); |
---|
124 | } |
---|
125 | } |
---|
126 | return headExecResDesc; |
---|
127 | } |
---|
128 | |
---|
129 | private String getNextLayer(String previousLayer) { |
---|
130 | String layer = null; |
---|
131 | for (int i = 0; i < resourceLayers.size(); i++) { |
---|
132 | if (resourceLayers.get(i).compareTo(previousLayer) == 0) { |
---|
133 | if (i < resourceLayers.size() - 1) { |
---|
134 | layer = resourceLayers.get(i + 1); |
---|
135 | break; |
---|
136 | } |
---|
137 | } |
---|
138 | } |
---|
139 | return layer; |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | private ComputingResource createResources(ExecResourceDescription headExecResDes) { |
---|
144 | |
---|
145 | ComputingResource headResource = ResourceFactory.createResource(headExecResDes); |
---|
146 | Stack<ExecResourceDescription> toExamine = new Stack<ExecResourceDescription>(); |
---|
147 | toExamine.push(headExecResDes); |
---|
148 | Stack<ComputingResource> resStructure = new Stack<ComputingResource>(); |
---|
149 | resStructure.push(headResource); |
---|
150 | while (!toExamine.isEmpty()) { |
---|
151 | ComputingResource parentResource = resStructure.pop(); |
---|
152 | ExecResourceDescription parentResDesc = toExamine.pop(); |
---|
153 | List<AbstractResourceDescription> childrenResDesc = parentResDesc.getChildren(); |
---|
154 | if (childrenResDesc == null){ |
---|
155 | continue; |
---|
156 | } |
---|
157 | int resAmount = childrenResDesc.size(); |
---|
158 | for (int i = 0; i < resAmount; i++) { |
---|
159 | ExecResourceDescription execResDesc = (ExecResourceDescription) childrenResDesc.get(i); |
---|
160 | ComputingResource resource = ResourceFactory.createResource(execResDesc); |
---|
161 | parentResource.addChild(resource); |
---|
162 | toExamine.push(execResDesc); |
---|
163 | resStructure.push(resource); |
---|
164 | } |
---|
165 | } |
---|
166 | return headResource; |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | private LogicalResource createLogicalResources(ComputingResource headResource) { |
---|
172 | |
---|
173 | Stack<ComputingResource> toExamine = new Stack<ComputingResource>(); |
---|
174 | toExamine.push(headResource); |
---|
175 | LogicalResource headLogicalResource = null; |
---|
176 | Stack<LogicalResource> logicalResStructure = new Stack<LogicalResource>(); |
---|
177 | LogicalResource parentLogicalResource = null; |
---|
178 | while (!toExamine.isEmpty()) { |
---|
179 | ComputingResource parentResource = toExamine.pop(); |
---|
180 | if (parentResource.getType() == ResourceType.COMPUTING_GRID) |
---|
181 | try { |
---|
182 | ManagementSystem ms = new GridBrokerNew(parentResource.getName(), |
---|
183 | globalSchedulingPluginName, execTimeEstimationPlugin, null); |
---|
184 | |
---|
185 | headLogicalResource = new LogicalResource(ms, parentResource.getChildren()); |
---|
186 | logicalResStructure.push(headLogicalResource); |
---|
187 | } catch (Exception e) { |
---|
188 | e.printStackTrace(); |
---|
189 | } |
---|
190 | |
---|
191 | if(parentResource.getType() == ResourceType.RACK || parentResource.getType() == ResourceType.COMPUTING_NODE || parentResource.getType() == ResourceType.CPU || parentResource.getType() == ResourceType.CORE ) |
---|
192 | { |
---|
193 | |
---|
194 | } |
---|
195 | else |
---|
196 | parentLogicalResource = logicalResStructure.pop(); |
---|
197 | |
---|
198 | List<ComputingResource> resChildren = parentResource.getChildren(); |
---|
199 | if (resChildren == null) |
---|
200 | continue; |
---|
201 | int resAmount = resChildren.size(); |
---|
202 | for (int i = 0; i < resAmount; i++) { |
---|
203 | ComputingResource resource = resChildren.get(i); |
---|
204 | |
---|
205 | if (resource.getType() == ResourceType.DATA_CENTER) |
---|
206 | { |
---|
207 | try { |
---|
208 | ManagementSystem ms = new LocalManagementSystem(resource.getName(), |
---|
209 | GssimConstants.MANAGEMENT_SYSTEM, |
---|
210 | localSchedulingPluginName, execTimeEstimationPlugin, null); |
---|
211 | |
---|
212 | LogicalResource logicalResource = new LogicalResource( |
---|
213 | ms, resource.getChildren()); |
---|
214 | parentLogicalResource.addChild(logicalResource); |
---|
215 | logicalResStructure.push(logicalResource); |
---|
216 | } catch (Exception e) { |
---|
217 | e.printStackTrace(); |
---|
218 | } |
---|
219 | } /*else if (resource.getType() == ResourceType.COMPUTING_NODE) { |
---|
220 | try { |
---|
221 | ManagementSystem ms = new LocalManagementSystem(resource.getName(), |
---|
222 | GssimConstants.MANAGEMENT_SYSTEM, |
---|
223 | "example.localplugin.FCFSLocalPlugin", execTimeEstimationPlugin, null); |
---|
224 | |
---|
225 | LogicalResource logicalResource = new LogicalResource(ms, resource.getChildren()); |
---|
226 | parentLogicalResource.addChild(logicalResource); |
---|
227 | logicalResStructure.push(logicalResource); |
---|
228 | } catch (Exception e) { |
---|
229 | // TODO Auto-generated catch block |
---|
230 | e.printStackTrace(); |
---|
231 | } |
---|
232 | }*/ |
---|
233 | toExamine.push(resource); |
---|
234 | } |
---|
235 | } |
---|
236 | return headLogicalResource; |
---|
237 | |
---|
238 | } |
---|
239 | |
---|
240 | private void prepareCalendar() { |
---|
241 | long seed = 11L * 13L * 17L * 19L * 23L + 1L; |
---|
242 | double timeZone = 0.0; |
---|
243 | double peakLoad = 0.0; // the resource load during peak hour |
---|
244 | double offPeakLoad = 0.0; // the resource load during off-peak hr |
---|
245 | double holidayLoad = 0.0; // the resource load during holiday |
---|
246 | |
---|
247 | // incorporates weekends so the grid resource is on 7 days a week |
---|
248 | LinkedList<Integer> Weekends = new LinkedList<Integer>(); |
---|
249 | Weekends.add(java.util.Calendar.SATURDAY); |
---|
250 | Weekends.add(java.util.Calendar.SUNDAY); |
---|
251 | |
---|
252 | // incorporates holidays. However, no holidays are set in this example |
---|
253 | LinkedList<Integer> Holidays = new LinkedList<Integer>(); |
---|
254 | resourceCalendar = new ResourceCalendar(timeZone, peakLoad, offPeakLoad, holidayLoad, Weekends, Holidays, |
---|
255 | seed); |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | |
---|
266 | |
---|
267 | |
---|
268 | /*private List<Resource> createResourcesAlternative(TempResourceDescriptionReader resourceDescriptionReader, |
---|
269 | ExecResourceDescription arcParent, ArrayList<ExecutingResourceDescription> resourcesDescriptions) { |
---|
270 | List<Resource> resources = new ArrayList<Resource>(); |
---|
271 | for(AbstractResourceDescription arc:arcParent.getChildren()) |
---|
272 | { |
---|
273 | ExecResourceDescription erc = (ExecResourceDescription)arc; |
---|
274 | Resource resource = ResourceFactory.createResource(erc); |
---|
275 | createResourcesIterative(resourceDescriptionReader, resource, erc); |
---|
276 | resources.add(resource); |
---|
277 | } |
---|
278 | |
---|
279 | return resources; |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | private LogicalResource createLogicalLayersStructureAlternative(List<Resource> resources) { |
---|
284 | LogicalResource logicalLayerWithMs = null; |
---|
285 | Stack<LogicalResource> tree = new Stack<LogicalResource>(); |
---|
286 | |
---|
287 | ManagementSystem ms = null; |
---|
288 | try { |
---|
289 | ms = new GridBrokerNew("COMPUTING_GRID_0", |
---|
290 | globalSchedulingPluginName, execTimeEstimationPlugin, null); |
---|
291 | } catch (Exception e1) { |
---|
292 | // TODO Auto-generated catch block |
---|
293 | e1.printStackTrace(); |
---|
294 | } |
---|
295 | |
---|
296 | try { |
---|
297 | logicalLayerWithMs = new LogicalResource(ms, resources); |
---|
298 | } catch (Exception e1) { |
---|
299 | // TODO Auto-generated catch block |
---|
300 | e1.printStackTrace(); |
---|
301 | } |
---|
302 | tree.push(logicalLayerWithMs); |
---|
303 | |
---|
304 | Stack<Resource> toExamine = new Stack<Resource>(); |
---|
305 | |
---|
306 | |
---|
307 | for(Resource resource:resources) |
---|
308 | toExamine.push(resource); |
---|
309 | LogicalResource ll = null; |
---|
310 | while (!toExamine.isEmpty()) { |
---|
311 | Resource resourceFromTop = toExamine.pop(); |
---|
312 | if (resourceFromTop.getType() == ResourceType.COMPUTING_RESOURCE) |
---|
313 | try { |
---|
314 | |
---|
315 | ms = new LocalManagementSystem(resourceFromTop.getName(), |
---|
316 | GssimConstants.MANAGEMENT_SYSTEM, |
---|
317 | localSchedulingPluginName, execTimeEstimationPlugin, null); |
---|
318 | |
---|
319 | LogicalResource logicalLayerWithMsChild = new LogicalResource(ms, resourceFromTop.getChildren()); |
---|
320 | tree.push(logicalLayerWithMs); |
---|
321 | logicalLayerWithMs.addChild(logicalLayerWithMsChild); |
---|
322 | // llstruct.add(new String(""), logicalLayerWithMs.get_name()); |
---|
323 | } catch (Exception e) { |
---|
324 | // TODO Auto-generated catch block |
---|
325 | e.printStackTrace(); |
---|
326 | } |
---|
327 | List<Resource> children = resourceFromTop.getChildren(); |
---|
328 | if (children == null) |
---|
329 | continue; |
---|
330 | int size = children.size(); |
---|
331 | |
---|
332 | if(resourceFromTop.getType() == ResourceType.RACK || resourceFromTop.getType() == ResourceType.COMPUTING_NODE || resourceFromTop.getType() == ResourceType.CPU || resourceFromTop.getType() == ResourceType.CORE ) |
---|
333 | { |
---|
334 | |
---|
335 | } |
---|
336 | else |
---|
337 | ll = tree.pop(); |
---|
338 | for (int j = 0; j < size; j++) { |
---|
339 | Resource resourceChild = children.get(j); |
---|
340 | |
---|
341 | if (resourceChild.getType() == ResourceType.COMPUTING_RESOURCE) |
---|
342 | { try { |
---|
343 | |
---|
344 | ms = new LocalManagementSystem(resourceChild.getName(), |
---|
345 | GssimConstants.MANAGEMENT_SYSTEM, |
---|
346 | localSchedulingPluginName, execTimeEstimationPlugin, null); |
---|
347 | |
---|
348 | LogicalResource logicalLayerWithMsChild = new LogicalResource( |
---|
349 | ms, resourceChild.getChildren()); |
---|
350 | ll.addChild(logicalLayerWithMsChild); |
---|
351 | tree.push(logicalLayerWithMsChild); |
---|
352 | /// llstruct.add(logicalLayerWithMs.get_name(), logicalLayerWithMsChild.get_name()); |
---|
353 | } catch (Exception e) { |
---|
354 | // TODO Auto-generated catch block |
---|
355 | e.printStackTrace(); |
---|
356 | } |
---|
357 | } else if (resourceChild.getType() == ResourceType.COMPUTING_NODE) |
---|
358 | { try { |
---|
359 | ms = new LocalManagementSystem(resourceChild.getName(), |
---|
360 | GssimConstants.DEFAULT_RESOURCE_MANAGER_NAME, |
---|
361 | "example.localplugin.FCFSLocalPlugin", execTimeEstimationPlugin, null); |
---|
362 | |
---|
363 | |
---|
364 | LogicalResource logicalLayerWithMsChild = new LogicalResource( |
---|
365 | ms, resourceChild.getChildren()); |
---|
366 | ll.addChild(logicalLayerWithMsChild); |
---|
367 | tree.push(logicalLayerWithMsChild); |
---|
368 | /// llstruct.add(logicalLayerWithMs.get_name(), logicalLayerWithMsChild.get_name()); |
---|
369 | } catch (Exception e) { |
---|
370 | // TODO Auto-generated catch block |
---|
371 | e.printStackTrace(); |
---|
372 | } |
---|
373 | } |
---|
374 | toExamine.push(resourceChild); |
---|
375 | } |
---|
376 | } |
---|
377 | return logicalLayerWithMs; |
---|
378 | |
---|
379 | } |
---|
380 | */ |
---|
381 | |
---|
382 | |
---|
383 | |
---|
384 | /*private ExecResourceDescription createEnvironmentDescription( |
---|
385 | TempResourceDescriptionReader resourceDescriptionReader, ComputingResource compResources) { |
---|
386 | |
---|
387 | physicalLayers = resourceDescriptionReader.resources; |
---|
388 | String headResName = physicalLayers.get(0); |
---|
389 | ExecResourceDescription arc = new ExecResourceDescription(null, compResources, ResourceType.valueOf(headResName), |
---|
390 | String.valueOf(0)); |
---|
391 | createEnvironmentDescriptionHierarchy(physicalLayers.get(1), arc, resourceDescriptionReader.layer_amount, |
---|
392 | compResources); |
---|
393 | return arc; |
---|
394 | } |
---|
395 | |
---|
396 | private void createEnvironmentDescriptionHierarchy(String layer, ExecResourceDescription arc, |
---|
397 | Map<String, String> layer_amount, ComputingResource compResources) { |
---|
398 | |
---|
399 | Stack<ExecResourceDescription> toExamine = new Stack<ExecResourceDescription>(); |
---|
400 | toExamine.push(arc); |
---|
401 | |
---|
402 | while (!toExamine.isEmpty()) { |
---|
403 | arc = toExamine.pop(); |
---|
404 | layer = getNextLayer(arc.getType().toString()); |
---|
405 | if (layer == null) |
---|
406 | continue; |
---|
407 | int amount = Integer.parseInt(layer_amount.get(layer)); |
---|
408 | ExecResourceDescription child; |
---|
409 | for (int j = 0; j < amount; j++) { |
---|
410 | child = new ExecResourceDescription(arc, compResources, ResourceType.valueOf(layer), |
---|
411 | String.valueOf(ResourceIDGenerator.getID(ResourceType.valueOf(layer)))); |
---|
412 | arc.addChildren(child); |
---|
413 | toExamine.insertElementAt(child, 0); |
---|
414 | } |
---|
415 | } |
---|
416 | } |
---|
417 | |
---|
418 | private Resource createResources(TempResourceDescriptionReader resourceDescriptionReader, |
---|
419 | ExecResourceDescription arcParent) { |
---|
420 | Resource resource = ResourceFactory.createResource(arcParent); |
---|
421 | createResourcesIterative(resourceDescriptionReader, resource, arcParent); |
---|
422 | return resource; |
---|
423 | } |
---|
424 | |
---|
425 | private void createResourcesIterative(TempResourceDescriptionReader resourceDescriptionReader, |
---|
426 | Resource resourceParent, ExecResourceDescription arcParent) { |
---|
427 | |
---|
428 | Stack<ExecResourceDescription> toExamine = new Stack<ExecResourceDescription>(); |
---|
429 | Stack<Resource> tree = new Stack<Resource>(); |
---|
430 | toExamine.push(arcParent); |
---|
431 | tree.push(resourceParent); |
---|
432 | Resource parentResource; |
---|
433 | while (!toExamine.isEmpty()) { |
---|
434 | AbstractResourceDescription node = toExamine.pop(); |
---|
435 | parentResource = tree.pop(); |
---|
436 | List<AbstractResourceDescription> children = node.getChildren(); |
---|
437 | if (children == null){ |
---|
438 | //parentResource.handleEvent(new EnergyEvent(EnergyEventType.POWER_STATE_CHANGED, null)); |
---|
439 | continue; |
---|
440 | } |
---|
441 | int size = children.size(); |
---|
442 | for (int j = 0; j < size; j++) { |
---|
443 | ExecResourceDescription arc = (ExecResourceDescription) children.get(j); |
---|
444 | Resource resource = ResourceFactory.createResource(arc); |
---|
445 | //resource.setParent(parentResource); |
---|
446 | parentResource.addChild(resource); |
---|
447 | toExamine.push(arc); |
---|
448 | tree.push(resource); |
---|
449 | } |
---|
450 | } |
---|
451 | }*/ |
---|
452 | |
---|
453 | |
---|
454 | } |
---|