Search in sources :

Example 1 with RepoDumpException

use of com.enonic.xp.repo.impl.dump.RepoDumpException in project xp by enonic.

the class AbstractDumpReader method doLoadEntries.

private EntriesLoadResult doLoadEntries(final LineProcessor<EntryLoadResult> processor, final PathRef tarFile) {
    final EntriesLoadResult.Builder result = EntriesLoadResult.create();
    try (TarArchiveInputStream tarInputStream = openStream(tarFile)) {
        TarArchiveEntry entry = tarInputStream.getNextTarEntry();
        while (entry != null) {
            final EntryLoadResult entryLoadResult = handleEntry(processor, tarInputStream);
            result.add(entryLoadResult);
            entry = tarInputStream.getNextTarEntry();
        }
    } catch (IOException e) {
        throw new RepoDumpException("Cannot read meta-data", e);
    }
    return result.build();
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 2 with RepoDumpException

use of com.enonic.xp.repo.impl.dump.RepoDumpException in project xp by enonic.

the class AbstractDumpUpgrader method processEntries.

public void processEntries(final BiConsumer<String, String> processor, final Path tarFile) {
    try (TarArchiveInputStream tarInputStream = openStream(tarFile)) {
        TarArchiveEntry entry = tarInputStream.getNextTarEntry();
        while (entry != null) {
            String entryContent = new String(tarInputStream.readAllBytes(), StandardCharsets.UTF_8);
            processor.accept(entryContent, entry.getName());
            entry = tarInputStream.getNextTarEntry();
        }
    } catch (IOException e) {
        throw new RepoDumpException("Cannot read meta-data", e);
    }
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException) IOException(java.io.IOException) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 3 with RepoDumpException

use of com.enonic.xp.repo.impl.dump.RepoDumpException in project xp by enonic.

the class AbstractDumpWriter method writeBinaryBlob.

@Override
public void writeBinaryBlob(final RepositoryId repositoryId, final BlobKey blobKey) {
    final Segment dumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_BINARY_SEGMENT_LEVEL);
    final BlobRecord binaryRecord = blobStore.getRecord(dumpSegment, blobKey);
    if (binaryRecord == null) {
        throw new RepoDumpException("Cannot write binary with key [" + blobKey + "], not found in blobStore");
    }
    final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL);
    this.dumpBlobStore.addRecord(segment, binaryRecord.getBytes());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException) Segment(com.enonic.xp.blob.Segment)

Example 4 with RepoDumpException

use of com.enonic.xp.repo.impl.dump.RepoDumpException in project xp by enonic.

the class AbstractDumpWriter method writeNodeVersionBlobs.

@Override
public void writeNodeVersionBlobs(final RepositoryId repositoryId, final NodeVersionKey nodeVersionKey) {
    final Segment nodeDumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_NODE_SEGMENT_LEVEL);
    final BlobRecord existingNodeBlobRecord = blobStore.getRecord(nodeDumpSegment, nodeVersionKey.getNodeBlobKey());
    if (existingNodeBlobRecord == null) {
        throw new RepoDumpException("Cannot write node blob with key [" + nodeVersionKey.getNodeBlobKey() + "], not found in blobStore");
    }
    final Segment indexConfigDumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_INDEX_CONFIG_SEGMENT_LEVEL);
    final BlobRecord existingIndexConfigBlobRecord = blobStore.getRecord(indexConfigDumpSegment, nodeVersionKey.getIndexConfigBlobKey());
    if (existingIndexConfigBlobRecord == null) {
        throw new RepoDumpException("Cannot write index config blob with key [" + nodeVersionKey.getIndexConfigBlobKey() + "], not found in blobStore");
    }
    final Segment accessControlDumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_ACCESS_CONTROL_SEGMENT_LEVEL);
    final BlobRecord existingAccessControlBlobRecord = blobStore.getRecord(accessControlDumpSegment, nodeVersionKey.getAccessControlBlobKey());
    if (existingAccessControlBlobRecord == null) {
        throw new RepoDumpException("Cannot write access control blob with key [" + nodeVersionKey.getAccessControlBlobKey() + "], not found in blobStore");
    }
    final Segment nodeSegment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.NODE_SEGMENT_LEVEL);
    this.dumpBlobStore.addRecord(nodeSegment, existingNodeBlobRecord.getBytes());
    final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.INDEX_CONFIG_SEGMENT_LEVEL);
    this.dumpBlobStore.addRecord(indexConfigSegment, existingIndexConfigBlobRecord.getBytes());
    final Segment accessControlSegment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.ACCESS_CONTROL_SEGMENT_LEVEL);
    this.dumpBlobStore.addRecord(accessControlSegment, existingAccessControlBlobRecord.getBytes());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException) Segment(com.enonic.xp.blob.Segment)

Example 5 with RepoDumpException

use of com.enonic.xp.repo.impl.dump.RepoDumpException in project xp by enonic.

the class AbstractDumpWriter method openTarStream.

private void openTarStream(final PathRef metaPath) {
    try {
        this.tarOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(openMetaFileStream(metaPath)));
        this.tarOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    } catch (Exception e) {
        throw new RepoDumpException("Could not open meta-file", e);
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) IOException(java.io.IOException) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException)

Aggregations

RepoDumpException (com.enonic.xp.repo.impl.dump.RepoDumpException)6 IOException (java.io.IOException)4 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)3 BlobRecord (com.enonic.xp.blob.BlobRecord)2 Segment (com.enonic.xp.blob.Segment)2 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)2 UncheckedIOException (java.io.UncheckedIOException)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)1