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

Revision 490, 12.8 KB checked in by wojtekp, 13 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       
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";
63
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";
69        public static final String CREATEDIAGRAMS_RESOURCES_SCALE = CREATEDIAGRAMS_UTILIZATION + ".scale";
70        public static final String CREATEDIAGRAMS_TASKS = CREATEDIAGRAMS + ".tasks";
71        public static final String CREATEDIAGRAMS_TASKSWAITINGTIME = CREATEDIAGRAMS + ".taskswaitingtime";
72       
73        public static final String CREATESTATISTICS = "createstatistics";
74        public static final String ACCUMULATED_RESOURCES_STATISTICS = CREATESTATISTICS + ".accumulatedresources";
75        public static final String EXTENDED_TASKS_STATISTICS = CREATESTATISTICS + ".extendedtasks";
76        public static final String JOBS_STATISTICS = CREATESTATISTICS + ".jobs";
77        public static final String SIMULATION_STATISTICS = CREATESTATISTICS + ".simulation";
78        public static final String FORMAT_STATISTICS_OUTPUT = CREATESTATISTICS + ".formatoutput";
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;
166        public boolean creatediagrams_tasks = true;
167        public boolean creatediagrams_taskswaitingtime = true;
168        public double  creatediagrams_resources_scale = 1;
169       
170        public boolean createaccumulatedresourcesstatistics = true;
171        public boolean createextendedtasksstatistics = true;
172        public boolean createjobsstatistics = true;
173        public boolean createsimulationstatistics = true;
174        public boolean formatstatisticsoutput = false;
175       
176        public String[] resForEnergyChart;
177        public String[] resForUtilizationChart;
178       
179        /**
180         * An empty constructor.
181         */
182        protected ConfigurationOptions() {
183        }
184
185        /**
186         * A static method used to read a resource bundle file and set all the
187         * fields in this class according to the contents of the file
188         *
189         * @param resBundleFileName
190         *            the path to the resource bundle file that stores the
191         *            configuration
192         * @return a ConfigurationOptions object with information set according to
193         *         the properties file, <code>null</code> if any exception occurs
194         */
195        public static ConfigurationOptions getConfiguration(String resBundleFileName) {
196
197                ConfigurationOptions co = new ConfigurationOptions();
198                File resBundleFile = new File(resBundleFileName);
199                ResourceBundle bundle = null;
200                try {
201                        bundle = new PropertyResourceBundle(new FileInputStream(resBundleFile));
202                } catch (FileNotFoundException e) {
203                        e.printStackTrace();
204                        return null;
205                } catch (IOException e) {
206                        e.printStackTrace();
207                        return null;
208                }
209               
210                co.resdescFileName = bundle.getString(RESOURCE_DESC_MODIFIER);
211
212               
213                try {
214                        co.workloadDescFileName = bundle.getString(CREATE_SCENARIO_TASK_DESC);
215                        co.outputFolder = getSeparatorTerminatedPath(bundle
216                                        .getString(CREATE_SCENARIO_OUTPUT_FOLDER));
217                        File f = new File(co.outputFolder);
218                        String parent = f.getParent();
219                        // output folder will have the same parent as the task description
220                        // file
221                        if (parent == null) {
222                                f = new File(co.workloadDescFileName);
223                                parent = f.getParent();
224                                co.outputFolder = new File(parent, co.outputFolder)
225                                                .getAbsolutePath();
226                                co.outputFolder = getSeparatorTerminatedPath(co.outputFolder);
227                        }
228                        co.outputWorkloadFileName = bundle
229                                        .getString(CREATE_SCENARIO_WORKLOAD_FILE);
230                        co.overwriteFiles = Boolean.valueOf(
231                                        bundle.getString(CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER))
232                                        .booleanValue();
233                        co.createScenario = true; // success
234
235                } catch (MissingResourceException e) {
236                        co.createScenario = false; // do not create scenario
237                }
238
239                if (co.createScenario == false) {
240                        // read scenario
241                        try {
242                                co.inputFolder = getSeparatorTerminatedPath(bundle
243                                        .getString(READ_SCENARIO_INPUT_FOLDER));
244                        } catch (MissingResourceException e) {
245                                co.inputFolder = null;
246                        }
247                       
248                        try {
249                                co.inputWorkloadFileName = bundle
250                                                .getString(READ_SCENARIO_WORKLOAD_FILE);
251                        } catch (MissingResourceException e){
252                                co.inputWorkloadFileName = null;
253                        }
254                }
255
256                try {
257                       
258                        if(Boolean.parseBoolean(
259                                        bundle.getString(CREATE_XML_SUPPLEMENT_FILES)))
260                                co.createXMLSupplement = true;
261                        else
262                                co.createXMLSupplement = false;
263                       
264                } catch (MissingResourceException e){
265                        co.createXMLSupplement = false;
266                }
267
268                // create diagrams
269               
270                boolean createDiagrams = true;
271                try {
272                        createDiagrams = Boolean.valueOf(
273                                        bundle.getString(CREATEDIAGRAMS)).booleanValue();
274                } catch(MissingResourceException e){
275                        createDiagrams = true;
276                }
277                try {
278                        co.creatediagrams_processors = Boolean.valueOf(
279                                        bundle.getString(CREATEDIAGRAMS_GANTT)).booleanValue() && createDiagrams;
280                } catch(MissingResourceException e){
281                        co.creatediagrams_processors = createDiagrams;
282                }
283
284                try {
285                        co.resForUtilizationChart = bundle.getString(CREATEDIAGRAMS_UTILIZATION).split(";");
286                        if(co.resForUtilizationChart.length > 0){
287                                co.creatediagrams_resources = true && createDiagrams;
288                        }
289                } catch(MissingResourceException e){
290                        co.creatediagrams_resources = createDiagrams;
291                }
292                try {
293                        co.creatediagrams_resources_scale = Double.valueOf(
294                                        bundle.getString(CREATEDIAGRAMS_RESOURCES_SCALE)).doubleValue();
295                } catch(MissingResourceException e){
296                        co.creatediagrams_resources_scale = -1;
297                }
298                try {
299                        co.resForEnergyChart = bundle.getString(CREATEDIAGRAMS_ENERGYUSAGE).split(";");
300                        if(co.resForEnergyChart.length > 0){
301                                co.creatediagrams_energyusage = true && createDiagrams;
302                        }
303                } catch(MissingResourceException e){
304                        co.creatediagrams_energyusage = createDiagrams;
305                }
306                try {
307                        co.creatediagrams_tasks = Boolean.valueOf(
308                                        bundle.getString(CREATEDIAGRAMS_TASKS)).booleanValue() && createDiagrams;
309                } catch(MissingResourceException e){
310                        co.creatediagrams_tasks = createDiagrams;
311                }
312                try {
313                        co.creatediagrams_taskswaitingtime = Boolean.valueOf(
314                                        bundle.getString(CREATEDIAGRAMS_TASKSWAITINGTIME)).booleanValue() && createDiagrams;
315                } catch(MissingResourceException e){
316                        co.creatediagrams_taskswaitingtime = createDiagrams;
317                }
318               
319                try {
320                        co.statsOutputSubfolderNameCreate = bundle.getString(STATS_OUTPUT_SUBFOLDER_NAME);
321                        co.statsOutputSubfolderNameRerad = co.statsOutputSubfolderNameCreate;
322                } catch(MissingResourceException e){
323                        co.statsOutputSubfolderNameCreate = "stats_create";
324                        co.statsOutputSubfolderNameRerad = "stats_read";
325                }
326
327                try {
328                        co.createaccumulatedresourcesstatistics = Boolean.valueOf(
329                                        bundle.getString(ACCUMULATED_RESOURCES_STATISTICS)).booleanValue();
330                } catch(MissingResourceException e){
331                        co.createaccumulatedresourcesstatistics = true;
332                }
333                try {
334                        co.createextendedtasksstatistics = Boolean.valueOf(
335                                        bundle.getString(EXTENDED_TASKS_STATISTICS)).booleanValue();
336                } catch(MissingResourceException e){
337                        co.createextendedtasksstatistics = true;
338                }
339
340                try {
341                        co.createjobsstatistics = Boolean.valueOf(
342                                        bundle.getString(JOBS_STATISTICS)).booleanValue();
343                } catch(MissingResourceException e){
344                        co.createjobsstatistics = true;
345                }
346                try {
347                        co.createsimulationstatistics = Boolean.valueOf(
348                                        bundle.getString(SIMULATION_STATISTICS)).booleanValue();
349                } catch(MissingResourceException e){
350                        co.createsimulationstatistics = true;
351                }
352                try {
353                        co.formatstatisticsoutput = Boolean.valueOf(
354                                        bundle.getString(FORMAT_STATISTICS_OUTPUT)).booleanValue();
355                } catch(MissingResourceException e){
356                        co.formatstatisticsoutput = false;
357                }
358               
359                try {
360                        co.numberOfSimulations = Integer.valueOf(bundle.getString(NUMBER_OF_SIMULATIONS)).intValue();
361                } catch(MissingResourceException e){
362                        co.numberOfSimulations = 1;
363                }
364                return co;
365        }
366
367        public static String getSeparatorTerminatedPath(String path) {
368                if (path.endsWith(File.separator))
369                        return new String(path);
370                else {
371                        StringBuilder result = new StringBuilder(path.length()
372                                        + File.separator.length());
373                        result.append(path);
374                        result.append(File.separator);
375                        return result.toString();
376                }
377        }
378       
379        public void setNumberOfSimulations(int numberOfSimulations) {
380                this.numberOfSimulations = numberOfSimulations;
381        }
382       
383        public int getNumberOfSimulations() {
384                return numberOfSimulations;
385        }
386       
387        public void setWorkloadDescFileName(String workloadDescFileName) {
388                this.workloadDescFileName = workloadDescFileName;
389        }
390       
391        public String getWorkloadDescFileName() {
392                return workloadDescFileName;
393        }
394}
Note: See TracBrowser for help on using the repository browser.