Search in sources :

Example 1 with Notification

use of org.eclipse.titan.executor.views.notification.Notification in project titan.EclipsePlug-ins by eclipse.

the class CliExecutor method processConsoleOutput.

/**
 * Processes the output of the Main Controller
 * <p>
 * Note that the output is not reported in full lines.
 *
 * @param text the newly reported text
 *
 * @see #readFullLineOnly(BufferedReader)
 */
// TODO add support for following batch mode (exit)
private void processConsoleOutput(final String text) {
    if (thread != null) {
        thread.reset();
    }
    builder.append(text);
    StringReader reader = new StringReader(builder.toString());
    BufferedReader stdout = new BufferedReader(reader);
    fastOffset = 0;
    readFullLineOnly(stdout);
    while (fastLine != null) {
        while (fastLine.startsWith("MC2> ")) {
            fastLine = fastLine.substring(5);
        }
        if (fastLine.startsWith("MC information:")) {
            processInfoOutput(stdout);
            if (fastLine == null) {
                break;
            }
            if (Activator.getMainView() != null) {
                Activator.getMainView().refreshAll();
            }
        } else if (consoleTimeStampLength < fastLine.length() && fastLine.substring(consoleTimeStampLength).startsWith("MTC@")) {
            fastLine = fastLine.substring(consoleTimeStampLength);
            addNotification(new Notification((new Formatter()).format(PADDEDDATETIMEFORMAT, new Date()).toString(), "", "", fastLine));
            testExecution();
        } else if (consoleTimeStampLength < fastLine.length() && fastLine.substring(consoleTimeStampLength).startsWith("MC@")) {
            fastLine = fastLine.substring(consoleTimeStampLength);
            addNotification(new Notification((new Formatter()).format(PADDEDDATETIMEFORMAT, new Date()).toString(), "", "", fastLine));
            int index = fastLine.indexOf(':');
            String shortversion = fastLine.substring(index + 1);
            if (SHUTDOWN_COMPLETE.equals(shortversion)) {
                running = false;
                executeRequested = false;
                createMTCRequested = false;
                if (mainControllerRoot != null) {
                    mainControllerRoot.setTerminated();
                }
                if (Activator.getMainView() != null) {
                    Activator.getMainView().refreshAll();
                }
                if (thread != null) {
                    thread.cancel();
                    thread = null;
                }
            } else if (hcConnectedMatcher.reset(shortversion).matches()) {
                suspectedLastState = JniExecutor.MC_HC_CONNECTED;
            } else if (MTC_CREATED.equals(shortversion)) {
                suspectedLastState = JniExecutor.MC_READY;
            } else if (TEST_EXECUTION_FINISHED.equals(shortversion)) {
                if (!executingConfigFile) {
                    suspectedLastState = JniExecutor.MC_READY;
                }
            } else if (EXECUTE_SECTION_FINISHED.equals(shortversion)) {
                suspectedLastState = JniExecutor.MC_READY;
                executingConfigFile = false;
            } else if (TERMINATING_MTC.equals(shortversion)) {
                suspectedLastState = JniExecutor.MC_TERMINATING_MTC;
            } else if (MTC_TERMINATED.equals(shortversion)) {
                suspectedLastState = JniExecutor.MC_ACTIVE;
            } else if (successfulStartUpMatcher.reset(fastLine).matches()) {
                mcHost = successfulStartUpMatcher.group(2);
                mcPort = successfulStartUpMatcher.group(3);
                suspectedLastState = JniExecutor.MC_LISTENING;
            } else if (fullSuccessfulStartUpMatcher.reset(shortversion).matches()) {
                mcHost = fullSuccessfulStartUpMatcher.group(1);
                mcPort = fullSuccessfulStartUpMatcher.group(2);
                suspectedLastState = JniExecutor.MC_LISTENING;
            }
        } else if (consoleTimeStampLength < fastLine.length() && fastLine.substring(consoleTimeStampLength).startsWith("HC@")) {
            fastLine = fastLine.substring(consoleTimeStampLength);
            addNotification(new Notification((new Formatter()).format(PADDEDDATETIMEFORMAT, new Date()).toString(), "", "", fastLine));
        } else {
            // to avoid expensive steps and using cheap comparisons instead, if possible:
            if (consoleTimeStampLength > 0 && consoleTimeStampLength < fastLine.length()) {
                Matcher m = COMPONENT_LOG_PATTERN.matcher(fastLine);
                if (m.matches()) {
                    fastLine = fastLine.substring(consoleTimeStampLength);
                }
            }
            addNotification(new Notification((new Formatter()).format(PADDEDDATETIMEFORMAT, new Date()).toString(), "", "", fastLine));
        }
        builder.delete(0, fastOffset);
        if (Activator.getMainView() != null) {
            Activator.getMainView().refreshIfSelected(mainControllerRoot);
        } else {
            TestExecutionView.refreshInput(this);
        }
        fastOffset = 0;
        readFullLineOnly(stdout);
        TITANDebugConsole.getConsole().newMessageStream().println("MC in suspected state: " + suspectedLastState);
    }
    statusChangeHandler();
}
Also used : Matcher(java.util.regex.Matcher) Formatter(java.util.Formatter) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Notification(org.eclipse.titan.executor.views.notification.Notification) Date(java.util.Date)

