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

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