1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.reliability.solver.sensitivity; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.List; |
8 | |
9 | import org.apache.log4j.Logger; |
10 | import org.eclipse.emf.common.util.EList; |
11 | |
12 | import de.uka.ipd.sdq.pcm.reliability.SoftwareInducedFailureType; |
13 | import de.uka.ipd.sdq.reliability.core.helper.EMFHelper; |
14 | import de.uka.ipd.sdq.sensitivity.CombinedSensitivityParameter; |
15 | import de.uka.ipd.sdq.sensitivity.CommunicationLinkReliabilityParameter; |
16 | import de.uka.ipd.sdq.sensitivity.ComponentReliabilityParameter; |
17 | import de.uka.ipd.sdq.sensitivity.DoubleParameterVariation; |
18 | import de.uka.ipd.sdq.sensitivity.HardwareMTTFParameter; |
19 | import de.uka.ipd.sdq.sensitivity.HardwareMTTRParameter; |
20 | import de.uka.ipd.sdq.sensitivity.InternalActionReliabilityParameter; |
21 | import de.uka.ipd.sdq.sensitivity.NetworkReliabilityParameter; |
22 | import de.uka.ipd.sdq.sensitivity.ProbabilisticBranchParameter; |
23 | import de.uka.ipd.sdq.sensitivity.ResourceMTTFParameter; |
24 | import de.uka.ipd.sdq.sensitivity.ResourceMTTRParameter; |
25 | import de.uka.ipd.sdq.sensitivity.SensitivityConfiguration; |
26 | import de.uka.ipd.sdq.sensitivity.SensitivityPackage; |
27 | import de.uka.ipd.sdq.sensitivity.SensitivityParameter; |
28 | import de.uka.ipd.sdq.sensitivity.SensitivityParameterVariation; |
29 | import de.uka.ipd.sdq.sensitivity.SensitivityResultSpecification; |
30 | import de.uka.ipd.sdq.sensitivity.SoftwareFailureTypesParameter; |
31 | import de.uka.ipd.sdq.sensitivity.SoftwareReliabilityParameter; |
32 | import de.uka.ipd.sdq.sensitivity.StringParameterSequence; |
33 | import de.uka.ipd.sdq.sensitivity.UsageBranchParameter; |
34 | import de.uka.ipd.sdq.sensitivity.VariableUsageParameter; |
35 | |
36 | /** |
37 | * Creates sensitivity information from a given input sensitivity model. |
38 | * |
39 | * @author brosch |
40 | * |
41 | */ |
42 | public class MarkovSensitivityBuilder { |
43 | |
44 | /** |
45 | * A logger to give detailed information about the PCM instance traversal. |
46 | */ |
47 | private static Logger logger = Logger |
48 | .getLogger(MarkovSensitivityBuilder.class.getName()); |
49 | |
50 | /** |
51 | * Creates the sensitivity information. |
52 | * |
53 | * @param sensitivityModelFileName |
54 | * the sensitivity model file name |
55 | * @param sensitivityLogFileName |
56 | * the sensitivity log file name |
57 | * @return |
58 | */ |
59 | public MarkovSensitivity buildSensitivity( |
60 | final String sensitivityModelFileName, |
61 | final String sensitivityLogFileName) { |
62 | SensitivityConfiguration sensitivityConfig = (SensitivityConfiguration) EMFHelper |
63 | .loadFromXMIFile(sensitivityModelFileName, |
64 | SensitivityPackage.eNS_URI, |
65 | SensitivityPackage.eINSTANCE); |
66 | return createMarkovSensitivity( |
67 | sensitivityConfig |
68 | .getSensitivityParameters__SensitivityConfiguration(), |
69 | sensitivityConfig |
70 | .getSensitivityResultSpecifications__SensitivityConfiguration(), |
71 | sensitivityLogFileName); |
72 | } |
73 | |
74 | /** |
75 | * |
76 | * @param parameter |
77 | * @return |
78 | */ |
79 | private ComponentSensitivity createComponentSensitivity( |
80 | final ComponentReliabilityParameter parameter) { |
81 | SensitivityParameterVariation variation = parameter |
82 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
83 | if (variation instanceof DoubleParameterVariation) { |
84 | return new ComponentSensitivity(parameter.getEntityName(), |
85 | parameter |
86 | .getBasicComponent__ComponentReliabilityParameter() |
87 | .getId(), (DoubleParameterVariation) variation); |
88 | } else { |
89 | logger.error("Parameter variation type \"" |
90 | + variation.eClass().toString() |
91 | + "\" not supported for parameter type \"" |
92 | + parameter.eClass().toString() + "\"."); |
93 | return null; |
94 | } |
95 | } |
96 | |
97 | /** |
98 | * |
99 | * @param parameter |
100 | * @return |
101 | */ |
102 | private FailureTypeSensitivity createFailureTypeSensitivity( |
103 | final SoftwareFailureTypesParameter parameter) { |
104 | SensitivityParameterVariation variation = parameter |
105 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
106 | if (variation instanceof DoubleParameterVariation) { |
107 | ArrayList<String> failureTypeIds = new ArrayList<String>(); |
108 | for (SoftwareInducedFailureType failureType : parameter |
109 | .getSoftwareInducedFailureTypes__SoftwareFailureTypeReliabilityParameter()) { |
110 | failureTypeIds.add(failureType.getId()); |
111 | } |
112 | return new FailureTypeSensitivity(parameter.getEntityName(), |
113 | failureTypeIds, (DoubleParameterVariation) variation); |
114 | } else { |
115 | logger.error("Parameter variation type \"" |
116 | + variation.eClass().toString() |
117 | + "\" not supported for parameter type \"" |
118 | + parameter.eClass().toString() + "\"."); |
119 | return null; |
120 | } |
121 | } |
122 | |
123 | /** |
124 | * |
125 | * @param parameter |
126 | * @return |
127 | */ |
128 | private InternalActionSensitivity createInternalActionSensitivity( |
129 | final InternalActionReliabilityParameter parameter) { |
130 | SensitivityParameterVariation variation = parameter |
131 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
132 | if (variation instanceof DoubleParameterVariation) { |
133 | return new InternalActionSensitivity( |
134 | parameter.getEntityName(), |
135 | parameter |
136 | .getInternalAction__InternalActionReliabilityParameter() |
137 | .getId(), |
138 | parameter |
139 | .getSoftwareInducedFailureType__InternalActionReliabilityParameter() |
140 | .getId(), (DoubleParameterVariation) variation); |
141 | } else { |
142 | logger.error("Parameter variation type \"" |
143 | + variation.eClass().toString() |
144 | + "\" not supported for parameter type \"" |
145 | + parameter.eClass().toString() + "\"."); |
146 | return null; |
147 | } |
148 | } |
149 | |
150 | /** |
151 | * Creates a Markov sensitivity object according to the given parameter. |
152 | * |
153 | * @param parameter |
154 | * the sensitivity parameter |
155 | * @param resultSpecifications |
156 | * the list of result specifications |
157 | * @param logFileName |
158 | * the sensitivity log file name |
159 | * @return the resulting Markov sensitivity object |
160 | */ |
161 | private MarkovSensitivity createMarkovSensitivity( |
162 | final SensitivityParameter parameter, |
163 | EList<SensitivityResultSpecification> resultSpecifications, |
164 | final String logFileName) { |
165 | MarkovSensitivity result = null; |
166 | if (parameter instanceof CombinedSensitivityParameter) { |
167 | result = createMultiSensitivity( |
168 | (CombinedSensitivityParameter) parameter, |
169 | resultSpecifications, logFileName); |
170 | } else if (parameter instanceof CommunicationLinkReliabilityParameter) { |
171 | logger.error("Parameter type \"" + parameter.eClass().toString() |
172 | + "\" not yet supported."); |
173 | return null; |
174 | } else if (parameter instanceof ComponentReliabilityParameter) { |
175 | result = createComponentSensitivity((ComponentReliabilityParameter) parameter); |
176 | } else if (parameter instanceof HardwareMTTFParameter) { |
177 | result = createMTTFSensitivity((HardwareMTTFParameter) parameter); |
178 | } else if (parameter instanceof HardwareMTTRParameter) { |
179 | result = createMTTRSensitivity((HardwareMTTRParameter) parameter); |
180 | } else if (parameter instanceof InternalActionReliabilityParameter) { |
181 | result = createInternalActionSensitivity((InternalActionReliabilityParameter) parameter); |
182 | } else if (parameter instanceof NetworkReliabilityParameter) { |
183 | result = createNetworkSensitivity((NetworkReliabilityParameter) parameter); |
184 | } else if (parameter instanceof ProbabilisticBranchParameter) { |
185 | result = createProbabilisticBranchSensitivity((ProbabilisticBranchParameter) parameter); |
186 | } else if (parameter instanceof ResourceMTTFParameter) { |
187 | result = createResourceMTTFSensitivity((ResourceMTTFParameter) parameter); |
188 | } else if (parameter instanceof ResourceMTTRParameter) { |
189 | result = createResourceMTTRSensitivity((ResourceMTTRParameter) parameter); |
190 | } else if (parameter instanceof SoftwareReliabilityParameter) { |
191 | result = createSoftwareSensitivity((SoftwareReliabilityParameter) parameter); |
192 | } else if (parameter instanceof VariableUsageParameter) { |
193 | result = createVariableUsageSensitivity((VariableUsageParameter) parameter); |
194 | } else if (parameter instanceof UsageBranchParameter) { |
195 | result = createUsageBranchSensitivity((UsageBranchParameter) parameter); |
196 | } else if (parameter instanceof SoftwareFailureTypesParameter) { |
197 | result = createFailureTypeSensitivity((SoftwareFailureTypesParameter) parameter); |
198 | } else { |
199 | logger.error("Parameter type \"" + parameter.eClass().toString() |
200 | + "\" not yet supported."); |
201 | return null; |
202 | } |
203 | result.setLogFileName(logFileName); |
204 | result.setResultSpecifications(resultSpecifications); |
205 | return result; |
206 | } |
207 | |
208 | /** |
209 | * |
210 | * @param parameter |
211 | * @return |
212 | */ |
213 | private MTTFSensitivity createMTTFSensitivity( |
214 | final HardwareMTTFParameter parameter) { |
215 | SensitivityParameterVariation variation = parameter |
216 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
217 | if (variation instanceof DoubleParameterVariation) { |
218 | return new MTTFSensitivity(parameter.getEntityName(), |
219 | (DoubleParameterVariation) variation); |
220 | } else { |
221 | logger.error("Parameter variation type \"" |
222 | + variation.eClass().toString() |
223 | + "\" not supported for parameter type \"" |
224 | + parameter.eClass().toString() + "\"."); |
225 | return null; |
226 | } |
227 | } |
228 | |
229 | /** |
230 | * |
231 | * @param parameter |
232 | * @return |
233 | */ |
234 | private MTTRSensitivity createMTTRSensitivity( |
235 | final HardwareMTTRParameter parameter) { |
236 | SensitivityParameterVariation variation = parameter |
237 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
238 | if (variation instanceof DoubleParameterVariation) { |
239 | return new MTTRSensitivity(parameter.getEntityName(), |
240 | (DoubleParameterVariation) variation); |
241 | } else { |
242 | logger.error("Parameter variation type \"" |
243 | + variation.eClass().toString() |
244 | + "\" not supported for parameter type \"" |
245 | + parameter.eClass().toString() + "\"."); |
246 | return null; |
247 | } |
248 | } |
249 | |
250 | /** |
251 | * |
252 | * @param parameter |
253 | * @param resultSpecifications |
254 | * @param logFileName |
255 | * @return |
256 | */ |
257 | private MultiSensitivity createMultiSensitivity( |
258 | final CombinedSensitivityParameter parameter, |
259 | EList<SensitivityResultSpecification> resultSpecifications, |
260 | final String logFileName) { |
261 | List<MarkovSensitivity> subSensitivities = new ArrayList<MarkovSensitivity>(); |
262 | for (SensitivityParameter subParameter : parameter |
263 | .getChildParameters__CombinedSensitivityParameter()) { |
264 | subSensitivities.add(createMarkovSensitivity(subParameter, |
265 | resultSpecifications, logFileName)); |
266 | } |
267 | return new MultiSensitivity(parameter.getEntityName(), |
268 | subSensitivities, parameter.isCombinatory()); |
269 | } |
270 | |
271 | /** |
272 | * |
273 | * @param parameter |
274 | * @return |
275 | */ |
276 | private NetworkSensitivity createNetworkSensitivity( |
277 | final NetworkReliabilityParameter parameter) { |
278 | SensitivityParameterVariation variation = parameter |
279 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
280 | if (variation instanceof DoubleParameterVariation) { |
281 | return new NetworkSensitivity(parameter.getEntityName(), |
282 | (DoubleParameterVariation) variation); |
283 | } else { |
284 | logger.error("Parameter variation type \"" |
285 | + variation.eClass().toString() |
286 | + "\" not supported for parameter type \"" |
287 | + parameter.eClass().toString() + "\"."); |
288 | return null; |
289 | } |
290 | } |
291 | |
292 | /** |
293 | * |
294 | * @param parameter |
295 | * @return |
296 | */ |
297 | private ProbabilisticBranchSensitivity createProbabilisticBranchSensitivity( |
298 | final ProbabilisticBranchParameter parameter) { |
299 | SensitivityParameterVariation variation = parameter |
300 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
301 | if (variation instanceof DoubleParameterVariation) { |
302 | return new ProbabilisticBranchSensitivity( |
303 | parameter.getEntityName(), |
304 | parameter |
305 | .getProbabilisticBranchTransition__ProbabilisticBranchParameter() |
306 | .getId(), (DoubleParameterVariation) variation); |
307 | } else { |
308 | logger.error("Parameter variation type \"" |
309 | + variation.eClass().toString() |
310 | + "\" not supported for parameter type \"" |
311 | + parameter.eClass().toString() + "\"."); |
312 | return null; |
313 | } |
314 | } |
315 | |
316 | /** |
317 | * |
318 | * @param parameter |
319 | * @return |
320 | */ |
321 | private ResourceMTTFSensitivity createResourceMTTFSensitivity( |
322 | final ResourceMTTFParameter parameter) { |
323 | SensitivityParameterVariation variation = parameter |
324 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
325 | if (variation instanceof DoubleParameterVariation) { |
326 | return new ResourceMTTFSensitivity(parameter.getEntityName(), |
327 | parameter.getResourceContainer__ResourceMTTFParameter() |
328 | .getId(), parameter |
329 | .getProcessingResourceType__ResourceMTTFParameter() |
330 | .getId(), (DoubleParameterVariation) variation); |
331 | } else { |
332 | logger.error("Parameter variation type \"" |
333 | + variation.eClass().toString() |
334 | + "\" not supported for parameter type \"" |
335 | + parameter.eClass().toString() + "\"."); |
336 | return null; |
337 | } |
338 | } |
339 | |
340 | /** |
341 | * |
342 | * @param parameter |
343 | * @return |
344 | */ |
345 | private ResourceMTTRSensitivity createResourceMTTRSensitivity( |
346 | final ResourceMTTRParameter parameter) { |
347 | SensitivityParameterVariation variation = parameter |
348 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
349 | if (variation instanceof DoubleParameterVariation) { |
350 | return new ResourceMTTRSensitivity(parameter.getEntityName(), |
351 | parameter.getResourceContainer__ResourceMTTRParameter() |
352 | .getId(), parameter |
353 | .getProcessingResourceType__ResourceMTTRParameter() |
354 | .getId(), (DoubleParameterVariation) variation); |
355 | } else { |
356 | logger.error("Parameter variation type \"" |
357 | + variation.eClass().toString() |
358 | + "\" not supported for parameter type \"" |
359 | + parameter.eClass().toString() + "\"."); |
360 | return null; |
361 | } |
362 | } |
363 | |
364 | /** |
365 | * |
366 | * @param parameter |
367 | * @return |
368 | */ |
369 | private SoftwareSensitivity createSoftwareSensitivity( |
370 | final SoftwareReliabilityParameter parameter) { |
371 | SensitivityParameterVariation variation = parameter |
372 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
373 | if (variation instanceof DoubleParameterVariation) { |
374 | return new SoftwareSensitivity(parameter.getEntityName(), |
375 | (DoubleParameterVariation) variation); |
376 | } else { |
377 | logger.error("Parameter variation type \"" |
378 | + variation.eClass().toString() |
379 | + "\" not supported for parameter type \"" |
380 | + parameter.eClass().toString() + "\"."); |
381 | return null; |
382 | } |
383 | } |
384 | |
385 | /** |
386 | * |
387 | * @param parameter |
388 | * @return |
389 | */ |
390 | private UsageBranchSensitivity createUsageBranchSensitivity( |
391 | final UsageBranchParameter parameter) { |
392 | SensitivityParameterVariation variation = parameter |
393 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
394 | if (variation instanceof DoubleParameterVariation) { |
395 | return new UsageBranchSensitivity(parameter.getEntityName(), |
396 | parameter.getBranch__UsageBranchParameter().getId(), |
397 | parameter.getScenarioBehaviour__UsageBranchParameter() |
398 | .getId(), (DoubleParameterVariation) variation); |
399 | } else { |
400 | logger.error("Parameter variation type \"" |
401 | + variation.eClass().toString() |
402 | + "\" not supported for parameter type \"" |
403 | + parameter.eClass().toString() + "\"."); |
404 | return null; |
405 | } |
406 | } |
407 | |
408 | /** |
409 | * |
410 | * @param parameter |
411 | * @return |
412 | */ |
413 | private VariableUsageSensitivity createVariableUsageSensitivity( |
414 | final VariableUsageParameter parameter) { |
415 | SensitivityParameterVariation variation = parameter |
416 | .getSensitivityParameterVariation__SingleSensitivityParameter(); |
417 | if (variation instanceof StringParameterSequence) { |
418 | String paramId = null; |
419 | switch (parameter.getVariableUsageType__VariableUsageParameter()) { |
420 | case SYSTEM_CALL_INPUT: |
421 | paramId = parameter |
422 | .getEntryLevelSystemCall__VariableUsageParameter() |
423 | .getId(); |
424 | break; |
425 | case COMPONENT_CONFIGURATION: |
426 | paramId = parameter.getBasicComponent__VariableUsageParameter() |
427 | .getId(); |
428 | break; |
429 | } |
430 | return new VariableUsageSensitivity( |
431 | parameter.getEntityName(), |
432 | paramId, |
433 | parameter.getVariableName(), |
434 | parameter |
435 | .getVariableCharacterisationType__VariableUsageParameter(), |
436 | parameter.getVariableUsageType__VariableUsageParameter(), |
437 | (StringParameterSequence) variation); |
438 | } else { |
439 | logger.error("Parameter variation type \"" |
440 | + variation.eClass().toString() |
441 | + "\" not supported for parameter type \"" |
442 | + parameter.eClass().toString() + "\"."); |
443 | return null; |
444 | } |
445 | } |
446 | } |