Example 2 with Notification

use of org.eclipse.titan.executor.views.notification.Notification in project titan.EclipsePlug-ins by eclipse.

the class HostJob method processConsoleOutput.

/**
 * Processes the output of the Main Controller
 * <p>
 * Note that the output is not reported in full lines.
 *
 * @param text the newly reported text
 *
 * @see #readFullLineOnly(BufferedReader)
 */
private void processConsoleOutput(final String text) {
    builder.append(text);
    final StringReader reader = new StringReader(builder.toString());
    final BufferedReader stdout = new BufferedReader(reader);
    fastOffset = 0;
    readFullLineOnly(stdout);
    while (null != fastLine) {
        executor.addNotification(new Notification((new Formatter()).format(BaseExecutor.PADDEDDATETIMEFORMAT, new Date()).toString(), "", "", fastLine));
        builder.delete(0, fastOffset);
        if (!firstOutput && null != Activator.getMainView()) {
            Activator.getMainView().refreshIfSelected(executor.mainControllerRoot);
            firstOutput = true;
        }
        fastOffset = 0;
        readFullLineOnly(stdout);
    }
    try {
        stdout.close();
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    reader.close();
}
Also used : Formatter(java.util.Formatter) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Notification(org.eclipse.titan.executor.views.notification.Notification) Date(java.util.Date)

Example 3 with Notification

use of org.eclipse.titan.executor.views.notification.Notification in project titan.EclipsePlug-ins by eclipse.

the class HostJob method run.

@Override
protected IStatus run(final IProgressMonitor monitor) {
    IProcess process = DebugPlugin.newProcess(executor.getLaunchStarted(), proc, getName());
    final IStreamsProxy proxy = process.getStreamsProxy();
    if (null != proxy) {
        final IStreamMonitor outputStreamMonitor = proxy.getOutputStreamMonitor();
        final IStreamListener listener = new IStreamListener() {

            @Override
            public void streamAppended(final String text, final IStreamMonitor monitor) {
                processConsoleOutput(text);
            }
        };
        if (null != outputStreamMonitor) {
            final String temp = outputStreamMonitor.getContents();
            processConsoleOutput(temp);
            outputStreamMonitor.addListener(listener);
        }
    }
    final MessageConsoleStream stream = TITANConsole.getConsole().newMessageStream();
    String line;
    final BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    final BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    try {
        final int exitVal = proc.waitFor();
        if (0 == exitVal) {
            executor.addNotification(new Notification((new Formatter()).format(BaseExecutor.PADDEDDATETIMEFORMAT, new Date()).toString(), EMPTY, EMPTY, "Host Controller executed successfully"));
        } else {
            if (stderr.ready()) {
                final String tempDate = (new Formatter()).format(BaseExecutor.PADDEDDATETIMEFORMAT, new Date()).toString();
                executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, "Host Controller execution failed"));
                executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, "  returned with value:" + exitVal));
                executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, "Sent the following error messages:"));
                line = stderr.readLine();
                while (null != line) {
                    executor.addNotification(new Notification(tempDate, EMPTY, EMPTY, line));
                    line = stderr.readLine();
                }
            }
        }
        proc.destroy();
    } catch (IOException e) {
        stream.println("execution failed beacuse of interrupion");
        ErrorReporter.logExceptionStackTrace(e);
        return Status.CANCEL_STATUS;
    } catch (InterruptedException e) {
        stream.println("execution failed beacuse of interrupion");
        ErrorReporter.logExceptionStackTrace(e);
        return Status.CANCEL_STATUS;
    } finally {
        try {
            stdout.close();
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
        try {
            stderr.close();
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    return Status.OK_STATUS;
}
Also used : IStreamListener(org.eclipse.debug.core.IStreamListener) InputStreamReader(java.io.InputStreamReader) Formatter(java.util.Formatter) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) IOException(java.io.IOException) Notification(org.eclipse.titan.executor.views.notification.Notification) Date(java.util.Date) IStreamMonitor(org.eclipse.debug.core.model.IStreamMonitor) BufferedReader(java.io.BufferedReader) IStreamsProxy(org.eclipse.debug.core.model.IStreamsProxy) IProcess(org.eclipse.debug.core.model.IProcess)

Example 4 with Notification

use of org.eclipse.titan.executor.views.notification.Notification in project titan.EclipsePlug-ins by eclipse.

the class JniExecutor method batchedInsertNotify.

/**
 * Inserts a lists of messages into the notifications view in a batched manner
 * <p>
 * A list of String arrays issued to store every data reported regarding the message in a undecoded way. On this way if a data is not needed we
 * don't need to decode it.
 *
 * @param s the list of String arrays.
 */
@Override
public void batchedInsertNotify(final ArrayList<String[]> s) {
    if (loggingIsEnabled && consoleLogging) {
        for (String[] sv : s) {
            consoleStream.println(sv[2] + ": " + sv[4]);
        }
    }
    List<String> times = new ArrayList<String>(s.size());
    List<Notification> tempNotifications = new ArrayList<Notification>(s.size());
    if (severityLevelExtraction) {
        int severity;
        for (String[] value : s) {
            severity = Integer.parseInt(value[3]);
            Formatter formatter = new Formatter();
            formatter.format(DATETIMEFORMAT, new Date(Long.parseLong(value[0]) * 1000), Long.valueOf(value[1]));
            times.add(formatter.toString());
            tempNotifications.add(new Notification(formatter.toString(), SeverityResolver.getSeverityString(severity), value[2], value[4]));
            formatter.close();
        }
    } else {
        for (String[] value : s) {
            Formatter formatter = new Formatter();
            formatter.format(DATETIMEFORMAT, new Date(Long.parseLong(value[0]) * 1000), Long.valueOf(value[1]));
            times.add(formatter.toString());
            tempNotifications.add(new Notification(formatter.toString(), EMPTY_STRING, value[2], value[4]));
            formatter.close();
        }
    }
    addNotifications(tempNotifications);
    if (verdictExtraction) {
        for (int i = 0; i < s.size(); i++) {
            if (executionFinishedMatcher.reset(s.get(i)[4]).matches()) {
                String reason = executionFinishedMatcher.group(2);
                if (reasonMatcher.reset(reason).matches()) {
                    executedTests.add(new ExecutedTestcase(times.get(i), executionFinishedMatcher.group(1), reasonMatcher.group(1), reasonMatcher.group(2)));
                } else {
                    executedTests.add(new ExecutedTestcase(times.get(i), executionFinishedMatcher.group(1), executionFinishedMatcher.group(2), ""));
                }
            }
        }
    }
}
Also used : ExecutedTestcase(org.eclipse.titan.executor.views.testexecution.ExecutedTestcase) Formatter(java.util.Formatter) ArrayList(java.util.ArrayList) Notification(org.eclipse.titan.executor.views.notification.Notification) Date(java.util.Date)

Example 5 with Notification

use of org.eclipse.titan.executor.views.notification.Notification in project titan.EclipsePlug-ins by eclipse.

the class JniExecutor method initialization.

/**
 * Initializes the test session loading the configuration file if provided.
 * <p>
 * If automatic execution is selected the HostControllers are started as the last step
 * <p>
 * This is called startSession in mctr_gui
 */
private void initialization() {
    configHandler = null;
    int tcpport = 0;
    String localAddress = null;
    if ((new File(configFilePath)).exists()) {
        configHandler = readConfigFile();
        Map<String, String> env = new HashMap<String, String>(System.getenv());
        if (!appendEnvironmentalVariables) {
            env.clear();
        }
        if (environmentalVariables != null) {
            try {
                EnvironmentHelper.resolveVariables(env, environmentalVariables);
            } catch (CoreException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
        }
        EnvironmentHelper.setTitanPath(env);
        EnvironmentHelper.set_LICENSE_FILE_PATH(env);
        if (configHandler == null) {
            ErrorReporter.parallelErrorDisplayInMessageDialog("An error was found while processing the configuration file", "Please refer to the Error Log view for further information.");
            return;
        } else if (configHandler.isErroneous()) {
            if (configHandler.parseExceptions().isEmpty()) {
                ErrorReporter.parallelErrorDisplayInMessageDialog("An error was found while processing the configuration file", "Please refer to the Error Log view for further information.");
            } else {
                Throwable exception = configHandler.parseExceptions().get(configHandler.parseExceptions().size() - 1);
                ErrorReporter.parallelErrorDisplayInMessageDialog("Error while processing the configuration file", exception.getMessage() + "\n Please refer to the Error Log view for further information.");
            }
            return;
        }
        tcpport = configHandler.getTcpPort();
        double killTimer = configHandler.getKillTimer();
        localAddress = configHandler.getLocalAddress();
        jnimw.set_kill_timer(killTimer);
        jnimw.destroy_host_groups();
        Map<String, String[]> groups = configHandler.getGroups();
        Map<String, String> components = configHandler.getComponents();
        for (Map.Entry<String, String[]> group : groups.entrySet()) {
            for (String hostName : group.getValue()) {
                jnimw.add_host(group.getKey(), hostName);
            }
        }
        for (Map.Entry<String, String> component : components.entrySet()) {
            jnimw.assign_component(component.getValue(), component.getKey());
        }
    }
    if (localAddress != null && !EMPTY_STRING.equals(localAddress) && 0 == tcpport) {
        addNotification(new Notification((new Formatter()).format(PADDEDDATETIMEFORMAT, new Date()).toString(), EMPTY_STRING, EMPTY_STRING, "If LocalAddress is specified you must also set the TCPPort in the configuration file: " + configFilePath));
        ErrorReporter.parallelErrorDisplayInMessageDialog("Error in the configuration", "If LocalAddress is specified you must also set the TCPPort in the configuration file: " + configFilePath);
        shutdownSession();
        return;
    }
    if (localAddress == null) {
        localAddress = "NULL";
    }
    mcHost = localAddress;
    int port = jnimw.start_session(localAddress, tcpport, (configHandler != null) && configHandler.unixDomainSocketEnabled());
    if (port == 0) {
        // there were some errors starting the session
        shutdownSession();
        return;
    }
    mcPort = EMPTY_STRING + port;
    if (configFileExecutionRequestCounter != -1 && configHandler != null) {
        for (int i = 0; i < configFileExecutionRequestCounter; i++) {
            executeList.addAll(configHandler.getExecuteElements());
        }
        configFileExecutionRequestCounter = -1;
    }
    if (startHCRequested) {
        startHC();
    }
}
Also used : HashMap(java.util.HashMap) Formatter(java.util.Formatter) Notification(org.eclipse.titan.executor.views.notification.Notification) Date(java.util.Date) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Date (java.util.Date)9 Formatter (java.util.Formatter)9 Notification (org.eclipse.titan.executor.views.notification.Notification)9 IOException (java.io.IOException)5 BufferedReader (java.io.BufferedReader)4 StringReader (java.io.StringReader)3 CoreException (org.eclipse.core.runtime.CoreException)3 ExecutedTestcase (org.eclipse.titan.executor.views.testexecution.ExecutedTestcase)3 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 IProcess (org.eclipse.debug.core.model.IProcess)2 MessageConsoleStream (org.eclipse.ui.console.MessageConsoleStream)2 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IStreamListener (org.eclipse.debug.core.IStreamListener)1