use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class AbstractBlobsInWorkflowTest method setUp.
/**
* {@inheritDoc}
*/
@Override
protected void setUp() throws Exception {
m_wfmDir = FileUtil.createTempDir(getClass().getSimpleName());
WorkflowCreationHelper creationHelper = new WorkflowCreationHelper();
creationHelper.setWorkflowContext(new WorkflowContext.Factory(m_wfmDir).createContext());
WorkflowManager m = WorkflowManager.ROOT.createAndAddProject("Blob test", creationHelper);
RuntimeNodeModel createModel = new RuntimeNodeModel(0, 1) {
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
return new BufferedDataTable[] { createBDT(exec) };
}
};
NodeID createID = m.createAndAddNode(new RuntimeNodeFactory(createModel));
// add a sequence of cache nodes
NodeID[] cacheIDs = new NodeID[10];
CacheNodeFactory cacheNodeFactory = new CacheNodeFactory();
for (int i = 0; i < cacheIDs.length; i++) {
cacheIDs[i] = m.createAndAddNode(cacheNodeFactory);
if (i == 0) {
m.addConnection(createID, 1, cacheIDs[i], 1);
} else {
m.addConnection(cacheIDs[i - 1], 1, cacheIDs[i], 1);
}
}
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
RuntimeNodeModel checkModel = new RuntimeNodeModel(1, 0) {
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
try {
new DataTableDiffer().compare(inData[0], createBDT(exec));
} catch (TestEvaluationException tee) {
failure.set(tee);
throw tee;
}
return new BufferedDataTable[] {};
}
};
NodeID checkID = m.createAndAddNode(new RuntimeNodeFactory(checkModel));
m.addConnection(cacheIDs[cacheIDs.length - 1], 1, checkID, 1);
m_flow = m;
m.executeAllAndWaitUntilDone();
assertNull(failure.get());
assertTrue(m.getNodeContainerState().isExecuted());
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class ReadContextPropertyConfiguration method extractContextProperty.
private static String extractContextProperty(final String property) {
WorkflowManager manager = NodeContext.getContext().getWorkflowManager();
if (CONTEXT_WORKFLOW_NAME.equals(property)) {
return manager.getName();
}
if (CONTEXT_WORKFLOW_PATH.equals(property)) {
WorkflowContext context = manager.getContext();
File wfLocation = context.getOriginalLocation() == null ? context.getCurrentLocation() : context.getOriginalLocation();
File mpLocation = context.getMountpointRoot();
if (mpLocation == null || wfLocation == null) {
return "";
}
String wfPath = wfLocation.getAbsolutePath();
String mpPath = mpLocation.getAbsolutePath();
assert wfPath.startsWith(mpPath);
String resultPath = wfPath.substring(mpPath.length());
return resultPath.replace("\\", "/");
}
if (CONTEXT_WORKFLOW_ABSOLUTE_PATH.equals(property)) {
WorkflowContext context = manager.getContext();
File wfLocation = context.getCurrentLocation();
if (wfLocation == null) {
return "";
}
return wfLocation.getAbsolutePath().replace("\\", "/");
}
if (CONTEXT_SERVER_USER.equals(property)) {
return manager.getContext().getUserid();
}
if (CONTEXT_TEMP_LOCATION.equals(property)) {
return manager.getContext().getTempLocation().getAbsolutePath();
}
AuthorInformation author = manager.getAuthorInformation();
if (author != null) {
if (CONTEXT_AUTHOR.equals(property)) {
return author.getAuthor();
}
if (CONTEXT_EDITOR.equals(property)) {
return author.getLastEditor();
}
if (CONTEXT_CREATION_DATE.equals(property)) {
Date creationDate = author.getAuthoredDate();
if (creationDate != null) {
return creationDate.toString();
}
}
if (CONTEXT_LAST_MODIFIED.equals(property)) {
Date modDate = author.getLastEditDate();
if (modDate != null) {
return modDate.toString();
}
}
}
return null;
}
use of org.knime.core.node.workflow.WorkflowManager 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.WorkflowManager in project knime-core by knime.
the class ExpandSubnodeResult method undo.
public void undo() {
WorkflowManager hostWFM = m_hostWFM;
for (NodeID id : m_expandedCopyContent.getNodeIDs()) {
hostWFM.removeNode(id);
}
for (WorkflowAnnotation anno : m_expandedCopyContent.getAnnotations()) {
hostWFM.removeAnnotation(anno);
}
hostWFM.paste(m_undoCopyPersistor);
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class CollapseIntoMetaNodeResult method undo.
public void undo() {
WorkflowManager hostWFM = m_hostWFM;
try (WorkflowLock l = m_hostWFM.lock()) {
m_hostWFM.removeNode(m_collapsedMetanodeID);
hostWFM.paste(m_undoCopyPersistor);
}
}
Aggregations