Search in sources :

Example 76 with ProcessVO

use of com.centurylink.mdw.model.value.process.ProcessVO in project mdw-designer by CenturyLinkCloud.

the class Graph method removeSubGraph.

public void removeSubGraph(SubGraph subgraph) {
    ProcessVO subProcDef = subgraph.getProcessVO();
    String entryTransId = subProcDef.getAttribute(WorkAttributeConstant.ENTRY_TRANSITION_ID);
    List<ProcessVO> subprocs = processVO.getSubProcesses();
    subprocs.remove(subProcDef);
    subgraphs.remove(subgraph);
    if (entryTransId != null) {
        Long deleteTransId = new Long(entryTransId);
        if (deleteTransId.longValue() > 0)
            processVO.addDeletedTransitions(deleteTransId);
    }
    setDirtyLevel(DIRTY);
}
Also used : ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO)

Example 77 with ProcessVO

use of com.centurylink.mdw.model.value.process.ProcessVO in project mdw-designer by CenturyLinkCloud.

the class AutoTestAntTask method runTests.

public void runTests() throws Exception {
    if (!baseDir.exists() || !baseDir.isDirectory())
        throw new IOException("Directory does not exist: " + baseDir);
    ThreadPool threadPool = new ThreadPool(threadCount);
    HashMap<String, ProcessVO> processCache = new HashMap<>();
    boolean hasGherkin = false;
    boolean hasNonGherkin = false;
    if (workflowDir != null) {
        DirectoryScanner scanner = getDirectoryScanner(workflowDir);
        scanner.scan();
        String jsonString;
        if (testResultsSummaryFile.exists() && testResultsSummaryFile.getName().endsWith(".json")) {
            jsonString = new String(Files.readAllBytes(testResultsSummaryFile.toPath()));
            if (jsonString != null && !jsonString.isEmpty())
                testCaseList = new TestCaseList(workflowDir, new JSONObject(jsonString));
        }
        if (testCaseList == null) {
            testCaseList = new TestCaseList(workflowDir);
            testCaseList.setPackageTests(new ArrayList<PackageTests>());
        }
        String workflowPath = workflowDir.toString().replace('\\', '/');
        String[] caseFilePaths = scanner.getIncludedFiles();
        for (String caseFilePath : caseFilePaths) {
            String casePath = caseFilePath.replace('\\', '/');
            int lastSlash = casePath.lastIndexOf('/');
            String pkgName = casePath.substring(0, lastSlash).replace('/', '.');
            File caseFile = new File(workflowPath + "/" + casePath);
            PackageTests pkgTests = testCaseList.getPackageTests(pkgName);
            if (pkgTests == null) {
                PackageDir pkgDir = new PackageDir(workflowDir, caseFile.getParentFile(), null);
                pkgDir.parse();
                pkgTests = new PackageTests(pkgDir);
                pkgTests.setTestCases(new ArrayList<com.centurylink.mdw.test.TestCase>());
                testCaseList.getPackageTests().add(pkgTests);
            }
            pkgTests.getTestCases().add(new com.centurylink.mdw.test.TestCase(pkgName, new AssetInfo(caseFile)));
            TestCase tc = new TestCase(pkgName, caseFile);
            if (tc.isGherkin())
                hasGherkin = true;
            else
                hasNonGherkin = true;
            testCases.add(tc);
        }
    } else if (jdbcUrl != null) {
        // db asset tests
        if (dbAssetTests == null)
            throw new BuildException("Attribute dbAssetTests required for non-VCS asset tests");
        String[] assets = dbAssetTests.split("\\s?,\\s?");
        for (String asset : assets) {
            int lastSlash = asset.lastIndexOf('/');
            String pkg = asset.substring(0, lastSlash);
            String assetName = asset.substring(lastSlash + 1);
            String language = RuleSetVO.getLanguage(assetName.substring(assetName.lastIndexOf('.')));
            RuleSetVO ruleSet = designerDataAccess.getRuleSet(assetName, language, 0);
            ruleSet.setPackageName(pkg);
            TestCase tc = new TestCase(pkg, ruleSet);
            testCases.add(tc);
        }
    } else {
        throw new BuildException("Missing attribute: workflowDir");
    }
    if (hasGherkin && hasNonGherkin)
        throw new BuildException("Gherkin/non-Gherkin tests require separate task/target executions.");
    // gradle
    boolean useStdErr = System.getProperty("org.gradle.appname") != null;
    // does
    // not
    // show
    // output
    // otherwise
    LogMessageMonitor monitor = hasGherkin ? null : new LogMessageMonitor(designerDataAccess, oldNamespaces);
    if (monitor != null)
        monitor.start(true);
    for (TestCase testCase : testCases) {
        String masterRequestId = user + "-" + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
        File resultDir = new File(testResultsDir + "/" + testCase.getPrefix());
        testCase.prepare();
        TestCaseRun run;
        if (testCase.isGherkin()) {
            // User defined masterRequestId
            if (testCase.getMasterRequestId() != null) {
                if (testCase.getMasterRequestId().indexOf("${masterRequestId}") != -1) {
                    masterRequestId = testCase.getMasterRequestId().replace("${masterRequestId}", masterRequestId);
                } else
                    masterRequestId = testCase.getMasterRequestId();
            }
            testCase.setMasterRequestId(masterRequestId);
            run = new GherkinTestCaseRun(testCase, 0, masterRequestId, new DesignerDataAccess(designerDataAccess), monitor, processCache, oldNamespaces, resultDir, stubbing, stubPort);
        } else if (testCase.isGroovy())
            run = new GroovyTestCaseRun(testCase, 0, masterRequestId, new DesignerDataAccess(designerDataAccess), monitor, processCache, loadTests, true, oldNamespaces, null);
        else
            run = new TestCaseRun(testCase, 0, masterRequestId, new DesignerDataAccess(designerDataAccess), monitor, processCache, loadTests, true, oldNamespaces);
        File executeLog = new File(resultDir.getPath() + "/" + testCase.getCaseName() + ".log");
        if (!executeLog.getParentFile().exists() && !executeLog.getParentFile().mkdirs())
            throw new IOException("Unable to create test run directory: " + executeLog.getParentFile());
        PrintStream log = verbose ? new TeePrintStream(useStdErr ? System.err : System.out, executeLog) : new PrintStream(executeLog);
        run.prepareTest(false, resultDir, true, singleServer, stubbing, log);
        if (verbose)
            log("Test case prepared: " + testCase.getCaseName(), useStdErr ? Project.MSG_ERR : Project.MSG_INFO);
        masterRequestRunMap.put(run.getMasterRequestId(), run);
        threadPool.execute(run);
        updateResults(false);
        try {
            Thread.sleep(intervalSecs * 1000);
        } catch (InterruptedException e) {
        }
    }
    log("All cases prepared. Waiting for completion ...", Project.MSG_INFO);
    threadPool.shutdown();
    while (!threadPool.isTerminated()) {
        updateResults(false);
        try {
            Thread.sleep(2500);
        } catch (InterruptedException e) {
        }
    }
    if (monitor != null)
        monitor.shutdown();
    updateResults(true);
    log("All cases completed.", Project.MSG_ERR);
}
Also used : HashMap(java.util.HashMap) AssetInfo(com.centurylink.mdw.test.AssetInfo) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) PackageTests(com.centurylink.mdw.test.PackageTests) PackageDir(com.centurylink.mdw.dataaccess.file.PackageDir) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) TestCaseList(com.centurylink.mdw.test.TestCaseList) PrintStream(java.io.PrintStream) TeePrintStream(com.centurylink.mdw.common.utilities.file.TeePrintStream) TeePrintStream(com.centurylink.mdw.common.utilities.file.TeePrintStream) IOException(java.io.IOException) Date(java.util.Date) JSONObject(org.json.JSONObject) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 78 with ProcessVO

