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 java.util.logging.FileHandler;
/**
* 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";
public static final String READ_SCENARIO_INPUT_TAR = READ_SCENARIO_MODIFIER+ ".tar";
/** The name of the workload file */
public static final String READ_SCENARIO_WORKLOAD_FILE = READ_SCENARIO_MODIFIER
+ ".workloadfilename";
/** Shall a detailed history be printed */
public static final String PRINT_HISTORY_MODIFIER = "printhistory";
/** 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 PROVIDER_LIST_FILE = "in/provider.list";
/** Network topology file path */
public static final String NETWORK_TOPOLOGY_FILE_MODIFIER = "networktopologyfilename";
public static final String CREATEDIAGRAMS = "creatediagrams";
public static final String CREATEDIAGRAMS_GANTT = CREATEDIAGRAMS +".gantt";
public static final String CREATEDIAGRAMS_UTILIZATION = CREATEDIAGRAMS + ".utilization";
public static final String CREATEDIAGRAMS_ENERGYUSAGE = CREATEDIAGRAMS + ".energyusage";
public static final String CREATEDIAGRAMS_RESOURCES_SCALE = CREATEDIAGRAMS_UTILIZATION + ".scale";
public static final String CREATEDIAGRAMS_TASKS = CREATEDIAGRAMS + ".tasks";
public static final String CREATEDIAGRAMS_TASKSWAITINGTIME = CREATEDIAGRAMS + ".taskswaitingtime";
public static final String CREATEDIAGRAMS_RESERVATIONS = CREATEDIAGRAMS + ".reservations";
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 GRIDLET_HISTORY_STATISTICS = CREATESTATISTICS + ".gridlethistory";
public static final String JOBS_STATISTICS = CREATESTATISTICS + ".jobs";
public static final String SIMULATION_STATISTICS = CREATESTATISTICS + ".simulation";
public static final String FORMAT_STATISTICS_OUTPUT = CREATESTATISTICS + ".formatoutput";
/**
* 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 statsOutputSubfolderNameRerad = null;
/* =============================================================================================== */
public String providerListFile = 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 inputTar = null;
/**
* the name of the .swf simulator.workload file in the inputFolder folder
*/
public String inputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME;
/**
* a txt file name with topology description
*/
public String networkTopologyFileName = null;
/**
* 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;
/**
* true if the history files are to be generated (makes the simulation
* slower)
*/
public boolean printHistory = false;
/**
* The number of simulation runs that is to be performed. Default value is 1
.
*/
public int numberOfSimulations = 1; //default value
public boolean creatediagrams_processors = true;
public boolean creatediagrams_reservations = true;
public boolean creatediagrams_resources = true;
public boolean creatediagrams_energyusage = true;
public boolean creatediagrams_tasks = true;
public boolean creatediagrams_taskswaitingtime = true;
public double creatediagrams_resources_scale = 1;
public boolean createaccumulatedresourcesstatistics = true;
public boolean createextendedtasksstatistics = true;
public boolean creategridlethistorystatistics = true;
public boolean createjobsstatistics = true;
public boolean createsimulationstatistics = true;
public boolean formatstatisticsoutput = false;
public static final String ENV_DESC_MODIFIER = "envdesc";
public String envDescFileName = null;
/**
* 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.envDescFileName = bundle.getString(ENV_DESC_MODIFIER);
} catch(MissingResourceException e){
co.envDescFileName = null;
}
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
}
try {
co.networkTopologyFileName = bundle
.getString(NETWORK_TOPOLOGY_FILE_MODIFIER);
} catch(MissingResourceException e){
co.networkTopologyFileName = null;
}
if (co.createScenario == false) {
// read scenario
try {
co.inputFolder = getSeparatorTerminatedPath(bundle
.getString(READ_SCENARIO_INPUT_FOLDER));
} catch (MissingResourceException e) {
co.inputFolder = null;
}
try {
co.inputTar = getSeparatorTerminatedPath(bundle
.getString(READ_SCENARIO_INPUT_TAR));
} catch (MissingResourceException e) {
co.inputTar = 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;
}
try {
co.printHistory = Boolean.valueOf(
bundle.getString(PRINT_HISTORY_MODIFIER)).booleanValue();
} catch(MissingResourceException e){
co.printHistory = false;
}
// create diagrams
boolean createDiagrams = true;
try {
createDiagrams = Boolean.valueOf(
bundle.getString(CREATEDIAGRAMS)).booleanValue();
} catch(MissingResourceException e){
createDiagrams = true;
}
try {
co.creatediagrams_processors = Boolean.valueOf(
bundle.getString(CREATEDIAGRAMS_GANTT)).booleanValue() && createDiagrams;
} catch(MissingResourceException e){
co.creatediagrams_processors = createDiagrams;
}
try {
co.creatediagrams_reservations = Boolean.valueOf(
bundle.getString(CREATEDIAGRAMS_RESERVATIONS)).booleanValue() && createDiagrams;
} catch(MissingResourceException e){
co.creatediagrams_reservations = createDiagrams;
}
try {
co.creatediagrams_resources = Boolean.valueOf(
bundle.getString(CREATEDIAGRAMS_UTILIZATION)).booleanValue() && createDiagrams;
} catch(MissingResourceException e){
co.creatediagrams_resources = createDiagrams;
}
try {
co.creatediagrams_resources_scale = Double.valueOf(
bundle.getString(CREATEDIAGRAMS_RESOURCES_SCALE)).doubleValue();
} catch(MissingResourceException e){
co.creatediagrams_resources_scale = -1;
}
try {
co.creatediagrams_energyusage = Boolean.valueOf(
bundle.getString(CREATEDIAGRAMS_ENERGYUSAGE)).booleanValue() && createDiagrams;
} catch(MissingResourceException e){
co.creatediagrams_energyusage = createDiagrams;
}
try {
co.creatediagrams_tasks = Boolean.valueOf(
bundle.getString(CREATEDIAGRAMS_TASKS)).booleanValue() && createDiagrams;
} catch(MissingResourceException e){
co.creatediagrams_tasks = createDiagrams;
}
try {
co.creatediagrams_taskswaitingtime = Boolean.valueOf(
bundle.getString(CREATEDIAGRAMS_TASKSWAITINGTIME)).booleanValue() && createDiagrams;
} catch(MissingResourceException e){
co.creatediagrams_taskswaitingtime = createDiagrams;
}
try {
co.statsOutputSubfolderNameCreate = bundle.getString(STATS_OUTPUT_SUBFOLDER_NAME);
co.statsOutputSubfolderNameRerad = co.statsOutputSubfolderNameCreate;
} catch(MissingResourceException e){
co.statsOutputSubfolderNameCreate = "stats_create";
co.statsOutputSubfolderNameRerad = "stats_read";
}
try {
co.createaccumulatedresourcesstatistics = Boolean.valueOf(
bundle.getString(ACCUMULATED_RESOURCES_STATISTICS)).booleanValue();
} catch(MissingResourceException e){
co.createaccumulatedresourcesstatistics = true;
}
try {
co.createextendedtasksstatistics = Boolean.valueOf(
bundle.getString(EXTENDED_TASKS_STATISTICS)).booleanValue();
} catch(MissingResourceException e){
co.createextendedtasksstatistics = true;
}
try {
co.creategridlethistorystatistics = Boolean.valueOf(
bundle.getString(GRIDLET_HISTORY_STATISTICS)).booleanValue();
} catch(MissingResourceException e){
co.creategridlethistorystatistics = true;
}
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.formatstatisticsoutput = Boolean.valueOf(
bundle.getString(FORMAT_STATISTICS_OUTPUT)).booleanValue();
} catch(MissingResourceException e){
co.formatstatisticsoutput = false;
}
try {
co.numberOfSimulations = Integer.valueOf(bundle.getString(NUMBER_OF_SIMULATIONS)).intValue();
} catch(MissingResourceException e){
co.numberOfSimulations = 1;
}
return co;
}
/**
* Creates a new configuration object in the CREATE_SCENARIO mode.
*
* @param gridSchedulingPluginName
* @param forecastFinishTimePluginName
* @param localAllocPolicyPluginName
* @param resdescFileName
* @param taskParamFileName
* @param outputFolder
* @param outputWorkloadFileName
* @param overwriteFiles
* @param printHistory
*/
public ConfigurationOptions(String gridSchedulingPluginName,
String exectimeestimationplugin,
String localAllocPolicyPluginName, String resdescFileName,
String taskParamFileName, String outputFolder,
String outputWorkloadFileName, boolean overwriteFiles,
boolean printHistory) {
super();
this.resdescFileName = resdescFileName;
this.workloadDescFileName = taskParamFileName;
this.outputFolder = getSeparatorTerminatedPath(outputFolder);
this.outputWorkloadFileName = outputWorkloadFileName;
this.overwriteFiles = overwriteFiles;
this.printHistory = printHistory;
// the create mode
this.createScenario = true;
}
/**
* Creates a new configuration object in the READ_SCENARIO mode.
*
* @param gridSchedulingPluginName
* @param forecastFinishTimePluginName
* @param localAllocPolicyPluginName
* @param resdescFileName
* @param inputFolder
* @param inputWorkloadFileName
* @param overwriteFiles
* @param printHistory
*/
public ConfigurationOptions(String gridSchedulingPluginName,
String exectimeestimationplugin,
String localAllocPolicyPluginName, String resdescFileName,
String inputFolder, String inputWorkloadFileName,
boolean overwriteFiles, boolean printHistory) {
super();
this.resdescFileName = resdescFileName;
this.inputFolder = getSeparatorTerminatedPath(inputFolder);
this.inputWorkloadFileName = inputWorkloadFileName;
this.overwriteFiles = overwriteFiles;
this.printHistory = printHistory;
//FileHandler.loadDataset(new File("iris.data"), 4, ",");
// the read mode
this.createScenario = false;
}
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;
}
}