[477] | 1 | package simulator; |
---|
| 2 | |
---|
| 3 | import java.io.File; |
---|
| 4 | import java.io.FileInputStream; |
---|
| 5 | import java.io.FileNotFoundException; |
---|
| 6 | import java.io.IOException; |
---|
| 7 | import java.util.MissingResourceException; |
---|
| 8 | import java.util.PropertyResourceBundle; |
---|
| 9 | import java.util.ResourceBundle; |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * This aim of this class is to store all the configuration options passed to |
---|
| 13 | * the program to steer its functionality. <br> |
---|
| 14 | * As a general contract of this class, all fields, that store a path name to a |
---|
| 15 | * folder will always be terminated with {@link File#separator} string. |
---|
| 16 | * |
---|
| 17 | * @author Stanislaw Szczepanowski |
---|
| 18 | * |
---|
| 19 | */ |
---|
| 20 | public class ConfigurationOptions { |
---|
| 21 | |
---|
| 22 | /* |
---|
| 23 | * ============================================================================================= |
---|
| 24 | * Constants describing the contents of the resource bundle file |
---|
| 25 | * ============================================================================================= |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | /** The path to the resource description file */ |
---|
| 29 | public static final String RESOURCE_DESC_MODIFIER = "resdesc"; |
---|
| 30 | |
---|
| 31 | /** The create scenario mode of the simulation */ |
---|
| 32 | public static final String CREATE_SCENARIO_MODIFIER = "createscenario"; |
---|
| 33 | /** The path to the file with the tasks description */ |
---|
| 34 | public static final String CREATE_SCENARIO_TASK_DESC = CREATE_SCENARIO_MODIFIER |
---|
| 35 | + ".tasksdesc"; |
---|
| 36 | /** The path to the output folder for generated tasks */ |
---|
| 37 | public static final String CREATE_SCENARIO_OUTPUT_FOLDER = CREATE_SCENARIO_MODIFIER |
---|
| 38 | + ".outputfolder"; |
---|
| 39 | /** The name of the workload file */ |
---|
| 40 | public static final String CREATE_SCENARIO_WORKLOAD_FILE = CREATE_SCENARIO_MODIFIER |
---|
| 41 | + ".workloadfilename"; |
---|
| 42 | /** |
---|
| 43 | * Shall the files in the output directory be overwritten, if the folder is |
---|
| 44 | * not empty |
---|
| 45 | */ |
---|
| 46 | public static final String CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER = CREATE_SCENARIO_MODIFIER |
---|
| 47 | + ".overwrite_files"; |
---|
| 48 | |
---|
| 49 | /** The read scenario mode of the simulation */ |
---|
| 50 | public static final String READ_SCENARIO_MODIFIER = "readscenario"; |
---|
| 51 | /** The input folder with generated tasks */ |
---|
| 52 | public static final String READ_SCENARIO_INPUT_FOLDER = READ_SCENARIO_MODIFIER |
---|
| 53 | + ".inputfolder"; |
---|
| 54 | |
---|
| 55 | /** The name of the workload file */ |
---|
| 56 | public static final String READ_SCENARIO_WORKLOAD_FILE = READ_SCENARIO_MODIFIER |
---|
| 57 | + ".workloadfilename"; |
---|
| 58 | |
---|
| 59 | /** The default name of a workload file */ |
---|
| 60 | public static final String DEFAULT_WORKLOAD_FILE_NAME = "workload.swf"; |
---|
| 61 | |
---|
| 62 | public static final String CREATE_XML_SUPPLEMENT_FILES = "createXMLSupplement"; |
---|
[490] | 63 | |
---|
[477] | 64 | |
---|
| 65 | public static final String CREATEDIAGRAMS = "creatediagrams"; |
---|
| 66 | public static final String CREATEDIAGRAMS_GANTT = CREATEDIAGRAMS +".gantt"; |
---|
| 67 | public static final String CREATEDIAGRAMS_TASKS = CREATEDIAGRAMS + ".tasks"; |
---|
| 68 | public static final String CREATEDIAGRAMS_TASKSWAITINGTIME = CREATEDIAGRAMS + ".taskswaitingtime"; |
---|
[501] | 69 | public static final String CREATEDIAGRAMS_UTILIZATION = CREATEDIAGRAMS + ".resutilization"; |
---|
| 70 | public static final String CREATEDIAGRAMS_ENERGYUSAGE = CREATEDIAGRAMS + ".respowerusage"; |
---|
| 71 | public static final String CREATEDIAGRAMS_AIRFLOW = CREATEDIAGRAMS + ".resairflow"; |
---|
[802] | 72 | public static final String CREATEDIAGRAMS_TEMPERATURE = CREATEDIAGRAMS + ".restemperature"; |
---|
[501] | 73 | public static final String CREATEDIAGRAMS_RESOURCES_SCALE = CREATEDIAGRAMS_UTILIZATION + ".scale"; |
---|
| 74 | |
---|
[477] | 75 | |
---|
| 76 | public static final String CREATESTATISTICS = "createstatistics"; |
---|
| 77 | public static final String ACCUMULATED_RESOURCES_STATISTICS = CREATESTATISTICS + ".accumulatedresources"; |
---|
| 78 | public static final String EXTENDED_TASKS_STATISTICS = CREATESTATISTICS + ".extendedtasks"; |
---|
| 79 | public static final String JOBS_STATISTICS = CREATESTATISTICS + ".jobs"; |
---|
| 80 | public static final String SIMULATION_STATISTICS = CREATESTATISTICS + ".simulation"; |
---|
| 81 | |
---|
[787] | 82 | public static final String COOLEMALL = "coolemall"; |
---|
| 83 | public static final String COOLEMALL_RESOURCE = COOLEMALL + ".resdesc"; |
---|
| 84 | |
---|
[477] | 85 | /** |
---|
| 86 | * The main output folders base name |
---|
| 87 | */ |
---|
| 88 | public static final String STATS_OUTPUT_SUBFOLDER_NAME = "stats.outputfolder"; |
---|
| 89 | |
---|
| 90 | public static final String USER_DN = "user.dn"; |
---|
| 91 | public static final String EXPERIMENT_ID = "experiment.id"; |
---|
| 92 | |
---|
| 93 | public static final String NUMBER_OF_SIMULATIONS = "numberofsimulations"; |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * Suffix for create scenario output folder |
---|
| 97 | */ |
---|
| 98 | public String statsOutputSubfolderNameCreate = null; |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * Suffix for read scenario output folder |
---|
| 102 | */ |
---|
| 103 | public String statsOutputSubfolderNameRerad = null; |
---|
| 104 | |
---|
| 105 | /* =============================================================================================== */ |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * the xml file name with resource description (according to the |
---|
| 111 | * HostParamSchema.xsd), e.g. simulator/schemas/ResourceDescription.xml |
---|
| 112 | */ |
---|
| 113 | public String resdescFileName = null; |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * a xml file name (according to the simulator.schemas.WorkloadSchema.xsd) |
---|
| 117 | * with the description of jobs and tasks to be generated |
---|
| 118 | */ |
---|
| 119 | public String workloadDescFileName = null; |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * the path to the folder, to which the generated xml job descriptions are |
---|
| 123 | * to be stored |
---|
| 124 | */ |
---|
| 125 | public String outputFolder = null; |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * the name of the .swf simulator.workload file into which the |
---|
| 129 | * simulator.workload is to be written (it will be stored in the |
---|
| 130 | * outputFolder folder) |
---|
| 131 | */ |
---|
| 132 | public String outputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME; |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * the path to the folder where previously generated xml jobs descriptions |
---|
| 136 | * are stored |
---|
| 137 | */ |
---|
| 138 | public String inputFolder = null; |
---|
| 139 | |
---|
| 140 | public String inputTar = null; |
---|
| 141 | |
---|
| 142 | /** |
---|
| 143 | * the name of the .swf simulator.workload file in the inputFolder folder |
---|
| 144 | */ |
---|
| 145 | public String inputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME; |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * Shows the mode of the simulator: true if it is the create scenario, false |
---|
| 150 | * if it is the read scenario mode |
---|
| 151 | */ |
---|
| 152 | public boolean createScenario = false; |
---|
| 153 | |
---|
| 154 | public boolean createXMLSupplement = false; |
---|
| 155 | |
---|
| 156 | /** |
---|
| 157 | * true if the outputFolder is not empty and shall be overwritten, false |
---|
| 158 | * otherwise |
---|
| 159 | */ |
---|
| 160 | public boolean overwriteFiles = false; |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * The number of simulation runs that is to be performed. Default value is <code>1</code>. |
---|
| 165 | */ |
---|
| 166 | public int numberOfSimulations = 1; //default value |
---|
| 167 | |
---|
[501] | 168 | public boolean creatediagrams_gantt = false; |
---|
| 169 | public boolean creatediagrams_tasks = false; |
---|
| 170 | public boolean creatediagrams_taskswaitingtime = false; |
---|
| 171 | |
---|
| 172 | public boolean creatediagrams_resutilization = false; |
---|
| 173 | public boolean creatediagrams_respowerusage = false; |
---|
| 174 | public boolean creatediagrams_resairflow = false; |
---|
[802] | 175 | public boolean creatediagrams_restemperature = false; |
---|
[490] | 176 | public double creatediagrams_resources_scale = 1; |
---|
[501] | 177 | |
---|
[477] | 178 | public boolean createjobsstatistics = true; |
---|
| 179 | public boolean createsimulationstatistics = true; |
---|
| 180 | |
---|
[501] | 181 | public String [] resForEnergyChart; |
---|
| 182 | public String [] resForAirFlowChart; |
---|
[802] | 183 | public String [] resForTemperatureChart; |
---|
[501] | 184 | public String [] resForUtilizationChart; |
---|
[490] | 185 | |
---|
[787] | 186 | public String coolEmAllResdescFileName = null; |
---|
| 187 | |
---|
[477] | 188 | /** |
---|
| 189 | * An empty constructor. |
---|
| 190 | */ |
---|
| 191 | protected ConfigurationOptions() { |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | /** |
---|
| 195 | * A static method used to read a resource bundle file and set all the |
---|
| 196 | * fields in this class according to the contents of the file |
---|
| 197 | * |
---|
| 198 | * @param resBundleFileName |
---|
| 199 | * the path to the resource bundle file that stores the |
---|
| 200 | * configuration |
---|
| 201 | * @return a ConfigurationOptions object with information set according to |
---|
| 202 | * the properties file, <code>null</code> if any exception occurs |
---|
| 203 | */ |
---|
| 204 | public static ConfigurationOptions getConfiguration(String resBundleFileName) { |
---|
| 205 | |
---|
| 206 | ConfigurationOptions co = new ConfigurationOptions(); |
---|
| 207 | File resBundleFile = new File(resBundleFileName); |
---|
| 208 | ResourceBundle bundle = null; |
---|
| 209 | try { |
---|
| 210 | bundle = new PropertyResourceBundle(new FileInputStream(resBundleFile)); |
---|
| 211 | } catch (FileNotFoundException e) { |
---|
| 212 | e.printStackTrace(); |
---|
| 213 | return null; |
---|
| 214 | } catch (IOException e) { |
---|
| 215 | e.printStackTrace(); |
---|
| 216 | return null; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | co.resdescFileName = bundle.getString(RESOURCE_DESC_MODIFIER); |
---|
| 220 | |
---|
| 221 | try { |
---|
| 222 | co.workloadDescFileName = bundle.getString(CREATE_SCENARIO_TASK_DESC); |
---|
| 223 | co.outputFolder = getSeparatorTerminatedPath(bundle |
---|
| 224 | .getString(CREATE_SCENARIO_OUTPUT_FOLDER)); |
---|
| 225 | File f = new File(co.outputFolder); |
---|
| 226 | String parent = f.getParent(); |
---|
| 227 | // output folder will have the same parent as the task description |
---|
| 228 | // file |
---|
| 229 | if (parent == null) { |
---|
| 230 | f = new File(co.workloadDescFileName); |
---|
| 231 | parent = f.getParent(); |
---|
| 232 | co.outputFolder = new File(parent, co.outputFolder) |
---|
| 233 | .getAbsolutePath(); |
---|
| 234 | co.outputFolder = getSeparatorTerminatedPath(co.outputFolder); |
---|
| 235 | } |
---|
| 236 | co.outputWorkloadFileName = bundle |
---|
| 237 | .getString(CREATE_SCENARIO_WORKLOAD_FILE); |
---|
| 238 | co.overwriteFiles = Boolean.valueOf( |
---|
| 239 | bundle.getString(CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER)) |
---|
| 240 | .booleanValue(); |
---|
| 241 | co.createScenario = true; // success |
---|
| 242 | |
---|
| 243 | } catch (MissingResourceException e) { |
---|
| 244 | co.createScenario = false; // do not create scenario |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | if (co.createScenario == false) { |
---|
| 248 | // read scenario |
---|
| 249 | try { |
---|
| 250 | co.inputFolder = getSeparatorTerminatedPath(bundle |
---|
| 251 | .getString(READ_SCENARIO_INPUT_FOLDER)); |
---|
| 252 | } catch (MissingResourceException e) { |
---|
| 253 | co.inputFolder = null; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | try { |
---|
| 257 | co.inputWorkloadFileName = bundle |
---|
| 258 | .getString(READ_SCENARIO_WORKLOAD_FILE); |
---|
| 259 | } catch (MissingResourceException e){ |
---|
| 260 | co.inputWorkloadFileName = null; |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | try { |
---|
| 265 | |
---|
| 266 | if(Boolean.parseBoolean( |
---|
| 267 | bundle.getString(CREATE_XML_SUPPLEMENT_FILES))) |
---|
| 268 | co.createXMLSupplement = true; |
---|
| 269 | else |
---|
| 270 | co.createXMLSupplement = false; |
---|
| 271 | |
---|
| 272 | } catch (MissingResourceException e){ |
---|
| 273 | co.createXMLSupplement = false; |
---|
| 274 | } |
---|
[490] | 275 | |
---|
[477] | 276 | // create diagrams |
---|
| 277 | |
---|
| 278 | boolean createDiagrams = true; |
---|
| 279 | try { |
---|
| 280 | createDiagrams = Boolean.valueOf( |
---|
| 281 | bundle.getString(CREATEDIAGRAMS)).booleanValue(); |
---|
| 282 | } catch(MissingResourceException e){ |
---|
[501] | 283 | createDiagrams = false; |
---|
[477] | 284 | } |
---|
| 285 | try { |
---|
[501] | 286 | co.creatediagrams_gantt = Boolean.valueOf( |
---|
| 287 | bundle.getString(CREATEDIAGRAMS_GANTT)).booleanValue(); |
---|
[477] | 288 | } catch(MissingResourceException e){ |
---|
[501] | 289 | co.creatediagrams_gantt = createDiagrams; |
---|
[477] | 290 | } |
---|
[490] | 291 | |
---|
[477] | 292 | try { |
---|
[490] | 293 | co.resForUtilizationChart = bundle.getString(CREATEDIAGRAMS_UTILIZATION).split(";"); |
---|
| 294 | if(co.resForUtilizationChart.length > 0){ |
---|
[501] | 295 | co.creatediagrams_resutilization = true; |
---|
[490] | 296 | } |
---|
[477] | 297 | } catch(MissingResourceException e){ |
---|
[501] | 298 | co.creatediagrams_resutilization = createDiagrams; |
---|
[477] | 299 | } |
---|
| 300 | try { |
---|
| 301 | co.creatediagrams_resources_scale = Double.valueOf( |
---|
| 302 | bundle.getString(CREATEDIAGRAMS_RESOURCES_SCALE)).doubleValue(); |
---|
| 303 | } catch(MissingResourceException e){ |
---|
| 304 | co.creatediagrams_resources_scale = -1; |
---|
| 305 | } |
---|
| 306 | try { |
---|
[490] | 307 | co.resForEnergyChart = bundle.getString(CREATEDIAGRAMS_ENERGYUSAGE).split(";"); |
---|
| 308 | if(co.resForEnergyChart.length > 0){ |
---|
[501] | 309 | co.creatediagrams_respowerusage = true; |
---|
[490] | 310 | } |
---|
[477] | 311 | } catch(MissingResourceException e){ |
---|
[501] | 312 | co.creatediagrams_respowerusage = createDiagrams; |
---|
[477] | 313 | } |
---|
[495] | 314 | |
---|
[477] | 315 | try { |
---|
[495] | 316 | co.resForAirFlowChart = bundle.getString(CREATEDIAGRAMS_AIRFLOW).split(";"); |
---|
| 317 | if(co.resForAirFlowChart.length > 0){ |
---|
[501] | 318 | co.creatediagrams_resairflow = true; |
---|
[495] | 319 | } |
---|
| 320 | } catch(MissingResourceException e){ |
---|
[501] | 321 | co.creatediagrams_resairflow = createDiagrams; |
---|
[495] | 322 | } |
---|
| 323 | |
---|
| 324 | try { |
---|
[802] | 325 | co.resForTemperatureChart = bundle.getString(CREATEDIAGRAMS_TEMPERATURE).split(";"); |
---|
| 326 | if(co.resForTemperatureChart.length > 0){ |
---|
| 327 | co.creatediagrams_restemperature = true; |
---|
| 328 | } |
---|
| 329 | } catch(MissingResourceException e){ |
---|
| 330 | co.creatediagrams_restemperature = createDiagrams; |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | try { |
---|
[477] | 334 | co.creatediagrams_tasks = Boolean.valueOf( |
---|
[501] | 335 | bundle.getString(CREATEDIAGRAMS_TASKS)).booleanValue(); |
---|
[477] | 336 | } catch(MissingResourceException e){ |
---|
| 337 | co.creatediagrams_tasks = createDiagrams; |
---|
| 338 | } |
---|
| 339 | try { |
---|
| 340 | co.creatediagrams_taskswaitingtime = Boolean.valueOf( |
---|
[501] | 341 | bundle.getString(CREATEDIAGRAMS_TASKSWAITINGTIME)).booleanValue(); |
---|
[477] | 342 | } catch(MissingResourceException e){ |
---|
| 343 | co.creatediagrams_taskswaitingtime = createDiagrams; |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | try { |
---|
| 347 | co.statsOutputSubfolderNameCreate = bundle.getString(STATS_OUTPUT_SUBFOLDER_NAME); |
---|
| 348 | co.statsOutputSubfolderNameRerad = co.statsOutputSubfolderNameCreate; |
---|
| 349 | } catch(MissingResourceException e){ |
---|
| 350 | co.statsOutputSubfolderNameCreate = "stats_create"; |
---|
| 351 | co.statsOutputSubfolderNameRerad = "stats_read"; |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | try { |
---|
| 355 | co.createjobsstatistics = Boolean.valueOf( |
---|
| 356 | bundle.getString(JOBS_STATISTICS)).booleanValue(); |
---|
| 357 | } catch(MissingResourceException e){ |
---|
| 358 | co.createjobsstatistics = true; |
---|
| 359 | } |
---|
| 360 | try { |
---|
| 361 | co.createsimulationstatistics = Boolean.valueOf( |
---|
| 362 | bundle.getString(SIMULATION_STATISTICS)).booleanValue(); |
---|
| 363 | } catch(MissingResourceException e){ |
---|
| 364 | co.createsimulationstatistics = true; |
---|
| 365 | } |
---|
[493] | 366 | |
---|
[477] | 367 | try { |
---|
| 368 | co.numberOfSimulations = Integer.valueOf(bundle.getString(NUMBER_OF_SIMULATIONS)).intValue(); |
---|
| 369 | } catch(MissingResourceException e){ |
---|
| 370 | co.numberOfSimulations = 1; |
---|
| 371 | } |
---|
[787] | 372 | |
---|
| 373 | try { |
---|
| 374 | co.coolEmAllResdescFileName = bundle.getString(COOLEMALL_RESOURCE); |
---|
| 375 | System.setProperty("coolemall.resdesc", co.coolEmAllResdescFileName); |
---|
| 376 | } catch(MissingResourceException e){ |
---|
| 377 | co.coolEmAllResdescFileName = null; |
---|
| 378 | } |
---|
[477] | 379 | return co; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | public static String getSeparatorTerminatedPath(String path) { |
---|
| 383 | if (path.endsWith(File.separator)) |
---|
| 384 | return new String(path); |
---|
| 385 | else { |
---|
| 386 | StringBuilder result = new StringBuilder(path.length() |
---|
| 387 | + File.separator.length()); |
---|
| 388 | result.append(path); |
---|
| 389 | result.append(File.separator); |
---|
| 390 | return result.toString(); |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | public void setNumberOfSimulations(int numberOfSimulations) { |
---|
| 395 | this.numberOfSimulations = numberOfSimulations; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | public int getNumberOfSimulations() { |
---|
| 399 | return numberOfSimulations; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | public void setWorkloadDescFileName(String workloadDescFileName) { |
---|
| 403 | this.workloadDescFileName = workloadDescFileName; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | public String getWorkloadDescFileName() { |
---|
| 407 | return workloadDescFileName; |
---|
| 408 | } |
---|
| 409 | } |
---|