Search in sources :

Example 1 with BlobServiceAsyncClient

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

Example 2 with BlobServiceAsyncClient

use of com.azure.storage.blob.BlobServiceAsyncClient in project samza by apache.

the class AzureBlobSystemProducer method setupAzureContainer.

@VisibleForTesting
void setupAzureContainer() {
    try {
        BlobServiceAsyncClient storageClient = new AzureBlobClientBuilder(systemName, AZURE_URL, config).getBlobServiceAsyncClient();
        validateFlushThresholdSizeSupported(storageClient);
        containerAsyncClient = storageClient.getBlobContainerAsyncClient(systemName);
        // Only way to check if container exists or not is by creating it and look for failure/success.
        createContainerIfNotExists(containerAsyncClient);
    } catch (Exception e) {
        metrics.updateAzureContainerMetrics();
        throw new SystemProducerException("Failed to set up Azure container for SystemName: " + systemName, e);
    }
}
Also used : AzureBlobClientBuilder(org.apache.samza.system.azureblob.AzureBlobClientBuilder) BlobServiceAsyncClient(com.azure.storage.blob.BlobServiceAsyncClient) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) SystemProducerException(org.apache.samza.system.SystemProducerException) IOException(java.io.IOException) SystemProducerException(org.apache.samza.system.SystemProducerException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BlobServiceAsyncClient (com.azure.storage.blob.BlobServiceAsyncClient)2 BlobServiceClient (com.azure.storage.blob.BlobServiceClient)1 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ExecutionException (java.util.concurrent.ExecutionException)1 SystemProducerException (org.apache.samza.system.SystemProducerException)1 AzureBlobClientBuilder (org.apache.samza.system.azureblob.AzureBlobClientBuilder)1