Search in sources :

Example 1 with ReExecutable

use of org.knime.core.node.interactive.ReExecutable in project knime-core by knime.

the class WorkflowManager method canReExecuteNode.

/**
 * @param id ...
 * @return true if node can be re-executed.
 * @throws IllegalArgumentException if node is not of proper type.
 * @since 2.8
 */
public boolean canReExecuteNode(final NodeID id) {
    try (WorkflowLock lock = lock()) {
        NodeContainer nc = getNodeContainer(id);
        if (!(nc instanceof NativeNodeContainer)) {
            throw new IllegalArgumentException("Can't reexecute sub- or metanodes.");
        }
        NativeNodeContainer snc = (NativeNodeContainer) nc;
        NodeModel nm = snc.getNodeModel();
        if (!(nm instanceof ReExecutable)) {
            throw new IllegalArgumentException("Only reexecutable nodes can be reexecuted.");
        }
        if (EXECUTED != snc.getInternalState()) {
            return false;
        }
        return canResetNode(id);
    }
}
Also used : VirtualParallelizedChunkPortObjectInNodeModel(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeModel) AbstractPortObjectRepositoryNodeModel(org.knime.core.node.workflow.virtual.AbstractPortObjectRepositoryNodeModel) NodeModel(org.knime.core.node.NodeModel) ReExecutable(org.knime.core.node.interactive.ReExecutable)

Example 2 with ReExecutable

use of org.knime.core.node.interactive.ReExecutable in project knime-core by knime.

the class NodeModel method executeModel.

/**
 * Invokes the abstract <code>#execute()</code> method of this model. In addition, this method notifies all assigned
 * views of the model about the changes.
 *
 * @param rawData An array of <code>PortObject</code> objects holding the data from the inputs (includes flow
 *            variable port).
 * @param exEnv The execution environment used for execution of this model.
 * @param exec The execution monitor which is passed to the execute method of this model.
 * @return The result of the execution in form of an array with <code>DataTable</code> elements, as many as the node
 *         has outputs.
 * @throws Exception any exception or error that is fired in the derived model will be just forwarded. It may throw
 *             an CanceledExecutionException if the user pressed cancel during execution. Even if the derived model
 *             doesn't check, the result will be discarded and the exception thrown.
 * @throws IllegalStateException If the number of <code>PortObject</code> objects returned by the derived
 *             <code>NodeModel</code> does not match the number of outputs. Or if any of them is null.
 * @see #execute(PortObject[],ExecutionContext)
 * @since 2.8
 * @noreference This method is not intended to be referenced by clients (use Node class instead)
 */
PortObject[] executeModel(final PortObject[] rawData, final ExecutionEnvironment exEnv, final ExecutionContext exec) throws Exception {
    final PortObject[] data = ArrayUtils.remove(rawData, 0);
    assert (data != null && data.length == getNrInPorts());
    assert (exec != null);
    setWarningMessage(null);
    executeModelCheckInput(data);
    // temporary storage for result of derived model.
    // EXECUTE DERIVED MODEL
    PortObject[] outData;
    try {
        if (!exEnv.reExecute()) {
            outData = execute(data, exec);
        } else {
            if (this instanceof ReExecutable) {
                @SuppressWarnings("rawtypes") ReExecutable // NOSONAR
                reExecutable = (ReExecutable) this;
                Object preReexecData = exEnv.getPreReExecuteData();
                reExecutable.preReExecute(preReexecData, exEnv.getUseAsDefault());
                outData = execute(data, exec);
            } else if (this instanceof LoopStartNode) {
                outData = execute(data, exec);
            } else {
                m_logger.coding("Cannot re-execute non-reexecutable node. Using normal execute instead.");
                outData = execute(data, exec);
            }
        }
        // if execution was canceled without exception flying return false
        if (exec.isCanceled()) {
            throw new CanceledExecutionException("Result discarded due to user cancel");
        }
    } catch (Exception e) {
        // clear local tables (which otherwise would continue to block resources)
        exec.onCancel();
        throw e;
    }
    outData = executeModelPostProcessOutput(data, outData, exec);
    // last iteration in loop end node...
    if (this instanceof LoopEndNode && getLoopContext() == null && ((LoopEndNode) this).shouldPropagateModifiedVariables()) {
        LoopEndNode.propagateModifiedVariables(this);
    }
    executeModelCheckTableWarnings(outData);
    setHasContent(true);
    PortObject[] rawOutData = new PortObject[getNrOutPorts() + 1];
    rawOutData[0] = FlowVariablePortObject.INSTANCE;
    System.arraycopy(outData, 0, rawOutData, 1, outData.length);
    return rawOutData;
}
Also used : ReExecutable(org.knime.core.node.interactive.ReExecutable) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) LoopStartNode(org.knime.core.node.workflow.LoopStartNode) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) LoopEndNode(org.knime.core.node.workflow.LoopEndNode)

Aggregations

ReExecutable (org.knime.core.node.interactive.ReExecutable)2 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)1 NodeModel (org.knime.core.node.NodeModel)1 PortObject (org.knime.core.node.port.PortObject)1 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)1 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)1 LoopEndNode (org.knime.core.node.workflow.LoopEndNode)1 LoopStartNode (org.knime.core.node.workflow.LoopStartNode)1 AbstractPortObjectRepositoryNodeModel (org.knime.core.node.workflow.virtual.AbstractPortObjectRepositoryNodeModel)1 VirtualParallelizedChunkPortObjectInNodeModel (org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeModel)1