use of com.microsoft.azure.storage.blob.CloudBlobClient in project cloudbreak by hortonworks.
the class AzureClient method getBlobContainer.
public CloudBlobContainer getBlobContainer(String resourceGroup, String storageName, String containerName) {
LOGGER.debug("get blob container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
List<StorageAccountKey> keys = getStorageAccountKeys(resourceGroup, storageName);
String storageConnectionString = String.format("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s", storageName, keys.get(0).value());
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
return blobClient.getContainerReference(containerName);
} catch (URISyntaxException e) {
throw new CloudConnectorException("can't get blob container, URI is not valid", e);
} catch (InvalidKeyException e) {
throw new CloudConnectorException("can't get blob container, credentials in the connection string contain an invalid key", e);
} catch (StorageException e) {
throw new CloudConnectorException("can't get blob container, storage service error occurred", e);
}
}
use of com.microsoft.azure.storage.blob.CloudBlobClient in project cloudbreak by hortonworks.
the class FilesystemUtil method createWasbContainer.
static void createWasbContainer(Map<String, String> cloudProviderParams, String accountName, String containerName) {
try {
String storageConnectionString = "DefaultEndpointsProtocol=http;" + "AccountName=" + accountName + ";AccountKey=" + cloudProviderParams.get("accountKeyWasb");
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);
container.createIfNotExists();
} catch (URISyntaxException e) {
LOGGER.error("Error during creating the Wasb container, wrong URI syntax ", e);
} catch (InvalidKeyException e) {
LOGGER.error("Error during creating the Wasb container, invalid key ", e);
} catch (StorageException e) {
LOGGER.error("Error during creating the Wasb container, problem with storage ", e);
}
}
use of com.microsoft.azure.storage.blob.CloudBlobClient in project cloudbreak by hortonworks.
the class FilesystemUtil method deleteWasbContainer.
private static void deleteWasbContainer(Map<String, String> cloudProviderParams, String accountName, String containerName) {
try {
String storageConnectionString = "DefaultEndpointsProtocol=http;" + "AccountName=" + accountName + ";AccountKey=" + cloudProviderParams.get("accountKeyWasb");
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);
container.deleteIfExists();
} catch (URISyntaxException e) {
LOGGER.error("Error during deleting the Wasb container, wrong URI syntax ", e);
} catch (InvalidKeyException e) {
LOGGER.error("Error during deleting the Wasb container, invalid key ", e);
} catch (StorageException e) {
LOGGER.error("Error during deleting the Wasb container, problem with storage ", e);
}
}
use of com.microsoft.azure.storage.blob.CloudBlobClient in project azure-tools-for-java by Microsoft.
the class JxBrowserUtil method downloadFromAzure.
/**
* Download file from Azure and save to target path specified. Return true if download succeeds
* @param filePathName
* @return
*/
private static Boolean downloadFromAzure(@NotNull Path filePathName) {
boolean result = true;
try {
URI cloudBlobUri = new URI(AZURE_BLOB_URI);
CloudBlobClient serviceClient = new CloudBlobClient(cloudBlobUri);
CloudBlobContainer container = serviceClient.getContainerReference("libcontainer1");
CloudBlockBlob blob = container.getBlockBlobReference(filePathName.getFileName().toString());
File downloadingFile = filePathName.toFile();
blob.downloadToFile(downloadingFile.getAbsolutePath());
} catch (Exception e) {
result = false;
log.warning("Fail to download file from Azure: " + e.getMessage());
}
return result;
}
use of com.microsoft.azure.storage.blob.CloudBlobClient 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()));
}
}
registryManager.close();
System.out.println("Export job completed. Results are in " + SampleUtils.exportFileLocation);
}
Aggregations