Search in sources :

Example 6 with NativeNodeContainer

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

the class InteractiveViewDelegate method setWorkflowManagerAndNodeID.

public void setWorkflowManagerAndNodeID(final WorkflowManager wfm, final NodeID id) {
    m_wfm = wfm;
    m_nodeID = id;
    NodeContainer nc = m_wfm.getNodeContainer(m_nodeID);
    // !! constructor argument matches this info...
    assert m_wfm.getNodeContainer(m_nodeID) == nc;
    if (!(nc instanceof NativeNodeContainer) && !(nc instanceof SubNodeContainer)) {
        throw new RuntimeException("Internal Error: Wrong type of node in " + this.getClass().getName());
    }
    if (nc instanceof NativeNodeContainer) {
        NodeModel nm = ((NativeNodeContainer) nc).getNodeModel();
        if (!(nm instanceof InteractiveNode)) {
            throw new RuntimeException("Internal Error: Wrong type of node in " + this.getClass().getName());
        }
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeModel(org.knime.core.node.NodeModel) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Example 7 with NativeNodeContainer

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

the class TimerinfoNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataContainer result = exec.createDataContainer(createSpec());
    WorkflowManager wfm = NodeContext.getContext().getWorkflowManager();
    for (NodeContainer nc : wfm.getNodeContainers()) {
        NodeTimer nt = nc.getNodeTimer();
        DataRow row = new DefaultRow(new RowKey("Node " + nc.getID().getIndex()), new StringCell(nc.getName()), nt.getLastExecutionDuration() >= 0 ? new LongCell(nt.getLastExecutionDuration()) : DataType.getMissingCell(), new LongCell(nt.getExecutionDurationSinceReset()), new LongCell(nt.getExecutionDurationSinceStart()), new IntCell(nt.getNrExecsSinceReset()), new IntCell(nt.getNrExecsSinceStart()), new StringCell(nc.getID().toString()), new StringCell(nc instanceof NativeNodeContainer ? ((NativeNodeContainer) nc).getNodeModel().getClass().getName() : "n/a"));
        result.addRowToTable(row);
    }
    result.close();
    return new PortObject[] { result.getTable() };
}
Also used : LongCell(org.knime.core.data.def.LongCell) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) NodeTimer(org.knime.core.node.workflow.NodeTimer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) IntCell(org.knime.core.data.def.IntCell)

Example 8 with NativeNodeContainer

use of org.knime.core.node.workflow.NativeNodeContainer 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)

Example 9 with NativeNodeContainer

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

the class OpenInteractiveWebViewAction method run.

@Override
public void run() {
    LOGGER.debug("Open Interactive Web Node View " + m_nodeContainer.getName());
    NativeNodeContainer nativeNC = m_webViewForNode.getNativeNodeContainer();
    try {
        @SuppressWarnings("rawtypes") AbstractWizardNodeView view = null;
        NodeContext.pushContext(nativeNC);
        try {
            NodeModel nodeModel = nativeNC.getNodeModel();
            view = getConfiguredWizardNodeView(nodeModel);
        } finally {
            NodeContext.removeLastContext();
        }
        view.setWorkflowManagerAndNodeID(nativeNC.getParent(), nativeNC.getID());
        final String title = m_webViewForNode.getViewName();
        Node.invokeOpenView(view, title, OpenViewAction.getAppBoundsAsAWTRec());
    } catch (Throwable t) {
        final MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
        mb.setText("Interactive View cannot be opened");
        mb.setMessage("The interactive view cannot be opened for the following reason:\n" + t.getMessage());
        mb.open();
        LOGGER.error("The interactive view for node '" + nativeNC.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an implementation error.", t);
    }
}
Also used : NodeModel(org.knime.core.node.NodeModel) AbstractWizardNodeView(org.knime.core.node.wizard.AbstractWizardNodeView) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 10 with NativeNodeContainer

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

the class ResumeLoopAction method internalCalculateEnabled.

/**
 * @return <code>true</code>, if just one loop end node part is selected
 *         which is executable and a loop is in progress.
 *
 * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
    if (parts.length != 1) {
        return false;
    }
    // enabled if the one selected node is a configured and "in progress"
    // LoopEndNode
    NodeContainerUI nc = parts[0].getNodeContainer();
    if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
        NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
        if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
            return true;
        }
    }
    return false;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) LoopEndNode(org.knime.core.node.workflow.LoopEndNode)

Aggregations

NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)14 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)6 NodeContainer (org.knime.core.node.workflow.NodeContainer)5 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)5 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)5 LoopEndNode (org.knime.core.node.workflow.LoopEndNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 PortObject (org.knime.core.node.port.PortObject)3 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Stack (java.util.Stack)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 TableItem (org.eclipse.swt.widgets.TableItem)2 ExecutionContext (org.knime.core.node.ExecutionContext)2 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)2 NodeModel (org.knime.core.node.NodeModel)2 NodeSettings (org.knime.core.node.NodeSettings)2