source: DCWoRMS/branches/coolemall/src/simulator/ConfigurationOptions.java @ 1423

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