Search in sources :

Example 6 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.

the class VerifyHandler method getSysInstance.

protected SystemInstance getSysInstance(ComponentImplementation ci, EphemeralImplementationUtil implUtil) {
    try {
        AnalysisErrorReporterManager errorManager = new AnalysisErrorReporterManager(QueuingAnalysisErrorReporter.factory);
        SystemInstance result = implUtil.generateEphemeralCompInstanceFromImplementation(ci);
        QueuingAnalysisErrorReporter errorReporter = (QueuingAnalysisErrorReporter) errorManager.getReporter(result.eResource());
        StringBuilder stringBuilder = new StringBuilder();
        List<Message> instantiationMarkers = errorReporter.getErrors();
        if (!instantiationMarkers.isEmpty()) {
            instantiationMarkers.stream().forEach(marker -> {
                stringBuilder.append(marker.message);
            });
            throw new AgreeException(stringBuilder.toString());
        }
        return result;
    } catch (Exception e) {
        Dialog.showError("Model Instantiate", "Error while re-instantiating the model: " + e.getMessage());
        throw new AgreeException("Error Instantiating model");
    }
}
Also used : Message(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter.Message) SystemInstance(org.osate.aadl2.instance.SystemInstance) QueuingAnalysisErrorReporter(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) PartInitException(org.eclipse.ui.PartInitException) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) JKindException(jkind.JKindException)

Example 7 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.

the class MATLABFunctionHandler method runJob.

@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
    Classifier classifier = getOutermostClassifier(root);
    if (!(classifier instanceof ComponentType)) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Must select an AADL Component Type");
    }
    ComponentType ct = (ComponentType) classifier;
    ComponentImplementation ci = null;
    EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
    try {
        SystemInstance si = implUtil.generateEphemeralCompInstanceFromType(ct);
        ComponentType sysType = AgreeUtils.getInstanceType(si);
        EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
        if (annexSubClauses.size() == 0) {
            throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
        }
        // Get Agree program
        AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
        if (agreeProgram.containsRealTimePatterns) {
            throw new AgreeException("'" + sysType.getName() + "' system type contains AGREE Real Time Patterns." + " Export of AGREE Real Time Patterns NOT Supported - they are considered scheduling properties" + " of components and can be decomposed further.");
        }
        // Translate Agree Node to Lustre Node with pre-statement flatten, helper nodes inlined,
        // and variable declarations sorted so they are declared before use
        Node lustreNode = AgreeNodeToLustreContract.translate(agreeProgram.topNode, agreeProgram);
        // Translate Lustre Node to MATLAB Function AST
        MATLABPrimaryFunction matlabFunction = LustreToMATLABTranslator.translate(lustreNode, agreeProgram);
        ModelInfo info = getModelInfo(ct);
        if (info == null) {
            // return;
            return Status.CANCEL_STATUS;
        }
        String dirStr = info.outputDirPath;
        if (dirStr == null || dirStr.isEmpty()) {
            // return;
            return Status.CANCEL_STATUS;
        }
        boolean exportContractsPressed = info.exportPressed;
        boolean genImplPressed = info.generatePressed;
        boolean genVerificationPressed = info.updatePressed;
        boolean verifySubsysPressed = info.verifyPressed;
        String matlabFuncScriptName = matlabFunction.name + ".m";
        if (genImplPressed) {
            // Write MATLAB script to generate subsystem in the selected
            // output folder
            String subsysName = "";
            if (info.subsystemName.equals("")) {
                subsysName = sysType.getName();
            } else {
                subsysName = info.subsystemName;
            }
            MdlScriptCreator implMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, subsysName, matlabFunction.ports, matlabFuncScriptName, true, info.verifyPressed);
            String implMdlScriptName = "generate_" + subsysName + ".m";
            // generate the script to create the impl model file into the path specified for the model
            File implMdlFile = new File(info.implMdlPath);
            String implMdlDir = implMdlFile.getParent();
            if (implMdlDir != null) {
                Path implMdlScriptPath = Paths.get(implMdlDir, implMdlScriptName);
                writeToFile(implMdlScriptPath, implMdlScript.toString());
            }
        }
        if (exportContractsPressed || genVerificationPressed || verifySubsysPressed) {
            Path matlabFuncScriptPath = Paths.get(dirStr, matlabFuncScriptName);
            // Write MATLAB function code into the specified file in the
            // selected output folder
            writeToFile(matlabFuncScriptPath, matlabFunction.toString());
            if (genVerificationPressed || verifySubsysPressed) {
                // Create Simulink Model Update script into the output
                // folder
                MdlScriptCreator verifMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, info.subsystemName, matlabFunction.ports, matlabFuncScriptName, false, info.verifyPressed);
                String verifMdlScriptName = matlabFunction.name + "_Observer.m";
                Path verifMdlScriptPath = Paths.get(dirStr, verifMdlScriptName);
                writeToFile(verifMdlScriptPath, verifMdlScript.toString());
            }
        }
        // return;
        return Status.OK_STATUS;
    } catch (Throwable e) {
        String messages = getNestedMessages(e);
        e.printStackTrace();
        Dialog.showError("AGREE Error", e.toString());
        // return;
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
    } finally {
        if (ci != null) {
            ci.eResource().getContents().remove(ci);
        }
        implUtil.cleanup();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Path(java.nio.file.Path) ComponentType(org.osate.aadl2.ComponentType) Node(jkind.lustre.Node) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) Classifier(org.osate.aadl2.Classifier) MATLABPrimaryFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABPrimaryFunction) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) SystemInstance(org.osate.aadl2.instance.SystemInstance) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) File(java.io.File) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 8 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.

the class SimulationLaunchConfigurationDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    SimulationService simulationService = null;
    try {
        simulationService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationService.class);
        Objects.requireNonNull(configuration, "configuration must not be null");
        // Find the component implementation
        final String componentImplementationName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.COMPONENT_IMPLEMENTATION_NAME, (String) null);
        final String projectName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.PROJECT_NAME, (String) null);
        final IProject project = projectName == null ? null : findProject(projectName);
        final EObject obj = componentImplementationName == null ? null : findComponentImplementation(project, componentImplementationName);
        if (obj instanceof ComponentImplementation) {
            // Refresh the component implementation
            final ComponentImplementation ci = refreshComponentImplementation((ComponentImplementation) obj);
            // (Re)instantiate the model
            final SystemInstance systemInstance = InstantiateModel.buildInstanceModelFile(ci);
            // Get the selected simulation engine type.
            final String selectedEngineTypeId = Objects.requireNonNull(configuration.getAttribute(SimulationLaunchConfigurationAttributes.ENGINE_TYPE_ID, (String) null), "Simulation Engine must be specified");
            final EngineType engineType = Objects.requireNonNull(simulationService.getEngineTypeById(selectedEngineTypeId), "Unable to find specified simulation engine");
            final SimulationEngine newEngine = simulationService.createEngine(engineType, systemInstance);
            final SimulationService simService = simulationService;
            simulationService.addSimulationEngineChangeListener(new SimulationEngineChangeListener() {

                @Override
                public void onSimulationEngineCreated(final SimulationEngine engine) {
                }

                @Override
                public void onSimulationEngineDisposed(final SimulationEngine engine) {
                    if (engine == newEngine) {
                        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
                        simService.removeSimulationEngineChangeListener(this);
                    }
                }
            });
            if (launch instanceof SimulationLaunch) {
                ((SimulationLaunch) launch).setSimulationEngine(newEngine);
            }
        } else {
            simulationService.getExceptionHandler().handleException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Unable to find Component Implementation.")));
        }
    } catch (final Exception e) {
        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
        if (simulationService == null) {
            throw new RuntimeException(e);
        } else {
            simulationService.getExceptionHandler().handleException(e);
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) CoreException(org.eclipse.core.runtime.CoreException) SystemInstance(org.osate.aadl2.instance.SystemInstance) EObject(org.eclipse.emf.ecore.EObject) SimulationEngineChangeListener(edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener) EngineType(edu.uah.rsesc.aadlsimulator.services.EngineType) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService)

