Search in sources :

Example 11 with TypeToken

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

the class EMV2TypeSetUtil method reverseMapTypeTokenToContributor.

public static TypeSet reverseMapTypeTokenToContributor(TypeToken targettoken, TypeTransformationSet tts) {
    if (tts == null) {
        return null;
    }
    EList<TypeTransformation> ttlist = tts.getTransformation();
    for (TypeTransformation typeXform : ttlist) {
        TypeSet target = typeXform.getTarget();
        TypeSet contrib = typeXform.getContributor();
        if (contains(target, targettoken)) {
            return contrib;
        }
    }
    return null;
}
Also used : TypeTransformation(org.osate.xtext.aadl2.errormodel.errorModel.TypeTransformation) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)

Example 12 with TypeToken

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

the class PropagateErrorSources method traceErrorFlows.

/**
 * traverse through the destination of the connection instance
 * @param conni
 */
protected void traceErrorFlows(ComponentInstance ci, ErrorPropagation ep, TypeToken tt, int depth, String entryText) {
    if (ci == null) {
        return;
    }
    /**
     * With alreadyTreated, we have a cache that keep track of existing report
     * text for each component. For each component, we maintain a list of existing
     * entryText already reported. So, we do not duplicate the error report for each component
     * and make sure to report each entry only once.
     */
    if (!alreadyTreated.containsKey(ci)) {
        alreadyTreated.put(ci, new ArrayList<String>());
    }
    if (alreadyTreated.get(ci).contains(entryText)) {
        return;
    }
    alreadyTreated.get(ci).add(entryText);
    boolean handled = false;
    Collection<ErrorFlow> outefs = EMV2Util.findErrorFlowFromComponentInstance(ci, ep);
    for (ErrorFlow ef : outefs) {
        if (ef instanceof ErrorSink && Util.conditionHolds(ef, ci)) {
            /**
             * We try to find additional error propagation for this error sink.
             * For example, if the error sink triggers to switch to
             * another behavior state and that states is used to propagate
             * an error through an error source. Then, we do not consider
             * it as an error sink but as an error path and continue
             * to trace the flow using this additional error propagation.
             */
            if (EMV2TypeSetUtil.contains(ef.getTypeTokenConstraint(), tt)) {
                String maskText = ", " + generateFailureModeText(ci, ep, tt) + " [Masked],";
                reportEntry(entryText + maskText, depth);
                handled = true;
            } else {
                Collection<TypeToken> intersection = EMV2TypeSetUtil.getConstrainedTypeTokens(ef.getTypeTokenConstraint(), tt);
                for (TypeToken typeToken : intersection) {
                    String maskText = ", " + generateFailureModeText(ci, ep, typeToken) + " [Masked],";
                    reportEntry(entryText + maskText, depth);
                    handled = true;
                }
            }
        } else if (ef instanceof ErrorPath) {
            // error path
            Collection<ErrorPropagation> eplist = EMV2Util.getOutgoingPropagationOrAll((ErrorPath) ef);
            ErrorPropagation inep = ((ErrorPath) ef).getIncoming();
            if (ef.getTypeTokenConstraint() != null ? EMV2TypeSetUtil.contains(ef.getTypeTokenConstraint(), tt) : (inep != null ? EMV2TypeSetUtil.contains(inep.getTypeSet(), tt) : ((ErrorPath) ef).isAllIncoming())) {
                TypeToken newtt = EMV2Util.mapToken(tt, ef);
                for (ErrorPropagation outp : eplist) {
                    traceErrorPaths(ci, outp, newtt, depth + 1, entryText + ", " + generateFailureModeText(ci, ep, tt));
                    handled = true;
                }
            } else {
                Collection<TypeToken> intersection = Collections.emptyList();
                TypeSet ts = null;
                if (ef.getTypeTokenConstraint() != null) {
                    ts = ef.getTypeTokenConstraint();
                } else if (inep != null) {
                    ts = inep.getTypeSet();
                }
                if (ts != null) {
                    intersection = EMV2TypeSetUtil.getConstrainedTypeTokens(ts, tt);
                }
                for (TypeToken typeToken : intersection) {
                    TypeToken newtt = EMV2Util.mapToken(typeToken, ef);
                    for (ErrorPropagation outp : eplist) {
                        traceErrorPaths(ci, outp, newtt, depth + 1, entryText + ",\"" + generateFailureModeText(ci, ep, typeToken) + " [Subtype]\"");
                        handled = true;
                    }
                }
            }
        }
    }
    if (!handled) {
        // no error flows:. and no flows condition
        // try flows or propagate to all outgoing error propagations
        EList<FlowSpecificationInstance> flowlist = ci.getFlowSpecifications();
        if (!flowlist.isEmpty()) {
            for (FlowSpecificationInstance flowSpecificationInstance : flowlist) {
                if (flowSpecificationInstance.getSource() != null && flowSpecificationInstance.getSource().getFeature() == EMV2Util.getErrorPropagationFeature(ep, ci)) {
                    FeatureInstance outfi = flowSpecificationInstance.getDestination();
                    if (outfi != null) {
                        ErrorPropagation outp = EMV2Util.getOutgoingErrorPropagation(outfi);
                        if (outp != null) {
                            TypeToken newtt = EMV2Util.mapToken(tt, flowSpecificationInstance);
                            if (EMV2TypeSetUtil.contains(outp.getTypeSet(), newtt)) {
                                traceErrorPaths(ci, outp, newtt, depth + 1, entryText + ", " + generateFailureModeText(ci, ep, tt) + " [FlowPath]");
                                handled = true;
                            } else {
                                Collection<TypeToken> intersection = EMV2TypeSetUtil.getConstrainedTypeTokens(outp.getTypeSet(), newtt);
                                for (TypeToken typeToken : intersection) {
                                    traceErrorPaths(ci, outp, typeToken, depth + 1, entryText + ", " + generateFailureModeText(ci, ep, tt) + " [FlowPath TypeSubset]");
                                    handled = true;
                                }
                            }
                        }
                    } else {
                        // do all since we have a flow sink
                        EList<FeatureInstance> filist = ci.getFeatureInstances();
                        boolean res = doAllOutPropagationsOrFeatures(ci, filist, ep, tt, depth, entryText);
                        if (res) {
                            handled = true;
                        }
                    }
                }
            }
        } else {
            // now all outgoing propagations or features since we did not find flows
            EList<FeatureInstance> filist = ci.getFeatureInstances();
            boolean res = doAllOutPropagationsOrFeatures(ci, filist, ep, tt, depth, entryText);
            if (res) {
                handled = true;
            }
        }
    }
    if (!handled) {
        String errorText = "," + generateFailureModeText(ci, ep, tt) + " [Unhandled Failure Effect]";
        reportEntry(entryText + errorText, depth);
    }
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) Collection(java.util.Collection) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Example 13 with TypeToken

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

