Search in sources :

Example 1 with NativeNodeContainer

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

the class NodeContainerFigure method setStateFromNC.

/**
 * @param nc new state of underlying node
 */
public void setStateFromNC(final NodeContainerUI nc) {
    boolean isInactive = false;
    LoopStatus loopStatus = LoopStatus.NONE;
    if (nc instanceof SingleNodeContainerUI) {
        SingleNodeContainerUI snc = (SingleNodeContainerUI) nc;
        isInactive = snc.isInactive();
        if (Wrapper.wraps(snc, NativeNodeContainer.class)) {
            NativeNodeContainer nnc = Wrapper.unwrap(snc, NativeNodeContainer.class);
            loopStatus = nnc.getLoopStatus();
        }
    }
    NodeContainerState state = nc.getNodeContainerState();
    if (!isInactive) {
        if (state.isIdle()) {
            setStatusAmple();
            m_statusFigure.setIcon(RED);
        } else if (state.isConfigured()) {
            setStatusAmple();
            m_statusFigure.setIcon(YELLOW);
        } else if (state.isExecuted()) {
            setStatusAmple();
            m_statusFigure.setIcon(GREEN);
        } else if (state.isWaitingToBeExecuted()) {
            if (LoopStatus.PAUSED.equals(loopStatus)) {
                setProgressBar(ProgressMode.PAUSED);
            } else {
                setProgressBar(ProgressMode.QUEUED);
            }
        } else if (state.isExecutionInProgress()) {
            setProgressBar(ProgressMode.EXECUTING);
        } else {
            setStatusAmple();
            m_statusFigure.setIcon(INACTIVE);
        }
    } else {
        setStatusAmple();
        m_statusFigure.setIcon(INACTIVE);
    }
    setLoopStatus(loopStatus, state.isExecuted());
    repaint();
}
Also used : SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) LoopStatus(org.knime.core.node.workflow.NativeNodeContainer.LoopStatus) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Example 2 with NativeNodeContainer

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

the class ResumeLoopAction method runOnNodes.

/**
 * Resume paused loop.
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    LOGGER.debug("Creating 'Resume Loop Execution' job for " + nodeParts.length + " node(s)...");
    WorkflowManager manager = getManager();
    for (NodeContainerEditPart p : nodeParts) {
        NodeContainerUI nc = p.getNodeContainer();
        if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
            NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
            if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
                manager.resumeLoopExecution(nnc, /*oneStep=*/
                false);
            }
        }
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) LoopEndNode(org.knime.core.node.workflow.LoopEndNode)

Example 3 with NativeNodeContainer

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

the class StepLoopAction 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)) {
            // either the node is paused...
            return true;
        }
        WorkflowManager wm = getEditor().getWorkflowManager().get();
        if (wm.canExecuteNodeDirectly(nc.getID())) {
            // ...or we can execute it (then this will be the first step)
            return true;
        }
    }
    return false;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) LoopEndNode(org.knime.core.node.workflow.LoopEndNode)

Example 4 with NativeNodeContainer

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

the class WorkflowCoachView method updateInput.

private void updateInput(final ISelection selection) {
    if (NodeRecommendationManager.getInstance().getNumLoadedProviders() == 0) {
        // if there is at least one enabled triple provider then the statistics might need to be download first
        if (NodeRecommendationManager.getInstance().getNodeTripleProviders().stream().anyMatch(ntp -> ntp.isEnabled())) {
            if (m_loadState.get() == LoadState.Disposed) {
                return;
            }
            m_loadState.set(LoadState.LoadingNodes);
            updateInput("Loading recommendations ...");
            // try updating the triple provider that are enabled and require an update
            updateTripleProviders(e -> {
                m_loadState.set(LoadState.Initizalized);
                if (e.isPresent()) {
                    updateInputNoProvider();
                } else {
                    try {
                        NodeRecommendationManager.getInstance().loadRecommendations();
                        if (NodeRecommendationManager.getInstance().getNumLoadedProviders() == 0) {
                            // if there are still no triple provider, show link
                            updateInputNoProvider();
                        } else {
                            updateInput("Statistics successfully loaded. Select a node...");
                        }
                    } catch (Exception e1) {
                        updateInputNoProvider();
                    }
                }
            }, true, false);
        } else {
            // no triple provider enabled -> needs to be configured
            updateInputNoProvider();
            return;
        }
    }
    IStructuredSelection structSel = (IStructuredSelection) selection;
    if (structSel.size() > 1) {
        updateInput("No recommendation for multiple selected nodes.");
        return;
    }
    // retrieve first (and only!) selection:
    Iterator<?> selIt = structSel.iterator();
    boolean nodeSelected = selIt.hasNext();
    NodeContainer nc = null;
    if (nodeSelected) {
        Object sel = selIt.next();
        nodeSelected &= (sel instanceof NodeContainerEditPart);
        if (nodeSelected) {
            NodeContainerUI uinc = ((NodeContainerEditPart) sel).getNodeContainer();
            if (!Wrapper.wraps(uinc, NodeContainer.class)) {
                updateInput("Worklfow coach only supports native nodes, so far.\nBut the selected one is of type '" + uinc.getClass().getSimpleName() + "'.");
                return;
            } else {
                nc = Wrapper.unwrapNC(uinc);
                nodeSelected &= nc instanceof NativeNodeContainer;
            }
        }
    }
    // -> in that case no redraw is required
    if (nodeSelected) {
        if (m_lastSelection.equals(nc.getNameWithID())) {
            return;
        } else {
            m_lastSelection = nc.getNameWithID();
        }
    } else {
        if (m_lastSelection.equals("no node selected")) {
            return;
        } else {
            m_lastSelection = "no node selected";
        }
    }
    List<NodeRecommendation>[] recommendations;
    if (nodeSelected) {
        // retrieve node recommendations if exactly one node is selected
        recommendations = NodeRecommendationManager.getInstance().getNodeRecommendationFor((NativeNodeContainer) nc);
    } else if (nc == null) {
        // retrieve node recommendations if no node is selected (most likely the source nodes etc.)
        recommendations = NodeRecommendationManager.getInstance().getNodeRecommendationFor();
    } else {
        Display.getDefault().syncExec(() -> {
            m_viewer.setInput("");
            m_viewer.refresh();
        });
        return;
    }
    if (recommendations == null) {
        // something went wrong with loading the node recommendations, show the configure link
        updateInputNoProvider();
        return;
    }
    // TODO: cache node recommendations??
    int maxSize = 0;
    for (List<NodeRecommendation> l : recommendations) {
        maxSize = Math.max(maxSize, l.size());
    }
    List<NodeRecommendation[]> recommendationsJoined = joinRecommendations(recommendations, maxSize);
    // remove duplicates from list
    Set<String> duplicates = new HashSet<>();
    List<NodeRecommendation[]> recommendationsWithoutDups = new ArrayList<>(recommendationsJoined.size());
    for (NodeRecommendation[] nrs : recommendationsJoined) {
        int idx = getNonNullIdx(nrs);
        if (duplicates.add(nrs[idx].toString())) {
            recommendationsWithoutDups.add(nrs);
        }
    }
    // update viewer
    changeViewerStateTo(ViewerState.RECOMMENDATIONS);
    Display.getDefault().syncExec(() -> {
        m_viewer.setInput(recommendationsWithoutDups);
        m_viewer.refresh();
        m_recommendationsAvailable = true;
        // scroll to the very top
        if (!recommendationsWithoutDups.isEmpty()) {
            m_viewer.getTable().setTopIndex(0);
        }
    });
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeRecommendation(org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation) ArrayList(java.util.ArrayList) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) List(java.util.List) ArrayList(java.util.ArrayList) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) HashSet(java.util.HashSet)

Example 5 with NativeNodeContainer

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

the class SandboxedNodeCreator method copyFileStoreHandlerReference.

