source: DCWoRMS/trunk/src/simulator/ConfigurationOptions.java @ 495

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