use of com.microsoft.azure.storage.blob.CloudBlobContainer 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);
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project azure-sdk-for-java by Azure.
the class ManageLinuxWebAppStorageAccountConnection method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
// New resources
final String suffix = ".azurewebsites.net";
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app1Url = app1Name + suffix;
final String storageName = SdkContext.randomResourceName("jsdkstore", 20);
final String containerName = SdkContext.randomResourceName("jcontainer", 20);
final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
try {
//============================================================
// Create a storage account for the web app to use
System.out.println("Creating storage account " + storageName + "...");
StorageAccount storageAccount = azure.storageAccounts().define(storageName).withRegion(Region.US_WEST).withNewResourceGroup(rgName).create();
String accountKey = storageAccount.getKeys().get(0).value();
String connectionString = String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s", storageAccount.name(), accountKey);
System.out.println("Created storage account " + storageAccount.name());
//============================================================
// Upload a few files to the storage account blobs
System.out.println("Uploading 2 blobs to container " + containerName + "...");
CloudBlobContainer container = setUpStorageAccount(connectionString, containerName);
uploadFileToContainer(container, "helloworld.war", ManageLinuxWebAppStorageAccountConnection.class.getResource("/helloworld.war").getPath());
uploadFileToContainer(container, "install_apache.sh", ManageLinuxWebAppStorageAccountConnection.class.getResource("/install_apache.sh").getPath());
System.out.println("Uploaded 2 blobs to container " + container.getName());
//============================================================
// Create a web app with a new app service plan
System.out.println("Creating web app " + app1Name + "...");
WebApp app1 = azure.webApps().define(app1Name).withRegion(Region.US_WEST).withExistingResourceGroup(rgName).withNewLinuxPlan(PricingTier.STANDARD_S1).withPublicDockerHubImage("tomcat:8-jre8").withStartUpCommand("/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"").withConnectionString("storage.connectionString", connectionString, ConnectionStringType.CUSTOM).withAppSetting("storage.containerName", containerName).withAppSetting("PORT", "8080").create();
System.out.println("Created web app " + app1.name());
Utils.print(app1);
//============================================================
// Deploy a web app that connects to the storage account
// Source code: https://github.com/jianghaolu/azure-samples-blob-explorer
System.out.println("Deploying azure-samples-blob-traverser.war to " + app1Name + " through FTP...");
Utils.uploadFileToFtp(app1.getPublishingProfile(), "azure-samples-blob-traverser.war", ManageLinuxWebAppStorageAccountConnection.class.getResourceAsStream("/azure-samples-blob-traverser.war"));
System.out.println("Deployment azure-samples-blob-traverser.war to web app " + app1.name() + " completed");
Utils.print(app1);
// warm up
System.out.println("Warming up " + app1Url + "/azure-samples-blob-traverser...");
curl("http://" + app1Url + "/azure-samples-blob-traverser");
Thread.sleep(5000);
System.out.println("CURLing " + app1Url + "/azure-samples-blob-traverser...");
System.out.println(curl("http://" + app1Url + "/azure-samples-blob-traverser"));
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method init.
@Override
public void init() throws DataStoreException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
long start = System.currentTimeMillis();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
LOG.debug("Started backend initialization");
if (null == properties) {
try {
properties = Utils.readConfig(Utils.DEFAULT_CONFIG_FILE);
} catch (IOException e) {
throw new DataStoreException("Unable to initialize Azure Data Store from " + Utils.DEFAULT_CONFIG_FILE, e);
}
}
secret = properties.getProperty("secret");
try {
Utils.setProxyIfNeeded(properties);
containerName = (String) properties.get(AzureConstants.AZURE_BLOB_CONTAINER_NAME);
connectionString = Utils.getConnectionStringFromProperties(properties);
concurrentRequestCount = PropertiesUtil.toInteger(properties.get(AzureConstants.AZURE_BLOB_CONCURRENT_REQUESTS_PER_OPERATION), 1);
LOG.info("Using concurrentRequestsPerOperation={}", concurrentRequestCount);
retryPolicy = Utils.getRetryPolicy((String) properties.get(AzureConstants.AZURE_BLOB_MAX_REQUEST_RETRY));
if (properties.getProperty(AzureConstants.AZURE_BLOB_REQUEST_TIMEOUT) != null) {
requestTimeout = PropertiesUtil.toInteger(properties.getProperty(AzureConstants.AZURE_BLOB_REQUEST_TIMEOUT), RetryPolicy.DEFAULT_CLIENT_RETRY_COUNT);
}
CloudBlobContainer azureContainer = getAzureContainer();
if (azureContainer.createIfNotExists()) {
LOG.info("New container created. containerName={}", containerName);
} else {
LOG.info("Reusing existing container. containerName={}", containerName);
}
LOG.debug("Backend initialized. duration={}", +(System.currentTimeMillis() - start));
} catch (StorageException e) {
throw new DataStoreException(e);
}
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project druid by druid-io.
the class AzureStorage method uploadBlob.
public void uploadBlob(final File file, final String containerName, final String blobPath) throws IOException, StorageException, URISyntaxException {
CloudBlobContainer container = getCloudBlobContainer(containerName);
try (FileInputStream stream = new FileInputStream(file)) {
CloudBlockBlob blob = container.getBlockBlobReference(blobPath);
blob.upload(stream, file.length());
}
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project druid by druid-io.
the class AzureStorage method getCloudBlobContainer.
public CloudBlobContainer getCloudBlobContainer(final String containerName) throws StorageException, URISyntaxException {
CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
cloudBlobContainer.createIfNotExists();
return cloudBlobContainer;
}
Aggregations