use of com.microsoft.azure.hdinsight.sdk.common.azure.serverless.AzureSparkServerlessAccount in project azure-tools-for-java by Microsoft.
the class SynapseCosmosSparkPool method getConfigurationInfo.
@Override
public void getConfigurationInfo() throws IOException {
if (!isConfigInfoAvailable()) {
// Extract Subscription ID from ADLA resource ID
// Sample adlaResouceId: /subscriptions/a00b00a0-00a0-0000-b000-a000b0a00000/resourceGroups/testRG/providers/Microsoft.DataLakeAnalytics/accounts/testAccount
Matcher matcher = ADLA_RESOURCE_ID_PATTERN.matcher(getAdlaResourceId());
if (!matcher.matches()) {
String errorMsg = String.format("ADLA resource ID doesn't match with pattern. AdlaResourceId: %s. Pattern: %s", getAdlaResourceId(), ADLA_RESOURCE_ID_PATTERN);
throw new IOException(errorMsg);
}
String subscriptionId = matcher.group("sid");
// Get SubscriptionDetail from subscription ID
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
SubscriptionDetail subscription = subscriptionManager.getSubscriptionIdToSubscriptionDetailsMap().getOrDefault(subscriptionId, null);
if (subscription == null) {
throw new IOException("User has no permission to access subscription " + subscriptionId + ".");
}
// Get ADLA account details through Azure REST API
AzureHttpObservable managementHttp = new AzureManagementHttpObservable(subscription, ApiVersion.VERSION);
String resourceManagerEndpoint = CommonSettings.getAdEnvironment().resourceManagerEndpoint();
URI accountDetailUri = URI.create(resourceManagerEndpoint).resolve(getAdlaResourceId());
AzureSparkServerlessAccount azureSparkServerlessAccount = managementHttp.withUuidUserAgent().get(accountDetailUri.toString(), null, null, DataLakeAnalyticsAccount.class).doOnError(err -> log().warn("Error getting ADLA account details with error: " + err.getMessage())).map(dataLakeAnalyticsAccount -> new AzureSparkServerlessAccount(subscription, URI.create("https://" + dataLakeAnalyticsAccount.endpoint()), dataLakeAnalyticsAccount.name()).setDetailResponse(dataLakeAnalyticsAccount)).subscribeOn(Schedulers.io()).toBlocking().singleOrDefault(null);
// Get default storage account info from ADLA account
String storageRootPath = azureSparkServerlessAccount.getStorageRootPath();
IHDIStorageAccount adlsGen1StorageAccount = storageRootPath == null ? null : new AzureSparkCosmosCluster.StorageAccount(azureSparkServerlessAccount.getDetailResponse().defaultDataLakeStoreAccount(), storageRootPath, azureSparkServerlessAccount.getSubscription().getSubscriptionId());
synchronized (this) {
if (!isConfigInfoAvailable()) {
this.http = managementHttp;
this.storageAccount = adlsGen1StorageAccount;
isConfigInfoAvailable = true;
}
}
}
}
Aggregations