Search in sources :

Example 1 with IFileStoreHandler

use of org.knime.core.data.filestore.internal.IFileStoreHandler in project knime-core by knime.

the class NativeNodeContainer method initFileStore.

private IWriteFileStoreHandler initFileStore(final WorkflowFileStoreHandlerRepository fileStoreHandlerRepository) {
    final FlowObjectStack flowObjectStack = getFlowObjectStack();
    FlowLoopContext upstreamFLC = flowObjectStack.peek(FlowLoopContext.class);
    if (upstreamFLC == null) {
        // if node is contained in subnode check if the subnode is in a loop (see AP-5667)
        final FlowSubnodeScopeContext subnodeSC = flowObjectStack.peek(FlowSubnodeScopeContext.class);
        if (subnodeSC != null) {
            upstreamFLC = subnodeSC.getOuterFlowLoopContext();
        }
    }
    NodeID outerStartNodeID = upstreamFLC == null ? null : upstreamFLC.getHeadNode();
    // loop start nodes will put their loop context on the outgoing flow object stack
    assert !getID().equals(outerStartNodeID) : "Loop start on incoming flow stack can't be node itself";
    final FlowLoopContext innerFLC = getOutgoingFlowObjectStack().peek(FlowLoopContext.class);
    NodeID innerStartNodeID = innerFLC == null ? null : innerFLC.getHeadNode();
    // if there is a loop context on this node's stack, this node must be the start
    assert !(this.isModelCompatibleTo(LoopStartNode.class)) || getID().equals(innerStartNodeID);
    IFileStoreHandler oldFSHandler = m_node.getFileStoreHandler();
    IWriteFileStoreHandler newFSHandler;
    if (innerFLC == null && upstreamFLC == null) {
        // node is not a start node and not contained in a loop
        if (oldFSHandler instanceof IWriteFileStoreHandler) {
            clearFileStoreHandler();
        /*assert false : "Node " + getNameWithID() + " must not have file store handler at this point (not a "
                + "loop start and not contained in loop), disposing old handler";*/
        }
        newFSHandler = new WriteFileStoreHandler(getNameWithID(), UUID.randomUUID());
        newFSHandler.addToRepository(fileStoreHandlerRepository);
    } else if (innerFLC != null) {
        // node is a loop start node
        int loopIteration = innerFLC.getIterationIndex();
        if (loopIteration == 0) {
            if (oldFSHandler instanceof IWriteFileStoreHandler) {
                assert false : "Loop Start " + getNameWithID() + " must not have file store handler at this point " + "(no iteration ran), disposing old handler";
                clearFileStoreHandler();
            }
            if (upstreamFLC != null) {
                ILoopStartWriteFileStoreHandler upStreamFSHandler = upstreamFLC.getFileStoreHandler();
                newFSHandler = new LoopStartReferenceWriteFileStoreHandler(upStreamFSHandler, innerFLC);
            } else {
                newFSHandler = new LoopStartWritableFileStoreHandler(this, UUID.randomUUID(), innerFLC);
            }
            newFSHandler.addToRepository(fileStoreHandlerRepository);
            innerFLC.setFileStoreHandler((ILoopStartWriteFileStoreHandler) newFSHandler);
        } else {
            assert oldFSHandler instanceof IWriteFileStoreHandler : "Loop Start " + getNameWithID() + " must have file store handler in iteration " + loopIteration;
            newFSHandler = (IWriteFileStoreHandler) oldFSHandler;
        // keep the old one
        }
    } else {
        // ordinary node contained in loop
        assert innerFLC == null && upstreamFLC != null;
        ILoopStartWriteFileStoreHandler upStreamFSHandler = upstreamFLC.getFileStoreHandler();
        if (this.isModelCompatibleTo(LoopEndNode.class)) {
            if (upstreamFLC.getIterationIndex() > 0) {
                newFSHandler = (IWriteFileStoreHandler) oldFSHandler;
            } else {
                newFSHandler = new LoopEndWriteFileStoreHandler(upStreamFSHandler);
                newFSHandler.addToRepository(fileStoreHandlerRepository);
            }
        } else {
            newFSHandler = new ReferenceWriteFileStoreHandler(upStreamFSHandler);
            newFSHandler.addToRepository(fileStoreHandlerRepository);
        }
    }
    return newFSHandler;
}
Also used : IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) LoopEndWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopEndWriteFileStoreHandler) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) ReferenceWriteFileStoreHandler(org.knime.core.data.filestore.internal.ReferenceWriteFileStoreHandler) WriteFileStoreHandler(org.knime.core.data.filestore.internal.WriteFileStoreHandler) LoopEndWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopEndWriteFileStoreHandler) ILoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.ILoopStartWriteFileStoreHandler) LoopStartReferenceWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopStartReferenceWriteFileStoreHandler) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) ILoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.ILoopStartWriteFileStoreHandler) ReferenceWriteFileStoreHandler(org.knime.core.data.filestore.internal.ReferenceWriteFileStoreHandler) LoopStartReferenceWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopStartReferenceWriteFileStoreHandler) LoopStartReferenceWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopStartReferenceWriteFileStoreHandler) LoopStartWritableFileStoreHandler(org.knime.core.data.filestore.internal.LoopStartWritableFileStoreHandler)

