Search in sources :

Example 1 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class AzureBlobStoreBackend method getAllMetadataRecords.

@Override
public List<DataRecord> getAllMetadataRecords(String prefix) {
    if (null == prefix) {
        throw new NullPointerException("prefix");
    }
    long start = System.currentTimeMillis();
    final List<DataRecord> records = Lists.newArrayList();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
        for (ListBlobItem item : metaDir.listBlobs(prefix)) {
            if (item instanceof CloudBlob) {
                CloudBlob blob = (CloudBlob) item;
                records.add(new AzureBlobStoreDataRecord(this, connectionString, containerName, new DataIdentifier(stripMetaKeyPrefix(blob.getName())), blob.getProperties().getLastModified().getTime(), blob.getProperties().getLength(), true));
            }
        }
        LOG.debug("Metadata records read. recordsRead={} metadataFolder={} duration={}", records.size(), prefix, (System.currentTimeMillis() - start));
    } catch (StorageException e) {
        LOG.info("Error reading all metadata records. metadataFolder={}", prefix, e);
    } catch (DataStoreException | URISyntaxException e) {
        LOG.debug("Error reading all metadata records. metadataFolder={}", prefix, e);
    } finally {
        if (null != contextClassLoader) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
    return records;
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URISyntaxException(java.net.URISyntaxException) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) AbstractDataRecord(org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord) StorageException(com.microsoft.azure.storage.StorageException)

Example 2 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class AzureDataStoreTest method testCreateAndDeleteBlobHappyPath.

@Test
public void testCreateAndDeleteBlobHappyPath() throws DataStoreException, IOException {
    final DataRecord uploadedRecord = ds.addRecord(new ByteArrayInputStream(testBuffer));
    DataIdentifier identifier = uploadedRecord.getIdentifier();
    assertTrue(backend.exists(identifier));
    assertTrue(0 != uploadedRecord.getLastModified());
    assertEquals(testBuffer.length, uploadedRecord.getLength());
    final DataRecord retrievedRecord = ds.getRecord(identifier);
    validateRecord(retrievedRecord, new String(testBuffer), uploadedRecord);
    ds.deleteRecord(identifier);
    assertFalse(backend.exists(uploadedRecord.getIdentifier()));
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) Test(org.junit.Test)

Example 3 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class AzureDataStoreTest method testCreateAndReUploadBlob.

@Test
public void testCreateAndReUploadBlob() throws DataStoreException, IOException {
    final DataRecord createdRecord = ds.addRecord(new ByteArrayInputStream(testBuffer));
    DataIdentifier identifier1 = createdRecord.getIdentifier();
    assertTrue(backend.exists(identifier1));
    final DataRecord record1 = ds.getRecord(identifier1);
    validateRecord(record1, new String(testBuffer), createdRecord);
    try {
        Thread.sleep(1001);
    } catch (InterruptedException e) {
    }
    final DataRecord updatedRecord = ds.addRecord(new ByteArrayInputStream(testBuffer));
    DataIdentifier identifier2 = updatedRecord.getIdentifier();
    assertTrue(backend.exists(identifier2));
    assertTrue(identifier1.toString().equals(identifier2.toString()));
    validateRecord(record1, new String(testBuffer), createdRecord);
    ds.deleteRecord(identifier1);
    assertFalse(backend.exists(createdRecord.getIdentifier()));
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) Test(org.junit.Test)

Example 4 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class TestS3DataStore method testNoSecretDefined.

@Test
public void testNoSecretDefined() throws Exception {
    assumeTrue(isS3Configured());
    assumeTrue(s3Class.equals(S3DataStoreUtils.JR2_S3.getName()));
    Random randomGen = new Random();
    props = S3DataStoreUtils.getS3Config();
    ds = getS3DataStore(s3Class, props, dataStoreDir.getAbsolutePath());
    byte[] data = new byte[4096];
    randomGen.nextBytes(data);
    DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
    assertEquals(data.length, rec.getLength());
    assertNull(rec.getReference());
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) Test(org.junit.Test)

Example 5 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class DataStoreBlobStore method getBlobId.

@Override
public String getBlobId(@Nonnull String reference) {
    checkNotNull(reference);
    DataRecord record;
    try {
        record = delegate.getRecordFromReference(reference);
        if (record != null) {
            return getBlobId(record);
        }
    } catch (DataStoreException e) {
        log.warn("Unable to access the blobId for  [{}]", reference, e);
    }
    return null;
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Aggregations

DataRecord (org.apache.jackrabbit.core.data.DataRecord)80 Test (org.junit.Test)45 ByteArrayInputStream (java.io.ByteArrayInputStream)38 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)30 File (java.io.File)24 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)20 FileInputStream (java.io.FileInputStream)17 Random (java.util.Random)13 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)6 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)6 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)6 IOException (java.io.IOException)4 AbstractBlobStoreTest (org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest)4 AbstractDataRecord (org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord)4 Function (com.google.common.base.Function)3 SequenceInputStream (java.io.SequenceInputStream)3 Mac (javax.crypto.Mac)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 RepositoryException (javax.jcr.RepositoryException)3