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

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