Search in sources :

Example 16 with ErrorSource

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource in project osate2 by osate.

the class CombinedErrorModelSubclause method create.

/**
 * Creates an instance for the specified classifier. Processes error model subclauses owned or inherited by the classifier.
 * @param classifier the classifier for which to create the instance.
 * @return the new instance
 */
public static CombinedErrorModelSubclause create(final Classifier classifier) {
    final Map<String, PropagationPoint> points = new HashMap<>();
    final Map<String, PropagationPath> paths = new HashMap<>();
    final Map<String, ErrorFlow> flows = new HashMap<>();
    final PropagationNode propagations = new PropagationNode();
    final Set<KeywordPropagationPointType> usedKeywordPointTypes = new HashSet<>();
    final EList<Classifier> classifiers = classifier.getSelfPlusAllExtended();
    if (classifier instanceof ComponentImplementation) {
        final ComponentType ct = ((ComponentImplementation) classifier).getType();
        if (ct != null) {
            classifiers.addAll(ct.getSelfPlusAllExtended());
        }
    }
    final boolean[] subclauseFound = { false };
    for (final Classifier tmpClassifier : Lists.reverse(classifiers)) {
        ErrorModelGeUtil.getAllErrorModelSubclauses(tmpClassifier).forEachOrdered(subclause -> {
            subclauseFound[0] = true;
            addAllToMap(subclause.getPoints(), points);
            addAllToMap(subclause.getPaths(), paths);
            addAllToMap(subclause.getFlows(), flows);
            // Create a tree for error propagations
            for (final ErrorPropagation propagation : subclause.getPropagations()) {
                propagations.put(propagation);
            }
            // 
            for (final ErrorPropagation propagation : subclause.getPropagations()) {
                if (propagation.getKind() != null) {
                    usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(propagation.getKind()));
                }
            }
            for (final ErrorFlow errorFlow : subclause.getFlows()) {
                if (errorFlow instanceof ErrorPath) {
                    final ErrorPath errorPath = (ErrorPath) errorFlow;
                    if (errorPath.isAllIncoming() || errorPath.isAllOutgoing()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    }
                    if (errorPath.getIncoming() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getIncoming().getKind()));
                    }
                    if (errorPath.getOutgoing() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getOutgoing().getKind()));
                    }
                } else if (errorFlow instanceof ErrorSink) {
                    final ErrorSink errorSink = (ErrorSink) errorFlow;
                    if (errorSink.isAllIncoming()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    } else if (errorSink.getIncoming() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorSink.getIncoming().getKind()));
                    }
                } else if (errorFlow instanceof ErrorSource) {
                    final ErrorSource errorSrc = (ErrorSource) errorFlow;
                    if (errorSrc.isAll()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    } else if (errorSrc.getSourceModelElement() instanceof ErrorPropagation) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(((ErrorPropagation) errorSrc.getSourceModelElement()).getKind()));
                    }
                }
            }
        });
    }
    return new CombinedErrorModelSubclause(subclauseFound[0], points, paths, flows, usedKeywordPointTypes, propagations);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) PropagationPath(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPath) ComponentType(org.osate.aadl2.ComponentType) HashMap(java.util.HashMap) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) Classifier(org.osate.aadl2.Classifier) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) HashSet(java.util.HashSet)

Example 17 with ErrorSource

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource in project osate2 by osate.

the class PropagateErrorSources method startErrorFlows.

/**
 * traverse error flow if the component instance is an error source
 * @param ci component instance
 */
