use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method loadInternalHeldTablesPre210.
/**
* Reads internally held table in version {@link LoadVersion#V2100Pre} and before. Was replaced by
* #loadInternalHeldObjects then on.
*/
void loadInternalHeldTablesPre210(final Node node, final ExecutionMonitor execMon, final NodeSettingsRO settings, final Map<Integer, BufferedDataTable> loadTblRep, final HashMap<Integer, ContainerTable> tblRep, final FileStoreHandlerRepository fileStoreHandlerRepository) throws IOException, InvalidSettingsException, CanceledExecutionException {
if (getLoadVersion().isOlderThan(FileWorkflowPersistor.LoadVersion.V200)) {
return;
}
if (!settings.containsKey("internalTables")) {
return;
}
NodeSettingsRO subSettings = settings.getNodeSettings("internalTables");
String subDirName = subSettings.getString("location");
ReferencedFile subDirFile = new ReferencedFile(getNodeDirectory(), subDirName);
NodeSettingsRO portSettings = subSettings.getNodeSettings("content");
Set<String> keySet = portSettings.keySet();
BufferedDataTable[] result = new BufferedDataTable[keySet.size()];
for (String s : keySet) {
ExecutionMonitor subProgress = execMon.createSubProgress(1.0 / result.length);
NodeSettingsRO singlePortSetting = portSettings.getNodeSettings(s);
int index = singlePortSetting.getInt("index");
if (index < 0 || index >= result.length) {
throw new InvalidSettingsException("Invalid index: " + index);
}
String location = singlePortSetting.getString("table_dir_location");
if (location == null) {
result[index] = null;
} else {
ReferencedFile portDirRef = new ReferencedFile(subDirFile, location);
readDirectory(portDirRef.getFile());
portDirRef.getFile();
BufferedDataTable t = loadBufferedDataTable(portDirRef, subProgress, loadTblRep, tblRep, fileStoreHandlerRepository);
t.setOwnerRecursively(node);
result[index] = t;
}
subProgress.setProgress(1.0);
}
setInternalHeldPortObjects(result);
}
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 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;
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method loadPorts.
/**
* @noreference
* @nooverride
*/
void loadPorts(final Node node, final ExecutionMonitor exec, final NodeSettingsRO settings, final Map<Integer, BufferedDataTable> loadTblRep, final HashMap<Integer, ContainerTable> tblRep, final FileStoreHandlerRepository fileStoreHandlerRepository) throws IOException, InvalidSettingsException, CanceledExecutionException {
final int nrOutPorts = node.getNrOutPorts();
if (getLoadVersion().isOlderThan(FileWorkflowPersistor.LoadVersion.V200)) {
// skip flow variables port (introduced in v2.2)
for (int i = 1; i < nrOutPorts; i++) {
int oldIndex = getOldPortIndex(i);
ExecutionMonitor execPort = exec.createSubProgress(1.0 / nrOutPorts);
exec.setMessage("Port " + oldIndex);
PortType type = node.getOutputType(i);
boolean isDataPort = BufferedDataTable.class.isAssignableFrom(type.getPortObjectClass());
if (m_isConfigured) {
PortObjectSpec spec = loadPortObjectSpec(node, settings, oldIndex);
setPortObjectSpec(i, spec);
}
if (m_isExecuted) {
PortObject object;
if (isDataPort) {
object = loadBufferedDataTable(node, settings, execPort, loadTblRep, oldIndex, tblRep, fileStoreHandlerRepository);
} else {
throw new IOException("Can't restore model ports of " + "old 1.x workflows. Execute node again.");
}
String summary = object != null ? object.getSummary() : null;
setPortObject(i, object);
setPortObjectSummary(i, summary);
}
execPort.setProgress(1.0);
}
} else {
if (nrOutPorts == 1) {
// only the mandatory flow variable port
return;
}
NodeSettingsRO portsSettings = loadPortsSettings(settings);
exec.setMessage("Reading outport data");
for (String key : portsSettings.keySet()) {
NodeSettingsRO singlePortSetting = portsSettings.getNodeSettings(key);
ExecutionMonitor subProgress = exec.createSubProgress(1 / (double) nrOutPorts);
int index = loadPortIndex(singlePortSetting);
if (index < 0 || index >= nrOutPorts) {
throw new InvalidSettingsException("Invalid outport index in settings: " + index);
}
String portDirN = singlePortSetting.getString("port_dir_location");
if (portDirN != null) {
ReferencedFile portDir = new ReferencedFile(getNodeDirectory(), portDirN);
subProgress.setMessage("Port " + index);
loadPort(node, portDir, singlePortSetting, subProgress, index, loadTblRep, tblRep, fileStoreHandlerRepository);
}
subProgress.setProgress(1.0);
}
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class WorkflowManager method cleanup.
/**
* {@inheritDoc}
*/
@Override
void cleanup() {
try (WorkflowLock lock = lock()) {
super.cleanup();
ReferencedFile ncDir = getNodeContainerDirectory();
if (isProject() && ncDir != null) {
ncDir.fileUnlockRootForVM();
}
// breadth first sorted list - traverse backwards (downstream before upstream nodes)
final List<NodeID> idList = new ArrayList<NodeID>(m_workflow.createBreadthFirstSortedList(m_workflow.getNodeIDs(), true).keySet());
for (ListIterator<NodeID> reverseIt = idList.listIterator(idList.size()); reverseIt.hasPrevious(); ) {
NodeContainer nc = getNodeContainer(reverseIt.previous());
nc.cleanup();
}
getConnectionContainers().stream().forEach(c -> c.cleanup());
if (m_tmpDir != null) {
// delete the flow temp dir that we created
KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Runnable() {
@Override
public void run() {
if (m_tmpDir.isDirectory() && !FileUtil.deleteRecursively(m_tmpDir)) {
LOGGER.info("Could not delete temporary directory for workflow " + getName() + " at " + m_tmpDir);
}
}
});
}
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class WorkflowManager method loadNodesAndConnections.
private Map<Integer, NodeID> loadNodesAndConnections(final Map<Integer, ? extends NodeContainerPersistor> loaderMap, final Set<ConnectionContainerTemplate> connections, final LoadResult loadResult) {
// id suffix are made unique by using the entries in this map
@SuppressWarnings("serial") Map<Integer, NodeID> translationMap = new LinkedHashMap<Integer, NodeID>() {
/**
* {@inheritDoc}
*/
@Override
public NodeID get(final Object key) {
NodeID result = super.get(key);
if (result == null) {
result = new NodeID(getID(), (Integer) key);
}
return result;
}
};
List<ReferencedFile> deletedFilesInNCDir = getNodeContainerDirectory() == null ? Collections.<ReferencedFile>emptyList() : getNodeContainerDirectory().getDeletedNodesFileLocations();
List<ReferencedFile> deletedFilesInAutoSaveDir = getAutoSaveDirectory() == null ? Collections.<ReferencedFile>emptyList() : getAutoSaveDirectory().getDeletedNodesFileLocations();
for (Map.Entry<Integer, ? extends NodeContainerPersistor> nodeEntry : loaderMap.entrySet()) {
int suffix = nodeEntry.getKey();
NodeID subId = new NodeID(getID(), suffix);
// 100+ workflows simultaneously in a cluster environment)
try (WorkflowLock lock = lock()) {
if (m_workflow.containsNodeKey(subId)) {
subId = m_workflow.createUniqueID();
}
NodeContainerPersistor pers = nodeEntry.getValue();
translationMap.put(suffix, subId);
NodeContainer container = pers.getNodeContainer(this, subId);
NodeContainerMetaPersistor metaPersistor = pers.getMetaPersistor();
ReferencedFile ncRefDir = metaPersistor.getNodeContainerDirectory();
if (ncRefDir != null) {
// the nc dir is in the deleted locations list if the node was deleted and is now restored (undo)
deletedFilesInNCDir.remove(ncRefDir);
deletedFilesInAutoSaveDir.remove(ncRefDir);
}
addNodeContainer(container, false);
if (pers.isDirtyAfterLoad()) {
container.setDirty();
}
}
}
addConnectionsFromTemplates(connections, loadResult, translationMap, true);
return translationMap;
}
Aggregations