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

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