Search in sources :

Example 1 with BlobServiceClient

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

the class ExportImportTests method setUp.

@BeforeClass
public static void setUp() throws IOException {
    iotHubConnectionString = Tools.retrieveEnvironmentVariableValue(TestConstants.IOT_HUB_CONNECTION_STRING_ENV_VAR_NAME);
    isBasicTierHub = Boolean.parseBoolean(Tools.retrieveEnvironmentVariableValue(TestConstants.IS_BASIC_TIER_HUB_ENV_VAR_NAME));
    storageAccountConnectionString = Tools.retrieveEnvironmentVariableValue(TestConstants.STORAGE_ACCOUNT_CONNECTION_STRING_ENV_VAR_NAME);
    isPullRequest = Boolean.parseBoolean(Tools.retrieveEnvironmentVariableValue(TestConstants.IS_PULL_REQUEST));
    registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
    String uuid = UUID.randomUUID().toString();
    deviceId = deviceId.concat("-" + uuid);
    BlobServiceClient blobClient = new BlobServiceClientBuilder().connectionString(storageAccountConnectionString).buildClient();
    // Creating the export storage container and getting its URI
    String exportContainerName = "exportcontainersample-" + uuid;
    exportContainer = blobClient.getBlobContainerClient(exportContainerName);
    exportContainer.create();
    // Creating the import storage container and getting its URI
    String importContainerName = "importcontainersample-" + uuid;
    importContainer = blobClient.getBlobContainerClient(importContainerName);
    importContainer.create();
}
Also used : BlobServiceClient(com.azure.storage.blob.BlobServiceClient) BlobServiceClientBuilder(com.azure.storage.blob.BlobServiceClientBuilder) BeforeClass(org.junit.BeforeClass)

Example 2 with BlobServiceClient

use of com.azure.storage.blob.BlobServiceClient in project ambry by linkedin.

the class ADAuthBasedStorageClient method refreshTokenAndStorageClients.

/**
 * Refreshes AD authentication token and creates a new ABS client with the new token. Also, it schedules a task
 * for repeating this step before the obtained token expires.
 */
private synchronized void refreshTokenAndStorageClients() {
    azureMetrics.absTokenRefreshAttemptCount.inc();
    try {
        // if a task is already scheduled to refresh token then remove it.
        if (scheduledFutureRef.get() != null) {
            scheduledFutureRef.get().cancel(false);
            scheduledFutureRef.set(null);
        }
        // Refresh Token
        refreshToken();
        // Create new sync and async storage clients with refreshed token.
        if (azureCloudConfig.useAsyncAzureAPIs) {
            BlobServiceAsyncClient blobServiceAsyncClient = createBlobStorageAsyncClient();
            setAsyncClientReferences(blobServiceAsyncClient);
        } else {
            BlobServiceClient blobServiceClient = createBlobStorageClient();
            setClientReferences(blobServiceClient);
        }
        logger.info("Token refresh done.");
        // schedule a task to refresh token again and create new storage sync and async clients before it expires.
        scheduledFutureRef.set(tokenRefreshScheduler.schedule(this::refreshTokenAndStorageClients, (long) ((accessTokenRef.get().getExpiresAt().toEpochSecond() - OffsetDateTime.now().toEpochSecond()) * azureCloudConfig.azureStorageClientRefreshFactor), TimeUnit.SECONDS));
    } catch (MalformedURLException | InterruptedException | ExecutionException ex) {
        logger.error("Error building ABS blob service client: {}", ex.getMessage());
        throw new IllegalStateException(ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) BlobServiceClient(com.azure.storage.blob.BlobServiceClient) ExecutionException(java.util.concurrent.ExecutionException) BlobServiceAsyncClient(com.azure.storage.blob.BlobServiceAsyncClient)

Aggregations

BlobServiceClient (com.azure.storage.blob.BlobServiceClient)2 BlobServiceAsyncClient (com.azure.storage.blob.BlobServiceAsyncClient)1 BlobServiceClientBuilder (com.azure.storage.blob.BlobServiceClientBuilder)1 MalformedURLException (java.net.MalformedURLException)1 ExecutionException (java.util.concurrent.ExecutionException)1 BeforeClass (org.junit.BeforeClass)1