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() };
}
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();
}
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);
}
}
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);
}
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;
}
Aggregations