public void startErrorFlows(ComponentInstance ci) {
    Collection<ErrorSource> eslist = EMV2Util.getAllErrorSources(ci.getComponentClassifier());
    String componentText = ci.getComponentInstancePath();
    HashMultimap<ErrorPropagation, String> handledPropagations = HashMultimap.create();
    for (ErrorBehaviorEvent event : EMV2Util.getAllErrorBehaviorEvents(ci)) {
        if (!(event instanceof ErrorEvent) || !Util.conditionHolds((ErrorEvent) event, ci)) {
            continue;
        }
        TypeSet sourcetype = ((ErrorEvent) event).getTypeSet();
        if (sourcetype == null) {
            // no type on event
            for (ErrorBehaviorTransition trans : EMV2Util.getAllErrorBehaviorTransitions(ci)) {
                if (trans.getCondition() instanceof ConditionElement) {
                    ConditionElement conditionElement = (ConditionElement) trans.getCondition();
                    processTransition(ci, event, null, trans, conditionElement, componentText, handledPropagations);
                } else if (trans.getCondition() instanceof OrmoreExpression) {
                    EList<ConditionExpression> elems = ((OrmoreExpression) trans.getCondition()).getOperands();
                    for (ConditionExpression conditionExpression : elems) {
                        if (conditionExpression instanceof ConditionElement) {
                            ConditionElement conditionElement = (ConditionElement) conditionExpression;
                            processTransition(ci, event, null, trans, conditionElement, componentText, handledPropagations);
                        }
                    }
                } else if (trans.getCondition() instanceof OrExpression) {
                    EList<ConditionExpression> elems = ((OrExpression) trans.getCondition()).getOperands();
                    for (ConditionExpression conditionExpression : elems) {
                        if (conditionExpression instanceof ConditionElement) {
                            ConditionElement conditionElement = (ConditionElement) conditionExpression;
                            processTransition(ci, event, null, trans, conditionElement, componentText, handledPropagations);
                        }
                    }
                }
            }
        } else {
            EList<TypeToken> tokens = EMV2TypeSetUtil.generateAllLeafTypeTokens(((ErrorEvent) event).getTypeSet(), EMV2Util.getUseTypes(event));
            for (TypeToken typeToken : tokens) {
                for (ErrorBehaviorTransition trans : EMV2Util.getAllErrorBehaviorTransitions(ci)) {
                    // the only one that makes sense is an or of error events
                    if (trans.getCondition() instanceof ConditionElement) {
                        ConditionElement conditionElement = (ConditionElement) trans.getCondition();
                        processTransition(ci, event, typeToken, trans, conditionElement, componentText, handledPropagations);
                    } else if (trans.getCondition() instanceof OrmoreExpression) {
                        EList<ConditionExpression> elems = ((OrmoreExpression) trans.getCondition()).getOperands();
                        for (ConditionExpression conditionExpression : elems) {
                            if (conditionExpression instanceof ConditionElement) {
                                ConditionElement conditionElement = (ConditionElement) conditionExpression;
                                processTransition(ci, event, typeToken, trans, conditionElement, componentText, handledPropagations);
                            }
                        }
                    } else if (trans.getCondition() instanceof OrExpression) {
                        EList<ConditionExpression> elems = ((OrExpression) trans.getCondition()).getOperands();
                        for (ConditionExpression conditionExpression : elems) {
                            if (conditionExpression instanceof ConditionElement) {
                                ConditionElement conditionElement = (ConditionElement) conditionExpression;
                                processTransition(ci, event, typeToken, trans, conditionElement, componentText, handledPropagations);
                            }
                        }
                    }
                }
            }
        }
    }
    for (ErrorSource errorSource : eslist) {
        if (!Util.conditionHolds(errorSource, ci)) {
            continue;
        }
        EMSUtil.unsetAll(ci.getSystemInstance());
        Collection<ErrorPropagation> eplist = EMV2Util.getOutgoingPropagationOrAll(errorSource);
        TypeSet ts = errorSource.getTypeTokenConstraint();
        ErrorBehaviorState failureMode = errorSource.getFailureModeReference();
        TypeSet failureTypeSet = null;
        if (failureMode != null) {
            failureTypeSet = failureMode.getTypeSet();
        } else {
            // reference to named type set
            // or type set constructor
            failureTypeSet = errorSource.getFailureModeType();
        }
        String failuremodeDesc = errorSource.getFailureModeDescription();
        for (ErrorPropagation ep : eplist) {
            TypeSet tsep = ep.getTypeSet();
            if (ts != null || tsep != null) {
                EList<TypeToken> result = ts != null ? ts.getTypeTokens() : tsep.getTypeTokens();
                for (TypeToken typeToken : result) {
                    String failuremodeText;
                    if (handledPropagations.containsEntry(ep, EMV2Util.getPrintName(typeToken))) {
                        continue;
                    }
                    if (failuremodeDesc == null) {
                        failuremodeText = generateOriginalFailureModeText(failureMode != null ? failureMode : (failureTypeSet != null ? failureTypeSet : typeToken));
                    } else {
                        failuremodeText = failuremodeDesc;
                    }
                    traceErrorPaths(ci, ep, typeToken, 2, componentText + "," + failuremodeText);
                }
            }
        }
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) OrmoreExpression(org.osate.xtext.aadl2.errormodel.errorModel.OrmoreExpression) OrExpression(org.osate.xtext.aadl2.errormodel.errorModel.OrExpression) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) ConditionExpression(org.osate.xtext.aadl2.errormodel.errorModel.ConditionExpression) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Example 18 with ErrorSource

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource in project osate2 by osate.

