Search in sources :

Example 1 with NodeLogger

use of org.knime.core.node.NodeLogger in project knime-core by knime.

the class Bug_4423_saveDuringResetDeadlock method runTest.

private void runTest(final Pointer<Exception> throwablePointer) throws Exception {
    final Display currentDisplay = Display.getCurrent();
    final Thread displayThread = currentDisplay.getThread();
    final Thread currentThread = Thread.currentThread();
    // reset and save are getting called from UI thread - replicate it here.
    assertTrue("Not executing in display thread: " + currentThread, currentThread == displayThread);
    final WorkflowManager workflowManager = getManager();
    executeAllAndWait();
    final NodeContainer nc = findNodeContainer(m_tableView2);
    final AtomicReference<Progress> saveProgressPointer = new AtomicReference<>(Progress.NotStarted);
    NodeContext.pushContext(nc);
    try {
        AbstractNodeView<?> view = ((NativeNodeContainer) nc).getNode().getView(0, "Programmatically opened in test flow");
        Node.invokeOpenView(view, "Programmatically opened in test flow");
    } finally {
        NodeContext.removeLastContext();
    }
    final NodeLogger logger = NodeLogger.getLogger(getClass());
    Runnable saveRunnable = new Runnable() {

        @Override
        public void run() {
            // in the full application (and as part of the bug report) this job is scheduled while the reset is
            // ongoing; note, it's not possible to replicate the exact behavior here as the whole test case is
            // run in the display thread - we have to schedule the job up-front
            Job saveJob = new Job("Workflow Save") {

                @Override
                protected IStatus run(final IProgressMonitor monitor) {
                    saveProgressPointer.set(Progress.Ongoing);
                    try {
                        logger.info("Calling save");
                        workflowManager.save(m_workflowDirTemp, new ExecutionMonitor(), true);
                        logger.info("Called save");
                    } catch (Exception e) {
                        throwablePointer.set(e);
                    } finally {
                        saveProgressPointer.set(Progress.Done);
                    }
                    return Status.OK_STATUS;
                }
            };
            saveJob.schedule();
            long wait = 5000;
            while ((saveJob.getResult() == null) && (wait > 0)) {
                try {
                    Thread.sleep(250);
                    wait -= 250;
                } catch (InterruptedException e) {
                    throwablePointer.set(e);
                }
            }
            if (saveJob.getResult() == null) {
                saveJob.cancel();
                throwablePointer.set(new IllegalStateException("Workflow save job has not finished within 5 secs, very likely because we have a deadlock"));
            }
        }
    };
    // doesn't actually run as this thread is the display thread
    currentDisplay.asyncExec(saveRunnable);
    // this is the display thread, cannot execute async scheduled tasks
    assertEquals(Progress.NotStarted, saveProgressPointer.get());
    logger.info("Calling reset");
    reset(m_dataGenerator1);
    logger.info("Called reset");
    // this might change in the future so we let the test case do its job:
    while (!Progress.Done.equals(saveProgressPointer.get())) {
        if (!currentDisplay.readAndDispatch()) {
            currentDisplay.sleep();
        }
    }
}
Also used : NodeLogger(org.knime.core.node.NodeLogger) AtomicReference(java.util.concurrent.atomic.AtomicReference) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Display(org.eclipse.swt.widgets.Display)

Example 2 with NodeLogger

use of org.knime.core.node.NodeLogger in project knime-core by knime.

the class DatabaseUtility method tableExists.

/**
 * Returns whether the given table name exists in the database denoted by the connection.
 *
 * @param conn a database connection
 * @param tableName the table's name
 * @return <code>true</code> if the table exists, <code>false</code> otherwise
 * @throws SQLException if an DB error occurs
 * @since 2.10
 */
public boolean tableExists(final Connection conn, final String tableName) throws SQLException {
    final NodeLogger logger = NodeLogger.getLogger(getClass());
    logger.debug("Checking if table " + tableName + " exists");
    String sql = getStatementManipulator().forMetadataOnly("SELECT 1 as tmpcol FROM " + tableName);
    logger.debug("Execute query: " + sql);
    try (ResultSet rs = conn.createStatement().executeQuery(sql)) {
        logger.debug("Table " + tableName + " exists");
        return true;
    } catch (SQLException ex) {
        logger.debug("Got exception while checking for existence of table '" + tableName + "': " + ex.getMessage(), ex);
        // we assume this is because the table does not exist; must be fixed!!!
        return false;
    }
}
Also used : SQLException(java.sql.SQLException) NodeLogger(org.knime.core.node.NodeLogger) ResultSet(java.sql.ResultSet)

Example 3 with NodeLogger

use of org.knime.core.node.NodeLogger in project knime-core by knime.

the class PersistWorkflowRunnable method logPreseveLineBreaks.

/**
 * Logs the argument error to logger, preserving line breaks.
 * This method will hopefully go into the NodeLogger facilities (and hence
 * be public API).
 * @param isError Whether to report to LOGGER.error (otherwise warn only).
 * @param error The error string to log.
 */
protected final void logPreseveLineBreaks(final String error, final boolean isError) {
    StringTokenizer t = new StringTokenizer(error, "\n");
    NodeLogger logger = getLogger();
    while (t.hasMoreTokens()) {
        if (isError) {
            logger.error(t.nextToken());
        } else {
            logger.warn(t.nextToken());
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) NodeLogger(org.knime.core.node.NodeLogger)

Aggregations

NodeLogger (org.knime.core.node.NodeLogger)3 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 StringTokenizer (java.util.StringTokenizer)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 Display (org.eclipse.swt.widgets.Display)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1