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

Revision 477, 16.7 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;
10import java.util.logging.FileHandler;
11
12/**
13 * This aim of this class is to store all the configuration options passed to
14 * the program to steer its functionality. <br>
15 * As a general contract of this class, all fields, that store a path name to a
16 * folder will always be terminated with {@link File#separator} string.
17 *
18 * @author Stanislaw Szczepanowski
19 *
20 */
21public class ConfigurationOptions {
22
23        /*
24         * =============================================================================================
25         * Constants describing the contents of the resource bundle file
26         * =============================================================================================
27         */
28
29        /** The path to the resource description file */
30        public static final String RESOURCE_DESC_MODIFIER = "resdesc";
31
32        /** The create scenario mode of the simulation */
33        public static final String CREATE_SCENARIO_MODIFIER = "createscenario";
34        /** The path to the file with the tasks description */
35        public static final String CREATE_SCENARIO_TASK_DESC = CREATE_SCENARIO_MODIFIER
36                        + ".tasksdesc";
37        /** The path to the output folder for generated tasks */
38        public static final String CREATE_SCENARIO_OUTPUT_FOLDER = CREATE_SCENARIO_MODIFIER
39                        + ".outputfolder";
40        /** The name of the workload file */
41        public static final String CREATE_SCENARIO_WORKLOAD_FILE = CREATE_SCENARIO_MODIFIER
42                        + ".workloadfilename";
43        /**
44         * Shall the files in the output directory be overwritten, if the folder is
45         * not empty
46         */
47        public static final String CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER = CREATE_SCENARIO_MODIFIER
48                        + ".overwrite_files";
49
50        /** The read scenario mode of the simulation */
51        public static final String READ_SCENARIO_MODIFIER = "readscenario";
52        /** The input folder with generated tasks */
53        public static final String READ_SCENARIO_INPUT_FOLDER = READ_SCENARIO_MODIFIER
54                        + ".inputfolder";
55        public static final String READ_SCENARIO_INPUT_TAR = READ_SCENARIO_MODIFIER+ ".tar";
56       
57        /** The name of the workload file */
58        public static final String READ_SCENARIO_WORKLOAD_FILE = READ_SCENARIO_MODIFIER
59                        + ".workloadfilename";
60
61        /** Shall a detailed history be printed */
62        public static final String PRINT_HISTORY_MODIFIER = "printhistory";
63
64        /** The default name of a workload file */
65        public static final String DEFAULT_WORKLOAD_FILE_NAME = "workload.swf";
66
67        public static final String CREATE_XML_SUPPLEMENT_FILES = "createXMLSupplement";
68       
69        public static final String PROVIDER_LIST_FILE = "in/provider.list";
70       
71        /** Network topology file path */
72        public static final String NETWORK_TOPOLOGY_FILE_MODIFIER = "networktopologyfilename";
73       
74        public static final String CREATEDIAGRAMS = "creatediagrams";
75        public static final String CREATEDIAGRAMS_GANTT = CREATEDIAGRAMS +".gantt";
76        public static final String CREATEDIAGRAMS_UTILIZATION = CREATEDIAGRAMS + ".utilization";
77        public static final String CREATEDIAGRAMS_ENERGYUSAGE = CREATEDIAGRAMS + ".energyusage";
78        public static final String CREATEDIAGRAMS_RESOURCES_SCALE = CREATEDIAGRAMS_UTILIZATION + ".scale";
79        public static final String CREATEDIAGRAMS_TASKS = CREATEDIAGRAMS + ".tasks";
80        public static final String CREATEDIAGRAMS_TASKSWAITINGTIME = CREATEDIAGRAMS + ".taskswaitingtime";
81        public static final String CREATEDIAGRAMS_RESERVATIONS = CREATEDIAGRAMS + ".reservations";
82       
83        public static final String CREATESTATISTICS = "createstatistics";
84        public static final String ACCUMULATED_RESOURCES_STATISTICS = CREATESTATISTICS + ".accumulatedresources";
85        public static final String EXTENDED_TASKS_STATISTICS = CREATESTATISTICS + ".extendedtasks";
86        public static final String GRIDLET_HISTORY_STATISTICS = CREATESTATISTICS + ".gridlethistory";
87        public static final String JOBS_STATISTICS = CREATESTATISTICS + ".jobs";
88        public static final String SIMULATION_STATISTICS = CREATESTATISTICS + ".simulation";
89        public static final String FORMAT_STATISTICS_OUTPUT = CREATESTATISTICS + ".formatoutput";
90       
91        /**
92         * The main output folders base name
93         */
94        public static final String STATS_OUTPUT_SUBFOLDER_NAME = "stats.outputfolder";
95       
96        public static final String USER_DN = "user.dn";
97        public static final String EXPERIMENT_ID = "experiment.id";
98       
99        public static final String NUMBER_OF_SIMULATIONS = "numberofsimulations";
100       
101        /**
102         * Suffix for create scenario output folder
103         */
104        public String statsOutputSubfolderNameCreate = null;
105       
106        /**
107         * Suffix for read scenario output folder
108         */
109        public String statsOutputSubfolderNameRerad = null;
110       
111        /* =============================================================================================== */
112       
113        public String providerListFile = null;
114
115
116        /**
117         * the xml file name with resource description (according to the
118         * HostParamSchema.xsd), e.g. simulator/schemas/ResourceDescription.xml
119         */
120        public String resdescFileName = null;
121
122        /**
123         * a xml file name (according to the simulator.schemas.WorkloadSchema.xsd)
124         * with the description of jobs and tasks to be generated
125         */
126        public String workloadDescFileName = null;
127
128        /**
129         * the path to the folder, to which the generated xml job descriptions are
130         * to be stored
131         */
132        public String outputFolder = null;
133
134        /**
135         * the name of the .swf simulator.workload file into which the
136         * simulator.workload is to be written (it will be stored in the
137         * outputFolder folder)
138         */
139        public String outputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME;
140
141        /**
142         * the path to the folder where previously generated xml jobs descriptions
143         * are stored
144         */
145        public String inputFolder = 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         * a txt file name with topology description
156         */
157        public String networkTopologyFileName = null;
158       
159        /**
160         * Shows the mode of the simulator: true if it is the create scenario, false
161         * if it is the read scenario mode
162         */
163        public boolean createScenario = false;
164       
165        public boolean createXMLSupplement = false;
166
167        /**
168         * true if the outputFolder is not empty and shall be overwritten, false
169         * otherwise
170         */
171        public boolean overwriteFiles = false;
172
173        /**
174         * true if the history files are to be generated (makes the simulation
175         * slower)
176         */
177        public boolean printHistory = false;
178       
179        /**
180         * The number of simulation runs that is to be performed. Default value is <code>1</code>.
181         */
182        public int numberOfSimulations = 1; //default value
183
184        public boolean creatediagrams_processors = true;
185        public boolean creatediagrams_reservations = true;
186        public boolean creatediagrams_resources = true;
187        public boolean creatediagrams_energyusage = true;
188        public boolean creatediagrams_tasks = true;
189        public boolean creatediagrams_taskswaitingtime = true;
190        public double     creatediagrams_resources_scale = 1;
191       
192        public boolean createaccumulatedresourcesstatistics = true;
193        public boolean createextendedtasksstatistics = true;
194        public boolean creategridlethistorystatistics = true;
195        public boolean createjobsstatistics = true;
196        public boolean createsimulationstatistics = true;
197        public boolean formatstatisticsoutput = false;
198       
199        public static final String ENV_DESC_MODIFIER = "envdesc";
200        public String envDescFileName = null;
201        /**
202         * An empty constructor.
203         */
204        protected ConfigurationOptions() {
205        }
206
207        /**
208         * A static method used to read a resource bundle file and set all the
209         * fields in this class according to the contents of the file
210         *
211         * @param resBundleFileName
212         *            the path to the resource bundle file that stores the
213         *            configuration
214         * @return a ConfigurationOptions object with information set according to
215         *         the properties file, <code>null</code> if any exception occurs
216         */
217        public static ConfigurationOptions getConfiguration(String resBundleFileName) {
218
219                ConfigurationOptions co = new ConfigurationOptions();
220                File resBundleFile = new File(resBundleFileName);
221                ResourceBundle bundle = null;
222                try {
223                        bundle = new PropertyResourceBundle(new FileInputStream(resBundleFile));
224                } catch (FileNotFoundException e) {
225                        e.printStackTrace();
226                        return null;
227                } catch (IOException e) {
228                        e.printStackTrace();
229                        return null;
230                }
231               
232                co.resdescFileName = bundle.getString(RESOURCE_DESC_MODIFIER);
233               
234                try {
235                        co.envDescFileName = bundle.getString(ENV_DESC_MODIFIER);
236                } catch(MissingResourceException e){
237                        co.envDescFileName = null;
238                }
239               
240                try {
241                        co.workloadDescFileName = bundle.getString(CREATE_SCENARIO_TASK_DESC);
242                        co.outputFolder = getSeparatorTerminatedPath(bundle
243                                        .getString(CREATE_SCENARIO_OUTPUT_FOLDER));
244                        File f = new File(co.outputFolder);
245                        String parent = f.getParent();
246                        // output folder will have the same parent as the task description
247                        // file
248                        if (parent == null) {
249                                f = new File(co.workloadDescFileName);
250                                parent = f.getParent();
251                                co.outputFolder = new File(parent, co.outputFolder)
252                                                .getAbsolutePath();
253                                co.outputFolder = getSeparatorTerminatedPath(co.outputFolder);
254                        }
255                        co.outputWorkloadFileName = bundle
256                                        .getString(CREATE_SCENARIO_WORKLOAD_FILE);
257                        co.overwriteFiles = Boolean.valueOf(
258                                        bundle.getString(CREATE_SCENARIO_OVERWRITE_FILES_MODIFIER))
259                                        .booleanValue();
260                        co.createScenario = true; // success
261
262                } catch (MissingResourceException e) {
263                        co.createScenario = false; // do not create scenario
264                }
265
266
267                try {
268                        co.networkTopologyFileName = bundle
269                                        .getString(NETWORK_TOPOLOGY_FILE_MODIFIER);
270                } catch(MissingResourceException e){
271                        co.networkTopologyFileName = null;
272                }
273               
274                if (co.createScenario == false) {
275                        // read scenario
276                        try {
277                                co.inputFolder = getSeparatorTerminatedPath(bundle
278                                        .getString(READ_SCENARIO_INPUT_FOLDER));
279                        } catch (MissingResourceException e) {
280                                co.inputFolder = null;
281                        }
282                       
283                        try {
284                                co.inputTar = getSeparatorTerminatedPath(bundle
285                                        .getString(READ_SCENARIO_INPUT_TAR));
286                        } catch (MissingResourceException e) {
287                                co.inputTar = null;
288                        }
289                       
290                        try {
291                                co.inputWorkloadFileName = bundle
292                                                .getString(READ_SCENARIO_WORKLOAD_FILE);
293                        } catch (MissingResourceException e){
294                                co.inputWorkloadFileName = null;
295                        }
296                }
297
298                try {
299                       
300                        if(Boolean.parseBoolean(
301                                        bundle.getString(CREATE_XML_SUPPLEMENT_FILES)))
302                                co.createXMLSupplement = true;
303                        else
304                                co.createXMLSupplement = false;
305                       
306                } catch (MissingResourceException e){
307                        co.createXMLSupplement = false;
308                }
309               
310                try {
311                        co.printHistory = Boolean.valueOf(
312                                        bundle.getString(PRINT_HISTORY_MODIFIER)).booleanValue();
313                } catch(MissingResourceException e){
314                        co.printHistory = false;
315                }
316               
317                // create diagrams
318               
319                boolean createDiagrams = true;
320                try {
321                        createDiagrams = Boolean.valueOf(
322                                        bundle.getString(CREATEDIAGRAMS)).booleanValue();
323                } catch(MissingResourceException e){
324                        createDiagrams = true;
325                }
326                try {
327                        co.creatediagrams_processors = Boolean.valueOf(
328                                        bundle.getString(CREATEDIAGRAMS_GANTT)).booleanValue() && createDiagrams;
329                } catch(MissingResourceException e){
330                        co.creatediagrams_processors = createDiagrams;
331                }
332                try {
333                        co.creatediagrams_reservations = Boolean.valueOf(
334                                        bundle.getString(CREATEDIAGRAMS_RESERVATIONS)).booleanValue() && createDiagrams;
335                } catch(MissingResourceException e){
336                        co.creatediagrams_reservations = createDiagrams;
337                }
338                try {
339                        co.creatediagrams_resources = Boolean.valueOf(
340                                        bundle.getString(CREATEDIAGRAMS_UTILIZATION)).booleanValue() && createDiagrams;
341                } catch(MissingResourceException e){
342                        co.creatediagrams_resources = createDiagrams;
343                }
344                try {
345                        co.creatediagrams_resources_scale = Double.valueOf(
346                                        bundle.getString(CREATEDIAGRAMS_RESOURCES_SCALE)).doubleValue();
347                } catch(MissingResourceException e){
348                        co.creatediagrams_resources_scale = -1;
349                }
350                try {
351                        co.creatediagrams_energyusage = Boolean.valueOf(
352                                        bundle.getString(CREATEDIAGRAMS_ENERGYUSAGE)).booleanValue() && createDiagrams;
353                } catch(MissingResourceException e){
354                        co.creatediagrams_energyusage = createDiagrams;
355                }
356                try {
357                        co.creatediagrams_tasks = Boolean.valueOf(
358                                        bundle.getString(CREATEDIAGRAMS_TASKS)).booleanValue() && createDiagrams;
359                } catch(MissingResourceException e){
360                        co.creatediagrams_tasks = createDiagrams;
361                }
362                try {
363                        co.creatediagrams_taskswaitingtime = Boolean.valueOf(
364                                        bundle.getString(CREATEDIAGRAMS_TASKSWAITINGTIME)).booleanValue() && createDiagrams;
365                } catch(MissingResourceException e){
366                        co.creatediagrams_taskswaitingtime = createDiagrams;
367                }
368               
369               
370                try {
371                        co.statsOutputSubfolderNameCreate = bundle.getString(STATS_OUTPUT_SUBFOLDER_NAME);
372                        co.statsOutputSubfolderNameRerad = co.statsOutputSubfolderNameCreate;
373                } catch(MissingResourceException e){
374                        co.statsOutputSubfolderNameCreate = "stats_create";
375                        co.statsOutputSubfolderNameRerad = "stats_read";
376                }
377
378                try {
379                        co.createaccumulatedresourcesstatistics = Boolean.valueOf(
380                                        bundle.getString(ACCUMULATED_RESOURCES_STATISTICS)).booleanValue();
381                } catch(MissingResourceException e){
382                        co.createaccumulatedresourcesstatistics = true;
383                }
384                try {
385                        co.createextendedtasksstatistics = Boolean.valueOf(
386                                        bundle.getString(EXTENDED_TASKS_STATISTICS)).booleanValue();
387                } catch(MissingResourceException e){
388                        co.createextendedtasksstatistics = true;
389                }
390                try {
391                        co.creategridlethistorystatistics = Boolean.valueOf(
392                                        bundle.getString(GRIDLET_HISTORY_STATISTICS)).booleanValue();
393                } catch(MissingResourceException e){
394                        co.creategridlethistorystatistics = true;
395                }
396                try {
397                        co.createjobsstatistics = Boolean.valueOf(
398                                        bundle.getString(JOBS_STATISTICS)).booleanValue();
399                } catch(MissingResourceException e){
400                        co.createjobsstatistics = true;
401                }
402                try {
403                        co.createsimulationstatistics = Boolean.valueOf(
404                                        bundle.getString(SIMULATION_STATISTICS)).booleanValue();
405                } catch(MissingResourceException e){
406                        co.createsimulationstatistics = true;
407                }
408                try {
409                        co.formatstatisticsoutput = Boolean.valueOf(
410                                        bundle.getString(FORMAT_STATISTICS_OUTPUT)).booleanValue();
411                } catch(MissingResourceException e){
412                        co.formatstatisticsoutput = false;
413                }
414               
415                try {
416                        co.numberOfSimulations = Integer.valueOf(bundle.getString(NUMBER_OF_SIMULATIONS)).intValue();
417                } catch(MissingResourceException e){
418                        co.numberOfSimulations = 1;
419                }
420                return co;
421        }
422
423        /**
424         * Creates a new configuration object in the CREATE_SCENARIO mode.
425         *
426         * @param gridSchedulingPluginName
427         * @param forecastFinishTimePluginName
428         * @param localAllocPolicyPluginName
429         * @param resdescFileName
430         * @param taskParamFileName
431         * @param outputFolder
432         * @param outputWorkloadFileName
433         * @param overwriteFiles
434         * @param printHistory
435         */
436        public ConfigurationOptions(String gridSchedulingPluginName,
437                        String exectimeestimationplugin,
438                        String localAllocPolicyPluginName, String resdescFileName,
439                        String taskParamFileName, String outputFolder,
440                        String outputWorkloadFileName, boolean overwriteFiles,
441                        boolean printHistory) {
442                super();
443                this.resdescFileName = resdescFileName;
444                this.workloadDescFileName = taskParamFileName;
445                this.outputFolder = getSeparatorTerminatedPath(outputFolder);
446                this.outputWorkloadFileName = outputWorkloadFileName;
447                this.overwriteFiles = overwriteFiles;
448                this.printHistory = printHistory;
449
450                // the create mode
451                this.createScenario = true;
452        }
453
454        /**
455         * Creates a new configuration object in the READ_SCENARIO mode.
456         *
457         * @param gridSchedulingPluginName
458         * @param forecastFinishTimePluginName
459         * @param localAllocPolicyPluginName
460         * @param resdescFileName
461         * @param inputFolder
462         * @param inputWorkloadFileName
463         * @param overwriteFiles
464         * @param printHistory
465         */
466        public ConfigurationOptions(String gridSchedulingPluginName,
467                        String exectimeestimationplugin,
468                        String localAllocPolicyPluginName, String resdescFileName,
469                        String inputFolder, String inputWorkloadFileName,
470                        boolean overwriteFiles, boolean printHistory) {
471                super();
472                this.resdescFileName = resdescFileName;
473                this.inputFolder = getSeparatorTerminatedPath(inputFolder);
474                this.inputWorkloadFileName = inputWorkloadFileName;
475                this.overwriteFiles = overwriteFiles;
476                this.printHistory = printHistory;
477                //FileHandler.loadDataset(new File("iris.data"), 4, ",");
478                // the read mode
479                this.createScenario = false;
480        }
481
482        public static String getSeparatorTerminatedPath(String path) {
483                if (path.endsWith(File.separator))
484                        return new String(path);
485                else {
486                        StringBuilder result = new StringBuilder(path.length()
487                                        + File.separator.length());
488                        result.append(path);
489                        result.append(File.separator);
490                        return result.toString();
491                }
492        }
493       
494        public void setNumberOfSimulations(int numberOfSimulations) {
495                this.numberOfSimulations = numberOfSimulations;
496        }
497       
498        public int getNumberOfSimulations() {
499                return numberOfSimulations;
500        }
501       
502        public void setWorkloadDescFileName(String workloadDescFileName) {
503                this.workloadDescFileName = workloadDescFileName;
504        }
505       
506        public String getWorkloadDescFileName() {
507                return workloadDescFileName;
508        }
509}
Note: See TracBrowser for help on using the repository browser.