package simulator; //import eduni.cloudsim.GSSIM; import eduni.simjava.Sim_system; import gridsim.GridSim; import gridsim.gssim.GssimConstants; import gridsim.gssim.network.ExtendedGridSim; import gridsim.gssim.network.ExtendedGridSimCore; import gridsim.gssim.network.ExtendedGridSimTags; import gridsim.gssim.resource.AbstractComputingResource; import gssim.schedframe.scheduling.plugin.grid.network.manager.Topology; import gssim.schedframe.scheduling.plugin.grid.network.utils.GSSIMNetworkReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintStream; import java.security.InvalidParameterException; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.joda.time.DateTimeUtilsExt; import org.qcg.broker.schemas.jobdesc.QcgJob; import simulator.stats.AccumulatedStatistics; import simulator.stats.implementation.GSSimStatistics; import simulator.utils.LogErrStream; import simulator.workload.WorkloadLoader; import simulator.workload.reader.archive.AbstractWAReader; import simulator.workload.reader.archive.WAReader; import simulator.workload.reader.xmlJob.Grms3XmlJobReader; import simulator.workload.reader.xmlJob.XMLJobReader; import test.rewolucja.GSSimUsersNew; import test.rewolucja.resources.physical.base.ComputingResource; import test.rewolucja.resources.physical.implementation.DataCenter; import test.rewolucja.resources.reader.ResourceReaderNew; import test.rewolucja.resources.utils.ResourceController; import cern.jet.random.Uniform; import cern.jet.random.engine.MersenneTwister64; /** * The main class of the Grid Scheduling Simulator. It has the * {@link #main(String[])} method used to invoke the program. This class also * provides second possibility to start the simulator, namely one may use the * {@link #performSimulation(ConfigurationOptions, GSSimStatisticsOld)} method. * In this case, the input parameter, describing the simulation options, must be * earlier prepared. The results of the simulation can be acquired using the * {@link #getAccumulatedStatistics()} method. * * @author Stanislaw Szczepanowski */ public class GridSchedulingSimulator { /** * The name of the simulator application */ public static final String SIMULATOR_NAME = "Grid Scheduling Simulator"; /** * GridSim statistics output filename */ public static final String GridSim_stat = "GridSim_stat.txt"; /** * SimJava2 report filename */ public static final String sim_report = "sim_report"; /** * SimJava2 trace filename */ public static final String sim_trace = "sim_trace"; /** * The name of the file with the statistics for the whole run of the * experiment */ public static final String globalStatisticsFileName = "Statistics.txt"; /** * Stores the statistical data of last run of the simulator (it may consist * of several runs of simulations) */ protected static AccumulatedStatistics accumulatedStatistics; /** * Determines the maximum fraction digits when printing floating point * values */ public static int MAXIMUM_FRACTION_DIGITS = 3; /** * The format of the numbers that will be printed */ public static NumberFormat DFAULT_NUMBER_FORMAT = NumberFormat .getInstance(); static { DFAULT_NUMBER_FORMAT.setMaximumFractionDigits(MAXIMUM_FRACTION_DIGITS); // 0,001 } protected static int MAXIMUM_NETWORK_FRACTION_DIGITS = 6; // protected static NumberFormat DFAULT_NUMBER_FORMAT = // NumberFormat.getInstance(); public static NumberFormat NETWORK_NUMBER_FORMAT = NumberFormat .getInstance(); static { // DFAULT_NUMBER_FORMAT.setMaximumFractionDigits(MAXIMUM_FRACTION_DIGITS); NETWORK_NUMBER_FORMAT .setMaximumFractionDigits(MAXIMUM_NETWORK_FRACTION_DIGITS); } private Log log = LogFactory.getLog(GridSchedulingSimulator.class); protected ArrayList wl_ = new ArrayList(); protected ArrayList brokerInterface_ = new ArrayList(); // protected ArrayListstatsOutputPath_ = new ArrayList(); protected AbstractComputingResource resources_[]; protected String statsOutputPath; protected static int simulationRunNumber = 0; /** * Default empty constructor */ public GridSchedulingSimulator() { } /** * The main method to start the simulation the accepted arguments are: * args[0] - the name of the resource bundle file with the configuration * args[1] (optional) - the number of simulations that are to be performed * (the default value is 1) * * @param args * the arguments passed to the application */ public static void main(String[] args) { GridSchedulingSimulator gssim = new GridSchedulingSimulator(); gssim.run(args); } public void run(String args[]) { System.setErr(new PrintStream(new LogErrStream(log))); String propertiesFileName = null; if (args.length == 0) { JFileChooser ch = new JFileChooser("."); FileFilter filter = new FileFilter() { @Override public boolean accept(File f) { return f.getName().endsWith(".properties") || f.isDirectory(); } @Override public String getDescription() { return "GSSim experiment file"; } }; ch.setFileFilter(filter); ch.setDialogTitle("Choose the GSSim simulation experiment file"); int result = ch.showOpenDialog(ch); if (result == JFileChooser.APPROVE_OPTION) { propertiesFileName = ch.getSelectedFile().getAbsolutePath(); } else { if (log.isFatalEnabled()) log.fatal("Resource bundle file name was not provided."); return; } } else if (args.length == 2 && "-multiuser".equals(args[0])) { runMultiuser(args[1], this); return; } else { propertiesFileName = args[0]; } ConfigurationOptions configurationOptions = ConfigurationOptions .getConfiguration(propertiesFileName); int noOfSimulations = 1; // default value is one if(configurationOptions.getNumberOfSimulations() > 1) noOfSimulations = configurationOptions.getNumberOfSimulations(); else if (args.length == 2) {// second parameter is given noOfSimulations = Integer.parseInt(args[1]); if (noOfSimulations < 1) { throw new InvalidParameterException( "Number of simulations cannot be less than 1"); } } if (log.isInfoEnabled()) log.info(":: Starting " + SIMULATOR_NAME + ". " + noOfSimulations + " simulation runs will be performed. ::"); accumulatedStatistics = new AccumulatedStatistics(noOfSimulations); File outputDir = null; try { outputDir = prepareDirecotry(configurationOptions); } catch (Exception e) { if (log.isErrorEnabled()) log.error("FAILED to create the output path", e); return; } File outputPropertiesFile = new File(outputDir, "experiment.properties"); for (int i = 0; i < noOfSimulations; ++i) { simulationRunNumber++; String simulationIdentifier = "Simulation " + (i + 1); try { // GSSimStatisticsNew simulationStatistics = new // GSSimStatisticsNew(simulationIdentifier, // configurationOptions); // accumulatedStatistics.add(simulationStatistics); if (configurationOptions.networkTopologyFileName != null) performNetworkSimulation(simulationIdentifier, configurationOptions); // run the simulation using // network extension else performSimulation(simulationIdentifier, configurationOptions); // run the simulation } catch (Exception e) { if (log.isErrorEnabled()) log.error("ERROR in simulation run \"" + simulationIdentifier + "\":", e); break; } } /* * String outputPath; String outputFile = globalStatisticsFileName; if * (configurationOptions.createScenario) { outputPath = * configurationOptions.outputFolder + * configurationOptions.statsOutputSubfolderNameCreate + File.separator; * } else { String prefix = null; if(configurationOptions.inputFolder != * null) { prefix = configurationOptions.inputFolder; } else * if(configurationOptions.inputWorkloadFileName != null){ prefix = new * File(configurationOptions.inputWorkloadFileName).getParent(); } else * { prefix = System.getProperty("user.dir"); } * * * outputPath = prefix +"/"+ * configurationOptions.statsOutputSubfolderNameRerad + File.separator; * } * * if(log.isInfoEnabled()) log.info(":: Creating statistics ... "); * * //clean all gantts /*File file = new File(outputPath); File * fileList[] = file.listFiles(); for(int i = 0; i < fileList.length; * i++){ File tmpFile = fileList[i]; String name = tmpFile.getName(); * if(name.length() > 4){ String subName = name.substring(0, 5); * if(subName.compareTo("Gantt") == 0){ tmpFile.delete(); } } } */ //accumulatedStatistics.saveStatistics(); if (log.isInfoEnabled()) log.info("Done :: " + SIMULATOR_NAME + " has finished " + noOfSimulations + " simulation runs ::"); // fixed name with z in front to be last file in alphabetical order System.out.flush(); System.err.flush(); try { copyFile(new File(propertiesFileName), outputPropertiesFile); } catch (IOException e) { log .error("IO exception occured during copying properties file to output path"); } FilenameFilter fileFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return (!name.endsWith(".sjg") && !name.endsWith(".png")); } }; File tarArchive = new File(outputDir, "results.tar"); File networkTopologyFile = (configurationOptions.networkTopologyFileName == null) ? null : new File(configurationOptions.networkTopologyFileName); try { createResultsTar(tarArchive, outputDir.listFiles(fileFilter), networkTopologyFile); } catch (IOException e) { log.error("IOException occured while creating archive file", e); } } public void runMultiuser(String rootDirPath, GridSchedulingSimulator gssim) { /* * System.out.println("************ Runing in multiuser mode ************" * ); File mainDirectory = null; mainDirectory = new File(rootDirPath); * if(!mainDirectory.exists() || !mainDirectory.isDirectory()) throw new * RuntimeException("Second argument must be a root directory name."); * * java.io.FileFilter dirFilter = new WorkloadDirectoryFilter(); * java.io.FileFilter propertiesFilter = new PropertiesFileFilter(); * * File workloadDirs[] = mainDirectory.listFiles(dirFilter); File * propertiesFile[] = null; File dir; * * File localResProperiesFiles[] = * mainDirectory.listFiles(propertiesFilter); ConfigurationOptions * configurationOptions = * ConfigurationOptions.getConfiguration(localResProperiesFiles * [0].getAbsolutePath()); * * //BEGIN: Initializing the GridSim: * * // use simulation start time from one, specific swf file String * fileName = configurationOptions.inputWorkloadFileName; Date date = * null; try { date = AbstractSWFJobReader.getStartTime(fileName); } * catch (IOException e1) { date = new Date(0l); } catch * (NoSuchCommentException e1) { date = new Date(0l); } * * Calendar calendar = Calendar.getInstance(); calendar.setTime(date); * * boolean traceFlag = true; // means: trace GridSim events/activities * * String[] excludeFromFile = {""}, excludeFromProcessing = {""}; String * reportFileName = GssConstants.BrokerInterfaceEntityName+"_0"; //FIXME * solve this issue more elegant - this is a result of many brokers in * simulation * * GridSim.init(workloadDirs.length, calendar, traceFlag, * excludeFromFile, excludeFromProcessing, reportFileName); * * //END: Initializing the GridSim: * * VirtualClock vClock = VirtualClock.initialize(); * * //Startup of the random number generators must be set up with a * random seed that is greater than zero //if seed is not given then all * consecutive simulations are the same //if seed < 0 then the random * numbers are equal to zero Uniform uniform = new Uniform(new * MersenneTwister64(new Date())); //seed should be > 0 and fits to int * size (which is also important) long seed = uniform.nextLongFromTo(1, * Integer.MAX_VALUE); assert seed > 0 && seed <= Integer.MAX_VALUE : * "Initial seed is <= 0, what is improper"; Sim_system.set_seed(seed); * * accumulatedStatistics = new AccumulatedStatistics(); try { * * // wczytanie i zbudowanie opisu swiata * * ResourceGeneratorInterface hostDescGenerator = new ResourceGenerator( * configurationOptions.forecastFinishTimePluginName, * configurationOptions.localAllocPolicyPluginName); * hostDescGenerator_.add(hostDescGenerator); * hostDescGenerator.readConfigurationHostsDescriptionXMLFile( * configurationOptions.resdescFileName); * * hostDescGenerator.createResources(vClock); resources_ = * hostDescGenerator.getCreatedResources(); * System.out.println("localResources: " * +localResProperiesFiles[0].getAbsolutePath()); * * // wczytanie i przygotowanie opisu zadan for(int i = 0; i < * workloadDirs.length; i++){ dir = workloadDirs[i]; propertiesFile = * dir.listFiles(propertiesFilter); if(propertiesFile.length == 0) throw * new RuntimeException("No properties file in "+dir.getPath()); * if(propertiesFile.length > 1) throw new * RuntimeException("Leave only one properties file in "+dir.getPath()); * * System.out.println(propertiesFile[0].getAbsolutePath()); * configurationOptions = * ConfigurationOptions.getConfiguration(propertiesFile * [0].getAbsolutePath()); GSSimStatistics simulationStatistics = new * GSSimStatistics("stats_for_"+propertiesFile[0].getName()); * simulationStatistics_.add(simulationStatistics); * accumulatedStatistics.add(simulationStatistics); * gssim.prepareSimulation(configurationOptions, simulationStatistics, * vClock); * * } * * * gssim.runMultiuserSimulation(); * * } catch (Exception e) { e.printStackTrace(); } */ } public void prepareSimulation(ConfigurationOptions options, GSSimStatistics simulationStatistics/* , VirtualClock vClock */) throws Exception { /* * System.out.println("\n:: " + * simulationStatistics.getSimulationIdentifier() + "\" ::"); * System.out.print(":: In the the mode of "); String statsOutputPath = * null; if (options.createScenario) { File outputFolderFile = new * File(options.outputFolder); if (! outputFolderFile.exists()) { if (! * outputFolderFile.mkdirs()) throw new * IOException("Cannot create the output path: " * +statsOutputPath+". Cause: "); } * * System.out.println("CREATING SCENARIO ::"); statsOutputPath = * options.outputFolder + STATS_OUTPUT_SUBFOLDER_NAME_CREATE; } else { * System.out.println("READING SCENARIO ::"); statsOutputPath = * options.inputFolder + STATS_OUTPUT_SUBFOLDER_NAME_READ; } * statsOutputPath += File.separator; * statsOutputPath_.add(statsOutputPath); * * System.out.println(); * * Sim_system.set_trace_detail(true, true, true); * Sim_system.generate_graphs(statsOutputPath + * GssConstants.GraphsFileName); * Sim_system.set_trace_level(Integer.MAX_VALUE); * * // reseting the gridlet numbering // * GssConstants.resetGridletIDSequencer(); * * JobGenerator jobDescGenerator = new JobGenerator_GRMS3(); if * (options.createScenario) { * jobDescGenerator.generateWorkload(options.workloadDescFileName, * options.outputFolder, options.overwriteFiles, * options.outputWorkloadFileName); * jobDescGenerator.performPostprocessing(options.resdescFileName, * options.outputFolder, options.outputWorkloadFileName); * options.inputFolder = options.outputFolder; * options.inputWorkloadFileName = options.outputWorkloadFileName; } * * if(options.createXMLSupplement){ * jobDescGenerator.generateXMLSupplement(options.workloadDescFileName, * options.inputWorkloadFileName, options.outputFolder, * options.overwriteFiles); } * * jobDescGenerator.loadWorkload(options.inputFolder, * options.inputWorkloadFileName); * * * if (!jobDescGenerator.isReady()) { System.err.println( * "Error: xml job genereator is not fully initialized. The simulation will terminate." * ); System.exit(1); } * * * //creating the broker interface entity GridScheduler brokerInterface * = new GridScheduler(GssConstants.BrokerInterfaceEntityName + "_" + * brokerInterface_.size(), options, jobDescGenerator.getJobCount(), * jobDescGenerator.getTaskCount()); * * GSSimUsers wl = new * GSSimUsers("GridUsers"+wl_.size(), * GssConstants.BrokerInterfaceEntityName + "_" + * brokerInterface_.size(), jobDescGenerator); * * for(int i = 0; i < resources_.length; i++){ * brokerInterface.addToResourceSubset(resources_[i].get_id()); } * * wl_.add(wl); brokerInterface_.add(brokerInterface); * * //create the output folder File statsOutputPathFile = new * File(statsOutputPath); if (! statsOutputPathFile.exists()) { if (! * statsOutputPathFile.mkdirs()) throw new * IOException("Cannot create the output (stats) path: " * +statsOutputPath+". Cause: "); } */ } /** * Starts a single simulation run. * * @param options * the configuration options according to which the simulation is * to be performed * @param simulationStatistics * the statistics object that is to be filled after the * simulation run * @throws Exception * any exception that may occur */ public void performSimulation(String simulationIdentifier, ConfigurationOptions options) throws Exception { // Startup of the random number generators must be set up with a random // seed that is greater than zero // if seed is not given then all consecutive simulations are the same // if seed < 0 then the random numbers are equal to zero Uniform uniform = new Uniform(new MersenneTwister64(new Date())); // seed should be > 0 and fits to int size (which is also important) long seed = uniform.nextLongFromTo(1, Integer.MAX_VALUE); if (log.isDebugEnabled()) log.debug("Shuffled initial seed: " + seed); assert seed > 0 && seed <= Integer.MAX_VALUE : "Initial seed is <= 0, what is improper"; Sim_system.set_seed(seed); long startSimulation = System.currentTimeMillis(); if (log.isInfoEnabled()) { log.info(":: Starting simulation run: \"" + simulationIdentifier + "\" ::"); log.info(":: In the the mode of "); } /* * String statsOutputPath = null; if (options.createScenario) { File * outputFolderFile = new File(options.outputFolder); if (! * outputFolderFile.exists()) { if (! outputFolderFile.mkdirs()) throw * new * IOException("Cannot create the output path: "+statsOutputPath+". Cause: " * ); } * * if(log.isInfoEnabled()) log.info("CREATING SCENARIO ::"); * statsOutputPath = options.outputFolder + * options.statsOutputSubfolderNameCreate; } else { * if(log.isInfoEnabled()) log.info("READING SCENARIO ::"); String * prefix = null; if(options.inputFolder != null){ prefix = * options.inputFolder; }else if(options.inputWorkloadFileName != null){ * prefix = new File(options.inputWorkloadFileName).getParent(); }else{ * prefix = System.getProperty("user.dir"); } statsOutputPath = prefix + * "/" + options.statsOutputSubfolderNameRerad; } statsOutputPath += * File.separator; */ Sim_system.set_trace_detail(true, true, true); Sim_system.generate_graphs(statsOutputPath + GssimConstants.GraphsFileName); Sim_system.set_trace_level(Integer.MAX_VALUE); XMLJobReader xmlJobReader = null; WAReader swfReader = null; String wlFileName = options.inputWorkloadFileName; if (options.inputFolder != null) { File f = null; if (options.inputTar != null) { f = new File(options.inputFolder + File.separator + options.inputTar); } else { f = new File(options.inputFolder); } xmlJobReader = new Grms3XmlJobReader(f); wlFileName = options.inputFolder + File.separator + options.inputWorkloadFileName; } swfReader = AbstractWAReader.getInstace(wlFileName); WorkloadLoader workload = new WorkloadLoader(xmlJobReader, swfReader); workload.load(); /* * if (options.createScenario) { * jobDescGenerator.generateWorkload(options.workloadDescFileName, * options.outputFolder, options.overwriteFiles, * options.outputWorkloadFileName); * jobDescGenerator.performPostprocessing(options.resdescFileName, * options.outputFolder, options.outputWorkloadFileName); * options.inputFolder = options.outputFolder; * options.inputWorkloadFileName = options.outputWorkloadFileName; } * * if(options.createXMLSupplement){ * jobDescGenerator.generateXMLSupplement(options.workloadDescFileName, * options.inputWorkloadFileName, options.outputFolder, * options.overwriteFiles); } * * jobDescGenerator.loadWorkload(options.inputFolder, * options.inputWorkloadFileName); * * * if (!jobDescGenerator.isReady()) { System.err.println( * "Error: xml job genereator is not fully initialized. The simulation will terminate." * ); System.exit(1); } */ // BEGIN: Initializing the GridSim: int numUser = 1; // the number of users in the experiment simulation // (default 1) // Date date = jobDescGenerator.getSimulationStartTime(); Date date = workload.getSimulationStartTime(); Calendar calendar = Calendar.getInstance(); if (date == null) calendar.setTimeInMillis(0L); else calendar.setTime(date); boolean traceFlag = true; // means: trace GridSim events/activities String[] excludeFromFile = { "" }, excludeFromProcessing = { "" }; String reportFileName = GssimConstants.BrokerInterfaceEntityName; //GSSIM.init(numUser, calendar, traceFlag); GridSim.init(numUser, calendar, traceFlag, excludeFromFile, excludeFromProcessing, "COMPUTING_GRID_0"); // END: Initializing the GridSim: DateTimeUtilsExt.initVirtualTimeAccess(calendar); // creating the broker interface entity /*GridBroker brokerInterface = new GridBroker( GssimConstants.BrokerInterfaceEntityName, options, workload .getJobCount(), workload.getTaskCount());*/ // creating the resources only after GridSim had been initialized //AbstractComputingResource resources[] = null; ResourceReaderNew resourceReader = new ResourceReaderNew( options); //resources = new AbstractComputingResource[resourceReader // .getNoOfResources()]; //AbstractComputingResource resource = null; //int i = 0; //while ((resource = resourceReader.read()) != null // && i < resources.length) { // resources[i++] = resource; //} ResourceController rc = resourceReader.read(); GSSimUsersNew wl = new GSSimUsersNew("GridUsers", rc.getResources().getName(), workload); // create the output folder /* * File statsOutputPathFile = new File(statsOutputPath); if (! * statsOutputPathFile.exists()) { if (! statsOutputPathFile.mkdirs()) * throw new * IOException("Cannot create the output (stats) path: "+statsOutputPath * +". Cause: "); } */ GridSim.startGridSimulation(); //GSSIM.startSimulation(); long stopSimulation = System.currentTimeMillis(); GSSimStatistics stats = new GSSimStatistics(simulationIdentifier, options, wl, statsOutputPath, rc); accumulatedStatistics.add(stats); if (log.isInfoEnabled()) log.info("Generating statistics..."); stats.generateStatistics(); // Fill the statistical data // simulationStatistics.setGenPEdiagram(false); // simulationStatistics.gatherStatistics(wl, brokerInterface, // resources); // Print history /* * simulationStatistics.printTasksInformation(new PrintStream( new * FileOutputStream( new File(statsOutputPath, * GssimConstants.tasksStatisitcsOutputFileName))), * options.printHistory); * simulationStatistics.printResourcesInformation(new PrintStream( new * FileOutputStream( new File(statsOutputPath, * GssimConstants.resourceStatisticsOutputFileName)))); */ long duration = (stopSimulation - startSimulation) / 1000; if (log.isInfoEnabled()) log.info("The simulation run took " + duration + " seconds"); // Move output files to the output directory String name = GridSim_stat; String fileName = statsOutputPath + name; if (!moveFile(name, fileName)) if (log.isErrorEnabled()) log.error("Error moving file " + fileName); name = "sim_report"; fileName = statsOutputPath + name; if (!moveFile(name, fileName)) if (log.isErrorEnabled()) log.error("Error moving file " + fileName); name = "sim_trace"; fileName = statsOutputPath + name; if (!moveFile(name, fileName)) if (log.isErrorEnabled()) log.error("Error moving file " + fileName); // if necessary generate gifs from sjvg - need to rewrite the SJVG // classes for public methods if (log.isInfoEnabled()) log.info(":: Finished simulation run: \"" + simulationIdentifier + "\" ::"); System.out.flush(); System.err.flush(); } /** * Starts a single network simulation run. * * @param options * the configuration options according to which the simulation is * to be performed * @param simulationStatistics * the statistics object that is to be filled after the * simulation run * @throws Exception * any exception that may occur */ public void performNetworkSimulation(String simulationIdentifier, ConfigurationOptions options) throws Exception { // Startup of the random number generators must be set up with a random // seed that is greater than zero // if seed is not given then all consecutive simulations are the same // if seed < 0 then the random numbers are equal to zero Uniform uniform = new Uniform(new MersenneTwister64(new Date())); // seed should be > 0 and fits to int size (which is also important) long seed = uniform.nextLongFromTo(1, Integer.MAX_VALUE); if (log.isDebugEnabled()) log.debug("Shuffled initial seed: " + seed); assert seed > 0 && seed <= Integer.MAX_VALUE : "Initial seed is <= 0, what is improper"; Sim_system.set_seed(seed); long startSimulation = System.currentTimeMillis(); if (log.isInfoEnabled()) { log.info(":: Starting simulation run: \"" + simulationIdentifier + "\" ::"); log.info(":: In the the mode of "); } /* * String statsOutputPath = null; if (options.createScenario) { File * outputFolderFile = new File(options.outputFolder); if (! * outputFolderFile.exists()) { if (! outputFolderFile.mkdirs()) throw * new * IOException("Cannot create the output path: "+statsOutputPath+". Cause: " * ); } * * if(log.isInfoEnabled()) log.info("CREATING SCENARIO ::"); * statsOutputPath = options.outputFolder + * options.statsOutputSubfolderNameCreate; } else { * if(log.isInfoEnabled()) log.info("READING SCENARIO ::"); String * prefix = null; if(options.inputFolder != null){ prefix = * options.inputFolder; }else if(options.inputWorkloadFileName != null){ * prefix = new File(options.inputWorkloadFileName).getParent(); }else{ * prefix = System.getProperty("user.dir"); } statsOutputPath = prefix + * "/" + options.statsOutputSubfolderNameRerad; } statsOutputPath += * File.separator; */ Sim_system.set_trace_detail(true, true, true); Sim_system.generate_graphs(statsOutputPath + GssimConstants.GraphsFileName); Sim_system.set_trace_level(Integer.MAX_VALUE); XMLJobReader xmlJobReader = null; WAReader swfReader = null; String wlFileName = options.inputWorkloadFileName; if (options.inputFolder != null) { File f = new File(options.inputFolder); xmlJobReader = new Grms3XmlJobReader(f); if (f.isDirectory()) { wlFileName = options.inputFolder + File.separator + options.inputWorkloadFileName; } } swfReader = AbstractWAReader.getInstace(wlFileName); WorkloadLoader workload = new WorkloadLoader(xmlJobReader, swfReader); workload.load(); /* * if (options.createScenario) { * jobDescGenerator.generateWorkload(options.workloadDescFileName, * options.outputFolder, options.overwriteFiles, * options.outputWorkloadFileName); * jobDescGenerator.performPostprocessing(options.resdescFileName, * options.outputFolder, options.outputWorkloadFileName); * options.inputFolder = options.outputFolder; * options.inputWorkloadFileName = options.outputWorkloadFileName; } * * if(options.createXMLSupplement){ * jobDescGenerator.generateXMLSupplement(options.workloadDescFileName, * options.inputWorkloadFileName, options.outputFolder, * options.overwriteFiles); } * * jobDescGenerator.loadWorkload(options.inputFolder, * options.inputWorkloadFileName); * * * if (!jobDescGenerator.isReady()) { System.err.println( * "Error: xml job genereator is not fully initialized. The simulation will terminate." * ); System.exit(1); } */ // BEGIN: Initializing the GridSim: int numUser = 1; // the number of users in the experiment simulation // (default 1) // Date date = jobDescGenerator.getSimulationStartTime(); Date date = workload.getSimulationStartTime(); Calendar calendar = Calendar.getInstance(); if (date == null) calendar.setTimeInMillis(0L); else calendar.setTime(date); boolean traceFlag = true; // means: trace GridSim events/activities String[] excludeFromFile = { "" }, excludeFromProcessing = { "" }; String reportFileName = GssimConstants.BrokerInterfaceEntityName; ExtendedGridSim .initNetworkType(ExtendedGridSimTags.RESERVATION_NET_FLOW_LEVEL); ExtendedGridSimCore .initNetworkType(ExtendedGridSimTags.RESERVATION_NET_FLOW_LEVEL); //ExtendedGridSim.init(numUser, calendar, traceFlag, excludeFromFile, // excludeFromProcessing, reportFileName); ExtendedGridSim.init(numUser, calendar, traceFlag, excludeFromFile, excludeFromProcessing, "COMPUTING_GRID_0"); // END: Initializing the GridSim: DateTimeUtilsExt.initVirtualTimeAccess(calendar); // creating the network broker interface entity /* * NetworkGridBroker brokerInterface = new * NetworkGridBroker(GssimConstants.BrokerInterfaceEntityName, new * GSSIMFlowLink(GssimConstants.BrokerInterfaceEntityName + "_link", * Double .parseDouble("1")* 1000000, Double.parseDouble("300"), * Integer.parseInt("100000")), options, workload.getJobCount(), * workload.getTaskCount()); */ // creating networktopology Topology topology = GSSIMNetworkReader .createNetworkTopology(options.networkTopologyFileName); // creating the network broker interface entity /*NetworkGridBroker brokerInterface = new NetworkGridBroker( GssimConstants.BrokerInterfaceEntityName, ((GSSIMFlowLink) GSSIMNetworkReader.getBrokerLinkMapping().get( GssimConstants.BrokerInterfaceEntityName)), topology, options, workload.getJobCount(), workload.getTaskCount()); */ AbstractComputingResource resources[] = null; /* ResourceReader resourceReader = new ResourceReader( options); resources = new AbstractComputingResource[resourceReader .getNoOfResources()]; AbstractComputingResource resource = null; int i = 0; //while ((resource = resourceReader.read()) != null // && i < resources.length) { // resources[i++] = resource; //} AbstractResource res = resourceReader.close(); GSSimUsersNew wl = new GSSimUsersNew("GridUsers", res.getResourceName(), workload); */ GSSIMNetworkReader.createResourceConnections(); /* * brokerInterface.networkManager.getTopology().printLinks(); * brokerInterface.networkManager.getTopology().printResourcesNames(); * brokerInterface.networkManager.getTopology().printRouters(); * brokerInterface.networkManager.getTopology().printUsers(); * List list= * brokerInterface.networkManager.getAbstractTopology().getLinks(); * Iterator it=list.iterator(); while(it.hasNext()){ DataLink l = * (DataLink)it.next(); * System.out.println(l.getId()+";"+l.getEndpoint1() * .getId()+";"+l.getEndpoint2().getId()); } List list2= * brokerInterface.networkManager.getAbstractTopology().getNodes(); * Iterator it2=list2.iterator(); while(it2.hasNext()){ Node n = * (Node)it2.next(); * System.out.println(n.getId()+";"+n.getType().toString()); } */ // create the output folder /* * File statsOutputPathFile = new File(statsOutputPath); if (! * statsOutputPathFile.exists()) { if (! statsOutputPathFile.mkdirs()) * throw new * IOException("Cannot create the output (stats) path: "+statsOutputPath * +". Cause: "); } */ ExtendedGridSim.startGridSimulation(); long stopSimulation = System.currentTimeMillis(); /*GSSimStatistics stats = new GSSimStatistics(simulationIdentifier, options, wl, null, resources, null, statsOutputPath); accumulatedStatistics.add(stats); if (log.isInfoEnabled()) log.info("Generating statistics..."); stats.generateStatistics();*/ // Fill the statistical data // GSSimStatistics simulationStatistics = new GSSimStatistics("old", // options); // simulationStatistics.setGenPEdiagram(false); // simulationStatistics.gatherStatistics(wl, brokerInterface, // resources); // Print history /* * simulationStatistics.printTasksInformation(new PrintStream( new * FileOutputStream( new File(statsOutputPath, * GssimConstants.tasksStatisitcsOutputFileName))), * options.printHistory); * simulationStatistics.printResourcesInformation(new PrintStream( new * FileOutputStream( new File(statsOutputPath, * GssimConstants.resourceStatisticsOutputFileName)))); */ long duration = (stopSimulation - startSimulation) / 1000; if (log.isInfoEnabled()) log.info("The simulation run took " + duration + " seconds"); // Move output files to the output directory String name = GridSim_stat; String fileName = statsOutputPath + name; if (!moveFile(name, fileName)) if (log.isErrorEnabled()) log.error("Error moving file " + fileName); name = "sim_report"; fileName = statsOutputPath + name; if (!moveFile(name, fileName)) if (log.isErrorEnabled()) log.error("Error moving file " + fileName); name = "sim_trace"; fileName = statsOutputPath + name; if (!moveFile(name, fileName)) if (log.isErrorEnabled()) log.error("Error moving file " + fileName); // if necessary generate gifs from sjvg - need to rewrite the SJVG // classes for public methods if (log.isInfoEnabled()) log.info(":: Finished simulation run: \"" + simulationIdentifier + "\" ::"); System.out.flush(); System.err.flush(); } /** * Static method to move a file from given "from" location to "to" location * * @param from * from location * @param to * to location * @return true if the operation succeeded, false otherwise */ public static boolean moveFile(String from, String to) { File fromFile = new File(from); File toFile = new File(to); if (toFile.exists()) { if (!toFile.delete()) return false; } if (!fromFile.renameTo(toFile)) { return false; } return true; } /** * Removes the given directory no matter if it is empty or non empty. If the * given parameter represents a file, it is not deleted. See the description * of the return statement. * * @param dirPath * the file representing the directory to be deleted. * @return true, if the given directory with all its contents have been * remove; false if deletion of any of files ended with error (all * other files are possibly also deleted) */ public static boolean deleteDirectory(File dirPath) { if (dirPath.exists() && dirPath.isDirectory()) { boolean result = true; File[] files = dirPath.listFiles(); for (File file : files) { if (file.isFile()) result |= file.delete(); else result |= deleteDirectory(file); } result |= dirPath.delete(); return result; } return false; // it is not a directory } /** * Returns the accumulated simulation statistics from the last run of the * simulator * * @return the accumulated simulation statistics from the last run of the * simulator */ public static AccumulatedStatistics getAccumulatedStatistics() { return accumulatedStatistics; } protected class WorkloadDirectoryFilter implements java.io.FileFilter { public boolean accept(File file) { if (file.isDirectory() && file.getName().startsWith("workload")) return true; else return false; } } protected class PropertiesFileFilter implements java.io.FileFilter { public boolean accept(File file) { if (file.isFile() && file.getName().endsWith(".properties")) return true; else return false; } } public File prepareDirecotry(ConfigurationOptions options) throws Exception { // String statsOutputPath = null; if (options.createScenario) { File outputFolderFile = new File(options.outputFolder); if (!outputFolderFile.exists()) { if (!outputFolderFile.mkdirs()) throw new IOException("Cannot create the output path: " + statsOutputPath + ". Cause: "); } if (log.isInfoEnabled()) log.info("CREATING SCENARIO ::"); statsOutputPath = options.outputFolder + options.statsOutputSubfolderNameCreate; } else { if (log.isInfoEnabled()) log.info("READING SCENARIO ::"); String prefix = null; if (options.inputFolder != null) { prefix = options.inputFolder; } else if (options.inputWorkloadFileName != null) { prefix = new File(options.inputWorkloadFileName).getParent(); } else { prefix = System.getProperty("user.dir"); } statsOutputPath = prefix + File.separator + options.statsOutputSubfolderNameRerad; } statsOutputPath += File.separator; // create the output folder File statsOutputPathFile = new File(statsOutputPath); if (!statsOutputPathFile.exists()) { if (!statsOutputPathFile.mkdirs()) throw new IOException("Cannot create the output (stats) path: " + statsOutputPath + ". Cause: "); } File folder = new File(statsOutputPath); File fileList[] = folder.listFiles(); for (int i = 0; i < fileList.length; i++) { File tmpFile = fileList[i]; String name = tmpFile.getName(); if (name.length() > 4) { String subName = name.substring(0, 5); if (subName.compareTo("Chart") == 0 || subName.compareTo("Stats") == 0) { tmpFile.delete(); } } } return statsOutputPathFile; } public void createResultsTar(File outputTar, File[] files, File networkFile) throws IOException { if (!outputTar.exists()) outputTar.createNewFile(); TarArchiveOutputStream tos = null; try { tos = new TarArchiveOutputStream(new FileOutputStream(outputTar)); for (File file : files) { if (file.exists()) addEntryToArchive(tos, file); else log.warn("File " + file.getName() + " does not exist"); } if (networkFile != null) addEntryWithParentsToArchive(tos, networkFile); } catch (FileNotFoundException e1) { log.error("Archive output file was not found", e1); } finally { if (tos != null) try { tos.close(); } catch (IOException e) { log.error("IOException occured while " + "closing tar archive", e); } } } private void addEntryWithParentsToArchive(TarArchiveOutputStream tos, File file) { File parent = file.getParentFile(); if (parent != null) addEntryWithParentsToArchive(tos, parent); String filePath = file.isDirectory() ? file.getPath() + File.separator : file.getPath(); addEntryToArchive(tos, file, filePath); } private void addEntryToArchive(TarArchiveOutputStream tos, File file) { addEntryToArchive(tos, file, file.getName()); } private void addEntryToArchive(TarArchiveOutputStream tos, File file, String name) { FileInputStream fis = null; TarArchiveEntry in = new TarArchiveEntry(name); in.setModTime(file.lastModified()); if (!file.isDirectory()) in.setSize(file.length()); try { tos.putArchiveEntry(in); if (!file.isDirectory()) { byte[] b = new byte[(int) file.length()]; fis = new FileInputStream(file); while (fis.read(b) > 0) { tos.write(b); } } } catch (FileNotFoundException e) { log.error("File " + file.getName() + " was not found", e); } catch (IOException e) { log.error("IOException occured while adding file " + file.getName() + " to archive"); } finally { try { if (fis != null) fis.close(); tos.closeArchiveEntry(); } catch (IOException e) { log.error("IOException occured while closing " + "archive input stream or entry", e); } } } public void copyFile(File inputFile, File outputFile) throws IOException { FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); } public static int getSimulationRunNumber(){ return simulationRunNumber; } }