Search in sources :

Example 1 with NativeNodeContainerExecutionResult

use of org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult in project knime-core by knime.

the class NativeNodeContainer method createExecutionResult.

/**
 * {@inheritDoc}
 */
@Override
public NativeNodeContainerExecutionResult createExecutionResult(final ExecutionMonitor exec) throws CanceledExecutionException {
    synchronized (m_nodeMutex) {
        NativeNodeContainerExecutionResult result = new NativeNodeContainerExecutionResult();
        super.saveExecutionResult(result);
        NodeContext.pushContext(this);
        try {
            result.setNodeExecutionResult(m_node.createNodeExecutionResult(exec));
        } finally {
            NodeContext.removeLastContext();
        }
        return result;
    }
}
Also used : NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult)

Example 2 with NativeNodeContainerExecutionResult

use of org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult in project knime-core by knime.

the class NativeNodeContainer method loadExecutionResult.

/**
 * {@inheritDoc}
 */
@Override
public void loadExecutionResult(final NodeContainerExecutionResult execResult, final ExecutionMonitor exec, final LoadResult loadResult) {
    synchronized (m_nodeMutex) {
        if (InternalNodeContainerState.EXECUTED.equals(getInternalState())) {
            LOGGER.debug(getNameWithID() + " is already executed; won't load execution result");
            return;
        }
        if (!(execResult instanceof NativeNodeContainerExecutionResult)) {
            throw new IllegalArgumentException("Argument must be instance " + "of \"" + NativeNodeContainerExecutionResult.class.getSimpleName() + "\": " + execResult.getClass().getSimpleName());
        }
        super.loadExecutionResult(execResult, exec, loadResult);
        NativeNodeContainerExecutionResult sncExecResult = (NativeNodeContainerExecutionResult) execResult;
        NodeExecutionResult nodeExecResult = sncExecResult.getNodeExecutionResult();
        boolean success = sncExecResult.isSuccess();
        if (success) {
            NodeContext.pushContext(this);
            try {
                m_node.loadExecutionResult(nodeExecResult, new ExecutionMonitor(), loadResult);
                m_node.putOutputTablesIntoGlobalRepository(getParent().getGlobalTableRepository());
            } finally {
                NodeContext.removeLastContext();
            }
        }
        boolean needsReset = nodeExecResult.needsResetAfterLoad();
        if (!needsReset && success) {
            for (int i = 0; i < getNrOutPorts(); i++) {
                if (m_node.getOutputObject(i) == null) {
                    loadResult.addError("Output object at port " + i + " is null");
                    needsReset = true;
                }
            }
        }
        if (needsReset) {
            execResult.setNeedsResetAfterLoad();
        }
    }
}
Also used : NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 3 with NativeNodeContainerExecutionResult

use of org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult in project knime-core by knime.

the class SandboxedNodeCreator method copyExistingTablesIntoSandboxContainer.

/**
 * Copies the tables (port and internal) into the context of the corresponding node in the targetWFM. The execution
 * result must fit to the passed node container.
 *
 * @param execResult the object holding the result of the sourceNC. If the sourceNC is a workflow, this must hold
 *            all results of all contained nodes.
 * @param sourceNC the node that produced the execution result.
 * @param targetNC the context into which the tables are copied into
 * @param progressMon For progress information
 * @param copyDataIntoNewContext as per {@link #setCopyData(boolean)}
 * @throws CanceledExecutionException
 * @throws IOException
 */
