Ignore:
Timestamp:
11/26/13 11:56:07 (11 years ago)
Author:
wojtekp
Message:
 
Location:
DCWoRMS/branches/coolemall/src/simulator/reader
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/simulator/reader/EnvironmentWrapper.java

    r477 r1207  
    1818public class EnvironmentWrapper { 
    1919 
    20         Environment environment; 
     20        private Environment environment; 
    2121 
    2222        public void wrap(Environment environment) { 
     
    5353        public ComputingResource[] getComputingResources() throws UnknownParameter{ 
    5454                 
    55                 ArrayList<ComputingResource>tab = null; 
    56                  
    5755                if(environment == null) 
    5856                        throw new UnknownParameter("Environment parameters are not defined."); 
     
    6159                        return null; 
    6260                 
    63                 tab = new ArrayList<ComputingResource>(); 
     61                ArrayList<ComputingResource> computingResources = new ArrayList<ComputingResource>(); 
    6462                  
    6563                for(int i = 0; i < resources.getComputingResourceCount(); i++){ 
    6664                        ComputingResource compRes = resources.getComputingResource(i); 
    67                         tab.add(compRes); 
     65                        computingResources.add(compRes); 
    6866                } 
    69                 if(tab.size() == 0) 
     67                if(computingResources.size() == 0) 
    7068                        return null; 
    7169                else 
    72                         return tab.toArray(new ComputingResource[0]); 
     70                        return computingResources.toArray(new ComputingResource[0]); 
    7371        } 
    7472         
  • DCWoRMS/branches/coolemall/src/simulator/reader/ResourceReader.java

    r1042 r1207  
    11package simulator.reader; 
    2  
    3 import gridsim.ResourceCalendar; 
    42 
    53import java.io.File; 
     
    1917import java.util.Set; 
    2018 
     19import org.apache.commons.io.FilenameUtils; 
    2120import org.exolab.castor.xml.MarshalException; 
    2221import org.exolab.castor.xml.ValidationException; 
     
    2625import schedframe.Parameter; 
    2726import schedframe.Parameters; 
    28 import schedframe.ResourceController; 
     27import schedframe.SimulatedEnvironment; 
    2928import schedframe.exceptions.ResourceException; 
     29import schedframe.resources.CoolEmAllResourceFactory; 
    3030import schedframe.resources.Resource; 
    3131import schedframe.resources.StandardResourceType; 
    3232import schedframe.resources.computing.ComputingResource; 
    3333import schedframe.resources.computing.ResourceFactory; 
    34 import schedframe.resources.computing.description.AbstractResourceDescription; 
     34import schedframe.resources.computing.StandardResourceFactory; 
    3535import schedframe.resources.computing.description.ComputingResourceDescription; 
     36import schedframe.resources.computing.description.ResourceDescription; 
    3637import schedframe.resources.units.ResourceUnit; 
    3738import schedframe.resources.units.ResourceUnitName; 
     
    4546import schemas.ManagedComputingResources; 
    4647import schemas.StringValueWithUnit; 
    47 import simulator.ConfigurationOptions; 
     48import simulator.DataCenterWorkloadSimulator; 
    4849import simulator.utils.InstanceFactory; 
     50import test.DEBBTranslator.src.PLMXMLTranslator; 
    4951 
    5052public class ResourceReader { 
    5153         
    5254        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                 
    5858        private ExecutionTimeEstimationPlugin execTimeEstimationPlugin; 
    59         private String globalSchedulingPluginName; 
    6059         
    6160        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, 
    7272                        UnknownParameter { 
    7373 
    7474                File file = new File(resDescFileName); 
    75                  
    76                 Environment env; 
     75 
     76                Environment env = null; 
    7777                try{ 
    7878                        env = Environment.unmarshal(new FileReader(file)); 
     79                         
    7980                } 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                } 
    8499                System.out.println("started creating environment description"); 
    85100                List<ComputingResourceDescription> mainCompResDescList = createEnvironmentDescription(env); 
     
    94109                System.out.println("finished creating schedulers"); 
    95110 
    96                 ResourceController rc = new ResourceController(mainScheduler, computingResources); 
     111                SimulatedEnvironment simEnv = new SimulatedEnvironment(mainScheduler, computingResources); 
    97112                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; 
    101116        } 
    102117 
     
    181196                 
    182197                for(ComputingResourceDescription mainExecResDes : mainCompResDesList){ 
    183                         ComputingResource mainResource = ResourceFactory.createResource(mainExecResDes); 
     198                        ComputingResource mainResource = resFactory.createComputingResource(mainExecResDes); 
    184199                        toExamine.push(mainExecResDes); 
    185200                        resStructure.push(mainResource); 
     
    192207                        toInit.add(parentResource); 
    193208                        compResLayers.add(parentResource.getType().getName()); 
    194                         List<AbstractResourceDescription> childrenResDesc = parentResDesc.getChildren(); 
     209                        List<ResourceDescription> childrenResDesc = parentResDesc.getChildren(); 
    195210                        if (childrenResDesc == null){ 
    196211                                continue; 
     
    200215                                ComputingResourceDescription compResDesc = (ComputingResourceDescription) childrenResDesc.get(i); 
    201216                                toExamine.push(compResDesc); 
    202                                 ComputingResource resource = ResourceFactory.createResource(compResDesc); 
     217                                ComputingResource resource = resFactory.createComputingResource(compResDesc); 
    203218                                parentResource.addChild(resource); 
    204219                                resStructure.push(resource); 
     
    254269                } 
    255270                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"); 
    269272                } 
    270273                return mainScheduler; 
     
    332335                //TODO - refactor (create scheduler in 1 line) 
    333336                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); 
    335338                } 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); 
    337340                } 
    338341                return scheduler; 
     
    374377                                ComputingResource computingResource; 
    375378                                try { 
    376                                         if(resourceName.equals(mainCompRes.getName())) 
     379                                        if(mainCompRes.getFullName().contains(resourceName)) 
    377380                                                computingResource = mainCompRes; 
    378381                                        else 
     
    421424                return resourceUnits; 
    422425        } 
    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 
    441427         
    442428        class ResourceTypeComparator implements Comparator<Initializable>{ 
Note: See TracChangeset for help on using the changeset viewer.