use of com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method getStorageAccounts.
/**
* Retrieve storage accounts from Azure.
*/
private void getStorageAccounts(StorageEnumContext context, StorageEnumStages next) {
String uriStr = context.enumNextPageLink;
URI uri;
if (uriStr == null) {
uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_STORAGE_ACCOUNTS, context.endpointAuth.userLink);
uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(uriStr), QUERY_PARAM_API_VERSION, STORAGE_ACCOUNT_REST_API_VERSION);
} else {
uri = UriUtils.buildUri(uriStr);
}
context.storageAccountsToUpdateCreate.clear();
context.storageAccountBlobUriMap.clear();
context.storageAccountMap.clear();
Operation operation = Operation.createGet(uri);
operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
try {
operation.addRequestHeader(Operation.AUTHORIZATION_HEADER, AUTH_HEADER_BEARER_PREFIX + context.azureSdkClients.credentials.getToken(AzureUtils.getAzureBaseUri()));
} catch (Exception ex) {
this.handleError(context, ex);
return;
}
operation.setCompletion((op, er) -> {
if (er != null) {
op.complete();
handleError(context, er);
return;
}
StorageAccountResultList results = op.getBody(StorageAccountResultList.class);
op.complete();
List<StorageAccount> storageAccounts = results.value;
context.apiStorageAccountsCount += results.value.size();
// If there are no storage accounts in Azure move to storage account cleanup.
if (storageAccounts == null || storageAccounts.size() == 0) {
context.subStage = StorageEnumStages.DISASSOCIATE_STORAGE_DESCRIPTIONS;
handleSubStage(context);
return;
}
context.enumNextPageLink = results.nextLink;
logFine(() -> String.format("Retrieved %d storage accounts from Azure", storageAccounts.size()));
for (StorageAccount storageAccount : storageAccounts) {
String id = canonizeId(storageAccount.id);
storageAccount.id = id;
context.storageAccountsToUpdateCreate.put(id, storageAccount);
context.storageAccountIds.add(id);
context.storageAccountMap.put(id, storageAccount);
}
logFine(() -> String.format("Processing %d storage accounts", context.storageAccountIds.size()));
context.subStage = next;
handleSubStage(context);
});
sendRequest(operation);
context.apiListStorageAccounts++;
}
use of com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount in project photon-model by vmware.
the class AzureComputeHostStorageStatsGatherer method getStorageAccounts.
private void getStorageAccounts(AzureStorageStatsDataHolder statsData, StorageMetricsStages next) {
String uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_STORAGE_ACCOUNTS, statsData.parentAuth.userLink);
URI uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(uriStr), QUERY_PARAM_API_VERSION, STORAGE_ACCOUNT_REST_API_VERSION);
Operation operation = Operation.createGet(uri);
operation.addRequestHeader(Operation.ACCEPT_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
operation.addRequestHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_APPLICATION_JSON);
try {
operation.addRequestHeader(Operation.AUTHORIZATION_HEADER, AUTH_HEADER_BEARER_PREFIX + statsData.azureClients.credentials.getToken(AZURE_CORE_MANAGEMENT_URI));
} catch (Exception ex) {
this.handleError(statsData, ex);
return;
}
operation.setCompletion((op, er) -> {
if (er != null) {
handleError(statsData, er);
return;
}
StorageAccountResultList results = op.getBody(StorageAccountResultList.class);
List<StorageAccount> storageAccounts = results.value;
// If there are no storage accounts in Azure, the are no bytes being used/billed
if (storageAccounts == null || storageAccounts.size() == 0) {
statsData.stage = StorageMetricsStages.FINISHED;
handleStorageMetricDiscovery(statsData);
return;
}
logFine(() -> String.format("Retrieved %d storage accounts from Azure", storageAccounts.size()));
for (StorageAccount storageAccount : storageAccounts) {
statsData.storageAccounts.put(storageAccount.id, storageAccount);
}
logFine(() -> String.format("Processing %d storage accounts", statsData.storageAccounts.size()));
statsData.stage = next;
handleStorageMetricDiscovery(statsData);
});
sendRequest(operation);
}
Aggregations