Example 9 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project AMASE by loonwerks.

the class GenMCSHandler method runJob.

@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
    EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
    // this flag is set by the rerun handler to prevent clearing the advice map
    if (!calledFromRerun) {
        rerunAdviceMap.clear();
    }
    calledFromRerun = false;
    disableRerunHandler();
    handlerService = getWindow().getService(IHandlerService.class);
    try {
        // Make sure the user selected a component implementation
        ComponentImplementation ci = getComponentImplementation(root, implUtil);
        SystemInstance si = getSysInstance(ci, implUtil);
        AnalysisResult result;
        CompositeAnalysisResult wrapper = new CompositeAnalysisResult("");
        // SystemType sysType = si.getSystemImplementation().getType();
        ComponentType sysType = AgreeUtils.getInstanceType(si);
        EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
        if (annexSubClauses.size() == 0) {
            throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
        }
        if (isRecursive()) {
            if (AgreeUtils.usingKind2()) {
                throw new AgreeException("Kind2 only supports monolithic verification");
            }
            result = buildAnalysisResult(((NamedElement) root).getName(), si);
            wrapper.addChild(result);
            result = wrapper;
        } else if (isRealizability()) {
            AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
            Program program = LustreAstBuilder.getRealizabilityLustreProgram(agreeProgram);
            wrapper.addChild(createVerification("Realizability Check", si, program, agreeProgram, AnalysisType.Realizability));
            result = wrapper;
        } else {
            wrapVerificationResult(si, wrapper);
            result = wrapper;
        }
        showView(result, linker);
        return doAnalysis(root, monitor, result, linker);
    } catch (Throwable e) {
        String messages = getNestedMessages(e);
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
    } finally {
        implUtil.cleanup();
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ComponentType(org.osate.aadl2.ComponentType) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AnalysisResult(jkind.api.results.AnalysisResult) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) IHandlerService(org.eclipse.ui.handlers.IHandlerService) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) SystemInstance(org.osate.aadl2.instance.SystemInstance) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) NamedElement(org.osate.aadl2.NamedElement) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 10 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.

the class ComponentInstanceHandler method getCanonicalReference.

@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
    final ComponentInstance bo = ctx.getBusinessObject(ComponentInstance.class).get();
    final String systemInstanceKey = AadlReferenceUtil.getSystemInstanceKey(bo);
    if (bo instanceof SystemInstance) {
        return AadlReferenceUtil.getCanonicalBusinessObjectReferenceForSystemInstance(systemInstanceKey);
    } else {
        return new CanonicalBusinessObjectReference(AadlReferenceUtil.INSTANCE_ID, AadlReferenceUtil.COMPONENT_INSTANCE_KEY, systemInstanceKey, bo.getInstanceObjectPath());
    }
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Aggregations

SystemInstance (org.osate.aadl2.instance.SystemInstance)100 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)52 InstanceObject (org.osate.aadl2.instance.InstanceObject)26 ComponentImplementation (org.osate.aadl2.ComponentImplementation)25 Element (org.osate.aadl2.Element)25 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)22 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)21 Classifier (org.osate.aadl2.Classifier)18 ForAllElement (org.osate.aadl2.modelsupport.modeltraversal.ForAllElement)18 ComponentCategory (org.osate.aadl2.ComponentCategory)17 NamedElement (org.osate.aadl2.NamedElement)16 List (java.util.List)14 Resource (org.eclipse.emf.ecore.resource.Resource)14 AadlPackage (org.osate.aadl2.AadlPackage)14 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)14 ArrayList (java.util.ArrayList)13 EList (org.eclipse.emf.common.util.EList)13 IOException (java.io.IOException)12 IStatus (org.eclipse.core.runtime.IStatus)12 Optional (java.util.Optional)10