Search in sources :

Example 1 with GSNInterface

use of com.ge.verdict.gsn.GSNInterface in project VERDICT by ge-high-assurance.

the class App method runGsn.

/**
 * call the GSN creation interface from verdict-assurance-case Behavior: 1. If security cases
 * have not been enabled - Creates normal GSN for every requirement specified 2. If security
 * cases have been enabled - creates a security GSN for every cyber requirement that is
 * specified - creates a normal GSN for all other requirements
 *
 * @param rootGoalId
 * @param gsnOutputDir
 * @param soteriaOutputDir
 * @param caseAadlPath
 */
private static void runGsn(String inputLine, String gsnOutputDir, String soteriaOutputDir, String modelAadlPath, boolean generateXml, boolean securityCases, String modelName, String hostSTEMDir) throws VerdictRunException {
    logHeader("GSN");
    // The prefix for SOteria++ text outputs that are linked from solution nodes
    String soteriaOutputLinkPathPrefix = hostSTEMDir + "/Output/Soteria_Output/" + modelName;
    // Fetch the model first
    File modelXml = new File(gsnOutputDir, "modelXML.xml");
    // Fetch the DeliveryDrone model from the XML
    Model model = VdmTranslator.unmarshalFromXml(modelXml);
    // get all cyber Ids
    List<String> cyberIds = new ArrayList<>();
    for (verdict.vdm.vdm_model.CyberReq aCyberReq : model.getCyberReq()) {
        cyberIds.add(aCyberReq.getId());
    }
    // splitting the input by ';'
    String[] inputIds = inputLine.split(";");
    List<String> allIds = new ArrayList<>();
    for (String inputId : inputIds) {
        allIds.add(inputId);
    }
    // remove duplicates
    List<String> duplicateFreeIds = new ArrayList<>(new HashSet<>(allIds));
    for (String id : duplicateFreeIds) {
        // if cyberId
        if (cyberIds.contains(id)) {
            if (securityCases) {
                // if security is enabled
                // calling the function to create security GSN artefacts
                SecurityGSNInterface createGsnObj = new SecurityGSNInterface();
                try {
                    createGsnObj.runGsnArtifactsGenerator(id, gsnOutputDir, soteriaOutputDir, modelAadlPath, securityCases, generateXml, soteriaOutputLinkPathPrefix, hostSTEMDir);
                } catch (IOException | ParserConfigurationException | SAXException e) {
                    // TODO Auto-generated catch block
                    throw new VerdictRunException("Failed to create GSN fragments", e);
                }
            } else {
                // calling the function to create normal GSN artefacts
                GSNInterface createGsnObj = new GSNInterface();
                try {
                    createGsnObj.runGsnArtifactsGenerator(id, gsnOutputDir, soteriaOutputDir, modelAadlPath, generateXml, soteriaOutputLinkPathPrefix, hostSTEMDir);
                } catch (IOException | ParserConfigurationException | SAXException e) {
                    // TODO Auto-generated catch block
                    throw new VerdictRunException("Failed to create GSN fragments", e);
                }
            }
        } else {
            // if not cyberId
            // calling the function to create normal GSN artefacts
            GSNInterface createGsnObj = new GSNInterface();
            try {
                createGsnObj.runGsnArtifactsGenerator(id, gsnOutputDir, soteriaOutputDir, modelAadlPath, generateXml, soteriaOutputLinkPathPrefix, hostSTEMDir);
            } catch (IOException | ParserConfigurationException | SAXException e) {
                // TODO Auto-generated catch block
                throw new VerdictRunException("Failed to create GSN fragments", e);
            }
        }
    }
    // if running inside docker
    if (isRunningInsideDocker()) {
        // sleep for three seconds to allow docker to exit gracefully
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            throw new VerdictRunException("Failed to create GSN fragments. Thread.sleep exception.", e);
        }
    }
    logHeader("Finished");
}
Also used : GSNInterface(com.ge.verdict.gsn.GSNInterface) SecurityGSNInterface(com.ge.verdict.gsn.SecurityGSNInterface) SecurityGSNInterface(com.ge.verdict.gsn.SecurityGSNInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Model(verdict.vdm.vdm_model.Model) CostModel(com.ge.verdict.synthesis.CostModel) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Aggregations

GSNInterface (com.ge.verdict.gsn.GSNInterface)1 SecurityGSNInterface (com.ge.verdict.gsn.SecurityGSNInterface)1 CostModel (com.ge.verdict.synthesis.CostModel)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1 Model (verdict.vdm.vdm_model.Model)1