Search in sources :

Example 46 with ExecutionMonitor

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

the class Bug3673_CredentialsInputNode_Test1_SimpleNodeWithSavedPassword method testLoadWhileInactive.

@Test
public void testLoadWhileInactive() throws Exception {
    getManager().addConnection(m_activeBranchInverter_3, 1, m_credentialsInput_1, 0);
    getManager().save(m_workflowDirTemp, new ExecutionMonitor(), true);
    executeAllAndWait();
    checkState(getManager(), EXECUTED);
    assertTrue(((NativeNodeContainer) findNodeContainer(m_credentialsInput_1)).isInactive());
    // don't save
    closeWorkflow();
    initFlow();
    checkState(m_credentialsInput_1, CONFIGURED);
    assertFalse("Not expected to be dirty", getManager().isDirty());
    executeAllAndWait();
    assertTrue(((NativeNodeContainer) findNodeContainer(m_credentialsInput_1)).isInactive());
    checkState(m_credentialsValidate_2, EXECUTED);
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Test(org.junit.Test)

Example 47 with ExecutionMonitor

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

the class Bug3673_CredentialsInputNode_Test2_SimpleNodeWithNoSavedPassword method testPartialExecuteSaveLoadExecute.

@Test
public void testPartialExecuteSaveLoadExecute() throws Exception {
    TestWorkflowLoadHelper loadHelper = initFlow(new TestWorkflowLoadHelper("some-fixed-password"));
    executeAndWait(m_credentialsInput_1);
    checkState(m_credentialsInput_1, InternalNodeContainerState.EXECUTED);
    checkState(m_credentialsValidate_2, InternalNodeContainerState.CONFIGURED);
    getManager().save(m_workflowDirTemp, new ExecutionMonitor(), true);
    assertTrue("No password prompted", loadHelper.hasBeenPrompted());
    closeWorkflow();
    loadHelper = initFlow(new TestWorkflowLoadHelper("some-fixed-password"));
    // input node is executed - so no prompt expected
    assertFalse("Password prompted but shouldn't", loadHelper.hasBeenPrompted());
    checkState(m_credentialsInput_1, InternalNodeContainerState.EXECUTED);
    checkState(m_credentialsValidate_2, InternalNodeContainerState.IDLE);
    // because 2nd validator is now idle
    assertTrue("Expected to be dirty", getManager().isDirty());
    executeAndWait(m_credentialsValidate_2, m_credentialsValidate_4);
    // expected to fail - null password
    checkState(m_credentialsValidate_2, InternalNodeContainerState.IDLE);
    checkState(m_credentialsValidate_4, InternalNodeContainerState.EXECUTED);
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Test(org.junit.Test)

Example 48 with ExecutionMonitor

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

the class Bug6729_InvalidConfigOnInactiveNodes method init.

private void init() throws Exception {
    WorkflowLoadResult loadResult = loadWorkflow(m_workflowDirTemp, new ExecutionMonitor(), new WorkflowLoadHelper(m_workflowDirTemp));
    assertThat("Expected non-error/non-warning load result: " + loadResult.getMessage(), loadResult.getType(), is(LoadResultEntryType.Ok));
    final WorkflowManager workflowManager = loadResult.getWorkflowManager();
    setManager(workflowManager);
    NodeID baseID = workflowManager.getID();
    m_fileReader2 = new NodeID(baseID, 2);
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)

Example 49 with ExecutionMonitor

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

the class Bug6339_LoopEndColAppend_PathTooLong method testMain.

/**
 * Load workflow, execute, check, save, close, reopen, check, reset, execute, check.
 */
@Test
public void testMain() throws Exception {
    WorkflowManager m = getManager();
    checkState(m, IDLE);
    checkState(m_javaSnippet_7, IDLE);
    checkState(m_dataGen1, CONFIGURED);
    executeAndWait(m_loopEnd_5);
    m.save(m_tmpWorkflowDir, new ExecutionMonitor(), true);
    executeAllAndWait();
    checkState(getManager(), EXECUTED);
    m.save(m_tmpWorkflowDir, new ExecutionMonitor(), true);
    closeWorkflow();
    assertNull(getManager());
    loadAndSetWorkflow(m_tmpWorkflowDir);
    m = getManager();
    checkState(m, EXECUTED);
    reset(m_javaSnippet_7);
    checkState(m_javaSnippet_7, CONFIGURED);
    executeAllAndWait();
    checkState(m, EXECUTED);
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Test(org.junit.Test)

Example 50 with ExecutionMonitor

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

the class AbstractParallelNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final BufferedDataTable[] execute(final BufferedDataTable[] data, final ExecutionContext exec) throws Exception {
    final DataTableSpec[] outSpecs = prepareExecute(data);
    final List<Future<BufferedDataContainer[]>> futures = new ArrayList<>();
    final BufferedDataTable[] additionalTables = new BufferedDataTable[Math.max(0, data.length - 1)];
    System.arraycopy(data, 1, additionalTables, 0, additionalTables.length);
    // do some consistency checks to bail out as early as possible
    if (outSpecs == null) {
        throw new NullPointerException("Implementation Error: The " + "array of generated output table specs can't be null.");
    }
    if (outSpecs.length != getNrOutPorts()) {
        throw new IllegalStateException("Implementation Error: Number of" + " provided DataTableSpecs doesn't match number of output" + " ports");
    }
    for (DataTableSpec outSpec : outSpecs) {
        if (outSpec == null) {
            throw new IllegalStateException("Implementation Error: The" + " generated output DataTableSpec is null.");
        }
    }
    final double max = data[0].size();
    final Callable<Void> submitter = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            final RowIterator it = data[0].iterator();
            BufferedDataContainer container = null;
            int count = 0, chunks = 0;
            while (true) {
                if ((count++ % m_chunkSize == 0) || !it.hasNext()) {
                    exec.checkCanceled();
                    if (container != null) {
                        container.close();
                        final BufferedDataContainer temp = container;
                        chunks++;
                        final int temp2 = chunks;
                        futures.add(m_workers.submit(new Callable<BufferedDataContainer[]>() {

                            @Override
                            public BufferedDataContainer[] call() throws Exception {
                                ExecutionMonitor subProg = exec.createSilentSubProgress((m_chunkSize > max) ? 1 : m_chunkSize / max);
                                exec.setMessage("Processing chunk " + temp2);
                                BufferedDataContainer[] result = new BufferedDataContainer[outSpecs.length];
                                for (int i = 0; i < outSpecs.length; i++) {
                                    result[i] = exec.createDataContainer(outSpecs[i], true, 0);
                                }
                                executeByChunk(temp.getTable(), additionalTables, result, subProg);
                                for (DataContainer c : result) {
                                    c.close();
                                }
                                exec.setProgress(temp2 * m_chunkSize / max);
                                return result;
                            }
                        }));
                    }
                    if (!it.hasNext()) {
                        break;
                    }
                    container = exec.createDataContainer(data[0].getDataTableSpec());
                }
                container.addRowToTable(it.next());
            }
            return null;
        }
    };
    try {
        m_workers.runInvisible(submitter);
    } catch (IllegalThreadStateException ex) {
        // this node has not been started by a thread from a thread pool.
        // This is odd, but may happen
        submitter.call();
    }
    final BufferedDataTable[][] tempTables = new BufferedDataTable[outSpecs.length][futures.size()];
    int k = 0;
    for (Future<BufferedDataContainer[]> results : futures) {
        try {
            exec.checkCanceled();
        } catch (CanceledExecutionException ex) {
            for (Future<BufferedDataContainer[]> cancel : futures) {
                cancel.cancel(true);
            }
            throw ex;
        }
        final BufferedDataContainer[] temp = results.get();
        if ((temp == null) || (temp.length != getNrOutPorts())) {
            throw new IllegalStateException("Invalid result. Execution " + " failed, reason: data is null or number " + "of outputs wrong.");
        }
        for (int i = 0; i < temp.length; i++) {
            tempTables[i][k] = temp[i].getTable();
        }
        k++;
    }
    final BufferedDataTable[] resultTables = new BufferedDataTable[outSpecs.length];
    for (int i = 0; i < resultTables.length; i++) {
        resultTables[i] = exec.createConcatenateTable(exec, tempTables[i]);
    }
    return resultTables;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataContainer(org.knime.core.data.container.DataContainer) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) RowIterator(org.knime.core.data.RowIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable) Future(java.util.concurrent.Future) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Aggregations

ExecutionMonitor (org.knime.core.node.ExecutionMonitor)160 BufferedDataTable (org.knime.core.node.BufferedDataTable)50 DataTableSpec (org.knime.core.data.DataTableSpec)43 DataRow (org.knime.core.data.DataRow)39 DataCell (org.knime.core.data.DataCell)35 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)35 Test (org.junit.Test)33 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)33 File (java.io.File)29 IOException (java.io.IOException)25 PortObject (org.knime.core.node.port.PortObject)25 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)23 DataColumnSpec (org.knime.core.data.DataColumnSpec)21 RowKey (org.knime.core.data.RowKey)20 ArrayList (java.util.ArrayList)19 WorkflowLoadResult (org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)17 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)16 ExecutionException (java.util.concurrent.ExecutionException)14 ExecutionContext (org.knime.core.node.ExecutionContext)13 FileOutputStream (java.io.FileOutputStream)12