Search in sources :

Example 6 with CloudBlobDirectory

use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project jackrabbit-oak by apache.

the class SegmentTarFixture method getOak.

@Override
public Oak getOak(int clusterId) throws Exception {
    FileStoreBuilder fileStoreBuilder = fileStoreBuilder(parentPath).withMaxFileSize(maxFileSize).withSegmentCacheSize(segmentCacheSize).withMemoryMapping(memoryMapping);
    if (azureConnectionString != null) {
        CloudStorageAccount cloud = CloudStorageAccount.parse(azureConnectionString);
        CloudBlobContainer container = cloud.createCloudBlobClient().getContainerReference(azureContainerName);
        container.createIfNotExists();
        CloudBlobDirectory directory = container.getDirectoryReference(azureRootPath);
        fileStoreBuilder.withCustomPersistence(new AzurePersistence(directory));
    }
    if (useBlobStore) {
        FileDataStore fds = new FileDataStore();
        fds.setMinRecordLength(4092);
        fds.init(parentPath.getAbsolutePath());
        BlobStore blobStore = new DataStoreBlobStore(fds);
        fileStoreBuilder.withBlobStore(blobStore);
    }
    FileStore fs = fileStoreBuilder.build();
    return newOak(SegmentNodeStoreBuilders.builder(fs).build());
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) AzurePersistence(org.apache.jackrabbit.oak.segment.azure.AzurePersistence) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)

Example 7 with CloudBlobDirectory

use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project jackrabbit-oak by apache.

the class AzureArchiveManager method copyFile.

@Override
public void copyFile(String from, String to) throws IOException {
    CloudBlobDirectory targetDirectory = getDirectory(to);
    getBlobs(from).forEach(cloudBlob -> {
        try {
            copyBlob(cloudBlob, targetDirectory);
        } catch (IOException e) {
            log.error("Can't copy segment {}", cloudBlob.getUri().getPath(), e);
        }
    });
}
Also used : CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) IOException(java.io.IOException)

Example 8 with CloudBlobDirectory

use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project jackrabbit-oak by apache.

the class SegmentAzureFixture method createNodeStore.

@Override
public NodeStore createNodeStore() {
    AzurePersistence persistence;
    CloudBlobContainer container;
    try {
        CloudStorageAccount cloud = CloudStorageAccount.parse(AZURE_CONNECTION_STRING);
        int i = 1;
        while (true) {
            String containerName;
            if (i == 1) {
                containerName = AZURE_CONTAINER;
            } else {
                containerName = AZURE_CONTAINER + "_" + i;
            }
            container = cloud.createCloudBlobClient().getContainerReference(containerName);
            if (!container.exists()) {
                container.create();
                break;
            }
            i++;
        }
        CloudBlobDirectory directory = container.getDirectoryReference(AZURE_ROOT_PATH);
        persistence = new AzurePersistence(directory);
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
    try {
        FileStore fileStore = FileStoreBuilder.fileStoreBuilder(Files.createTempDir()).withCustomPersistence(persistence).build();
        NodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
        fileStoreMap.put(nodeStore, fileStore);
        containerMap.put(nodeStore, container);
        return nodeStore;
    } catch (IOException | InvalidFileStoreVersionException e) {
        throw new RuntimeException(e);
    }
}
Also used : AzurePersistence(org.apache.jackrabbit.oak.segment.azure.AzurePersistence) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageException(com.microsoft.azure.storage.StorageException)

Example 9 with CloudBlobDirectory

use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project jackrabbit-oak by apache.

the class AzurePersistence method segmentFilesExist.

@Override
public boolean segmentFilesExist() {
    try {
        for (ListBlobItem i : segmentstoreDirectory.listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), null, null)) {
            if (i instanceof CloudBlobDirectory) {
                CloudBlobDirectory dir = (CloudBlobDirectory) i;
                String name = Paths.get(dir.getPrefix()).getFileName().toString();
                if (name.endsWith(".tar")) {
                    return true;
                }
            }
        }
        return false;
    } catch (StorageException | URISyntaxException e) {
        log.error("Can't check if the segment archives exists", e);
        return false;
    }
}
Also used : BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Example 10 with CloudBlobDirectory

use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project jackrabbit-oak by apache.

the class AzureBlobStoreBackend method addMetadataRecordImpl.

private void addMetadataRecordImpl(final InputStream input, String name, long recordLength) throws DataStoreException {
    try {
        CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
        CloudBlockBlob blob = metaDir.getBlockBlobReference(name);
        blob.upload(input, recordLength);
    } catch (StorageException e) {
        LOG.info("Error adding metadata record. metadataName={} length={}", name, recordLength, e);
        throw new DataStoreException(e);
    } catch (URISyntaxException | IOException e) {
        throw new DataStoreException(e);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)12 StorageException (com.microsoft.azure.storage.StorageException)6 URISyntaxException (java.net.URISyntaxException)6 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)5 IOException (java.io.IOException)5 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)4 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)4 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)3 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)3 AzurePersistence (org.apache.jackrabbit.oak.segment.azure.AzurePersistence)3 BlobListingDetails (com.microsoft.azure.storage.blob.BlobListingDetails)2 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)2 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)2 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)2 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)2 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1