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

Revision 1299, 15.0 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 CREATESTATISTICS = "createstatistics";
80        public static final String ACCUMULATED_RESOURCES_STATISTICS = CREATESTATISTICS + ".accumulatedresources";
81        public static final String EXTENDED_TASKS_STATISTICS = CREATESTATISTICS + ".extendedtasks";
82        public static final String JOBS_STATISTICS = CREATESTATISTICS + ".jobs";
83        public static final String SIMULATION_STATISTICS = CREATESTATISTICS + ".simulation";
84
85        public static final String PRESSURE_DROP = "pressuredrop";
86        public static final String OUTLET_ROOM_AIR_TEMPERATURE = "outletroomairtemperature";
87        public static final String INLET_ROOM_AIR_TEMPERATURE = "inletroomairtemperature";
88        public static final String AMBIENT_AIR_TEMPERATURE = "ambientairtemperature";
89        public static final String AIR_FLOW_VOLUME = "airflowvolume";
90        public static final String ALPHA = "alpha";
91       
92        /**
93         * The main output folders base name
94         */
95        public static final String STATS_OUTPUT_SUBFOLDER_NAME = "stats.outputfolder";
96       
97        public static final String USER_DN = "user.dn";
98        public static final String EXPERIMENT_ID = "experiment.id";
99       
100        public static final String NUMBER_OF_SIMULATIONS = "numberofsimulations";
101       
102        /**
103         * Suffix for create scenario output folder
104         */
105        public String statsOutputSubfolderNameCreate = null;
106       
107        /**
108         * Suffix for read scenario output folder
109         */
110        public String statsOutputSubfolderNameRead = null;
111       
112        /* =============================================================================================== */
113       
114
115
116        /**
117         * the xml file name with resource description (according to the
118         * HostParamSchema.xsd), e.g. simulator/schemas/ResourceDescription.xml
119         */
120        public String resdescFileName = null;
121
122        /**
123         * a xml file name (according to the simulator.schemas.WorkloadSchema.xsd)
124         * with the description of jobs and tasks to be generated
125         */
126        public String workloadDescFileName = null;
127
128        /**
129         * the path to the folder, to which the generated xml job descriptions are
130         * to be stored
131         */
132        public String outputFolder = null;
133
134        /**
135         * the name of the .swf simulator.workload file into which the
136         * simulator.workload is to be written (it will be stored in the
137         * outputFolder folder)
138         */
139        public String outputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME;
140
141        /**
142         * the path to the folder where previously generated xml jobs descriptions
143         * are stored
144         */
145        public String inputFolder = null;
146       
147        public String appProfilesFolder = null;
148
149        /**
150         * the name of the .swf simulator.workload file in the inputFolder folder
151         */
152        public String inputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME;
153
154       
155        /**
156         * Shows the mode of the simulator: true if it is the create scenario, false
157         * if it is the read scenario mode
158         */
159        public boolean createScenario = false;
160       
161        public boolean createXMLSupplement = false;
162
163        /**
164         * true if the outputFolder is not empty and shall be overwritten, false
165         * otherwise
166         */
167        public boolean overwriteFiles = false;
168
169       
170        /**
171         * The number of simulation runs that is to be performed. Default value is <code>1</code>.
172         */
173        public int numberOfSimulations = 1; //default value
174
175        public boolean creatediagrams_gantt = false;
176        public boolean creatediagrams_tasks = false;
177        public boolean creatediagrams_taskswaitingtime = false;
178       
179        public boolean creatediagrams_resutilization = false;
180        public boolean creatediagrams_respowerusage = false;
181        public boolean creatediagrams_resairflow = false;
182        public boolean creatediagrams_restemperature = false;
183        public double  creatediagrams_resources_scale = 1;
184
185        public boolean createjobsstatistics = true;
186        public boolean createsimulationstatistics = true;
187       
188        public String [] resForEnergyChart;
189        public String [] resForAirFlowChart;
190        public String [] resForTemperatureChart;
191        public String [] resForUtilizationChart;
192       
193        public double pressureDrop;
194        public double outletRoomAirTempeature;
195        public double inletRoomAirTempeature;
196        public double ambientAirTempeature;
197        public double airFlowVolume;
198        public double alpha;
199       
200        public static CoolingModelData coolingData;
201        /**
202         * An empty constructor.
203         */
204        protected ConfigurationOptions() {
205        }
206
207        /**
208         * A static method used to read a resource bundle file and set all the
209         * fields in this class according to the contents of the file
210         *
211         * @param resBundleFileName
212         *            the path to the resource bundle file that stores the
213         *            configuration
214         * @return a ConfigurationOptions object with information set according to
215         *         the properties file, <code>null</code> if any exception occurs
216         */
217        public static ConfigurationOptions getConfiguration(String resBundleFileName) {
218
219                ConfigurationOptions co = new ConfigurationOptions();
220                File resBundleFile = new File(resBundleFileName);
221                ResourceBundle bundle = null;
222                try {
223                        bundle = new PropertyResourceBundle(new FileInputStream(resBundleFile));
224                } catch (FileNotFoundException e) {
225                        e.printStackTrace();
226                        return null;
227                } catch (IOException e) {
228                        e.printStackTrace();
229                        return null;
230                }
231               
232                co.resdescFileName = bundle.getString(RESOURCE_DESC_MODIFIER);
233               
234                try {
235                        co.workloadDescFileName = bundle.getString(CREATE_SCENARIO_TASK_DESC);
236                        co.outputFolder = getSeparatorTerminatedPath(bundle
237                                        .getString(CREATE_SCENARIO_OUTPUT_FOLDER));
238                        File f = new File(co.outputFolder);
239                        String parent = f.getParent();
240                        // output folder will have the same parent as the task description
241                        // file
242                        if (parent == null) {
243                                f = new File(co.workloadDescFileName);
244                                parent = f.getParent();
245                                co.outputFolder = new File(parent, co.outputFolder)
246                                                .getAbsolutePath();
247                                co.outputFolder = getSeparatorTerminatedPath(co.outputFolder);
248                        }
249                        co.outputWorkloadFileName = bundle
250                                        .getString(CREATE_SCENARIO_WORKLOAD_FILE);
251                        co.overwriteFiles = Boolean.valueOf(
252                                        bundle.getString(CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER))
253                                        .booleanValue();
254                        co.createScenario = true; // success
255
256                } catch (MissingResourceException e) {
257                        co.createScenario = false; // do not create scenario
258                }
259
260                if (co.createScenario == false) {
261                        // read scenario
262                        try {
263                                co.inputFolder = getSeparatorTerminatedPath(bundle
264                                        .getString(READ_SCENARIO_INPUT_FOLDER));
265                        } catch (MissingResourceException e) {
266                                co.inputFolder = null;
267                        }
268                       
269                        try {
270                                co.appProfilesFolder  = getSeparatorTerminatedPath(bundle
271                                        .getString(READ_SCENARIO_APPLCIATION_PROFILES));
272                        } catch (MissingResourceException e) {
273                                co.appProfilesFolder  = null;
274                        }
275                       
276                        try {
277                                co.inputWorkloadFileName = bundle
278                                                .getString(READ_SCENARIO_WORKLOAD_FILE);
279                        } catch (MissingResourceException e){
280                                co.inputWorkloadFileName = null;
281                        }
282                }
283
284                try {
285                       
286                        if(Boolean.parseBoolean(
287                                        bundle.getString(CREATE_XML_SUPPLEMENT_FILES)))
288                                co.createXMLSupplement = true;
289                        else
290                                co.createXMLSupplement = false;
291                       
292                } catch (MissingResourceException e){
293                        co.createXMLSupplement = false;
294                }
295
296                // create diagrams
297               
298                boolean createDiagrams = true;
299                try {
300                        createDiagrams = Boolean.valueOf(
301                                        bundle.getString(CREATEDIAGRAMS)).booleanValue();
302                } catch(MissingResourceException e){
303                        createDiagrams = false;
304                }
305                try {
306                        co.creatediagrams_gantt = Boolean.valueOf(
307                                        bundle.getString(CREATEDIAGRAMS_GANTT)).booleanValue();
308                } catch(MissingResourceException e){
309                        co.creatediagrams_gantt = createDiagrams;
310                }
311
312                try {
313                        co.resForUtilizationChart = bundle.getString(CREATEDIAGRAMS_UTILIZATION).split(";");
314                        if(co.resForUtilizationChart.length > 0){
315                                co.creatediagrams_resutilization = true;
316                        }
317                } catch(MissingResourceException e){
318                        co.creatediagrams_resutilization = createDiagrams;
319                }
320                try {
321                        co.creatediagrams_resources_scale = Double.valueOf(
322                                        bundle.getString(CREATEDIAGRAMS_RESOURCES_SCALE)).doubleValue();
323                } catch(MissingResourceException e){
324                        co.creatediagrams_resources_scale = -1;
325                }
326                try {
327                        co.resForEnergyChart = bundle.getString(CREATEDIAGRAMS_ENERGYUSAGE).split(";");
328                        if(co.resForEnergyChart.length > 0){
329                                co.creatediagrams_respowerusage = true;
330                        }
331                } catch(MissingResourceException e){
332                        co.creatediagrams_respowerusage = createDiagrams;
333                }
334               
335                try {
336                        co.resForAirFlowChart = bundle.getString(CREATEDIAGRAMS_AIRFLOW).split(";");
337                        if(co.resForAirFlowChart.length > 0){
338                                co.creatediagrams_resairflow = true;
339                        }
340                } catch(MissingResourceException e){
341                        co.creatediagrams_resairflow = createDiagrams;
342                }
343               
344                try {
345                        co.resForTemperatureChart = bundle.getString(CREATEDIAGRAMS_TEMPERATURE).split(";");
346                        if(co.resForTemperatureChart.length > 0){
347                                co.creatediagrams_restemperature = true;
348                        }
349                } catch(MissingResourceException e){
350                        co.creatediagrams_restemperature = createDiagrams;
351                }
352               
353                try {
354                        co.creatediagrams_tasks = Boolean.valueOf(
355                                        bundle.getString(CREATEDIAGRAMS_TASKS)).booleanValue();
356                } catch(MissingResourceException e){
357                        co.creatediagrams_tasks = createDiagrams;
358                }
359                try {
360                        co.creatediagrams_taskswaitingtime = Boolean.valueOf(
361                                        bundle.getString(CREATEDIAGRAMS_TASKSWAITINGTIME)).booleanValue();
362                } catch(MissingResourceException e){
363                        co.creatediagrams_taskswaitingtime = createDiagrams;
364                }
365               
366                try {
367                        co.statsOutputSubfolderNameCreate = bundle.getString(STATS_OUTPUT_SUBFOLDER_NAME);
368                        co.statsOutputSubfolderNameRead = co.statsOutputSubfolderNameCreate;
369                } catch(MissingResourceException e){
370                        co.statsOutputSubfolderNameCreate = "stats_create";
371                        co.statsOutputSubfolderNameRead = "stats_read";
372                }
373
374                try {
375                        co.createjobsstatistics = Boolean.valueOf(
376                                        bundle.getString(JOBS_STATISTICS)).booleanValue();
377                } catch(MissingResourceException e){
378                        co.createjobsstatistics = true;
379                }
380                try {
381                        co.createsimulationstatistics = Boolean.valueOf(
382                                        bundle.getString(SIMULATION_STATISTICS)).booleanValue();
383                } catch(MissingResourceException e){
384                        co.createsimulationstatistics = true;
385                }
386
387                try {
388                        co.numberOfSimulations = Integer.valueOf(bundle.getString(NUMBER_OF_SIMULATIONS)).intValue();
389                } catch(MissingResourceException e){
390                        co.numberOfSimulations = 1;
391                }
392
393                try {
394                        co.pressureDrop = Double.valueOf(bundle.getString(PRESSURE_DROP)).doubleValue();
395                } catch(MissingResourceException e){
396                        co.pressureDrop = -1;
397                }
398               
399                try {
400                        co.outletRoomAirTempeature = Double.valueOf(bundle.getString(OUTLET_ROOM_AIR_TEMPERATURE)).doubleValue();
401                } catch(MissingResourceException e){
402                        co.outletRoomAirTempeature = -1;
403                }
404               
405                try {
406                        co.inletRoomAirTempeature = Double.valueOf(bundle.getString(INLET_ROOM_AIR_TEMPERATURE)).doubleValue();
407                } catch(MissingResourceException e){
408                        co.inletRoomAirTempeature = -1;
409                }
410               
411                try {
412                        co.ambientAirTempeature = Double.valueOf(bundle.getString(AMBIENT_AIR_TEMPERATURE)).doubleValue();
413                } catch(MissingResourceException e){
414                        co.ambientAirTempeature = -1;
415                }
416               
417                try {
418                        co.airFlowVolume = Double.valueOf(bundle.getString(AIR_FLOW_VOLUME)).doubleValue();
419                } catch(MissingResourceException e){
420                        co.airFlowVolume = -1;
421                }
422               
423                try {
424                        co.alpha = Double.valueOf(bundle.getString(ALPHA)).doubleValue();
425                } catch(MissingResourceException e){
426                        co.alpha = -1;
427                }
428               
429                ConfigurationOptions.coolingData = new CoolingModelData(co.pressureDrop, co.outletRoomAirTempeature, co.inletRoomAirTempeature, co.ambientAirTempeature, co.airFlowVolume, co.alpha);
430                return co;
431        }
432
433        public static String getSeparatorTerminatedPath(String path) {
434                if (path.endsWith(File.separator))
435                        return new String(path);
436                else {
437                        StringBuilder result = new StringBuilder(path.length()
438                                        + File.separator.length());
439                        result.append(path);
440                        result.append(File.separator);
441                        return result.toString();
442                }
443        }
444       
445        public void setNumberOfSimulations(int numberOfSimulations) {
446                this.numberOfSimulations = numberOfSimulations;
447        }
448       
449        public int getNumberOfSimulations() {
450                return numberOfSimulations;
451        }
452       
453        public void setWorkloadDescFileName(String workloadDescFileName) {
454                this.workloadDescFileName = workloadDescFileName;
455        }
456       
457        public String getWorkloadDescFileName() {
458                return workloadDescFileName;
459        }
460}
Note: See TracBrowser for help on using the repository browser.