Search in sources :

Example 1 with CloudBlob

use of com.microsoft.azure.storage.blob.CloudBlob in project hadoop by apache.

the class NativeAzureFileSystemBaseTest method testSelfRenewingLease.

@Test
public // timeout, to make sure the lease renews itself.
void testSelfRenewingLease() throws IllegalArgumentException, IOException, InterruptedException, StorageException {
    SelfRenewingLease lease;
    final String FILE_KEY = "file";
    fs.create(new Path(FILE_KEY));
    NativeAzureFileSystem nfs = (NativeAzureFileSystem) fs;
    String fullKey = nfs.pathToKey(nfs.makeAbsolute(new Path(FILE_KEY)));
    AzureNativeFileSystemStore store = nfs.getStore();
    lease = store.acquireLease(fullKey);
    assertTrue(lease.getLeaseID() != null);
    // The sleep time for the keep-alive thread is 40 seconds, so sleep just
    // a little beyond that, to make sure the keep-alive thread wakes up
    // and renews the lease.
    Thread.sleep(42000);
    lease.free();
    // Check that the lease is really freed.
    CloudBlob blob = lease.getCloudBlob();
    // Try to acquire it again, using direct Azure blob access.
    // If that succeeds, then the lease was already freed.
    String differentLeaseID = null;
    try {
        differentLeaseID = blob.acquireLease(15, null);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Caught exception trying to directly re-acquire lease from Azure");
    } finally {
        assertTrue(differentLeaseID != null);
        AccessCondition accessCondition = AccessCondition.generateEmptyCondition();
        accessCondition.setLeaseID(differentLeaseID);
        blob.releaseLease(accessCondition);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) AccessCondition(com.microsoft.azure.storage.AccessCondition) StorageException(com.microsoft.azure.storage.StorageException) AzureException(org.apache.hadoop.fs.azure.AzureException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 2 with CloudBlob

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

use of com.microsoft.azure.storage.blob.CloudBlob in project azure-sdk-for-java by Azure.

the class ManageLinuxWebAppStorageAccountConnection method uploadFileToContainer.

private static void uploadFileToContainer(CloudBlobContainer container, String fileName, String filePath) {
    try {
        CloudBlob blob = container.getBlockBlobReference(fileName);
        blob.uploadFromFile(filePath);
    } catch (StorageException | URISyntaxException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Example 4 with CloudBlob

use of com.microsoft.azure.storage.blob.CloudBlob in project azure-sdk-for-java by Azure.

the class ManageWebAppStorageAccountConnection method uploadFileToContainer.

private static void uploadFileToContainer(CloudBlobContainer container, String fileName, String filePath) {
    try {
        CloudBlob blob = container.getBlockBlobReference(fileName);
        blob.uploadFromFile(filePath);
    } catch (StorageException | URISyntaxException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with CloudBlob

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

Aggregations

CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)24 StorageException (com.microsoft.azure.storage.StorageException)12 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)12 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)11 URISyntaxException (java.net.URISyntaxException)9 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)3 BlobProperties (com.microsoft.azure.storage.blob.BlobProperties)3 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)3 InputStream (java.io.InputStream)3 FlowFile (org.apache.nifi.flowfile.FlowFile)3 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)2 BlobListingDetails (com.microsoft.azure.storage.blob.BlobListingDetails)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2