Example 2 with IFileStoreHandler

use of org.knime.core.data.filestore.internal.IFileStoreHandler in project knime-core by knime.

the class FileNodePersistor method loadFileStoreHandler.

IFileStoreHandler loadFileStoreHandler(final Node node, final ExecutionMonitor execMon, final NodeSettingsRO settings, final WorkflowFileStoreHandlerRepository fileStoreHandlerRepository) throws InvalidSettingsException {
    if (getLoadVersion().isOlderThan(FileWorkflowPersistor.LoadVersion.V260)) {
        return new EmptyFileStoreHandler(fileStoreHandlerRepository);
    }
    NodeSettingsRO fsSettings = settings.getNodeSettings("filestores");
    String dirNameInFlow = fsSettings.getString("file_store_location");
    if (dirNameInFlow == null) {
        return new EmptyFileStoreHandler(fileStoreHandlerRepository);
    } else {
        String uuidS = fsSettings.getString("file_store_id");
        UUID uuid = UUID.fromString(uuidS);
        ReferencedFile subDirFile = new ReferencedFile(getNodeDirectory(), dirNameInFlow);
        IFileStoreHandler fsh = WriteFileStoreHandler.restore(node.getName(), uuid, fileStoreHandlerRepository, subDirFile.getFile());
        return fsh;
    }
}
Also used : IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) EmptyFileStoreHandler(org.knime.core.data.filestore.internal.EmptyFileStoreHandler) UUID(java.util.UUID) ReferencedFile(org.knime.core.internal.ReferencedFile)

Example 3 with IFileStoreHandler

use of org.knime.core.data.filestore.internal.IFileStoreHandler in project knime-core by knime.

the class NativeNodeContainer method initVirtualScopeFileStoreHandler.

/**
 * Inits file store handler for nodes that are part of a {@link FlowVirtualScopeContext}.
 *
 * @return the file store handler or <code>null</code> if not a virtual scope
 */
private IWriteFileStoreHandler initVirtualScopeFileStoreHandler() {
    FlowVirtualScopeContext virtualScope = getFlowScopeContextFromHierarchy(FlowVirtualScopeContext.class, getFlowObjectStack());
    NativeNodeContainer hostNode = virtualScope != null ? virtualScope.getHostNode().orElse(null) : null;
    if (hostNode != null) {
        IFileStoreHandler fsh = hostNode.getNode().getFileStoreHandler();
        if (fsh instanceof IWriteFileStoreHandler) {
            return initWriteFileStoreHandlerReference((IWriteFileStoreHandler) fsh);
        } else if (fsh == null) {
            // can happen if the node associated with the virtual scope is reset
            throw new IllegalStateException("No file store handler given. Try to re-execute '" + hostNode.getNameWithID() + "'");
        } else {
            throw new IllegalStateException("No file store handler given. Most likely an implementation error");
        }
    } else {
        return null;
    }
}
Also used : FlowVirtualScopeContext(org.knime.core.node.workflow.virtual.parchunk.FlowVirtualScopeContext) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler)

Example 4 with IFileStoreHandler

use of org.knime.core.data.filestore.internal.IFileStoreHandler in project knime-core by knime.

the class NativeNodeContainer method initLoopScopeFileStoreHandler.

/**
 * Inits the file store handler if node is part of a loop scope (including start and end).
 *
 * @param upstreamFLC optional loop context this node might be part of
 * @param innerFLC optional loop context beginning at this node if this node is a loop start
 * @param targetFSH file store handler to be referenced if given
 * @return the file store handler or <code>null</code> if not a loop scope
 */
