Search in sources :

Example 51 with NodeContainer

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

the class SandboxedNodeCreator method getFlowVariablesOnPort.

/**
 * Checks which flow variables are available on a port by looking on the output port connected to this input port.
 *
 * @param portIdx input port of the {@link NodeContainer} {@link #m_nc}
 * @return the flow variables available at this port
 */
private List<FlowVariable> getFlowVariablesOnPort(final int portIdx) {
    WorkflowManager wfm = m_nc.getParent();
    Optional<Stream<FlowVariable>> nodeInputFlowVariables = wfm.getNodeInputFlowVariables(m_nc.getID(), portIdx);
    if (nodeInputFlowVariables.isPresent()) {
        List<FlowVariable> result = nodeInputFlowVariables.get().filter(fv -> !fv.isGlobalConstant()).collect(Collectors.toList());
        // getNodeInputFlowVariables returns top down, make sure iterations on list return oldest entry first
        // (will be pushed onto node stack using an iterator)
        Collections.reverse(result);
        return result;
    }
    return Collections.emptyList();
}
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) UUID(java.util.UUID) 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) PortObjectIDSettings(org.knime.core.node.exec.dataexchange.PortObjectIDSettings) 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) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Stream(java.util.stream.Stream) IntStream(java.util.stream.IntStream) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 52 with NodeContainer

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

the class PortObjectInNodeModel method pushFlowVariables.

/**
 * Push flow variables onto stack.
 */
private void pushFlowVariables() {
    if (m_portObjectIDSettings.getReferenceType() == ReferenceType.NODE) {
        // if a node is referenced we can just take and clone the flow variables of that node
        // (by that, e.g., passwords of credential flow variables don't get lost)
        NodeContainer nc = getReferencedNode();
        nc.getOutPort(m_portObjectIDSettings.getPortIdx()).getFlowObjectStack().getAllAvailableFlowVariables().values().stream().filter(f -> f.getScope() == Scope.Flow).forEach(v -> Node.invokePushFlowVariable(this, v.withNewName(v.getName())));
    } else {
        for (FlowVariable fv : m_portObjectIDSettings.getFlowVariables()) {
            Node.invokePushFlowVariable(this, fv);
        }
    }
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) URISyntaxException(java.net.URISyntaxException) FlowVariable(org.knime.core.node.workflow.FlowVariable) NodeSettings(org.knime.core.node.NodeSettings) ExecutionContext(org.knime.core.node.ExecutionContext) NodeContainer(org.knime.core.node.workflow.NodeContainer) DataContainer(org.knime.core.data.container.DataContainer) Node(org.knime.core.node.Node) PortUtil(org.knime.core.node.port.PortUtil) Scope(org.knime.core.node.workflow.FlowVariable.Scope) ContainerTable(org.knime.core.data.container.ContainerTable) PortType(org.knime.core.node.port.PortType) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) UUID(java.util.UUID) NodeModel(org.knime.core.node.NodeModel) NodeContext(org.knime.core.node.workflow.NodeContext) File(java.io.File) PortObjectRepository(org.knime.core.node.exec.dataexchange.PortObjectRepository) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) PortObjectIDSettings(org.knime.core.node.exec.dataexchange.PortObjectIDSettings) Optional(java.util.Optional) FileUtil(org.knime.core.util.FileUtil) ReferenceType(org.knime.core.node.exec.dataexchange.PortObjectIDSettings.ReferenceType) PortObject(org.knime.core.node.port.PortObject) NodeContainer(org.knime.core.node.workflow.NodeContainer) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 53 with NodeContainer

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

the class NodeLogger method getLogObject.

/**
 * @param message the logging message
 * @return a KNIMELogMessage that not only contains the log message but also the information about the workflow
 * and node that belong to the log message if applicable
 */
private Object getLogObject(final Object message) {
    if (!LOG_NODE_ID && !LOG_IN_WF_DIR && !LOG_WF_DIR && !LOG_JOB_ID) {
        return message;
    }
    final NodeContext context = NodeContext.getContext();
    NodeID nodeID = null;
    String nodeName = null;
    File workflowDir = null;
    UUID jobID = null;
    if (context != null) {
        if (LOG_NODE_ID) {
            // retrieve and store the node id only if the user has requested to log it
            final NodeContainer nodeContainer = context.getNodeContainer();
            if (nodeContainer != null) {
                nodeID = nodeContainer.getID();
                nodeName = nodeContainer.getName();
            }
        }
        if (LOG_IN_WF_DIR || LOG_WF_DIR || LOG_JOB_ID) {
            final WorkflowManager workflowManager = context.getWorkflowManager();
            if (workflowManager != null) {
                final WorkflowContext workflowContext = workflowManager.getContext();
                if (workflowContext != null) {
                    workflowDir = workflowContext.getCurrentLocation();
                    jobID = workflowContext.getJobId().orElse(null);
                }
            }
        }
    }
    return new KNIMELogMessage(nodeID, nodeName, workflowDir, jobID, message);
}
Also used : NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer) UUID(java.util.UUID) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 54 with NodeContainer

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

the class WizardPageUtil method collectWizardPageNodes.

private static void collectWizardPageNodes(final WorkflowManager wfm, final boolean recurseIntoComponents, final boolean includeHiddenNodes, final List<NativeNodeContainer> res) {
    for (NodeContainer nc : wfm.getNodeContainers()) {
        if (nc instanceof NativeNodeContainer) {
            NativeNodeContainer nnc = (NativeNodeContainer) nc;
            var nodeModel = nnc.getNodeModel();
            if (!includeHiddenNodes && nodeModel instanceof ViewHideable && ((ViewHideable) nodeModel).isHideInWizard()) {
                continue;
            }
            if (isWizardPageNode(nnc)) {
                res.add(nnc);
            }
        } else if (recurseIntoComponents && nc instanceof SubNodeContainer) {
            collectWizardPageNodes(((SubNodeContainer) nc).getWorkflowManager(), recurseIntoComponents, includeHiddenNodes, res);
        }
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ViewHideable(org.knime.core.node.wizard.ViewHideable) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Example 55 with NodeContainer

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

the class AbstractRpcClient method createRpcServer.

/**
 * @return the node model's server if working local or an empty optional if working remotely.
 */
@SuppressWarnings("unchecked")
private static <N extends NodeModel> Optional<RpcServer> createRpcServer() {
    NodeContainer nc = NodeContext.getContext().getNodeContainer();
    if (nc instanceof NativeNodeContainer) {
        N nodeModel = (N) ((NativeNodeContainer) nc).getNodeModel();
        NodeFactory<NodeModel> factory = ((NativeNodeContainer) nc).getNode().getFactory();
        return Optional.of(getRpcServerFromNodeFactory(nodeModel, factory));
    }
    return Optional.empty();
}
Also used : NodeModel(org.knime.core.node.NodeModel) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Aggregations

NodeContainer (org.knime.core.node.workflow.NodeContainer)56 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)24 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)22 NodeID (org.knime.core.node.workflow.NodeID)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)17 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)13 IOException (java.io.IOException)9 Map (java.util.Map)9 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)9 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)9 ArrayList (java.util.ArrayList)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 File (java.io.File)6 List (java.util.List)6 PortObject (org.knime.core.node.port.PortObject)6 ConnectionID (org.knime.core.node.workflow.ConnectionID)6 UUID (java.util.UUID)5 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)5 NodeSettings (org.knime.core.node.NodeSettings)5