use of com.centurylink.mdw.model.value.process.ProcessVO in project mdw-designer by CenturyLinkCloud.

the class GroovyTestCaseRun method startProcess.

void startProcess(TestCaseProcess process) throws TestException {
    if (verbose)
        log.println("starting process " + process.getLabel() + "...");
    this.testCaseProcess = process;
    try {
        if (!getTestCase().isLegacy()) {
            // delete the (convention-based) result file if exists
            String resFileName = getTestCase().getName() + RuleSetVO.getFileExtension(RuleSetVO.YAML);
            File resFile = new File(getTestCase().getResultDirectory() + "/" + resFileName);
            if (resFile.isFile())
                resFile.delete();
        }
        ProcessVO vo = process.getProcessVo();
        Map<String, String> params = process.getParams();
        String server = getNextServer();
        String response;
        if (server == null) {
            response = dao.launchProcess(vo, getMasterRequestId(), null, params, false, oldNamespaces);
        } else {
            Server restServer = dao.getCurrentServer();
            if (restServer.isSchemaVersion61()) {
                Map<VariableVO, String> variables = new HashMap<>();
                for (Map.Entry<String, String> entry : params.entrySet()) {
                    VariableVO varVO = vo.getVariable(entry.getKey());
                    if (varVO != null)
                        variables.put(varVO, entry.getValue());
                }
                response = ((RestfulServer) restServer).launchProcess(vo.getProcessId(), masterRequestId, vo.getOwnerType(), vo.getOwnerId(), variables);
            } else {
                String request = restServer.buildLaunchProcessRequest(vo, getMasterRequestId(), null, params, false, oldNamespaces);
                response = dao.engineCall(dao.getPeerServerUrl(server), request);
            }
        }
        validateEngineCallResponse(response);
    } catch (Exception ex) {
        throw new TestException("Failed to start " + process.getLabel(), ex);
    }
}
Also used : Server(com.centurylink.mdw.designer.utils.Server) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) HashMap(java.util.HashMap) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) AssetFile(com.centurylink.mdw.dataaccess.file.AssetFile) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) JSONException(org.json.JSONException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException)