/**
 * Sets the file store handlers set on the original node recursively into the sandboxed node. This is
 * only done when the data is _not_ to be copied as the sandboxed node should use the data (includes file stores)
 * from the original node.
 * @param runNC The sandbox node container
 * @param origNCParent the parent of the original workflow
 * @param nullIt <code>true</code> to set a <code>null</code> file store handler - used in
 * {@link SandboxedNode#close()} (otherwise the file store handler is cleared when the temp flow is disposed).
 */
private void copyFileStoreHandlerReference(final NodeContainer runNC, final WorkflowManager origNCParent, final boolean nullIt) {
    final NodeID origParentID = origNCParent.getID();
    final int runNCIndex = runNC.getID().getIndex();
    if (runNC instanceof NativeNodeContainer) {
        NativeNodeContainer runNNC = (NativeNodeContainer) runNC;
        NativeNodeContainer origNNC = origNCParent.getNodeContainer(origParentID.createChild(runNCIndex), NativeNodeContainer.class, true);
        if (origNNC.getNodeContainerState().isExecutionInProgress()) {
            final IFileStoreHandler fsHdl = nullIt ? null : origNNC.getNode().getFileStoreHandler();
            if (!nullIt) {
                runNNC.clearFileStoreHandler();
            }
            runNNC.getNode().setFileStoreHandler(fsHdl);
        }
    } else if (runNC instanceof WorkflowManager) {
        WorkflowManager runWFM = (WorkflowManager) runNC;
        WorkflowManager origWFM = origNCParent.getNodeContainer(origParentID.createChild(runNCIndex), WorkflowManager.class, true);
        runWFM.getNodeContainers().stream().forEach(n -> copyFileStoreHandlerReference(n, origWFM, nullIt));
    } else {
        WorkflowManager runSubWFM = ((SubNodeContainer) runNC).getWorkflowManager();
        WorkflowManager origSubWFM = origNCParent.getNodeContainer(origParentID.createChild(runNCIndex), SubNodeContainer.class, true).getWorkflowManager();
        runSubWFM.getNodeContainers().stream().forEach(n -> copyFileStoreHandlerReference(n, origSubWFM, nullIt));
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ReferencedFile(org.knime.core.internal.ReferencedFile) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult) NodeContainer(org.knime.core.node.workflow.NodeContainer) Map(java.util.Map) PortObjectInNodeModel(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeModel) PortObjectInNodeFactory(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeFactory) PortType(org.knime.core.node.port.PortType) LockFailedException(org.knime.core.util.LockFailedException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Collection(java.util.Collection) ConnectionID(org.knime.core.node.workflow.ConnectionID) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) Collectors(java.util.stream.Collectors) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) Optional(java.util.Optional) CredentialsStore(org.knime.core.node.workflow.CredentialsStore) CheckUtils(org.knime.core.node.util.CheckUtils) PortObject(org.knime.core.node.port.PortObject) NodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NodeContainerExecutionResult) IntStream(java.util.stream.IntStream) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeExecutionJobManagerPool(org.knime.core.node.util.NodeExecutionJobManagerPool) FlowVariable(org.knime.core.node.workflow.FlowVariable) NodeSettings(org.knime.core.node.NodeSettings) BDTInNodeFactory(org.knime.core.node.exec.dataexchange.in.BDTInNodeFactory) ArrayList(java.util.ArrayList) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExecutionContext(org.knime.core.node.ExecutionContext) NodeExecutionJobManager(org.knime.core.node.workflow.NodeExecutionJobManager) NodeLogger(org.knime.core.node.NodeLogger) WorkflowExecutionResult(org.knime.core.node.workflow.execresult.WorkflowExecutionResult) NodeFactory(org.knime.core.node.NodeFactory) NodeInPort(org.knime.core.node.workflow.NodeInPort) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) File(java.io.File) PortObjectRepository(org.knime.core.node.exec.dataexchange.PortObjectRepository) NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) NodeID(org.knime.core.node.workflow.NodeID) FileUtil(org.knime.core.util.FileUtil) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) SubnodeContainerExecutionResult(org.knime.core.node.workflow.execresult.SubnodeContainerExecutionResult) Collections(java.util.Collections) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

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