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