Search in sources :

Example 11 with ReferencedFile

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);
}
Also used : ReferencedFile(org.knime.core.internal.ReferencedFile)

Example 12 with ReferencedFile

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;
    }
}
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 13 with ReferencedFile

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);
        }
    }
}
Also used : InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) IOException(java.io.IOException) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) ReferencedFile(org.knime.core.internal.ReferencedFile) PortType(org.knime.core.node.port.PortType)

Example 14 with ReferencedFile

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);
                    }
                }
            });
        }
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ReferencedFile(org.knime.core.internal.ReferencedFile)

Example 15 with ReferencedFile

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;
}
Also used : ReferencedFile(org.knime.core.internal.ReferencedFile) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) LinkedHashMap(java.util.LinkedHashMap) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Aggregations

ReferencedFile (org.knime.core.internal.ReferencedFile)46 File (java.io.File)29 IOException (java.io.IOException)22 BufferedInputStream (java.io.BufferedInputStream)11 FileInputStream (java.io.FileInputStream)11 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 PortObject (org.knime.core.node.port.PortObject)8 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)8 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)7 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)7 HashMap (java.util.HashMap)6 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)6 FileOutputStream (java.io.FileOutputStream)5 Map (java.util.Map)5 ContainerTable (org.knime.core.data.container.ContainerTable)5 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)5 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)5 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4