Search in sources :

Example 1 with EmptyFileStoreHandler

use of org.knime.core.data.filestore.internal.EmptyFileStoreHandler 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 2 with EmptyFileStoreHandler

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

the class Buffer method readMetaFromFile.

/**
 * Reads meta information, that is row count, version, byte assignments.
 *
 * @param metaIn To read from.
 * @throws IOException If reading fails.
 * @throws ClassNotFoundException If any of the classes can't be loaded.
 * @throws InvalidSettingsException If the internal structure is broken.
 */
private void readMetaFromFile(final InputStream metaIn, final File fileStoreDir) throws IOException, InvalidSettingsException {
    try (InputStream inStream = new BufferedInputStream(metaIn)) {
        NodeSettingsRO settings = NodeSettings.loadFromXML(inStream);
        NodeSettingsRO subSettings = settings.getNodeSettings(CFG_INTERNAL_META);
        String version = subSettings.getString(CFG_VERSION);
        m_version = validateVersion(version);
        if (subSettings.containsKey(CFG_SIZE_L)) {
            m_size = subSettings.getLong(CFG_SIZE_L);
        } else {
            m_size = subSettings.getInt(CFG_SIZE);
        }
        if (m_size < 0) {
            throw new IOException("Table size must not be < 0: " + m_size);
        }
        // added sometime between format 8 and 9
        m_containsBlobs = false;
        if (m_version >= 4) {
            // no blobs in version 1.1.x
            m_containsBlobs = subSettings.getBoolean(CFG_CONTAINS_BLOBS);
            int bufferID = subSettings.getInt(CFG_BUFFER_ID);
            // bufferID of -1. 1.0.0 contain no blobs, so that's ok.
            if (m_containsBlobs && bufferID != m_bufferID) {
                LOGGER.error("Table's buffer id is different from what has" + " been passed in constructor (" + bufferID + " vs. " + m_bufferID + "), unpredictable errors may occur");
            }
        }
        IFileStoreHandler fileStoreHandler = new EmptyFileStoreHandler(m_fileStoreHandlerRepository);
        if (m_version >= 8) {
            // file stores added between version 8 and 9
            String fileStoresUUIDS = subSettings.getString(CFG_FILESTORES_UUID, null);
            UUID fileStoresUUID = null;
            if (fileStoresUUIDS != null) {
                try {
                    fileStoresUUID = UUID.fromString(fileStoresUUIDS);
                } catch (IllegalArgumentException iae) {
                    throw new InvalidSettingsException("Can't parse UUID " + fileStoresUUIDS, iae);
                }
            }
            if (fileStoresUUID != null) {
                NotInWorkflowWriteFileStoreHandler notInWorkflowFSH = new NotInWorkflowWriteFileStoreHandler(fileStoresUUID, m_fileStoreHandlerRepository);
                notInWorkflowFSH.setBaseDir(fileStoreDir);
                fileStoreHandler = notInWorkflowFSH;
            }
        }
        m_fileStoreHandler = fileStoreHandler;
        if (m_version >= 8) {
            // with buffer version 8 (> 2.0)
            if (subSettings.getBoolean(CFG_IS_IN_MEMORY)) {
                restoreIntoMemory();
            }
        }
        String outputFormat = subSettings.getString(CFG_TABLE_FORMAT, DefaultTableStoreFormat.class.getName());
        m_outputFormat = TableStoreFormatRegistry.getInstance().getTableStoreFormat(outputFormat).orElseThrow(() -> new InvalidSettingsException(String.format("Invalid table format '%s' - unable to restore table.", outputFormat)));
        NodeSettingsRO outputFormatSettings = m_version >= 10 ? subSettings.getNodeSettings(CFG_TABLE_FORMAT_CONFIG) : subSettings;
        initOutputReader(outputFormatSettings, m_version);
    }
}
Also used : NotInWorkflowWriteFileStoreHandler(org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EmptyFileStoreHandler(org.knime.core.data.filestore.internal.EmptyFileStoreHandler) IOException(java.io.IOException) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)2 EmptyFileStoreHandler (org.knime.core.data.filestore.internal.EmptyFileStoreHandler)2 IFileStoreHandler (org.knime.core.data.filestore.internal.IFileStoreHandler)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ZipInputStream (java.util.zip.ZipInputStream)1 NotInWorkflowWriteFileStoreHandler (org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler)1 ReferencedFile (org.knime.core.internal.ReferencedFile)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1