use of org.knime.core.data.filestore.internal.WriteFileStoreHandler 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;
}
use of org.knime.core.data.filestore.internal.WriteFileStoreHandler in project knime-core by knime.
the class FileNodePersistor method saveFileStoreObjects.
/**
* @param node
* @param nodeDirRef
* @param settings
* @param fileStoreMon
* @param isSaveData
* @throws IOException
*/
private static void saveFileStoreObjects(final Node node, final ReferencedFile nodeDirRef, final NodeSettingsWO settings, final ExecutionMonitor fileStoreMon, final boolean isSaveData) throws IOException {
NodeSettingsWO fsSettings = settings.addNodeSettings("filestores");
IFileStoreHandler fileStoreHandler = node.getFileStoreHandler();
String uuidS;
String dirNameInFlow;
if (isSaveData && fileStoreHandler instanceof WriteFileStoreHandler) {
final WriteFileStoreHandler defFileStoreHandler = (WriteFileStoreHandler) fileStoreHandler;
File baseDir = defFileStoreHandler.getBaseDir();
dirNameInFlow = baseDir == null ? null : FILESTORE_FOLDER_PREFIX;
if (dirNameInFlow != null) {
File saveLocation = new File(nodeDirRef.getFile(), dirNameInFlow);
FileUtil.copyDir(baseDir, saveLocation);
}
uuidS = defFileStoreHandler.getStoreUUID().toString();
} else {
uuidS = null;
dirNameInFlow = null;
}
fsSettings.addString("file_store_location", dirNameInFlow);
fsSettings.addString("file_store_id", uuidS);
}
Aggregations