Search in sources :

Example 26 with NodeContainer

use of org.knime.core.node.workflow.NodeContainer 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 27 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) 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) 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 28 with NodeContainer

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

the class SandboxedNodeCreator method deepCopyFilesInWorkflowDir.

/**
 * Deep copies data and drop folders contained in the source directory to the target directory.
 * @param source Source node
 * @param targetParent Target node's parent
 */
private static void deepCopyFilesInWorkflowDir(final NodeContainer source, final WorkflowManager targetParent) {
    NodeContainer target = targetParent.getNodeContainer(targetParent.getID().createChild(source.getID().getIndex()));
    ReferencedFile sourceDirRef = source.getNodeContainerDirectory();
    ReferencedFile targetDirRef = target.getNodeContainerDirectory();
    if (sourceDirRef == null) {
        // The source node has never been saved, there are no files to copy
        return;
    }
    File sourceDir = sourceDirRef.getFile();
    File targetDir = targetDirRef.getFile();
    for (String magicFolderName : MAGIC_DATA_FOLDERS) {
        File dataSourceDir = new File(sourceDir, magicFolderName);
        if (dataSourceDir.isDirectory()) {
            File dataTargetDir = new File(targetDir, magicFolderName);
            try {
                FileUtils.copyDirectory(dataSourceDir, dataTargetDir);
                LOGGER.debugWithFormat("Copied directory \"%s\" to \"%s\"", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath());
            } catch (IOException ex) {
                LOGGER.error(String.format("Could not copy directory \"%s\" to \"%s\": %s", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath(), ex.getMessage()), ex);
            }
        }
    }
    Collection<NodeContainer> childrenList = Collections.emptyList();
    WorkflowManager childTargetParent = null;
    if (source instanceof WorkflowManager) {
        childrenList = ((WorkflowManager) source).getNodeContainers();
        childTargetParent = (WorkflowManager) target;
    } else if (source instanceof SubNodeContainer) {
        childrenList = ((SubNodeContainer) source).getWorkflowManager().getNodeContainers();
        childTargetParent = ((SubNodeContainer) target).getWorkflowManager();
    }
    for (NodeContainer child : childrenList) {
        deepCopyFilesInWorkflowDir(child, childTargetParent);
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 29 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) {
        return message;
    }
    final NodeContext context = NodeContext.getContext();
    NodeID nodeID = null;
    String nodeName = null;
    File workflowDir = 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) {
            final WorkflowManager workflowManager = context.getWorkflowManager();
            if (workflowManager != null) {
                final WorkflowContext workflowContext = workflowManager.getContext();
                if (workflowContext != null) {
                    workflowDir = workflowContext.getCurrentLocation();
                }
            }
        }
    }
    return new KNIMELogMessage(nodeID, nodeName, workflowDir, 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) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 30 with NodeContainer

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

the class CheckUpdateMetaNodeLinkAction method getNCTemplatesToCheck.

private List<NodeID> getNCTemplatesToCheck(final NodeContainerTemplate template) {
    List<NodeID> list = new ArrayList<NodeID>();
    for (NodeContainer nc : template.getNodeContainers()) {
        if (nc instanceof NodeContainerTemplate) {
            NodeContainerTemplate tnc = (NodeContainerTemplate) nc;
            if (tnc.getTemplateInformation().getRole().equals(Role.Link)) {
                if (!getManager().canUpdateMetaNodeLink(tnc.getID())) {
                    return Collections.emptyList();
                }
                list.add(tnc.getID());
            }
            list.addAll(getNCTemplatesToCheck(tnc));
        }
    }
    return list;
}
Also used : NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Aggregations

NodeContainer (org.knime.core.node.workflow.NodeContainer)51 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)21 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)20 NodeID (org.knime.core.node.workflow.NodeID)18 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)13 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)11 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)9 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)9 Map (java.util.Map)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)6 ConnectionID (org.knime.core.node.workflow.ConnectionID)6 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)6 File (java.io.File)5 List (java.util.List)5 GridData (org.eclipse.swt.layout.GridData)5 ReferencedFile (org.knime.core.internal.ReferencedFile)5 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)5