the class FTAHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ComponentInstance target;
    InstanceObject object = getTarget(HandlerUtil.getCurrentSelection(event));
    if (object == null) {
        Dialog.showInfo("Fault Tree Analysis", "Please choose an instance model");
        return IStatus.ERROR;
    }
    SystemInstance si = object.getSystemInstance();
    if (object instanceof ComponentInstance) {
        target = (ComponentInstance) object;
    } else {
        target = si;
    }
    if (!EMV2Util.hasComponentErrorBehaviorTransitions(target) && !EMV2Util.hasCompositeErrorBehavior(target) && !EMV2Util.hasOutgoingPropagations(target)) {
        Dialog.showInfo("Fault Tree Analysis", "Your system instance or selected component instance must have outgoing propagations, error state transitions, or composite error states.");
        return IStatus.ERROR;
    }
    stateNames = new ArrayList<String>();
    for (ErrorPropagation outprop : EMV2Util.getAllOutgoingErrorPropagations(target.getComponentClassifier())) {
        EList<TypeToken> result = EMV2TypeSetUtil.flattenTypesetElements(outprop.getTypeSet());
        for (TypeToken tt : result) {
            String epName = CreateFTAModel.prefixOutgoingPropagation + EMV2Util.getPrintName(outprop) + EMV2Util.getPrintName(tt);
            if (!stateNames.contains(epName)) {
                stateNames.add(epName);
            }
        }
    }
    Collection<ErrorBehaviorState> states = EMV2Util.getAllErrorBehaviorStates(target);
    if (!states.isEmpty()) {
        ErrorBehaviorState head = states.iterator().next();
        for (ErrorBehaviorState ebs : EMV2Util.getAllErrorBehaviorStates(target)) {
            if (ebs != head) {
                stateNames.add(CreateFTAModel.prefixState + EMV2Util.getPrintName(ebs));
            }
        }
        stateNames.add(CreateFTAModel.prefixState + EMV2Util.getPrintName(head));
    }
    if (stateNames.isEmpty()) {
        Dialog.showInfo("Fault Tree Analysis", "Selected system must have error states or error propagations");
        return IStatus.ERROR;
    }
    final Display d = PlatformUI.getWorkbench().getDisplay();
    d.syncExec(() -> {
        IWorkbenchWindow window;
        Shell sh;
        window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        sh = window.getShell();
        FTADialog diag = new FTADialog(sh);
        diag.setValues(stateNames);
        diag.setTarget("'" + (target instanceof SystemInstance ? target.getName() : target.getComponentInstancePath()) + "'");
        diag.open();
        ERROR_STATE_NAME = diag.getValue();
        FAULT_TREE_TYPE = diag.getFaultTreeType();
        GRAPHIC_VIEW = diag.isGraphicView();
    });
    if (ERROR_STATE_NAME != null) {
        if (FAULT_TREE_TYPE.equals(FaultTreeType.COMPOSITE_PARTS) && ERROR_STATE_NAME.startsWith(CreateFTAModel.prefixOutgoingPropagation)) {
            Dialog.showInfo("Fault Tree Analysis", "Select error state for composite parts fault tree");
            return IStatus.ERROR;
        }
        if (FAULT_TREE_TYPE.equals(FaultTreeType.COMPOSITE_PARTS) && !EMV2Util.hasCompositeErrorBehavior(target)) {
            Dialog.showInfo("Fault Tree Analysis", "Selected system must have composite error states for composite parts fault tree analysis");
            return IStatus.ERROR;
        }
        FaultTree ftmodel = CreateFTAModel.createModel(target, ERROR_STATE_NAME, FAULT_TREE_TYPE);
        if (ftmodel == null) {
            Dialog.showInfo("Fault Tree Analysis", "No fault tree generated. Selected error propagation has no out propagation condition or path from an inner component");
            return IStatus.ERROR;
        }
        saveFaultTree(ftmodel);
        if (GRAPHIC_VIEW) {
            SiriusUtil.INSTANCE.autoOpenModel(ftmodel, ResourceUtil.getFile(si.eResource()).getProject(), "viewpoint:/org.osate.aadl2.errormodel.faulttree.design/FaultTree", "IconicFaultTree", "Fault Tree");
        } else {
            if (FAULT_TREE_TYPE.equals(FaultTreeType.MINIMAL_CUT_SET)) {
                SiriusUtil.INSTANCE.autoOpenModel(ftmodel, ResourceUtil.getFile(si.eResource()).getProject(), "viewpoint:/org.osate.aadl2.errormodel.faulttree.design/FaultTree", "MinimalCutSetTable", "Minimal Cutset");
            } else {
                SiriusUtil.INSTANCE.autoOpenModel(ftmodel, ResourceUtil.getFile(si.eResource()).getProject(), "viewpoint:/org.osate.aadl2.errormodel.faulttree.design/FaultTree", "FaultTreeTable", "Fault Tree");
            }
        }
        return Status.OK_STATUS;
    }
    return IStatus.ERROR;
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InstanceObject(org.osate.aadl2.instance.InstanceObject) Shell(org.eclipse.swt.widgets.Shell) SystemInstance(org.osate.aadl2.instance.SystemInstance) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) FaultTree(org.osate.aadl2.errormodel.FaultTree.FaultTree) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) Display(org.eclipse.swt.widgets.Display)

