Search in sources :

Example 1 with CloudBlobDirectory

use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project tdi-studio-se by Talend.

the class AzureFileSystem method deleteFolder.

public void deleteFolder(String folder, CloudBlobContainer container) throws StorageException, URISyntaxException {
    for (ListBlobItem blobItem : container.listBlobs(folder)) {
        if (blobItem instanceof CloudBlob) {
            CloudBlob blob = (CloudBlob) blobItem;
            blob.delete();
        } else {
            if (blobItem instanceof CloudBlobDirectory)
                deleteFolder(((CloudBlobDirectory) blobItem).getPrefix(), container);
        }
    }
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory)

Example 2 with CloudBlobDirectory

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

the class AzureBlobStoreBackend method deleteAllMetadataRecords.

@Override
public void deleteAllMetadataRecords(String prefix) {
    if (null == prefix) {
        throw new NullPointerException("prefix");
    }
    long start = System.currentTimeMillis();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
        int total = 0;
        for (ListBlobItem item : metaDir.listBlobs(prefix)) {
            if (item instanceof CloudBlob) {
                if (((CloudBlob) item).deleteIfExists()) {
                    total++;
                }
            }
        }
        LOG.debug("Metadata records deleted. recordsDeleted={} metadataFolder={} duration={}", total, prefix, (System.currentTimeMillis() - start));
    } catch (StorageException e) {
        LOG.info("Error deleting all metadata records. metadataFolder={}", prefix, e);
    } catch (DataStoreException | URISyntaxException e) {
        LOG.debug("Error deleting all metadata records. metadataFolder={}", prefix, e);
    } finally {
        if (null != contextClassLoader) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) 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 3 with CloudBlobDirectory

use of com.microsoft.azure.storage.blob.CloudBlobDirectory 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 4 with CloudBlobDirectory

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

the class AzureArchiveManager method renameTo.

@Override
public boolean renameTo(String from, String to) {
    try {
        CloudBlobDirectory targetDirectory = getDirectory(to);
        getBlobs(from).forEach(cloudBlob -> {
            try {
                renameBlob(cloudBlob, targetDirectory);
            } catch (IOException e) {
                log.error("Can't rename segment {}", cloudBlob.getUri().getPath(), e);
            }
        });
        return true;
    } catch (IOException e) {
        log.error("Can't rename archive {} to {}", from, to, e);
        return false;
    }
}
Also used : CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) IOException(java.io.IOException)

Example 5 with CloudBlobDirectory

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

the class AzureBlobStoreBackend method getMetadataRecord.

@Override
public DataRecord getMetadataRecord(String name) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    long start = System.currentTimeMillis();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
        CloudBlockBlob blob = metaDir.getBlockBlobReference(name);
        if (!blob.exists()) {
            LOG.warn("Trying to read missing metadata. metadataName={}", name);
            return null;
        }
        blob.downloadAttributes();
        long lastModified = blob.getProperties().getLastModified().getTime();
        long length = blob.getProperties().getLength();
        AzureBlobStoreDataRecord record = new AzureBlobStoreDataRecord(this, connectionString, containerName, new DataIdentifier(name), lastModified, length, true);
        LOG.debug("Metadata record read. metadataName={} duration={} record={}", name, (System.currentTimeMillis() - start), record);
        return record;
    } catch (StorageException e) {
        LOG.info("Error reading metadata record. metadataName={}", name, e);
        throw new RuntimeException(e);
    } catch (Exception e) {
        LOG.debug("Error reading metadata record. metadataName={}", name, e);
        throw new RuntimeException(e);
    } finally {
        if (null != contextClassLoader) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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