use of org.knime.core.node.workflow.SubNodeContainer in project knime-core by knime.
the class SandboxedNodeCreator method setupConnectionProgressEventListeners.
/**
* For each connection in the sandbox add a progress listener that fires an event on the original connection.
*/
private void setupConnectionProgressEventListeners(final NodeContainer origNC, final NodeContainer sandboxNC) {
WorkflowManager origWFM;
WorkflowManager sandboxWFM;
if (origNC instanceof WorkflowManager) {
origWFM = (WorkflowManager) origNC;
sandboxWFM = (WorkflowManager) sandboxNC;
} else if (origNC instanceof SubNodeContainer) {
origWFM = ((SubNodeContainer) origNC).getWorkflowManager();
sandboxWFM = ((SubNodeContainer) sandboxNC).getWorkflowManager();
} else {
return;
}
for (ConnectionContainer cc : origWFM.getConnectionContainers()) {
NodeID sandboxTargetID = sandboxWFM.getID();
if (!cc.getDest().equals(origWFM.getID())) {
// real connection, not a wfm out or through connection
sandboxTargetID = new NodeID(sandboxTargetID, cc.getDest().getIndex());
}
ConnectionContainer sbCC = sandboxWFM.getConnection(new ConnectionID(sandboxTargetID, cc.getDestPort()));
sbCC.addProgressListener(pe -> cc.progressChanged(pe));
}
}
use of org.knime.core.node.workflow.SubNodeContainer 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());
}
}
}
use of org.knime.core.node.workflow.SubNodeContainer 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());
}
}
use of org.knime.core.node.workflow.SubNodeContainer 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.SubNodeContainer in project knime-core by knime.
the class DefaultOpenViewAction method runOnNodes.
/**
* This opens the first view of all the selected nodes.
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
LOGGER.debug("Creating open default view job for " + nodeParts.length + " node(s)...");
for (NodeContainerEditPart p : nodeParts) {
final NodeContainer cont = unwrapNC(p.getNodeContainer());
final InteractiveWebViewsResult webViewsResult = cont.getInteractiveWebViews();
boolean hasView = cont.getNrViews() > 0;
hasView |= cont.hasInteractiveView() || webViewsResult.size() > 0;
hasView |= OpenSubnodeWebViewAction.hasContainerView(cont);
if (cont.getNodeContainerState().isExecuted() && hasView) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
final IAction action;
if (cont.hasInteractiveView()) {
action = new OpenInteractiveViewAction(cont);
} else if (cont instanceof SubNodeContainer) {
action = new OpenSubnodeWebViewAction((SubNodeContainer) cont);
} else if (webViewsResult.size() > 0) {
action = new OpenInteractiveWebViewAction(cont, webViewsResult.get(0));
} else {
action = new OpenViewAction(cont, 0);
}
action.run();
} catch (Throwable t) {
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText("View cannot be opened");
mb.setMessage("The view cannot be opened for the " + "following reason:\n" + t.getMessage());
mb.open();
LOGGER.error("The view for node '" + cont.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an " + "implementation error.", t);
}
}
});
}
}
try {
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
} catch (Exception e) {
// ignore
}
}
Aggregations