Example 14 with TypeToken

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

the class FaultTreeUtils method addBasicEvent.

public static void addBasicEvent(Event parent, ConnectionInstance conni, NamedElement namedElement, TypeToken type) {
    Event newEvent = createBasicEvent((FaultTree) parent.eContainer(), conni, namedElement, type);
    parent.getSubEvents().add(newEvent);
}
Also used : Event(org.osate.aadl2.errormodel.FaultTree.Event) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)

Example 15 with TypeToken

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

the class FaultTreeUtils method createBasicEvent.

public static Event createBasicEvent(FaultTree ftaModel, ConnectionInstance conni, NamedElement namedElement, TypeToken type) {
    String name = buildName(conni, namedElement, type);
    Event result = findEvent(ftaModel, name);
    if (result != null) {
        return result;
    }
    Event newEvent = FaultTreeFactory.eINSTANCE.createEvent();
    ftaModel.getEvents().add(newEvent);
    newEvent.setName(name);
    newEvent.setType(EventType.BASIC);
    newEvent.setRelatedInstanceObject(conni);
    newEvent.setRelatedEMV2Object(namedElement);
    newEvent.setRelatedErrorType(type);
    return newEvent;
}
Also used : Event(org.osate.aadl2.errormodel.FaultTree.Event) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)

Aggregations

TypeToken (org.osate.xtext.aadl2.errormodel.errorModel.TypeToken)40 ErrorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)28 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)26 Event (org.osate.aadl2.errormodel.FaultTree.Event)24 ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)17 EObject (org.eclipse.emf.ecore.EObject)14 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)13 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)9 LinkedList (java.util.LinkedList)8 BasicEList (org.eclipse.emf.common.util.BasicEList)8 ErrorType (org.osate.xtext.aadl2.errormodel.errorModel.ErrorType)8 ErrorTypes (org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)7 NamedElement (org.osate.aadl2.NamedElement)5 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)5 ErrorSource (org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource)5 EList (org.eclipse.emf.common.util.EList)4 ConditionExpression (org.osate.xtext.aadl2.errormodel.errorModel.ConditionExpression)4 ErrorBehaviorTransition (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition)4 OrmoreExpression (org.osate.xtext.aadl2.errormodel.errorModel.OrmoreExpression)4 BigDecimal (java.math.BigDecimal)3