Search in sources :

Example 6 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class BinaryServiceImpl method store.

@Override
public AttachedBinary store(final RepositoryId repositoryId, final BinaryAttachment binaryAttachment) {
    final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL);
    final BlobRecord blob = this.blobStore.addRecord(segment, binaryAttachment.getByteSource());
    return new AttachedBinary(binaryAttachment.getReference(), blob.getKey().toString());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) Segment(com.enonic.xp.blob.Segment) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 7 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class AbstractDumpReader method getBinary.

@Override
public ByteSource getBinary(final RepositoryId repositoryId, final String blobKey) {
    final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_BINARY_SEGMENT_LEVEL);
    final DumpBlobRecord record = this.dumpBlobStore.getRecord(segment, BlobKey.from(blobKey));
    if (record == null) {
        throw new RepoLoadException("Cannot find referred blob id " + blobKey + " in dump");
    }
    return record.getBytes();
}
Also used : RepoLoadException(com.enonic.xp.repo.impl.dump.RepoLoadException) DumpBlobRecord(com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord) Segment(com.enonic.xp.blob.Segment)

Example 8 with Segment

use of com.enonic.xp.blob.Segment 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 9 with Segment

use of com.enonic.xp.blob.Segment 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 10 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class NodeVersionServiceImpl method getFromBlob.

private NodeVersion getFromBlob(final NodeVersionKey nodeVersionKey, final InternalContext context) {
    final Segment nodeSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.NODE_SEGMENT_LEVEL);
    final BlobRecord nodeBlobRecord = blobStore.getRecord(nodeSegment, nodeVersionKey.getNodeBlobKey());
    if (nodeBlobRecord == null) {
        throw new IllegalArgumentException("Cannot get node blob with blobKey: " + nodeVersionKey.getNodeBlobKey() + ": blob is null");
    }
    final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.INDEX_CONFIG_SEGMENT_LEVEL);
    final BlobRecord indexConfigBlobRecord = blobStore.getRecord(indexConfigSegment, nodeVersionKey.getIndexConfigBlobKey());
    if (indexConfigBlobRecord == null) {
        throw new IllegalArgumentException("Cannot get index config blob with blobKey: " + nodeVersionKey.getIndexConfigBlobKey() + ": blob is null");
    }
    final Segment accessControlSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.ACCESS_CONTROL_SEGMENT_LEVEL);
    final BlobRecord accessControlBlobRecord = blobStore.getRecord(accessControlSegment, nodeVersionKey.getAccessControlBlobKey());
    if (accessControlBlobRecord == null) {
        throw new IllegalArgumentException("Cannot get access control blob with blobKey: " + nodeVersionKey.getAccessControlBlobKey() + ": blob is null");
    }
    try {
        final byte[] nodeString = nodeBlobRecord.getBytes().read();
        final byte[] indexConfigString = indexConfigBlobRecord.getBytes().read();
        final byte[] accessControlString = accessControlBlobRecord.getBytes().read();
        return this.nodeVersionJsonSerializer.toNodeVersion(nodeString, indexConfigString, accessControlString);
    } catch (IOException e) {
        if (blobStore instanceof CachingBlobStore) {
            ((CachingBlobStore) blobStore).invalidate(indexConfigSegment, nodeBlobRecord.getKey());
            ((CachingBlobStore) blobStore).invalidate(indexConfigSegment, indexConfigBlobRecord.getKey());
            ((CachingBlobStore) blobStore).invalidate(indexConfigSegment, accessControlBlobRecord.getKey());
        }
        throw new RuntimeException("Failed to load blobs with keys: " + nodeBlobRecord.getKey() + ", " + indexConfigBlobRecord.getKey() + ", " + accessControlBlobRecord.getKey(), e);
    }
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) IOException(java.io.IOException) CachingBlobStore(com.enonic.xp.blob.CachingBlobStore) Segment(com.enonic.xp.blob.Segment)

Aggregations

Segment (com.enonic.xp.blob.Segment)28 BlobRecord (com.enonic.xp.blob.BlobRecord)20 Test (org.junit.jupiter.api.Test)15 ByteSource (com.google.common.io.ByteSource)11 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)3 BlobStore (com.enonic.xp.blob.BlobStore)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 Node (com.enonic.xp.node.Node)2 RepoDumpException (com.enonic.xp.repo.impl.dump.RepoDumpException)2 RepoLoadException (com.enonic.xp.repo.impl.dump.RepoLoadException)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 BlobKey (com.enonic.xp.blob.BlobKey)1 CachingBlobStore (com.enonic.xp.blob.CachingBlobStore)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 Pre4NodeVersionJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4NodeVersionJson)1 RepositoryExeption (com.enonic.xp.repository.RepositoryExeption)1