use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method loadBufferedDataTable.
private BufferedDataTable loadBufferedDataTable(final Node node, final NodeSettingsRO settings, final ExecutionMonitor execMon, final Map<Integer, BufferedDataTable> loadTblRep, final int index, final WorkflowDataRepository dataRepository) throws InvalidSettingsException, IOException, CanceledExecutionException {
// in 1.1.x and before the settings.xml contained the location
// of the data table specs file (spec_0.xml, e.g.). From 1.2.0 on,
// the spec is saved in data/data_0/spec.xml
boolean isVersion11x = settings.containsKey(CFG_SPEC_FILES);
ExecutionMonitor execSubData = execMon.createSubProgress(0.25);
ReferencedFile nodeDirectory = getNodeDirectory();
if (isVersion11x) {
/* In version 1.1.x the data was stored in a different way. The
* data.xml that is now contained in the data/data_x/ directory was
* aggregated in a data.xml file directly in the m_nodeDir. Also the
* spec was located at a different location.
*/
String dataConfigFileName = settings.getString(CFG_DATA_FILE);
File nodeDir = nodeDirectory.getFile();
// dataConfigFile = data.xml in node dir
File dataConfigFile = new File(nodeDir, dataConfigFileName);
NodeSettingsRO dataSettings = NodeSettings.loadFromXML(new BufferedInputStream(new FileInputStream(dataConfigFile)));
String dataPath = dataSettings.getString(CFG_DATA_FILE_DIR);
// dataDir = /data
ReferencedFile dataDirRef = new ReferencedFile(nodeDirectory, dataPath);
// note: we do not check for existence here - in some cases
// this directory may not exist (when exported and empty
// directories are pruned)
NodeSettingsRO portSettings = dataSettings.getNodeSettings(CFG_OUTPUT_PREFIX + index);
String dataName = portSettings.getString(CFG_DATA_FILE_DIR);
// dir = /data/data_i
ReferencedFile dirRef = new ReferencedFile(dataDirRef, dataName);
BufferedDataTable t = BufferedDataTable.loadFromFile(dirRef, portSettings, execSubData, loadTblRep, // no blobs or file stores in 1.1.x
WorkflowDataRepository.OLD_WORKFLOWS_INSTANCE);
t.setOwnerRecursively(node);
return t;
} else {
NodeSettingsRO dataSettings = settings.getNodeSettings(CFG_DATA_FILE);
String dataDirStr = dataSettings.getString(CFG_DATA_FILE_DIR);
ReferencedFile dataDirRef = new ReferencedFile(nodeDirectory, dataDirStr);
NodeSettingsRO portSettings = dataSettings.getNodeSettings(CFG_OUTPUT_PREFIX + index);
String dataName = portSettings.getString(CFG_DATA_FILE_DIR);
ReferencedFile dirRef = new ReferencedFile(dataDirRef, dataName);
File dir = dirRef.getFile();
readDirectory(dir);
BufferedDataTable t = BufferedDataTable.loadFromFile(dirRef, /* ignored in 1.2.0+ */
null, execMon, loadTblRep, dataRepository);
t.setOwnerRecursively(node);
return t;
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method saveInternalHeldTables.
private static void saveInternalHeldTables(final Node node, final ReferencedFile nodeDirRef, final NodeSettingsWO settings, final Set<Integer> savedTableIDs, final ExecutionMonitor exec, final boolean saveData) throws IOException, CanceledExecutionException {
PortObject[] internalObjects = node.getInternalHeldPortObjects();
if (internalObjects == null || !saveData) {
return;
}
final int internalTblsCount = internalObjects.length;
NodeSettingsWO subSettings = settings.addNodeSettings("internalObjects");
String subDirName = INTERNAL_TABLE_FOLDER_PREFIX;
ReferencedFile subDirFile = new ReferencedFile(nodeDirRef, subDirName);
subSettings.addString("location", subDirName);
NodeSettingsWO portSettings = subSettings.addNodeSettings("content");
FileUtil.deleteRecursively(subDirFile.getFile());
subDirFile.getFile().mkdirs();
exec.setMessage("Saving internally held objects");
for (int i = 0; i < internalTblsCount; i++) {
PortObject t = internalObjects[i];
String objName = "object_" + i;
ExecutionMonitor subProgress = exec.createSubProgress(1.0 / internalTblsCount);
NodeSettingsWO singlePortSetting = portSettings.addNodeSettings(objName);
ReferencedFile portDirRef = new ReferencedFile(subDirFile, objName);
File portDir = portDirRef.getFile();
singlePortSetting.addInt("index", i);
if (t == null) {
singlePortSetting.addString("type", "null");
} else if (t instanceof BufferedDataTable) {
BufferedDataTable table = (BufferedDataTable) t;
saveBufferedDataTable(table, savedTableIDs, createDirectory(portDir), exec);
singlePortSetting.addString("type", "table");
singlePortSetting.addString("table_dir_location", objName);
} else {
// other type of port object - object might be in output
int outputPortIndex = IntStream.range(0, node.getNrOutPorts()).filter(p -> node.getOutputObject(p) == t).findFirst().orElse(-1);
if (outputPortIndex >= 0) {
singlePortSetting.addString("type", "referenced_output");
singlePortSetting.addInt("outport", outputPortIndex);
} else {
singlePortSetting.addString("type", "non-table");
singlePortSetting.addString("port_dir_location", objName);
savePortObject(t.getSpec(), t, createDirectory(portDir), singlePortSetting, exec);
}
}
subProgress.setProgress(1.0);
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method loadFileStoreHandler.
IFileStoreHandler loadFileStoreHandler(final Node node, final ExecutionMonitor execMon, final NodeSettingsRO settings, final WorkflowDataRepository workflowDataRepository) throws InvalidSettingsException {
if (getLoadVersion().isOlderThan(LoadVersion.V260)) {
return new EmptyFileStoreHandler(workflowDataRepository);
}
NodeSettingsRO fsSettings = settings.getNodeSettings("filestores");
String dirNameInFlow = fsSettings.getString("file_store_location");
if (dirNameInFlow == null) {
return new EmptyFileStoreHandler(workflowDataRepository);
} 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, workflowDataRepository, subDirFile.getFile());
return fsh;
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method savePorts.
private static void savePorts(final Node node, final ReferencedFile nodeDirRef, final NodeSettingsWO settings, final Set<Integer> savedTableIDs, final ExecutionMonitor exec, final boolean saveData) throws IOException, CanceledExecutionException {
if (node.getNrOutPorts() == 0) {
return;
}
final int portCount = node.getNrOutPorts();
NodeSettingsWO portSettings = settings.addNodeSettings("ports");
exec.setMessage("Saving outport data");
// starting at port 1 (ignore default flow variable output)
for (int i = 1; i < portCount; i++) {
String portName = PORT_FOLDER_PREFIX + i;
ExecutionMonitor subProgress = exec.createSubProgress(1.0 / portCount);
NodeSettingsWO singlePortSetting = portSettings.addNodeSettings(portName);
singlePortSetting.addInt("index", i);
PortObject object = node.getOutputObject(i);
String portDirName;
if (object != null && saveData) {
portDirName = portName;
ReferencedFile portDirRef = new ReferencedFile(nodeDirRef, portDirName);
File portDir = portDirRef.getFile();
subProgress.setMessage("Cleaning directory " + portDir.getAbsolutePath());
FileUtil.deleteRecursively(portDir);
if (!portDir.mkdir() && !portDir.isDirectory()) {
throw new IOException("Cannot create port directory " + portDir.getAbsolutePath() + " (" + "exists: " + portDir.exists() + ", isDir: " + portDir.isDirectory() + ", " + "parent permissions: " + (portDir.getParentFile().canRead() ? "r" : "-") + (portDir.getParentFile().canWrite() ? "w" : "-") + (portDir.getParentFile().canExecute() ? "x" : "-") + ")");
}
if (!portDir.canWrite()) {
throw new IOException("Cannot write to port directory " + portDir.getAbsolutePath());
}
savePort(node, portDir, singlePortSetting, savedTableIDs, subProgress, i, saveData);
} else {
portDirName = null;
}
singlePortSetting.addString("port_dir_location", portDirName);
subProgress.setProgress(1.0);
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method save.
/**
* Saves the node, node settings, and all internal structures, spec, data, and models, to the given node directory
* (located at the node file).
*
* @param nnc ...
* @param settings ...
* @param execMon Used to report progress during saving.
* @param nodeDirRef Directory associated with node - will create internals folder in it
* @param isSaveData ...
* @throws IOException If the node file can't be found or read.
* @throws CanceledExecutionException If the saving has been canceled.
* @since 2.9
*/
public static void save(final NativeNodeContainer nnc, final NodeSettingsWO settings, final ExecutionMonitor execMon, final ReferencedFile nodeDirRef, final boolean isSaveData) throws IOException, CanceledExecutionException {
final Node node = nnc.getNode();
saveCustomName(node, settings);
saveHasContent(node, settings);
saveIsInactive(node, settings);
ReferencedFile nodeInternDirRef = getNodeInternDirectory(nodeDirRef);
File nodeInternDir = nodeInternDirRef.getFile();
if (nodeInternDir.exists()) {
FileUtil.deleteRecursively(nodeInternDir);
}
ExecutionMonitor internalMon = execMon.createSilentSubProgress(0.2);
ExecutionMonitor portMon = execMon.createSilentSubProgress(0.5);
ExecutionMonitor intTblsMon = execMon.createSilentSubProgress(0.1);
ExecutionMonitor fileStoreMon = execMon.createSilentSubProgress(0.1);
execMon.setMessage("Internals");
boolean isSaveInternals = isSaveData;
if (isSaveInternals) {
// do not save data for inactive nodes
isSaveInternals = node.isInactiveBranchConsumer() || !node.isInactive();
}
if (isSaveInternals) {
NodeContext.pushContext(nnc);
try {
saveNodeInternDirectory(node, nodeInternDir, settings, internalMon);
} finally {
NodeContext.removeLastContext();
}
}
internalMon.setProgress(1.0);
/* A hash set of all tables that originate from the corresponding node
* (owner ID of the table equals NodeID), which have already been saved.
* It is used to avoid multiple saves of the same table, e.g. when one
* table is returned in multiple outputs or if an output table is used
* as "internal" held table. See bug 2117. */
final Set<Integer> savedTableIDs = new HashSet<Integer>();
execMon.setMessage("Ports");
savePorts(node, nodeDirRef, settings, savedTableIDs, portMon, isSaveData);
portMon.setProgress(1.0);
execMon.setMessage("Internal Tables");
saveInternalHeldTables(node, nodeDirRef, settings, savedTableIDs, internalMon, isSaveData);
intTblsMon.setProgress(1.0);
// save them last as now all tables have been saved (all cells ran through persistor) and all
// FileStore#getFile() have been called and saved
execMon.setMessage("File Store Objects");
saveFileStoreObjects(node, nodeDirRef, settings, fileStoreMon, isSaveData);
fileStoreMon.setProgress(1.0);
execMon.setProgress(1.0);
}
Aggregations