private IWriteFileStoreHandler initLoopScopeFileStoreHandler(final FlowLoopContext upstreamFLC, final FlowLoopContext innerFLC, final IWriteFileStoreHandler targetFSH) {
    IFileStoreHandler oldFSHandler = m_node.getFileStoreHandler();
    IWriteFileStoreHandler newFSHandler = null;
    if (innerFLC != null) {
        // node is a loop start node
        assert innerFLC.getIterationIndex() == 0;
        if (oldFSHandler instanceof IWriteFileStoreHandler) {
            assert false : "Loop Start " + getNameWithID() + " must not have file store handler at this point " + "(no iteration ran), disposing old handler";
            clearFileStoreHandler();
        }
        if (upstreamFLC != null) {
            ILoopStartWriteFileStoreHandler upStreamFSHandler = upstreamFLC.getFileStoreHandler();
            newFSHandler = new NestedLoopStartWriteFileStoreHandler(upStreamFSHandler, innerFLC);
        } else if (targetFSH != null) {
            // there is another target file store handler
            // -> loop start file store handler references it
            newFSHandler = new LoopStartWriteFileStoreHandler(this, targetFSH, innerFLC);
        } else {
            // create entirely new loop start file store handler (without referencing another handler)
            newFSHandler = new LoopStartWriteFileStoreHandler(this, UUID.randomUUID(), innerFLC);
        }
        innerFLC.setFileStoreHandler((ILoopStartWriteFileStoreHandler) newFSHandler);
    } else {
        // ordinary node contained in loop
        assert upstreamFLC != null;
        assert upstreamFLC.getIterationIndex() == 0;
        ILoopStartWriteFileStoreHandler upStreamFSHandler = upstreamFLC.getFileStoreHandler();
        if (upStreamFSHandler != null) {
            if (this.isModelCompatibleTo(LoopEndNode.class)) {
                newFSHandler = new LoopEndWriteFileStoreHandler(upStreamFSHandler);
            } else {
                newFSHandler = new ReferenceWriteFileStoreHandler(upStreamFSHandler);
            }
        } else {
            // for an 'InactiveBranchConsumer-loop end'
            assert this.isModelCompatibleTo(InactiveBranchConsumer.class);
        }
    }
    return newFSHandler;
}
Also used : LoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopStartWriteFileStoreHandler) NestedLoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.NestedLoopStartWriteFileStoreHandler) ILoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.ILoopStartWriteFileStoreHandler) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) NestedLoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.NestedLoopStartWriteFileStoreHandler) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) ILoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.ILoopStartWriteFileStoreHandler) ReferenceWriteFileStoreHandler(org.knime.core.data.filestore.internal.ReferenceWriteFileStoreHandler) LoopEndWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopEndWriteFileStoreHandler)

Example 5 with IFileStoreHandler

use of org.knime.core.data.filestore.internal.IFileStoreHandler in project knime-core by knime.

the class NativeNodeContainer method initDefaultFileStoreHandler.

/**
 * Inits the default file store handler for a node, i.e. file stores are stored with the node itself.
 *
 * @return the file store handler, never <code>null</code>
 */
private IWriteFileStoreHandler initDefaultFileStoreHandler() {
    // node is not a start node and not contained in a loop
    IFileStoreHandler oldFSHandler = m_node.getFileStoreHandler();
    if (oldFSHandler instanceof IWriteFileStoreHandler) {
        clearFileStoreHandler();
    /*assert false : "Node " + getNameWithID() + " must not have file store handler at this point (not a "
            + "loop start and not contained in loop), disposing old handler";*/
    }
    IWriteFileStoreHandler newFSHandler = new WriteFileStoreHandler(getNameWithID(), UUID.randomUUID());
    return newFSHandler;
}
Also used : IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) LoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopStartWriteFileStoreHandler) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) ReferenceWriteFileStoreHandler(org.knime.core.data.filestore.internal.ReferenceWriteFileStoreHandler) WriteFileStoreHandler(org.knime.core.data.filestore.internal.WriteFileStoreHandler) LoopEndWriteFileStoreHandler(org.knime.core.data.filestore.internal.LoopEndWriteFileStoreHandler) NestedLoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.NestedLoopStartWriteFileStoreHandler) ILoopStartWriteFileStoreHandler(org.knime.core.data.filestore.internal.ILoopStartWriteFileStoreHandler) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler)

Aggregations

IFileStoreHandler (org.knime.core.data.filestore.internal.IFileStoreHandler)13 UUID (java.util.UUID)5 IWriteFileStoreHandler (org.knime.core.data.filestore.internal.IWriteFileStoreHandler)5 ReferencedFile (org.knime.core.internal.ReferencedFile)4 EmptyFileStoreHandler (org.knime.core.data.filestore.internal.EmptyFileStoreHandler)3 ILoopStartWriteFileStoreHandler (org.knime.core.data.filestore.internal.ILoopStartWriteFileStoreHandler)3 LoopEndWriteFileStoreHandler (org.knime.core.data.filestore.internal.LoopEndWriteFileStoreHandler)3 ReferenceWriteFileStoreHandler (org.knime.core.data.filestore.internal.ReferenceWriteFileStoreHandler)3 File (java.io.File)2 IOException (java.io.IOException)2 LoopStartWriteFileStoreHandler (org.knime.core.data.filestore.internal.LoopStartWriteFileStoreHandler)2 NestedLoopStartWriteFileStoreHandler (org.knime.core.data.filestore.internal.NestedLoopStartWriteFileStoreHandler)2 WriteFileStoreHandler (org.knime.core.data.filestore.internal.WriteFileStoreHandler)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1