Changeset 1207 for DCWoRMS/branches/coolemall/src/simulator/reader
- Timestamp:
- 11/26/13 11:56:07 (11 years ago)
- Location:
- DCWoRMS/branches/coolemall/src/simulator/reader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DCWoRMS/branches/coolemall/src/simulator/reader/EnvironmentWrapper.java
r477 r1207 18 18 public class EnvironmentWrapper { 19 19 20 Environment environment;20 private Environment environment; 21 21 22 22 public void wrap(Environment environment) { … … 53 53 public ComputingResource[] getComputingResources() throws UnknownParameter{ 54 54 55 ArrayList<ComputingResource>tab = null;56 57 55 if(environment == null) 58 56 throw new UnknownParameter("Environment parameters are not defined."); … … 61 59 return null; 62 60 63 tab= new ArrayList<ComputingResource>();61 ArrayList<ComputingResource> computingResources = new ArrayList<ComputingResource>(); 64 62 65 63 for(int i = 0; i < resources.getComputingResourceCount(); i++){ 66 64 ComputingResource compRes = resources.getComputingResource(i); 67 tab.add(compRes);65 computingResources.add(compRes); 68 66 } 69 if( tab.size() == 0)67 if(computingResources.size() == 0) 70 68 return null; 71 69 else 72 return tab.toArray(new ComputingResource[0]);70 return computingResources.toArray(new ComputingResource[0]); 73 71 } 74 72 -
DCWoRMS/branches/coolemall/src/simulator/reader/ResourceReader.java
r1042 r1207 1 1 package simulator.reader; 2 3 import gridsim.ResourceCalendar;4 2 5 3 import java.io.File; … … 19 17 import java.util.Set; 20 18 19 import org.apache.commons.io.FilenameUtils; 21 20 import org.exolab.castor.xml.MarshalException; 22 21 import org.exolab.castor.xml.ValidationException; … … 26 25 import schedframe.Parameter; 27 26 import schedframe.Parameters; 28 import schedframe. ResourceController;27 import schedframe.SimulatedEnvironment; 29 28 import schedframe.exceptions.ResourceException; 29 import schedframe.resources.CoolEmAllResourceFactory; 30 30 import schedframe.resources.Resource; 31 31 import schedframe.resources.StandardResourceType; 32 32 import schedframe.resources.computing.ComputingResource; 33 33 import schedframe.resources.computing.ResourceFactory; 34 import schedframe.resources.computing. description.AbstractResourceDescription;34 import schedframe.resources.computing.StandardResourceFactory; 35 35 import schedframe.resources.computing.description.ComputingResourceDescription; 36 import schedframe.resources.computing.description.ResourceDescription; 36 37 import schedframe.resources.units.ResourceUnit; 37 38 import schedframe.resources.units.ResourceUnitName; … … 45 46 import schemas.ManagedComputingResources; 46 47 import schemas.StringValueWithUnit; 47 import simulator. ConfigurationOptions;48 import simulator.DataCenterWorkloadSimulator; 48 49 import simulator.utils.InstanceFactory; 50 import test.DEBBTranslator.src.PLMXMLTranslator; 49 51 50 52 public class ResourceReader { 51 53 52 54 private static String COOLEMALL_RESDESC_PREFIX = "DCWORMS"; 53 protected String resDescFileName; 54 55 protected ResourceCalendar resourceCalendar; 56 protected List<Initializable> toInit = new ArrayList<Initializable>(); 57 55 private String resDescFileName; 56 private ResourceFactory resFactory; 57 58 58 private ExecutionTimeEstimationPlugin execTimeEstimationPlugin; 59 private String globalSchedulingPluginName;60 59 61 60 private Set<String> compResLayers; 62 63 public ResourceReader(ConfigurationOptions options) throws IOException { 64 65 resDescFileName = options.resdescFileName; 66 globalSchedulingPluginName = "example.globalplugin.GridFCFSRoundRobinPlugin"; 67 prepareCalendar(); 68 compResLayers = new LinkedHashSet<String>(); 69 } 70 71 public ResourceController read() throws MarshalException, ValidationException, FileNotFoundException, Exception, 61 private List<Initializable> toInit; 62 63 public ResourceReader(String resdescFileName) throws IOException { 64 65 this.resDescFileName = resdescFileName; 66 this.resFactory = new StandardResourceFactory(); 67 this.compResLayers = new LinkedHashSet<String>(); 68 this.toInit = new ArrayList<Initializable>(); 69 } 70 71 public SimulatedEnvironment read() throws MarshalException, ValidationException, FileNotFoundException, Exception, 72 72 UnknownParameter { 73 73 74 74 File file = new File(resDescFileName); 75 76 Environment env ;75 76 Environment env = null; 77 77 try{ 78 78 env = Environment.unmarshal(new FileReader(file)); 79 79 80 } catch (Exception e){ 80 File dcwormsFile = new File(file.getParent() + "/" + COOLEMALL_RESDESC_PREFIX + "_" + file.getName()); 81 env = Environment.unmarshal(new FileReader(dcwormsFile)); 82 } 83 81 //e.printStackTrace(); 82 try{ 83 File dcwormsFile = new File(FilenameUtils.getFullPath(file.getAbsolutePath()) + COOLEMALL_RESDESC_PREFIX + "_" + file.getName()); 84 env = Environment.unmarshal(new FileReader(dcwormsFile)); 85 } catch (Exception e2){ 86 PLMXMLTranslator plmxmlTranslator = new PLMXMLTranslator(); 87 String trasnlatedFileName = plmxmlTranslator.translate(new String[]{file.getAbsolutePath()}); 88 File dcwormsFile = new File(trasnlatedFileName); 89 //File dcwormsFile = new File(FilenameUtils.getFullPath(file.getAbsolutePath()) + COOLEMALL_RESDESC_PREFIX + "_" + file.getName()); 90 91 env = Environment.unmarshal(new FileReader(dcwormsFile)); 92 } 93 } 94 95 if(env.getResources().getMode().equals("CoolEmAll")){ 96 DataCenterWorkloadSimulator.MODE = "CoolEmAll"; 97 resFactory = new CoolEmAllResourceFactory(); 98 } 84 99 System.out.println("started creating environment description"); 85 100 List<ComputingResourceDescription> mainCompResDescList = createEnvironmentDescription(env); … … 94 109 System.out.println("finished creating schedulers"); 95 110 96 ResourceController rc = new ResourceController(mainScheduler, computingResources);111 SimulatedEnvironment simEnv = new SimulatedEnvironment(mainScheduler, computingResources); 97 112 Collections.sort(toInit, new ResourceTypeComparator(new ArrayList<String>(compResLayers))); 98 rc.setInitList(toInit);99 rc.setCompResLayers(compResLayers);100 return rc;113 simEnv.setInitList(toInit); 114 simEnv.setCompResLayers(compResLayers); 115 return simEnv; 101 116 } 102 117 … … 181 196 182 197 for(ComputingResourceDescription mainExecResDes : mainCompResDesList){ 183 ComputingResource mainResource = ResourceFactory.createResource(mainExecResDes);198 ComputingResource mainResource = resFactory.createComputingResource(mainExecResDes); 184 199 toExamine.push(mainExecResDes); 185 200 resStructure.push(mainResource); … … 192 207 toInit.add(parentResource); 193 208 compResLayers.add(parentResource.getType().getName()); 194 List< AbstractResourceDescription> childrenResDesc = parentResDesc.getChildren();209 List<ResourceDescription> childrenResDesc = parentResDesc.getChildren(); 195 210 if (childrenResDesc == null){ 196 211 continue; … … 200 215 ComputingResourceDescription compResDesc = (ComputingResourceDescription) childrenResDesc.get(i); 201 216 toExamine.push(compResDesc); 202 ComputingResource resource = ResourceFactory.createResource(compResDesc);217 ComputingResource resource = resFactory.createComputingResource(compResDesc); 203 218 parentResource.addChild(resource); 204 219 resStructure.push(resource); … … 254 269 } 255 270 else{ 256 SchedulingPlugin schedulingPlugin = (SchedulingPlugin) InstanceFactory.createInstance(globalSchedulingPluginName, 257 SchedulingPlugin.class); 258 TaskQueueList queues = new TaskQueueList(1); 259 TaskQueue queue = new TaskQueue(false); 260 queues.add(queue); 261 ManagedResources managedResources = new ManagedResources(mainCompResourceList, new HashMap<ResourceUnitName, List<ResourceUnit>>()); 262 mainScheduler = ResourceFactory.createScheduler(StandardResourceType.GS, "grid", schedulingPlugin , execTimeEstimationPlugin, queues, managedResources); 263 264 for(Scheduler lr: mainSchedulers){ 265 mainScheduler.addChild(lr); 266 } 267 //necessary if children list isn't initialized in Scheduler 268 //mainScheduler.init(); 271 throw new Exception("Worng schedule definition"); 269 272 } 270 273 return mainScheduler; … … 332 335 //TODO - refactor (create scheduler in 1 line) 333 336 if(schedulerDef.getClazz().equals("GridBroker")){ 334 scheduler = ResourceFactory.createScheduler(StandardResourceType.GS, "grid", schedulingPlugin, execTimeEstimationPlugin, queues, managedResources);337 scheduler = resFactory.createScheduler(StandardResourceType.GS, "grid", schedulingPlugin, execTimeEstimationPlugin, queues, managedResources); 335 338 } else { 336 scheduler = ResourceFactory.createScheduler(StandardResourceType.LS, schedulerDef.getName(), schedulingPlugin, execTimeEstimationPlugin, queues, managedResources);339 scheduler = resFactory.createScheduler(StandardResourceType.LS, schedulerDef.getName(), schedulingPlugin, execTimeEstimationPlugin, queues, managedResources); 337 340 } 338 341 return scheduler; … … 374 377 ComputingResource computingResource; 375 378 try { 376 if( resourceName.equals(mainCompRes.getName()))379 if(mainCompRes.getFullName().contains(resourceName)) 377 380 computingResource = mainCompRes; 378 381 else … … 421 424 return resourceUnits; 422 425 } 423 424 private void prepareCalendar() { 425 long seed = 11L * 13L * 17L * 19L * 23L + 1L; 426 double timeZone = 0.0; 427 double peakLoad = 0.0; // the resource load during peak hour 428 double offPeakLoad = 0.0; // the resource load during off-peak hr 429 double holidayLoad = 0.0; // the resource load during holiday 430 431 // incorporates weekends so the grid resource is on 7 days a week 432 LinkedList<Integer> Weekends = new LinkedList<Integer>(); 433 Weekends.add(java.util.Calendar.SATURDAY); 434 Weekends.add(java.util.Calendar.SUNDAY); 435 436 // incorporates holidays. However, no holidays are set in this example 437 LinkedList<Integer> Holidays = new LinkedList<Integer>(); 438 resourceCalendar = new ResourceCalendar(timeZone, peakLoad, offPeakLoad, holidayLoad, Weekends, Holidays, 439 seed); 440 } 426 441 427 442 428 class ResourceTypeComparator implements Comparator<Initializable>{
Note: See TracChangeset
for help on using the changeset viewer.