1 | package simulator.factory; |
---|
2 | |
---|
3 | import org.apache.commons.logging.Log; |
---|
4 | import org.apache.commons.logging.impl.LogFactoryImpl; |
---|
5 | |
---|
6 | import cern.jet.random.AbstractDistribution; |
---|
7 | import eduni.simjava.distributions.PeriodicGenerator; |
---|
8 | |
---|
9 | import simulator.RandomNumbers; |
---|
10 | import simulator.workload.generator.configuration.ComputingResourceHostParameter; |
---|
11 | import simulator.workload.generator.configuration.Dist; |
---|
12 | import simulator.workload.generator.configuration.ExecDuration; |
---|
13 | import simulator.workload.generator.configuration.ExecutionTime; |
---|
14 | import simulator.workload.generator.configuration.ExecutionTimeChoice; |
---|
15 | import simulator.workload.generator.configuration.Importance; |
---|
16 | import simulator.workload.generator.configuration.JobCount; |
---|
17 | import simulator.workload.generator.configuration.JobInterval; |
---|
18 | import simulator.workload.generator.configuration.JobPackageLength; |
---|
19 | import simulator.workload.generator.configuration.Max; |
---|
20 | import simulator.workload.generator.configuration.Min; |
---|
21 | import simulator.workload.generator.configuration.MultiDistribution; |
---|
22 | import simulator.workload.generator.configuration.OutputFileSize; |
---|
23 | import simulator.workload.generator.configuration.Parameter; |
---|
24 | import simulator.workload.generator.configuration.ParentCard; |
---|
25 | import simulator.workload.generator.configuration.ParentStates_OR; |
---|
26 | import simulator.workload.generator.configuration.PeriodDuration; |
---|
27 | import simulator.workload.generator.configuration.PeriodEnd; |
---|
28 | import simulator.workload.generator.configuration.PeriodStart; |
---|
29 | import simulator.workload.generator.configuration.PeriodicValidValues; |
---|
30 | import simulator.workload.generator.configuration.PrecedingConstraints; |
---|
31 | import simulator.workload.generator.configuration.Preferences; |
---|
32 | import simulator.workload.generator.configuration.RandParams; |
---|
33 | import simulator.workload.generator.configuration.RandParamsSequence; |
---|
34 | import simulator.workload.generator.configuration.Range; |
---|
35 | import simulator.workload.generator.configuration.RunSameHost; |
---|
36 | import simulator.workload.generator.configuration.TaskCount; |
---|
37 | import simulator.workload.generator.configuration.TaskLength; |
---|
38 | import simulator.workload.generator.configuration.Trigger; |
---|
39 | import simulator.workload.generator.configuration.Triggers; |
---|
40 | import simulator.workload.generator.configuration.Value; |
---|
41 | import simulator.workload.generator.configuration.WorkflowLevel; |
---|
42 | import simulator.workload.generator.configuration.WorkloadConfiguration; |
---|
43 | |
---|
44 | |
---|
45 | public class JobRandomNubersFactory { |
---|
46 | |
---|
47 | protected String triggerNames[]; |
---|
48 | |
---|
49 | private static Log log = LogFactoryImpl.getLog(JobRandomNubersFactory.class); |
---|
50 | |
---|
51 | /** |
---|
52 | * |
---|
53 | * @param workload |
---|
54 | * @param jobCountDescriptor |
---|
55 | * @param taskCountDescriptor |
---|
56 | * @param taskLengthDescriptor |
---|
57 | * @param tasksDistanceDescriptor |
---|
58 | * @param tasksPackageLengthDescriptor |
---|
59 | * @param taskWaitTimeDescriptor |
---|
60 | * @return |
---|
61 | */ |
---|
62 | public RandomNumbers initParameterRandomNumbers( |
---|
63 | WorkloadConfiguration workload){ |
---|
64 | |
---|
65 | RandomNumbers parameterRandomNumbers = new RandomNumbers(); |
---|
66 | String name = null; |
---|
67 | |
---|
68 | if (workload.getWorkloadConfigurationChoice().getJobCount() != null) { |
---|
69 | JobCount jobCount = workload.getWorkloadConfigurationChoice().getJobCount(); |
---|
70 | name = getGeneratorName(jobCount); |
---|
71 | if(log.isDebugEnabled()){ |
---|
72 | log.debug("Creating genrator for JobCount. Generator id: " + name); |
---|
73 | } |
---|
74 | addRandomNumbers(parameterRandomNumbers, jobCount, name); |
---|
75 | } |
---|
76 | |
---|
77 | TaskCount taskCount = workload.getTaskCount(); |
---|
78 | name = getGeneratorName(taskCount); |
---|
79 | if(log.isDebugEnabled()){ |
---|
80 | log.debug("Creating genrator for TaskCount range.min. Generator id: " + name); |
---|
81 | } |
---|
82 | addRandomNumbers(parameterRandomNumbers, taskCount, name); |
---|
83 | |
---|
84 | TaskLength taskLength = workload.getTaskLength(); |
---|
85 | name = getGeneratorName(taskLength); |
---|
86 | if(log.isDebugEnabled()){ |
---|
87 | log.debug("Creating genrator for TaskLength range.min. Generator id: " + name); |
---|
88 | } |
---|
89 | addRandomNumbers(parameterRandomNumbers, taskLength, name); |
---|
90 | |
---|
91 | JobInterval jobInterval = workload.getJobInterval(); |
---|
92 | name = getGeneratorName(jobInterval); |
---|
93 | if(log.isDebugEnabled()){ |
---|
94 | log.debug("Creating genrator for JobInterval range.min. Generator id: " + name); |
---|
95 | } |
---|
96 | addRandomNumbers(parameterRandomNumbers, jobInterval, name); |
---|
97 | |
---|
98 | JobPackageLength jobPackageLength = workload.getJobPackageLength(); |
---|
99 | name = getGeneratorName(jobPackageLength); |
---|
100 | if(log.isDebugEnabled()){ |
---|
101 | log.debug("Creating genrator for JobPackageLength range.min. Generator id: " + name); |
---|
102 | } |
---|
103 | addRandomNumbers(parameterRandomNumbers, jobPackageLength, name); |
---|
104 | |
---|
105 | return parameterRandomNumbers; |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * |
---|
110 | * @param workload |
---|
111 | * @param maxDescriptor |
---|
112 | * @param minDescriptor |
---|
113 | * @param valueDescriptor |
---|
114 | * @return |
---|
115 | */ |
---|
116 | public RandomNumbers initHardConstraintsRandomNumbers(WorkloadConfiguration workload){ |
---|
117 | |
---|
118 | RandomNumbers hardConstraintsRandomNumbers = new RandomNumbers(); |
---|
119 | |
---|
120 | ComputingResourceHostParameter[] hardConstraints = workload.getComputingResourceHostParameter(); |
---|
121 | if (hardConstraints != null && hardConstraints.length > 0) { |
---|
122 | for (int i = 0; i < hardConstraints.length; ++i) { |
---|
123 | ComputingResourceHostParameter hardConstraint = hardConstraints[i]; |
---|
124 | String name = hardConstraint.getMetric(); |
---|
125 | |
---|
126 | Range[] ranges = hardConstraint.getRange(); |
---|
127 | for (int r = 0; r < ranges.length; ++r) { |
---|
128 | Range range = ranges[r]; |
---|
129 | Max max = range.getMax(); |
---|
130 | if (max != null) { |
---|
131 | String maxName = getGeneratorName(max); |
---|
132 | if(log.isDebugEnabled()){ |
---|
133 | log.debug("Creating genrator for " + name + " " + r + " range.min. Generator id: " + maxName); |
---|
134 | } |
---|
135 | addRandomNumbers(hardConstraintsRandomNumbers, max, maxName); |
---|
136 | } |
---|
137 | Min min = range.getMin(); |
---|
138 | if (min != null) { |
---|
139 | String minName = getGeneratorName(min); |
---|
140 | if(log.isDebugEnabled()){ |
---|
141 | log.debug("Creating genrator for " + name + " " + r + " range.min. Generator id: " + minName); |
---|
142 | } |
---|
143 | addRandomNumbers(hardConstraintsRandomNumbers, min, minName); |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | Value[] values = hardConstraint.getValue(); |
---|
148 | for (int v = 0; v < values.length; ++v) { |
---|
149 | Value value = values[v]; |
---|
150 | String valueName = getGeneratorName(value); |
---|
151 | if(log.isDebugEnabled()){ |
---|
152 | log.debug("Creating genrator for " + name + " " + v + " value. Generator id: "+valueName); |
---|
153 | } |
---|
154 | addRandomNumbers(hardConstraintsRandomNumbers, value, valueName); |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | return hardConstraintsRandomNumbers; |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | * |
---|
164 | * @param workload |
---|
165 | * @param indiffThresholdDescriptor |
---|
166 | * @param importanceDescriptor |
---|
167 | * @return |
---|
168 | */ |
---|
169 | public RandomNumbers initSoftConstraintsRandomNumbers(WorkloadConfiguration workload){ |
---|
170 | |
---|
171 | RandomNumbers softConstraintsRandomNumbers = new RandomNumbers(); |
---|
172 | String name; |
---|
173 | String detailName; |
---|
174 | Preferences softConstraints = workload.getPreferences(); |
---|
175 | if (softConstraints != null) { |
---|
176 | Parameter[] constraints = softConstraints.getParameter(); |
---|
177 | for (int i = 0; i < constraints.length; ++i) { |
---|
178 | Parameter constraint = constraints[i]; |
---|
179 | //the name is a big concatenation |
---|
180 | name = constraint.getName(); |
---|
181 | |
---|
182 | Importance importance = constraint.getImportance(); |
---|
183 | detailName = getGeneratorName(importance); |
---|
184 | |
---|
185 | if(log.isDebugEnabled()){ |
---|
186 | log.debug("Creating genrator for parameter " + name + " importance. Generator id: " + detailName); |
---|
187 | } |
---|
188 | addRandomNumbers(softConstraintsRandomNumbers, importance, detailName); |
---|
189 | |
---|
190 | Range rangeTab[] = constraint.getRange(); |
---|
191 | if(rangeTab != null && rangeTab.length > 0){ |
---|
192 | Range range = rangeTab[0]; |
---|
193 | Min min = range.getMin(); |
---|
194 | detailName = getGeneratorName(min); |
---|
195 | if(log.isDebugEnabled()){ |
---|
196 | log.debug("Creating genrator for parameter " + name + " range.min. Generator id: " + detailName); |
---|
197 | } |
---|
198 | addRandomNumbers(softConstraintsRandomNumbers, min, detailName); |
---|
199 | |
---|
200 | Max max = range.getMax(); |
---|
201 | detailName = getGeneratorName(max); |
---|
202 | if(log.isDebugEnabled()){ |
---|
203 | log.debug("Creating genrator for parameter " + name + " range.max. Generator id: " + detailName); |
---|
204 | } |
---|
205 | |
---|
206 | addRandomNumbers(softConstraintsRandomNumbers, max, detailName); |
---|
207 | } |
---|
208 | |
---|
209 | Value value = constraint.getValue(); |
---|
210 | if(value != null){ |
---|
211 | detailName = getGeneratorName(value); |
---|
212 | if(log.isDebugEnabled()){ |
---|
213 | log.debug("Creating genrator for parameter " + name + " value. Generator id: " + detailName); |
---|
214 | } |
---|
215 | |
---|
216 | addRandomNumbers(softConstraintsRandomNumbers, value, detailName); |
---|
217 | } |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | return softConstraintsRandomNumbers; |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | /** |
---|
226 | * |
---|
227 | * @param workload |
---|
228 | * @return |
---|
229 | */ |
---|
230 | public RandomNumbers initTimeConstraintsRandomNumbers(WorkloadConfiguration workload){ |
---|
231 | RandomNumbers timeConstraintsRandomNumbers = new RandomNumbers(); |
---|
232 | ExecutionTime timeConstraints = workload.getExecutionTime(); |
---|
233 | |
---|
234 | if(timeConstraints != null) { |
---|
235 | String name = null; |
---|
236 | PeriodStart periodStart = timeConstraints.getPeriodStart(); |
---|
237 | if(periodStart != null){ |
---|
238 | name = getGeneratorName(periodStart); |
---|
239 | if(log.isDebugEnabled()){ |
---|
240 | log.debug("Creating genrator for parameter ExecutionTime.PeriodStart Generator id: " + name); |
---|
241 | } |
---|
242 | addRandomNumbers(timeConstraintsRandomNumbers, periodStart, name); |
---|
243 | } |
---|
244 | |
---|
245 | ExecDuration execDuration = timeConstraints.getExecDuration(); |
---|
246 | if(execDuration != null){ |
---|
247 | name = getGeneratorName(execDuration); |
---|
248 | if(log.isDebugEnabled()){ |
---|
249 | log.debug("Creating genrator for parameter ExecutionTime.ExecutionDuration Generator id: " + name); |
---|
250 | } |
---|
251 | addRandomNumbers(timeConstraintsRandomNumbers, execDuration, name); |
---|
252 | } |
---|
253 | |
---|
254 | ExecutionTimeChoice choice = timeConstraints.getExecutionTimeChoice(); |
---|
255 | if(choice != null) { |
---|
256 | |
---|
257 | PeriodDuration periodDuration = choice.getPeriodDuration(); |
---|
258 | if(periodDuration != null){ |
---|
259 | name = getGeneratorName(periodDuration); |
---|
260 | if(log.isDebugEnabled()){ |
---|
261 | log.debug("Creating genrator for parameter ExecutionTime.PeriodDuration Generator id: " + name); |
---|
262 | } |
---|
263 | addRandomNumbers(timeConstraintsRandomNumbers, periodDuration, name); |
---|
264 | } |
---|
265 | |
---|
266 | PeriodEnd periodEnd = choice.getPeriodEnd(); |
---|
267 | if(periodEnd != null) { |
---|
268 | name = getGeneratorName(periodEnd); |
---|
269 | if(log.isDebugEnabled()){ |
---|
270 | log.debug("Creating genrator for parameter ExecutionTime.PeriodEnd Generator id: " + name); |
---|
271 | } |
---|
272 | addRandomNumbers(timeConstraintsRandomNumbers, periodEnd, name); |
---|
273 | } |
---|
274 | } |
---|
275 | } |
---|
276 | return timeConstraintsRandomNumbers; |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | /** |
---|
281 | * |
---|
282 | * @param workload |
---|
283 | * @return |
---|
284 | */ |
---|
285 | public RandomNumbers initPrecedingConstraintsRandomNumbers(WorkloadConfiguration workload){ |
---|
286 | RandomNumbers precedingConstraintsRandomNumbers = new RandomNumbers(); |
---|
287 | PrecedingConstraints constraints = workload.getPrecedingConstraints(); |
---|
288 | |
---|
289 | if(constraints == null) |
---|
290 | return precedingConstraintsRandomNumbers; |
---|
291 | |
---|
292 | ParentCard parentCard = constraints.getParentCard(); |
---|
293 | String name = null; |
---|
294 | |
---|
295 | if(parentCard != null){ |
---|
296 | name = getGeneratorName(parentCard); |
---|
297 | if(log.isDebugEnabled()){ |
---|
298 | log.debug("Creating genrator for PrecedingConstraints.ParentCard Generator id: " + name); |
---|
299 | } |
---|
300 | addRandomNumbers(precedingConstraintsRandomNumbers, parentCard, name); |
---|
301 | } |
---|
302 | |
---|
303 | WorkflowLevel workflowLevel = constraints.getWorkflowLevel(); |
---|
304 | if(workflowLevel != null){ |
---|
305 | name = getGeneratorName(workflowLevel); |
---|
306 | if(log.isDebugEnabled()){ |
---|
307 | log.debug("Creating genrator for PrecedingConstraints.WorkflowLevel Generator id: " + name); |
---|
308 | } |
---|
309 | addRandomNumbers(precedingConstraintsRandomNumbers, workflowLevel, name); |
---|
310 | } |
---|
311 | |
---|
312 | OutputFileSize outputFileSize = constraints.getOutputFileSize(); |
---|
313 | if(outputFileSize != null){ |
---|
314 | name = getGeneratorName(outputFileSize); |
---|
315 | if(log.isDebugEnabled()){ |
---|
316 | log.debug("Creating genrator for PrecedingConstraints.OutputFileSize Generator id: " + name); |
---|
317 | } |
---|
318 | addRandomNumbers(precedingConstraintsRandomNumbers, outputFileSize, name); |
---|
319 | } |
---|
320 | |
---|
321 | ParentStates_OR parentStates = constraints.getParentStates_OR(); |
---|
322 | if(parentStates != null){ |
---|
323 | name = getGeneratorName(parentStates); |
---|
324 | if(log.isDebugEnabled()){ |
---|
325 | log.debug("Creating genrator for PrecedingConstraints.ParentStates_OR Generator id: " + name); |
---|
326 | } |
---|
327 | addRandomNumbers(precedingConstraintsRandomNumbers, parentStates, name); |
---|
328 | } |
---|
329 | |
---|
330 | RunSameHost runSameHost = constraints.getRunSameHost(); |
---|
331 | if(runSameHost != null){ |
---|
332 | name = getGeneratorName(runSameHost); |
---|
333 | if(log.isDebugEnabled()){ |
---|
334 | log.debug("Creating genrator for PrecedingConstraints.RunSameHost Generator id: " + name); |
---|
335 | } |
---|
336 | addRandomNumbers(precedingConstraintsRandomNumbers, runSameHost, name); |
---|
337 | } |
---|
338 | |
---|
339 | Trigger trigger; |
---|
340 | Triggers triggers = constraints.getTriggers(); |
---|
341 | String tname; |
---|
342 | if(triggers != null){ |
---|
343 | triggerNames = new String[triggers.getTriggerCount()]; |
---|
344 | |
---|
345 | for(int i = 0; i < triggers.getTriggerCount(); i++){ |
---|
346 | trigger = triggers.getTrigger(i); |
---|
347 | triggerNames[i] = (String)trigger.getName(); |
---|
348 | tname = getGeneratorName(trigger); |
---|
349 | if(log.isDebugEnabled()){ |
---|
350 | log.debug("Creating genrator for PrecedingConstraints.Trigger " + triggerNames[i] + " Generator id: " + tname); |
---|
351 | } |
---|
352 | addRandomNumbers(precedingConstraintsRandomNumbers, trigger, tname); |
---|
353 | } |
---|
354 | } |
---|
355 | |
---|
356 | return precedingConstraintsRandomNumbers; |
---|
357 | } |
---|
358 | |
---|
359 | protected RandomNumbers addPeriodicValidValues(RandomNumbers randomNumbers, RandParams params, String name){ |
---|
360 | PeriodicValidValues values[]; |
---|
361 | int len = 0; |
---|
362 | |
---|
363 | if(params.getRandParamsSequence() == null) |
---|
364 | return randomNumbers; |
---|
365 | |
---|
366 | len = params.getRandParamsSequence().getPeriodicValidValuesCount(); |
---|
367 | if(len == 0) |
---|
368 | return randomNumbers; |
---|
369 | |
---|
370 | values = params.getRandParamsSequence().getPeriodicValidValues(); |
---|
371 | for(int i = 0; i < values.length; i++){ |
---|
372 | if(randomNumbers.addRandomGenerator(name, values[i])){ |
---|
373 | if(values[i].getId() != null){ |
---|
374 | randomNumbers.addIdGeneratorNameMapping(values[i].getId(), name); |
---|
375 | } |
---|
376 | } |
---|
377 | } |
---|
378 | return randomNumbers; |
---|
379 | } |
---|
380 | |
---|
381 | protected RandomNumbers addDetailDistributions(RandomNumbers randomNumbers, RandParams params, String name){ |
---|
382 | MultiDistribution md = null; |
---|
383 | Dist distTable[] = null; |
---|
384 | |
---|
385 | md = params.getMultiDistribution(); |
---|
386 | if(md == null) |
---|
387 | return randomNumbers; |
---|
388 | |
---|
389 | distTable = md.getDist(); |
---|
390 | for(int i = 0; i < distTable.length; i++){ |
---|
391 | if(randomNumbers.addRandomGenerator(name, distTable[i])){ |
---|
392 | if(distTable[i].getId() != null) |
---|
393 | randomNumbers.addIdGeneratorNameMapping(distTable[i].getId(), name); |
---|
394 | } |
---|
395 | } |
---|
396 | return randomNumbers; |
---|
397 | } |
---|
398 | |
---|
399 | public boolean addRandomNumbers(RandomNumbers rn, RandParams rp, String name) { |
---|
400 | MultiDistribution md = null; |
---|
401 | RandParamsSequence randParamSeq = null; |
---|
402 | AbstractDistribution generator; |
---|
403 | |
---|
404 | md = rp.getMultiDistribution(); |
---|
405 | randParamSeq = rp.getRandParamsSequence(); |
---|
406 | |
---|
407 | // if simple generator definition is used |
---|
408 | if(md == null && randParamSeq == null){ |
---|
409 | |
---|
410 | if(rn.addRandomGenerator(rp.getDistribution().getType(), rp.hasAvg(), rp.getAvg(), rp.getStdev(), |
---|
411 | rp.hasMin(), rp.getMin(), rp.hasMax(), rp.getMax(), rp.hasSeed(), rp.getSeed(), name)) { |
---|
412 | if(rp.getId() != null) |
---|
413 | rn.addIdGeneratorNameMapping(rp.getId(), name); |
---|
414 | return true; |
---|
415 | } else { |
---|
416 | return false; |
---|
417 | } |
---|
418 | |
---|
419 | |
---|
420 | } else if(md != null && randParamSeq == null){ // if multidistribution is used |
---|
421 | /* |
---|
422 | * TODO Marcin: dopelnienie do 1 (do 100%) moze zostac zdefiniowane w glownym elemencie |
---|
423 | * Sprawdzic czy faktycznie potrzeba uzupelnienia do 100%, a nastepnie |
---|
424 | * trzeba by dodac tak opisany generator za pomoca rn.addRandomGenerator(parameterName, detailDist) |
---|
425 | */ |
---|
426 | addDetailDistributions(rn, rp, name); |
---|
427 | if(rp.getId() != null) |
---|
428 | rn.addIdGeneratorNameMapping(rp.getId(), name); |
---|
429 | |
---|
430 | } else if(md == null && randParamSeq != null){ // if periodic valid values are used |
---|
431 | |
---|
432 | generator = rn.createRandomGenerator(rp.getDistribution().getType(), rp.hasAvg(), rp.getAvg(), |
---|
433 | rp.getStdev(), rp.hasMin(), rp.getMin(), rp.hasMax(), rp.getMax(), rp.hasSeed(), rp.getSeed(), name); |
---|
434 | if(generator == null) |
---|
435 | throw new RuntimeException("Define default generator (which will be valid for whole simulation time) for "+name); |
---|
436 | |
---|
437 | PeriodicGenerator pg = new PeriodicGenerator(generator); |
---|
438 | rn.addRandomGenerator(name, pg); |
---|
439 | |
---|
440 | addPeriodicValidValues(rn, rp, name); |
---|
441 | if(rp.getId() != null) |
---|
442 | rn.addIdGeneratorNameMapping(rp.getId(), name); |
---|
443 | |
---|
444 | } else { |
---|
445 | throw new RuntimeException("Use Multidistribution _OR_ Periodic valid values. This two things can not be used togeter."); |
---|
446 | } |
---|
447 | |
---|
448 | return true; |
---|
449 | } |
---|
450 | |
---|
451 | |
---|
452 | |
---|
453 | /** |
---|
454 | * |
---|
455 | * @return |
---|
456 | */ |
---|
457 | public String[] getTriggerNames(){ |
---|
458 | return triggerNames; |
---|
459 | } |
---|
460 | |
---|
461 | public static String getGeneratorName(Object object){ |
---|
462 | return String.valueOf(object.hashCode()); |
---|
463 | } |
---|
464 | |
---|
465 | } |
---|
466 | |
---|