| 1 | package de.uka.ipd.sdq.reliability.core.helper; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Iterator; |
| 5 | import java.util.List; |
| 6 | |
| 7 | import org.eclipse.emf.common.util.EList; |
| 8 | import org.eclipse.emf.ecore.EObject; |
| 9 | |
| 10 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
| 11 | import de.uka.ipd.sdq.pcm.qosannotations.QoSAnnotations; |
| 12 | import de.uka.ipd.sdq.pcm.qosannotations.SpecifiedQoSAnnotation; |
| 13 | import de.uka.ipd.sdq.pcm.qosannotations.qos_reliability.SpecifiedReliabilityAnnotation; |
| 14 | import de.uka.ipd.sdq.pcm.reliability.ExternalFailureOccurrenceDescription; |
| 15 | import de.uka.ipd.sdq.pcm.reliability.FailureType; |
| 16 | import de.uka.ipd.sdq.pcm.reliability.HardwareInducedFailureType; |
| 17 | import de.uka.ipd.sdq.pcm.reliability.InternalFailureOccurrenceDescription; |
| 18 | import de.uka.ipd.sdq.pcm.reliability.NetworkInducedFailureType; |
| 19 | import de.uka.ipd.sdq.pcm.reliability.SoftwareInducedFailureType; |
| 20 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
| 21 | import de.uka.ipd.sdq.pcm.repository.OperationInterface; |
| 22 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
| 23 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
| 24 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
| 25 | import de.uka.ipd.sdq.pcm.repository.PassiveResource; |
| 26 | import de.uka.ipd.sdq.pcm.repository.ProvidedRole; |
| 27 | import de.uka.ipd.sdq.pcm.repository.Repository; |
| 28 | import de.uka.ipd.sdq.pcm.repository.RepositoryComponent; |
| 29 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
| 30 | import de.uka.ipd.sdq.pcm.resourceenvironment.CommunicationLinkResourceSpecification; |
| 31 | import de.uka.ipd.sdq.pcm.resourceenvironment.LinkingResource; |
| 32 | import de.uka.ipd.sdq.pcm.resourceenvironment.ProcessingResourceSpecification; |
| 33 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer; |
| 34 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment; |
| 35 | import de.uka.ipd.sdq.pcm.resourcetype.CommunicationLinkResourceType; |
| 36 | import de.uka.ipd.sdq.pcm.resourcetype.ProcessingResourceType; |
| 37 | import de.uka.ipd.sdq.pcm.seff.InternalAction; |
| 38 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
| 39 | import de.uka.ipd.sdq.pcm.seff.ServiceEffectSpecification; |
| 40 | import de.uka.ipd.sdq.pcm.system.System; |
| 41 | import de.uka.ipd.sdq.reliability.core.MarkovEvaluationType; |
| 42 | import de.uka.ipd.sdq.reliability.core.MarkovFailureType; |
| 43 | import de.uka.ipd.sdq.reliability.core.MarkovHardwareInducedFailureType; |
| 44 | import de.uka.ipd.sdq.reliability.core.MarkovNetworkInducedFailureType; |
| 45 | import de.uka.ipd.sdq.reliability.core.MarkovResourceTimeoutFailureType; |
| 46 | import de.uka.ipd.sdq.reliability.core.MarkovSoftwareInducedFailureType; |
| 47 | |
| 48 | /** |
| 49 | * This class provides auxiliary functionality for managing MarkovFailureTypes. |
| 50 | * |
| 51 | * @author brosch |
| 52 | * |
| 53 | */ |
| 54 | public class MarkovFailureTypeHelper { |
| 55 | |
| 56 | /** |
| 57 | * Provides EMF utility functions. |
| 58 | */ |
| 59 | private EMFHelper helper = new EMFHelper(); |
| 60 | |
| 61 | /** |
| 62 | * Retrieves a list of potential failure types from a given PCM model |
| 63 | * instance. |
| 64 | * |
| 65 | * @param evaluationType |
| 66 | * the degree of differentiation between failure types |
| 67 | * @param repositories |
| 68 | * the list of PCm Repository models |
| 69 | * @param environment |
| 70 | * the PCM ResourceEnvironment model |
| 71 | * @param system |
| 72 | * the PCM System model |
| 73 | * @return the list of potential failure types |
| 74 | */ |
| 75 | public List<MarkovFailureType> getFailureTypes( |
| 76 | final MarkovEvaluationType evaluationType, |
| 77 | final List<Repository> repositories, |
| 78 | final ResourceEnvironment environment, final System system) { |
| 79 | List<MarkovFailureType> failureTypes = getNetworkFailureTypes( |
| 80 | evaluationType, environment, system); |
| 81 | failureTypes.addAll(getHardwareFailureTypes(evaluationType, |
| 82 | environment, system)); |
| 83 | failureTypes.addAll(getResourceTimeoutFailureTypes(evaluationType, |
| 84 | system)); |
| 85 | failureTypes.addAll(getSoftwareFailureTypes(evaluationType, |
| 86 | repositories, system)); |
| 87 | return removeDoubleFailureTypes(failureTypes); |
| 88 | |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Retrieves the list of processing resource failure types from the given |
| 93 | * PCM model. |
| 94 | * |
| 95 | * @param evaluationType |
| 96 | * the degree of differentiation between failure types |
| 97 | * @param environment |
| 98 | * the PCM Resource Environment model |
| 99 | * @param system |
| 100 | * the PCM System model |
| 101 | * @return the list of processing resource failure types |
| 102 | */ |
| 103 | private List<MarkovFailureType> getHardwareFailureTypes( |
| 104 | final MarkovEvaluationType evaluationType, |
| 105 | final ResourceEnvironment environment, final System system) { |
| 106 | |
| 107 | // Initialize the list of results: |
| 108 | ArrayList<MarkovFailureType> resultList = new ArrayList<MarkovFailureType>(); |
| 109 | |
| 110 | // Handle the PCM resource environment model: |
| 111 | for (ResourceContainer container : environment |
| 112 | .getResourceContainer_ResourceEnvironment()) { |
| 113 | for (ProcessingResourceSpecification specification : container |
| 114 | .getActiveResourceSpecifications_ResourceContainer()) { |
| 115 | ProcessingResourceType resourceType = specification |
| 116 | .getActiveResourceType_ActiveResourceSpecification(); |
| 117 | resultList.add(MarkovHardwareInducedFailureType |
| 118 | .createInternalFailureType(evaluationType, container, |
| 119 | resourceType)); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Handle the PCM system model: |
| 124 | for (QoSAnnotations qos : system.getQosAnnotations_System()) { |
| 125 | for (SpecifiedQoSAnnotation annotation : qos |
| 126 | .getSpecifiedQoSAnnotations_QoSAnnotations()) { |
| 127 | if (annotation instanceof SpecifiedReliabilityAnnotation) { |
| 128 | SpecifiedReliabilityAnnotation relAnnotation = ((SpecifiedReliabilityAnnotation) annotation); |
| 129 | for (ExternalFailureOccurrenceDescription description : relAnnotation |
| 130 | .getExternalFailureOccurrenceDescriptions__SpecifiedReliabilityAnnotation()) { |
| 131 | FailureType failureType = description |
| 132 | .getFailureType__ExternalFailureOccurrenceDescription(); |
| 133 | if (failureType instanceof HardwareInducedFailureType) { |
| 134 | HardwareInducedFailureType hardwareFailureType = ((HardwareInducedFailureType) failureType); |
| 135 | resultList |
| 136 | .add(MarkovHardwareInducedFailureType |
| 137 | .createExternalFailureType( |
| 138 | evaluationType, |
| 139 | hardwareFailureType |
| 140 | .getProcessingResourceType__HardwareInducedFailureType(), |
| 141 | annotation |
| 142 | .getSignature_SpecifiedQoSAnnation(), |
| 143 | annotation |
| 144 | .getRole_SpecifiedQoSAnnotation(), |
| 145 | ((OperationRequiredRole) annotation |
| 146 | .getRole_SpecifiedQoSAnnotation()) |
| 147 | .getRequiredInterface__OperationRequiredRole())); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // Return the result: |
| 155 | return resultList; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Retrieves the list of communication failure types from the given PCM |
| 160 | * model. |
| 161 | * |
| 162 | * @param evaluationType |
| 163 | * the degree of differentiation between failure types |
| 164 | * @param environment |
| 165 | * the PCM Resource Environment model |
| 166 | * @param system |
| 167 | * the PCM System model |
| 168 | * @return the list of communication resource failure types |
| 169 | */ |
| 170 | private List<MarkovFailureType> getNetworkFailureTypes( |
| 171 | final MarkovEvaluationType evaluationType, |
| 172 | final ResourceEnvironment environment, final System system) { |
| 173 | |
| 174 | // Initialize the list of results: |
| 175 | ArrayList<MarkovFailureType> resultList = new ArrayList<MarkovFailureType>(); |
| 176 | |
| 177 | // Handle the PCM resource environment model: |
| 178 | for (LinkingResource commLink : environment |
| 179 | .getLinkingResources__ResourceEnvironment()) { |
| 180 | CommunicationLinkResourceSpecification specification = commLink |
| 181 | .getCommunicationLinkResourceSpecifications_LinkingResource(); |
| 182 | CommunicationLinkResourceType resourceType = specification |
| 183 | .getCommunicationLinkResourceType_CommunicationLinkResourceSpecification(); |
| 184 | resultList.add(MarkovNetworkInducedFailureType |
| 185 | .createInternalFailureType(evaluationType, commLink, |
| 186 | resourceType)); |
| 187 | } |
| 188 | |
| 189 | // Handle the PCM system model: |
| 190 | for (QoSAnnotations qos : system.getQosAnnotations_System()) { |
| 191 | for (SpecifiedQoSAnnotation annotation : qos |
| 192 | .getSpecifiedQoSAnnotations_QoSAnnotations()) { |
| 193 | if (annotation instanceof SpecifiedReliabilityAnnotation) { |
| 194 | SpecifiedReliabilityAnnotation relAnnotation = ((SpecifiedReliabilityAnnotation) annotation); |
| 195 | for (ExternalFailureOccurrenceDescription description : relAnnotation |
| 196 | .getExternalFailureOccurrenceDescriptions__SpecifiedReliabilityAnnotation()) { |
| 197 | FailureType failureType = description |
| 198 | .getFailureType__ExternalFailureOccurrenceDescription(); |
| 199 | if (failureType instanceof NetworkInducedFailureType) { |
| 200 | CommunicationLinkResourceType resourceType = ((NetworkInducedFailureType) failureType) |
| 201 | .getCommunicationLinkResourceType__NetworkInducedFailureType(); |
| 202 | resultList |
| 203 | .add(MarkovNetworkInducedFailureType |
| 204 | .createExternalFailureType( |
| 205 | evaluationType, |
| 206 | resourceType, |
| 207 | annotation |
| 208 | .getSignature_SpecifiedQoSAnnation(), |
| 209 | annotation |
| 210 | .getRole_SpecifiedQoSAnnotation(), |
| 211 | ((OperationRequiredRole) annotation |
| 212 | .getRole_SpecifiedQoSAnnotation()) |
| 213 | .getRequiredInterface__OperationRequiredRole())); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // Return the result: |
| 221 | return resultList; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Retrieves the list of resource timeout failure types from the given PCM |
| 226 | * model. |
| 227 | * |
| 228 | * @param evaluationType |
| 229 | * the degree of differentiation between failure types |
| 230 | * @param system |
| 231 | * the PCM System model |
| 232 | * @return the list of resource timeout failure types |
| 233 | */ |
| 234 | private List<MarkovFailureType> getResourceTimeoutFailureTypes( |
| 235 | final MarkovEvaluationType evaluationType, final System system) { |
| 236 | |
| 237 | // Initialize the list of results: |
| 238 | ArrayList<MarkovFailureType> resultList = new ArrayList<MarkovFailureType>(); |
| 239 | |
| 240 | // Handle the PCM system model: |
| 241 | for (AssemblyContext context : system |
| 242 | .getAssemblyContexts__ComposedStructure()) { |
| 243 | RepositoryComponent component = context |
| 244 | .getEncapsulatedComponent__AssemblyContext(); |
| 245 | if (!(component instanceof BasicComponent)) { |
| 246 | continue; |
| 247 | } |
| 248 | for (PassiveResource resource : ((BasicComponent) component) |
| 249 | .getPassiveResource_BasicComponent()) { |
| 250 | resultList |
| 251 | .add(MarkovResourceTimeoutFailureType |
| 252 | .createResourceTimeoutFailureType( |
| 253 | evaluationType, context, |
| 254 | ((BasicComponent) component), resource)); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // Return the result: |
| 259 | return resultList; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Retrieves the list of software failure types from the given PCM model. |
| 264 | * |
| 265 | * @param evaluationType |
| 266 | * the degree of differentiation between failure types |
| 267 | * @param repositories |
| 268 | * the PCM Repository models |
| 269 | * @param system |
| 270 | * the PCM System model |
| 271 | * @return the list of software failure types |
| 272 | */ |
| 273 | private List<MarkovFailureType> getSoftwareFailureTypes( |
| 274 | final MarkovEvaluationType evaluationType, |
| 275 | final List<Repository> repositories, final System system) { |
| 276 | |
| 277 | // Initialize the list of results: |
| 278 | ArrayList<MarkovFailureType> resultList = new ArrayList<MarkovFailureType>(); |
| 279 | |
| 280 | // Handle the PCM repository models: |
| 281 | for (Repository repository : repositories) { |
| 282 | EList<EObject> components = helper |
| 283 | .getElements(repository, RepositoryFactory.eINSTANCE |
| 284 | .createBasicComponent().eClass()); |
| 285 | for (Object c_object : components) { |
| 286 | BasicComponent component = (BasicComponent) c_object; |
| 287 | for (ProvidedRole role : component |
| 288 | .getProvidedRoles_InterfaceProvidingEntity()) { |
| 289 | if (role instanceof OperationProvidedRole) { |
| 290 | OperationProvidedRole opRole = (OperationProvidedRole) role; |
| 291 | OperationInterface iface = opRole |
| 292 | .getProvidedInterface__OperationProvidedRole(); |
| 293 | for (OperationSignature signature : iface |
| 294 | .getSignatures__OperationInterface()) { |
| 295 | ServiceEffectSpecification rdseff = getRDSEFF( |
| 296 | component, signature); |
| 297 | EList<EObject> internalActions = helper |
| 298 | .getElements(rdseff, SeffFactory.eINSTANCE |
| 299 | .createInternalAction().eClass()); |
| 300 | for (Object a_object : internalActions) { |
| 301 | InternalAction internalAction = (InternalAction) a_object; |
| 302 | for (InternalFailureOccurrenceDescription description : internalAction |
| 303 | .getInternalFailureOccurrenceDescriptions__InternalAction()) { |
| 304 | resultList |
| 305 | .add(MarkovSoftwareInducedFailureType |
| 306 | .createInternalFailureType( |
| 307 | evaluationType, |
| 308 | description |
| 309 | .getSoftwareInducedFailureType__InternalFailureOccurrenceDescription(), |
| 310 | internalAction, |
| 311 | signature, opRole, |
| 312 | iface, component)); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // Handle the PCM system model: |
| 322 | for (QoSAnnotations qos : system.getQosAnnotations_System()) { |
| 323 | for (SpecifiedQoSAnnotation annotation : qos |
| 324 | .getSpecifiedQoSAnnotations_QoSAnnotations()) { |
| 325 | if (annotation instanceof SpecifiedReliabilityAnnotation) { |
| 326 | SpecifiedReliabilityAnnotation relAnnotation = ((SpecifiedReliabilityAnnotation) annotation); |
| 327 | for (ExternalFailureOccurrenceDescription description : relAnnotation |
| 328 | .getExternalFailureOccurrenceDescriptions__SpecifiedReliabilityAnnotation()) { |
| 329 | FailureType failureType = description |
| 330 | .getFailureType__ExternalFailureOccurrenceDescription(); |
| 331 | if (failureType instanceof SoftwareInducedFailureType) { |
| 332 | SoftwareInducedFailureType softwareFailureType = ((SoftwareInducedFailureType) failureType); |
| 333 | resultList |
| 334 | .add(MarkovSoftwareInducedFailureType |
| 335 | .createExternalFailureType( |
| 336 | evaluationType, |
| 337 | softwareFailureType, |
| 338 | annotation |
| 339 | .getSignature_SpecifiedQoSAnnation(), |
| 340 | annotation |
| 341 | .getRole_SpecifiedQoSAnnotation(), |
| 342 | ((OperationRequiredRole) annotation |
| 343 | .getRole_SpecifiedQoSAnnotation()) |
| 344 | .getRequiredInterface__OperationRequiredRole())); |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // Return the result: |
| 352 | return resultList; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Retrieves an RDSEFF for a given component and signature. |
| 357 | * |
| 358 | * @param component |
| 359 | * the component |
| 360 | * @param signature |
| 361 | * the signature |
| 362 | * @return the RDSEFF |
| 363 | */ |
| 364 | private ServiceEffectSpecification getRDSEFF( |
| 365 | final BasicComponent component, final OperationSignature signature) { |
| 366 | for (ServiceEffectSpecification rdseff : component |
| 367 | .getServiceEffectSpecifications__BasicComponent()) { |
| 368 | if (rdseff.getDescribedService__SEFF().getId().equals( |
| 369 | signature.getId())) { |
| 370 | return rdseff; |
| 371 | } |
| 372 | } |
| 373 | return null; |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Removes doubles from the list of failure types. |
| 378 | * |
| 379 | * Double failure types can occur if the distinction of failure types is not |
| 380 | * at the most fine-granular level. |
| 381 | * |
| 382 | * @param failureTypes |
| 383 | * the list of failure types |
| 384 | * @return the result list |
| 385 | */ |
| 386 | private List<MarkovFailureType> removeDoubleFailureTypes( |
| 387 | final List<MarkovFailureType> failureTypes) { |
| 388 | ArrayList<MarkovFailureType> resultList = new ArrayList<MarkovFailureType>(); |
| 389 | Iterator<MarkovFailureType> iterator = failureTypes.iterator(); |
| 390 | while (iterator.hasNext()) { |
| 391 | MarkovFailureType failureType = iterator.next(); |
| 392 | if (!resultList.contains(failureType)) { |
| 393 | resultList.add(failureType); |
| 394 | } |
| 395 | } |
| 396 | return resultList; |
| 397 | } |
| 398 | } |