package simulator; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.MissingResourceException; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import test.CoolingModelData; /** * This aim of this class is to store all the configuration options passed to * the program to steer its functionality.
* As a general contract of this class, all fields, that store a path name to a * folder will always be terminated with {@link File#separator} string. * * @author Stanislaw Szczepanowski * */ public class ConfigurationOptions { /* * ============================================================================================= * Constants describing the contents of the resource bundle file * ============================================================================================= */ /** The path to the resource description file */ public static final String RESOURCE_DESC_MODIFIER = "resdesc"; /** The create scenario mode of the simulation */ public static final String CREATE_SCENARIO_MODIFIER = "createscenario"; /** The path to the file with the tasks description */ public static final String CREATE_SCENARIO_TASK_DESC = CREATE_SCENARIO_MODIFIER + ".tasksdesc"; /** The path to the output folder for generated tasks */ public static final String CREATE_SCENARIO_OUTPUT_FOLDER = CREATE_SCENARIO_MODIFIER + ".outputfolder"; /** The name of the workload file */ public static final String CREATE_SCENARIO_WORKLOAD_FILE = CREATE_SCENARIO_MODIFIER + ".workloadfilename"; /** * Shall the files in the output directory be overwritten, if the folder is * not empty */ public static final String CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER = CREATE_SCENARIO_MODIFIER + ".overwrite_files"; /** The read scenario mode of the simulation */ public static final String READ_SCENARIO_MODIFIER = "readscenario"; /** The input folder with generated tasks */ public static final String READ_SCENARIO_INPUT_FOLDER = READ_SCENARIO_MODIFIER + ".inputfolder"; /** The input folder with application profiles */ public static final String READ_SCENARIO_APPLCIATION_PROFILES = READ_SCENARIO_MODIFIER + ".applicationProfiles"; /** The name of the workload file */ public static final String READ_SCENARIO_WORKLOAD_FILE = READ_SCENARIO_MODIFIER + ".workloadfilename"; /** The default name of a workload file */ public static final String DEFAULT_WORKLOAD_FILE_NAME = "workload.swf"; public static final String CREATE_XML_SUPPLEMENT_FILES = "createXMLSupplement"; public static final String CREATEDIAGRAMS = "creatediagrams"; public static final String CREATEDIAGRAMS_GANTT = CREATEDIAGRAMS +".gantt"; public static final String CREATEDIAGRAMS_TASKS = CREATEDIAGRAMS + ".tasks"; public static final String CREATEDIAGRAMS_TASKSWAITINGTIME = CREATEDIAGRAMS + ".taskswaitingtime"; public static final String CREATEDIAGRAMS_UTILIZATION = CREATEDIAGRAMS + ".resutilization"; public static final String CREATEDIAGRAMS_ENERGYUSAGE = CREATEDIAGRAMS + ".respowerusage"; public static final String CREATEDIAGRAMS_AIRFLOW = CREATEDIAGRAMS + ".resairflow"; public static final String CREATEDIAGRAMS_TEMPERATURE = CREATEDIAGRAMS + ".restemperature"; public static final String CREATEDIAGRAMS_RESOURCES_SCALE = CREATEDIAGRAMS_UTILIZATION + ".scale"; public static final String CREATESTATISTICS = "createstatistics"; public static final String ACCUMULATED_RESOURCES_STATISTICS = CREATESTATISTICS + ".accumulatedresources"; public static final String EXTENDED_TASKS_STATISTICS = CREATESTATISTICS + ".extendedtasks"; public static final String JOBS_STATISTICS = CREATESTATISTICS + ".jobs"; public static final String SIMULATION_STATISTICS = CREATESTATISTICS + ".simulation"; public static final String PRESSURE_DROP = "pressuredrop"; public static final String OUTLET_ROOM_AIR_TEMPERATURE = "outletroomairtemperature"; public static final String INLET_ROOM_AIR_TEMPERATURE = "inletroomairtemperature"; public static final String AMBIENT_AIR_TEMPERATURE = "ambientairtemperature"; public static final String AIR_FLOW_VOLUME = "airflowvolume"; public static final String ALPHA = "alpha"; /** * The main output folders base name */ public static final String STATS_OUTPUT_SUBFOLDER_NAME = "stats.outputfolder"; public static final String USER_DN = "user.dn"; public static final String EXPERIMENT_ID = "experiment.id"; public static final String NUMBER_OF_SIMULATIONS = "numberofsimulations"; /** * Suffix for create scenario output folder */ public String statsOutputSubfolderNameCreate = null; /** * Suffix for read scenario output folder */ public String statsOutputSubfolderNameRead = null; /* =============================================================================================== */ /** * the xml file name with resource description (according to the * HostParamSchema.xsd), e.g. simulator/schemas/ResourceDescription.xml */ public String resdescFileName = null; /** * a xml file name (according to the simulator.schemas.WorkloadSchema.xsd) * with the description of jobs and tasks to be generated */ public String workloadDescFileName = null; /** * the path to the folder, to which the generated xml job descriptions are * to be stored */ public String outputFolder = null; /** * the name of the .swf simulator.workload file into which the * simulator.workload is to be written (it will be stored in the * outputFolder folder) */ public String outputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME; /** * the path to the folder where previously generated xml jobs descriptions * are stored */ public String inputFolder = null; public String appProfilesFolder = null; /** * the name of the .swf simulator.workload file in the inputFolder folder */ public String inputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME; /** * Shows the mode of the simulator: true if it is the create scenario, false * if it is the read scenario mode */ public boolean createScenario = false; public boolean createXMLSupplement = false; /** * true if the outputFolder is not empty and shall be overwritten, false * otherwise */ public boolean overwriteFiles = false; /** * The number of simulation runs that is to be performed. Default value is 1. */ public int numberOfSimulations = 1; //default value public boolean creatediagrams_gantt = false; public boolean creatediagrams_tasks = false; public boolean creatediagrams_taskswaitingtime = false; public boolean creatediagrams_resutilization = false; public boolean creatediagrams_respowerusage = false; public boolean creatediagrams_resairflow = false; public boolean creatediagrams_restemperature = false; public double creatediagrams_resources_scale = 1; public boolean createjobsstatistics = true; public boolean createsimulationstatistics = true; public String [] resForEnergyChart; public String [] resForAirflowChart; public String [] resForTemperatureChart; public String [] resForUtilizationChart; public double pressureDrop; public double outletRoomAirTempeature; public double inletRoomAirTempeature; public double ambientAirTempeature; public double airflowVolume; public double alpha; public static CoolingModelData coolingData; /** * An empty constructor. */ protected ConfigurationOptions() { } /** * A static method used to read a resource bundle file and set all the * fields in this class according to the contents of the file * * @param resBundleFileName * the path to the resource bundle file that stores the * configuration * @return a ConfigurationOptions object with information set according to * the properties file, null if any exception occurs */ public static ConfigurationOptions getConfiguration(String resBundleFileName) { ConfigurationOptions co = new ConfigurationOptions(); File resBundleFile = new File(resBundleFileName); ResourceBundle bundle = null; try { bundle = new PropertyResourceBundle(new FileInputStream(resBundleFile)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } co.resdescFileName = bundle.getString(RESOURCE_DESC_MODIFIER); try { co.workloadDescFileName = bundle.getString(CREATE_SCENARIO_TASK_DESC); co.outputFolder = getSeparatorTerminatedPath(bundle .getString(CREATE_SCENARIO_OUTPUT_FOLDER)); File f = new File(co.outputFolder); String parent = f.getParent(); // output folder will have the same parent as the task description // file if (parent == null) { f = new File(co.workloadDescFileName); parent = f.getParent(); co.outputFolder = new File(parent, co.outputFolder) .getAbsolutePath(); co.outputFolder = getSeparatorTerminatedPath(co.outputFolder); } co.outputWorkloadFileName = bundle .getString(CREATE_SCENARIO_WORKLOAD_FILE); co.overwriteFiles = Boolean.valueOf( bundle.getString(CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER)) .booleanValue(); co.createScenario = true; // success } catch (MissingResourceException e) { co.createScenario = false; // do not create scenario } if (co.createScenario == false) { // read scenario try { co.inputFolder = getSeparatorTerminatedPath(bundle .getString(READ_SCENARIO_INPUT_FOLDER)); } catch (MissingResourceException e) { co.inputFolder = null; } try { co.appProfilesFolder = getSeparatorTerminatedPath(bundle .getString(READ_SCENARIO_APPLCIATION_PROFILES)); } catch (MissingResourceException e) { co.appProfilesFolder = null; } try { co.inputWorkloadFileName = bundle .getString(READ_SCENARIO_WORKLOAD_FILE); } catch (MissingResourceException e){ co.inputWorkloadFileName = null; } } try { if(Boolean.parseBoolean( bundle.getString(CREATE_XML_SUPPLEMENT_FILES))) co.createXMLSupplement = true; else co.createXMLSupplement = false; } catch (MissingResourceException e){ co.createXMLSupplement = false; } // create diagrams boolean createDiagrams = true; try { createDiagrams = Boolean.valueOf( bundle.getString(CREATEDIAGRAMS)).booleanValue(); } catch(MissingResourceException e){ createDiagrams = false; } try { co.creatediagrams_gantt = Boolean.valueOf( bundle.getString(CREATEDIAGRAMS_GANTT)).booleanValue(); } catch(MissingResourceException e){ co.creatediagrams_gantt = createDiagrams; } try { co.resForUtilizationChart = bundle.getString(CREATEDIAGRAMS_UTILIZATION).split(";"); if(co.resForUtilizationChart.length > 0){ co.creatediagrams_resutilization = true; } } catch(MissingResourceException e){ co.creatediagrams_resutilization = createDiagrams; } try { co.creatediagrams_resources_scale = Double.valueOf( bundle.getString(CREATEDIAGRAMS_RESOURCES_SCALE)).doubleValue(); } catch(MissingResourceException e){ co.creatediagrams_resources_scale = -1; } try { co.resForEnergyChart = bundle.getString(CREATEDIAGRAMS_ENERGYUSAGE).split(";"); if(co.resForEnergyChart.length > 0){ co.creatediagrams_respowerusage = true; } } catch(MissingResourceException e){ co.creatediagrams_respowerusage = createDiagrams; } try { co.resForAirflowChart = bundle.getString(CREATEDIAGRAMS_AIRFLOW).split(";"); if(co.resForAirflowChart.length > 0){ co.creatediagrams_resairflow = true; } } catch(MissingResourceException e){ co.creatediagrams_resairflow = createDiagrams; } try { co.resForTemperatureChart = bundle.getString(CREATEDIAGRAMS_TEMPERATURE).split(";"); if(co.resForTemperatureChart.length > 0){ co.creatediagrams_restemperature = true; } } catch(MissingResourceException e){ co.creatediagrams_restemperature = createDiagrams; } try { co.creatediagrams_tasks = Boolean.valueOf( bundle.getString(CREATEDIAGRAMS_TASKS)).booleanValue(); } catch(MissingResourceException e){ co.creatediagrams_tasks = createDiagrams; } try { co.creatediagrams_taskswaitingtime = Boolean.valueOf( bundle.getString(CREATEDIAGRAMS_TASKSWAITINGTIME)).booleanValue(); } catch(MissingResourceException e){ co.creatediagrams_taskswaitingtime = createDiagrams; } try { co.statsOutputSubfolderNameCreate = bundle.getString(STATS_OUTPUT_SUBFOLDER_NAME); co.statsOutputSubfolderNameRead = co.statsOutputSubfolderNameCreate; } catch(MissingResourceException e){ co.statsOutputSubfolderNameCreate = "stats_create"; co.statsOutputSubfolderNameRead = "stats_read"; } try { co.createjobsstatistics = Boolean.valueOf( bundle.getString(JOBS_STATISTICS)).booleanValue(); } catch(MissingResourceException e){ co.createjobsstatistics = true; } try { co.createsimulationstatistics = Boolean.valueOf( bundle.getString(SIMULATION_STATISTICS)).booleanValue(); } catch(MissingResourceException e){ co.createsimulationstatistics = true; } try { co.numberOfSimulations = Integer.valueOf(bundle.getString(NUMBER_OF_SIMULATIONS)).intValue(); } catch(MissingResourceException e){ co.numberOfSimulations = 1; } try { co.pressureDrop = Double.valueOf(bundle.getString(PRESSURE_DROP)).doubleValue(); } catch(MissingResourceException e){ co.pressureDrop = -1; } try { co.outletRoomAirTempeature = Double.valueOf(bundle.getString(OUTLET_ROOM_AIR_TEMPERATURE)).doubleValue(); } catch(MissingResourceException e){ co.outletRoomAirTempeature = -1; } try { co.inletRoomAirTempeature = Double.valueOf(bundle.getString(INLET_ROOM_AIR_TEMPERATURE)).doubleValue(); } catch(MissingResourceException e){ co.inletRoomAirTempeature = -1; } try { co.ambientAirTempeature = Double.valueOf(bundle.getString(AMBIENT_AIR_TEMPERATURE)).doubleValue(); } catch(MissingResourceException e){ co.ambientAirTempeature = -1; } try { co.airflowVolume = Double.valueOf(bundle.getString(AIR_FLOW_VOLUME)).doubleValue(); } catch(MissingResourceException e){ co.airflowVolume = -1; } try { co.alpha = Double.valueOf(bundle.getString(ALPHA)).doubleValue(); } catch(MissingResourceException e){ co.alpha = -1; } ConfigurationOptions.coolingData = new CoolingModelData(co.pressureDrop, co.outletRoomAirTempeature, co.inletRoomAirTempeature, co.ambientAirTempeature, co.airflowVolume, co.alpha); return co; } public static String getSeparatorTerminatedPath(String path) { if (path.endsWith(File.separator)) return new String(path); else { StringBuilder result = new StringBuilder(path.length() + File.separator.length()); result.append(path); result.append(File.separator); return result.toString(); } } public void setNumberOfSimulations(int numberOfSimulations) { this.numberOfSimulations = numberOfSimulations; } public int getNumberOfSimulations() { return numberOfSimulations; } public void setWorkloadDescFileName(String workloadDescFileName) { this.workloadDescFileName = workloadDescFileName; } public String getWorkloadDescFileName() { return workloadDescFileName; } }