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

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