public static void copyExistingTablesIntoSandboxContainer(final NodeContainerExecutionResult execResult, final NodeContainer sourceNC, final NodeContainer targetNC, final ExecutionMonitor progressMon, final boolean copyDataIntoNewContext) throws CanceledExecutionException, IOException {
    assert targetNC.getNrOutPorts() == sourceNC.getNrOutPorts();
    if (execResult instanceof NativeNodeContainerExecutionResult) {
        NativeNodeContainerExecutionResult sncResult = (NativeNodeContainerExecutionResult) execResult;
        // execResult and node types must match
        assert sourceNC instanceof NativeNodeContainer;
        assert targetNC instanceof NativeNodeContainer;
        // data is to copy ... get the correct execution context
        ExecutionContext targetExec = copyDataIntoNewContext ? ((SingleNodeContainer) targetNC).createExecutionContext() : null;
        NodeExecutionResult ner = sncResult.getNodeExecutionResult();
        // TODO this copy process has to take place in a different place
        // though it needs the final execution context for correct copy
        // of BDT objects
        PortObject[] resultTables = new PortObject[targetNC.getNrOutPorts()];
        int copyCount = resultTables.length;
        // copy also the internally held tables (such as for instance
        // the table in the table view) -- use the copy of the outports
        // if they match (likely they don't)
        PortObject[] oldInternTables = ner.getInternalHeldPortObjects();
        PortObject[] newInternTables = null;
        if (oldInternTables != null) {
            newInternTables = new PortObject[oldInternTables.length];
            copyCount += newInternTables.length;
        }
        // skip flow variable output
        for (int i = 0; i < resultTables.length; i++) {
            ExecutionMonitor sub = progressMon.createSubProgress(1.0 / copyCount);
            progressMon.setMessage("Port " + i);
            PortObject o = ner.getPortObject(i);
            PortObject newPO = copyPortObject(o, sub, targetExec);
            if (newInternTables != null) {
                for (int j = 0; j < oldInternTables.length; j++) {
                    if (oldInternTables[j] == o) {
                        newInternTables[j] = newPO;
                    }
                }
            }
            sub.setProgress(1.0);
            resultTables[i] = newPO;
        }
        if (newInternTables != null) {
            for (int i = 0; i < newInternTables.length; i++) {
                ExecutionMonitor sub = progressMon.createSubProgress(1.0 / copyCount);
                progressMon.setMessage("Internal Table " + i);
                if (newInternTables[i] == null) {
                    PortObject oldT = oldInternTables[i];
                    PortObject newT = copyPortObject(oldT, sub, targetExec);
                    newInternTables[i] = newT;
                }
                sub.setProgress(1.0);
            }
        }
        if (oldInternTables != null) {
            ner.setInternalHeldPortObjects(newInternTables);
        }
        ner.setPortObjects(resultTables);
    } else if (execResult instanceof WorkflowExecutionResult) {
        WorkflowExecutionResult wfmResult = (WorkflowExecutionResult) execResult;
        // exec result and node types must match
        WorkflowManager targetWFM = (WorkflowManager) targetNC;
        WorkflowManager sourceWFM = (WorkflowManager) sourceNC;
        copyIntoSandboxContainerRecursive(sourceWFM, targetWFM, wfmResult, progressMon, copyDataIntoNewContext);
    } else if (execResult instanceof SubnodeContainerExecutionResult) {
        SubnodeContainerExecutionResult subResult = (SubnodeContainerExecutionResult) execResult;
        WorkflowExecutionResult wfmResult = subResult.getWorkflowExecutionResult();
        WorkflowManager targetWFM = ((SubNodeContainer) targetNC).getWorkflowManager();
        WorkflowManager sourceWFM = ((SubNodeContainer) sourceNC).getWorkflowManager();
        copyIntoSandboxContainerRecursive(sourceWFM, targetWFM, wfmResult, progressMon, copyDataIntoNewContext);
    } else {
        throw new IllegalStateException("Unsupported node result type: " + execResult.getClass().getSimpleName());
    }
}
Also used : NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowExecutionResult(org.knime.core.node.workflow.execresult.WorkflowExecutionResult) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExecutionContext(org.knime.core.node.ExecutionContext) NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult) SubnodeContainerExecutionResult(org.knime.core.node.workflow.execresult.SubnodeContainerExecutionResult) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PortObject(org.knime.core.node.port.PortObject) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Aggregations

NativeNodeContainerExecutionResult (org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult)3 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)2 NodeExecutionResult (org.knime.core.node.workflow.execresult.NodeExecutionResult)2 ExecutionContext (org.knime.core.node.ExecutionContext)1 PortObject (org.knime.core.node.port.PortObject)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 SubnodeContainerExecutionResult (org.knime.core.node.workflow.execresult.SubnodeContainerExecutionResult)1 WorkflowExecutionResult (org.knime.core.node.workflow.execresult.WorkflowExecutionResult)1