1 | package simulator; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.FileInputStream; |
---|
5 | import java.io.FileNotFoundException; |
---|
6 | import java.io.IOException; |
---|
7 | import java.util.MissingResourceException; |
---|
8 | import java.util.PropertyResourceBundle; |
---|
9 | import 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 | */ |
---|
20 | public 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 | /** |
---|
82 | * The main output folders base name |
---|
83 | */ |
---|
84 | public static final String STATS_OUTPUT_SUBFOLDER_NAME = "stats.outputfolder"; |
---|
85 | |
---|
86 | public static final String USER_DN = "user.dn"; |
---|
87 | public static final String EXPERIMENT_ID = "experiment.id"; |
---|
88 | |
---|
89 | public static final String NUMBER_OF_SIMULATIONS = "numberofsimulations"; |
---|
90 | |
---|
91 | /** |
---|
92 | * Suffix for create scenario output folder |
---|
93 | */ |
---|
94 | public String statsOutputSubfolderNameCreate = null; |
---|
95 | |
---|
96 | /** |
---|
97 | * Suffix for read scenario output folder |
---|
98 | */ |
---|
99 | public String statsOutputSubfolderNameRerad = null; |
---|
100 | |
---|
101 | /* =============================================================================================== */ |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | /** |
---|
106 | * the xml file name with resource description (according to the |
---|
107 | * HostParamSchema.xsd), e.g. simulator/schemas/ResourceDescription.xml |
---|
108 | */ |
---|
109 | public String resdescFileName = null; |
---|
110 | |
---|
111 | /** |
---|
112 | * a xml file name (according to the simulator.schemas.WorkloadSchema.xsd) |
---|
113 | * with the description of jobs and tasks to be generated |
---|
114 | */ |
---|
115 | public String workloadDescFileName = null; |
---|
116 | |
---|
117 | /** |
---|
118 | * the path to the folder, to which the generated xml job descriptions are |
---|
119 | * to be stored |
---|
120 | */ |
---|
121 | public String outputFolder = null; |
---|
122 | |
---|
123 | /** |
---|
124 | * the name of the .swf simulator.workload file into which the |
---|
125 | * simulator.workload is to be written (it will be stored in the |
---|
126 | * outputFolder folder) |
---|
127 | */ |
---|
128 | public String outputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME; |
---|
129 | |
---|
130 | /** |
---|
131 | * the path to the folder where previously generated xml jobs descriptions |
---|
132 | * are stored |
---|
133 | */ |
---|
134 | public String inputFolder = null; |
---|
135 | |
---|
136 | public String inputTar = null; |
---|
137 | |
---|
138 | /** |
---|
139 | * the name of the .swf simulator.workload file in the inputFolder folder |
---|
140 | */ |
---|
141 | public String inputWorkloadFileName = DEFAULT_WORKLOAD_FILE_NAME; |
---|
142 | |
---|
143 | |
---|
144 | /** |
---|
145 | * Shows the mode of the simulator: true if it is the create scenario, false |
---|
146 | * if it is the read scenario mode |
---|
147 | */ |
---|
148 | public boolean createScenario = false; |
---|
149 | |
---|
150 | public boolean createXMLSupplement = false; |
---|
151 | |
---|
152 | /** |
---|
153 | * true if the outputFolder is not empty and shall be overwritten, false |
---|
154 | * otherwise |
---|
155 | */ |
---|
156 | public boolean overwriteFiles = false; |
---|
157 | |
---|
158 | |
---|
159 | /** |
---|
160 | * The number of simulation runs that is to be performed. Default value is <code>1</code>. |
---|
161 | */ |
---|
162 | public int numberOfSimulations = 1; //default value |
---|
163 | |
---|
164 | public boolean creatediagrams_gantt = false; |
---|
165 | public boolean creatediagrams_tasks = false; |
---|
166 | public boolean creatediagrams_taskswaitingtime = false; |
---|
167 | |
---|
168 | public boolean creatediagrams_resutilization = false; |
---|
169 | public boolean creatediagrams_respowerusage = false; |
---|
170 | public boolean creatediagrams_resairflow = false; |
---|
171 | public double creatediagrams_resources_scale = 1; |
---|
172 | |
---|
173 | public boolean createjobsstatistics = true; |
---|
174 | public boolean createsimulationstatistics = true; |
---|
175 | |
---|
176 | public String [] resForEnergyChart; |
---|
177 | public String [] resForAirFlowChart; |
---|
178 | public String [] resForUtilizationChart; |
---|
179 | |
---|
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); |
---|
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 = false; |
---|
276 | } |
---|
277 | try { |
---|
278 | co.creatediagrams_gantt = Boolean.valueOf( |
---|
279 | bundle.getString(CREATEDIAGRAMS_GANTT)).booleanValue(); |
---|
280 | } catch(MissingResourceException e){ |
---|
281 | co.creatediagrams_gantt = createDiagrams; |
---|
282 | } |
---|
283 | |
---|
284 | try { |
---|
285 | co.resForUtilizationChart = bundle.getString(CREATEDIAGRAMS_UTILIZATION).split(";"); |
---|
286 | if(co.resForUtilizationChart.length > 0){ |
---|
287 | co.creatediagrams_resutilization = true; |
---|
288 | } |
---|
289 | } catch(MissingResourceException e){ |
---|
290 | co.creatediagrams_resutilization = 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_respowerusage = true; |
---|
302 | } |
---|
303 | } catch(MissingResourceException e){ |
---|
304 | co.creatediagrams_respowerusage = createDiagrams; |
---|
305 | } |
---|
306 | |
---|
307 | try { |
---|
308 | co.resForAirFlowChart = bundle.getString(CREATEDIAGRAMS_AIRFLOW).split(";"); |
---|
309 | if(co.resForAirFlowChart.length > 0){ |
---|
310 | co.creatediagrams_resairflow = true; |
---|
311 | } |
---|
312 | } catch(MissingResourceException e){ |
---|
313 | co.creatediagrams_resairflow = createDiagrams; |
---|
314 | } |
---|
315 | |
---|
316 | try { |
---|
317 | co.creatediagrams_tasks = Boolean.valueOf( |
---|
318 | bundle.getString(CREATEDIAGRAMS_TASKS)).booleanValue(); |
---|
319 | } catch(MissingResourceException e){ |
---|
320 | co.creatediagrams_tasks = createDiagrams; |
---|
321 | } |
---|
322 | try { |
---|
323 | co.creatediagrams_taskswaitingtime = Boolean.valueOf( |
---|
324 | bundle.getString(CREATEDIAGRAMS_TASKSWAITINGTIME)).booleanValue(); |
---|
325 | } catch(MissingResourceException e){ |
---|
326 | co.creatediagrams_taskswaitingtime = createDiagrams; |
---|
327 | } |
---|
328 | |
---|
329 | try { |
---|
330 | co.statsOutputSubfolderNameCreate = bundle.getString(STATS_OUTPUT_SUBFOLDER_NAME); |
---|
331 | co.statsOutputSubfolderNameRerad = co.statsOutputSubfolderNameCreate; |
---|
332 | } catch(MissingResourceException e){ |
---|
333 | co.statsOutputSubfolderNameCreate = "stats_create"; |
---|
334 | co.statsOutputSubfolderNameRerad = "stats_read"; |
---|
335 | } |
---|
336 | |
---|
337 | try { |
---|
338 | co.createjobsstatistics = Boolean.valueOf( |
---|
339 | bundle.getString(JOBS_STATISTICS)).booleanValue(); |
---|
340 | } catch(MissingResourceException e){ |
---|
341 | co.createjobsstatistics = true; |
---|
342 | } |
---|
343 | try { |
---|
344 | co.createsimulationstatistics = Boolean.valueOf( |
---|
345 | bundle.getString(SIMULATION_STATISTICS)).booleanValue(); |
---|
346 | } catch(MissingResourceException e){ |
---|
347 | co.createsimulationstatistics = true; |
---|
348 | } |
---|
349 | |
---|
350 | try { |
---|
351 | co.numberOfSimulations = Integer.valueOf(bundle.getString(NUMBER_OF_SIMULATIONS)).intValue(); |
---|
352 | } catch(MissingResourceException e){ |
---|
353 | co.numberOfSimulations = 1; |
---|
354 | } |
---|
355 | return co; |
---|
356 | } |
---|
357 | |
---|
358 | public static String getSeparatorTerminatedPath(String path) { |
---|
359 | if (path.endsWith(File.separator)) |
---|
360 | return new String(path); |
---|
361 | else { |
---|
362 | StringBuilder result = new StringBuilder(path.length() |
---|
363 | + File.separator.length()); |
---|
364 | result.append(path); |
---|
365 | result.append(File.separator); |
---|
366 | return result.toString(); |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | public void setNumberOfSimulations(int numberOfSimulations) { |
---|
371 | this.numberOfSimulations = numberOfSimulations; |
---|
372 | } |
---|
373 | |
---|
374 | public int getNumberOfSimulations() { |
---|
375 | return numberOfSimulations; |
---|
376 | } |
---|
377 | |
---|
378 | public void setWorkloadDescFileName(String workloadDescFileName) { |
---|
379 | this.workloadDescFileName = workloadDescFileName; |
---|
380 | } |
---|
381 | |
---|
382 | public String getWorkloadDescFileName() { |
---|
383 | return workloadDescFileName; |
---|
384 | } |
---|
385 | } |
---|