Search in sources :

Example 46 with WorkflowManager

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());
}
Also used : CacheNodeFactory(org.knime.base.node.util.cache.CacheNodeFactory) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) CacheNodeFactory(org.knime.base.node.util.cache.CacheNodeFactory) RuntimeNodeFactory(org.knime.testing.node.runtime.RuntimeNodeFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestEvaluationException(org.knime.testing.node.differNode.TestEvaluationException) DataTableDiffer(org.knime.testing.node.differNode.DataTableDiffer) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) ExecutionContext(org.knime.core.node.ExecutionContext) RuntimeNodeModel(org.knime.testing.node.runtime.RuntimeNodeModel) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeID(org.knime.core.node.workflow.NodeID) RuntimeNodeFactory(org.knime.testing.node.runtime.RuntimeNodeFactory)

Example 47 with WorkflowManager

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;
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) AuthorInformation(org.knime.core.node.workflow.WorkflowManager.AuthorInformation) File(java.io.File) Date(java.util.Date)

Example 48 with WorkflowManager

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() };
}
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 49 with WorkflowManager

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);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 50 with WorkflowManager

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);
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)88 NodeID (org.knime.core.node.workflow.NodeID)31 NodeContainer (org.knime.core.node.workflow.NodeContainer)20 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)12 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)12 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)10 ArrayList (java.util.ArrayList)9 MessageBox (org.eclipse.swt.widgets.MessageBox)9 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 IOException (java.io.IOException)8 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)8 Map (java.util.Map)7 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)7 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)7 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)7 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)7 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)6