the class FTAGenerator method processConnectionErrorSource.

@Override
protected EObject processConnectionErrorSource(ConnectionInstance conni, ErrorSource errorSource, TypeToken typeTokenConstraint, BigDecimal scale) {
    Event newEvent = FaultTreeUtils.createBasicEvent(ftaModel, conni, errorSource, typeTokenConstraint);
    newEvent.setScale(scale);
    return newEvent;
}
Also used : Event(org.osate.aadl2.errormodel.FaultTree.Event) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)

Example 19 with ErrorSource

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource in project osate2 by osate.

the class EMV2Util method findReverseErrorFlowFrom.

/**
 * find the error flow whose outgoing error propagation point is flowSource
 * @param eps List of error propagations
 * @param flowSource ErrorPropagation
 * @return ErrorFlow list
 */
public static EList<ErrorFlow> findReverseErrorFlowFrom(Collection<ErrorFlow> efs, ErrorPropagation flowSource) {
    EList<ErrorFlow> result = new BasicEList<ErrorFlow>();
    for (ErrorFlow ef : efs) {
        ErrorPropagation eprop = null;
        boolean isall = false;
        if (ef instanceof ErrorPath) {
            ErrorPath ep = (ErrorPath) ef;
            eprop = ep.getOutgoing();
            isall = ep.isAllOutgoing();
        } else if (ef instanceof ErrorSource && ((ErrorSource) ef).getSourceModelElement() instanceof ErrorPropagation) {
            ErrorSource es = (ErrorSource) ef;
            eprop = (ErrorPropagation) es.getSourceModelElement();
            isall = es.isAll();
        }
        if ((eprop != null && eprop == flowSource) || isall) {
            result.add(ef);
        }
    }
    return result;
}
Also used : ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) BasicEList(org.eclipse.emf.common.util.BasicEList) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Example 20 with ErrorSource

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource in project osate2 by osate.

the class EMV2Util method getAllErrorSources.

/**
 * return list of error sources including those inherited from classifiers being extended
 * @param cl Classifier
 * @return Collection<ErrorSource> list of error flow
 */
public static Collection<ErrorSource> getAllErrorSources(Classifier cl) {
    HashMap<String, ErrorSource> result = new LinkedHashMap<>();
    EList<ErrorModelSubclause> emslist = getAllContainingClassifierEMV2Subclauses(cl);
    for (ErrorModelSubclause errorModelSubclause : emslist) {
        EList<ErrorFlow> eflist = errorModelSubclause.getFlows();
        for (ErrorFlow errorFlow : eflist) {
            if (errorFlow instanceof ErrorSource) {
                if (!result.containsKey(errorFlow.getName())) {
                    result.put(errorFlow.getName(), (ErrorSource) errorFlow);
                }
            }
        }
    }
    return result.values();
}
Also used : ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ErrorSource (org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource)16 ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)13 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)9 ErrorFlow (org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow)7 TypeToken (org.osate.xtext.aadl2.errormodel.errorModel.TypeToken)7 ErrorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)6 ErrorPath (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath)6 EObject (org.eclipse.emf.ecore.EObject)5 NamedElement (org.osate.aadl2.NamedElement)5 ErrorModelSubclause (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause)5 LinkedHashMap (java.util.LinkedHashMap)4 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)4 ErrorSink (org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink)4 Classifier (org.osate.aadl2.Classifier)3 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)3 PropagationPathEnd (org.osate.aadl2.errormodel.PropagationGraph.PropagationPathEnd)3 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)3 ConditionExpression (org.osate.xtext.aadl2.errormodel.errorModel.ConditionExpression)3 ErrorBehaviorTransition (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition)3 LinkedList (java.util.LinkedList)2