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();
}
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();
}
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;
}
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), ""));
}
}
}
}
}
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();
}
}
Aggregations