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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations