Search in sources :

Example 1 with AZURE_CORE_MANAGEMENT_URI

use of com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_CORE_MANAGEMENT_URI 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);
}
Also used : CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) StorageAccount(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) AZURE_CORE_MANAGEMENT_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_CORE_MANAGEMENT_URI) StorageAccountResultList(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccountResultList) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)1 StorageException (com.microsoft.azure.storage.StorageException)1 AZURE_CORE_MANAGEMENT_URI (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_CORE_MANAGEMENT_URI)1 StorageAccount (com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount)1 StorageAccountResultList (com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccountResultList)1 Operation (com.vmware.xenon.common.Operation)1 URI (java.net.URI)1