Search in sources :

Example 6 with ListBlobItem

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

use of com.microsoft.azure.storage.blob.ListBlobItem in project azure-iot-sdk-java by Azure.

the class DeviceManagerExportSample method main.

public static void main(String[] args) throws Exception {
    System.out.println("Starting export sample...");
    CloudStorageAccount storageAccount = CloudStorageAccount.parse(SampleUtils.storageConnectionString);
    CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference(DeviceManagerExportSample.sampleContainerName);
    container.createIfNotExists();
    String containerSasUri = SampleUtils.getContainerSasUri(container);
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    JobProperties exportJob = registryManager.exportDevices(containerSasUri, excludeKeys);
    while (true) {
        exportJob = registryManager.getJob(exportJob.getJobId());
        if (exportJob.getStatus() == JobProperties.JobStatus.COMPLETED) {
            break;
        }
        Thread.sleep(500);
    }
    for (ListBlobItem blobItem : container.listBlobs()) {
        if (blobItem instanceof CloudBlob) {
            CloudBlob blob = (CloudBlob) blobItem;
            blob.download(new FileOutputStream(SampleUtils.exportFileLocation + blob.getName()));
        }
    }
    System.out.println("Export job completed. Results are in " + SampleUtils.exportFileLocation);
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) JobProperties(com.microsoft.azure.sdk.iot.service.JobProperties) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) FileOutputStream(java.io.FileOutputStream) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

Example 8 with ListBlobItem

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

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

use of com.microsoft.azure.storage.blob.ListBlobItem in project druid by druid-io.

the class AzureStorage method emptyCloudBlobDirectory.

public List<String> emptyCloudBlobDirectory(final String containerName, final String virtualDirPath) throws StorageException, URISyntaxException {
    List<String> deletedFiles = new ArrayList<>();
    CloudBlobContainer container = getCloudBlobContainer(containerName);
    for (ListBlobItem blobItem : container.listBlobs(virtualDirPath, true, null, null, null)) {
        CloudBlob cloudBlob = (CloudBlob) blobItem;
        log.info("Removing file[%s] from Azure.", cloudBlob.getName());
        if (cloudBlob.deleteIfExists()) {
            deletedFiles.add(cloudBlob.getName());
        }
    }
    if (deletedFiles.isEmpty()) {
        log.warn("No files were deleted on the following Azure path: [%s]", virtualDirPath);
    }
    return deletedFiles;
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) ArrayList(java.util.ArrayList) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

Aggregations

ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)11 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)5 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)5 StorageException (com.microsoft.azure.storage.StorageException)4 BlobProperties (com.microsoft.azure.storage.blob.BlobProperties)4 URISyntaxException (java.net.URISyntaxException)4 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)3 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)3 CloudBlobWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper)3 CloudBlockBlobWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudBlockBlobWrapper)3 CloudPageBlobWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudPageBlobWrapper)3 BlobListingDetails (com.microsoft.azure.storage.blob.BlobListingDetails)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 ArrayList (java.util.ArrayList)2 CloudBlobDirectoryWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudBlobDirectoryWrapper)2 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)2 JobProperties (com.microsoft.azure.sdk.iot.service.JobProperties)1 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)1