Example 79 with ProcessVO

use of com.centurylink.mdw.model.value.process.ProcessVO in project mdw-designer by CenturyLinkCloud.

the class PluginDataAccess method determineDefaultPackage.

private PackageVO determineDefaultPackage(List<PackageVO> packageList, List<ProcessVO> processes) {
    Map<String, PackageVO> processPackage = new HashMap<>();
    PackageVO defaultPackage = new PackageVO();
    List<ProcessVO> defaultProcesses = new ArrayList<>();
    for (PackageVO pkg : packageList) {
        for (ProcessVO proc : pkg.getProcesses()) processPackage.put(proc.getProcessName(), pkg);
    }
    for (ProcessVO proc : processes) {
        if (processPackage.get(proc.getProcessName()) == null)
            defaultProcesses.add(proc);
    }
    defaultPackage.setProcesses(defaultProcesses);
    defaultPackage.setExternalEvents(new ArrayList<ExternalEventVO>(0));
    defaultPackage.setPackageId(Long.valueOf(0));
    defaultPackage.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
    return defaultPackage;
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) HashMap(java.util.HashMap) ExternalEventVO(com.centurylink.mdw.model.value.event.ExternalEventVO) ArrayList(java.util.ArrayList) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO)

Example 80 with ProcessVO

use of com.centurylink.mdw.model.value.process.ProcessVO in project mdw-designer by CenturyLinkCloud.

the class ProcessValidator method validate.

public void validate(boolean checkImplementors, NodeMetaInfo implInfo) throws ValidationException {
    if (packageVO != null) {
        // check if processes are up to date
        for (ProcessVO proc : packageVO.getProcesses()) {
            if (proc.getNextVersion() != null)
                errors.add("Process " + proc.getProcessName() + " has newer versions");
        }
        // check implementors
        if (checkImplementors) {
            Map<String, ActivityImplementorVO> has = new HashMap<String, ActivityImplementorVO>();
            Map<String, String> hasnot = new HashMap<String, String>();
            for (ActivityImplementorVO ai : packageVO.getImplementors()) {
                has.put(ai.getImplementorClassName(), ai);
            }
            for (ProcessVO proc : packageVO.getProcesses()) {
                for (ActivityVO act : proc.getActivities()) {
                    String v = act.getImplementorClassName();
                    if (!has.containsKey(v))
                        hasnot.put(v, v);
                }
                if (proc.getSubProcesses() != null) {
                    for (ProcessVO subproc : proc.getSubProcesses()) {
                        for (ActivityVO act : subproc.getActivities()) {
                            String v = act.getImplementorClassName();
                            if (!has.containsKey(v))
                                hasnot.put(v, v);
                        }
                    }
                }
            }
            for (String v : hasnot.keySet()) {
                errors.add("Implementor " + v + " is used but not included");
            }
        }
        // validate each process
        for (ProcessVO proc : packageVO.getProcesses()) {
            process = proc;
            validateProcess(implInfo);
        }
    } else {
        validateProcess(implInfo);
    }
    if (errors.size() > 0)
        throw new ValidationException(errors);
}
Also used : ActivityImplementorVO(com.centurylink.mdw.model.value.activity.ActivityImplementorVO) HashMap(java.util.HashMap) ActivityVO(com.centurylink.mdw.model.value.activity.ActivityVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO)

Aggregations

ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)92 ArrayList (java.util.ArrayList)29 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)28 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)25 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)17 IOException (java.io.IOException)17 HashMap (java.util.HashMap)15 RemoteException (java.rmi.RemoteException)14 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)12 ActivityVO (com.centurylink.mdw.model.value.activity.ActivityVO)11 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)11 JSONException (org.json.JSONException)11 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)10 XmlException (org.apache.xmlbeans.XmlException)10 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)9 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)9 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)8 ExternalEventVO (com.centurylink.mdw.model.value.event.ExternalEventVO)8 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)7 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)5