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