Search in sources :

Example 1 with DISK_REST_API_VERSION

use of com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_REST_API_VERSION in project photon-model by vmware.

the class AzureDiskEnumerationAdapterService method getManagedDisks.

private void getManagedDisks(DiskEnumContext ctx, DiskEnumStages nextStage) {
    logInfo(() -> "Enumerating Azure Managed disks.");
    URI uri;
    if (ctx.enumNextPageLink == null) {
        // TODO- change to use sdk to fetch disks
        String uriStr = AdapterUriUtil.expandUriPathTemplate(LIST_DISKS_URI, ctx.endpointAuth.userLink);
        uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(uriStr), QUERY_PARAM_API_VERSION, DISK_REST_API_VERSION);
    } else {
        uri = UriUtils.buildUri(ctx.enumNextPageLink);
    }
    final 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 + ctx.credentials.getToken(AzureUtils.getAzureBaseUri()));
    } catch (Exception ex) {
        handleError(ctx, ex);
        return;
    }
    operation.setCompletion((op, th) -> {
        if (th != null) {
            handleError(ctx, th);
            return;
        }
        ManagedDiskList results = op.getBody(ManagedDiskList.class);
        // Store next page link
        ctx.enumNextPageLink = results.nextLink;
        logInfo(() -> String.format("Next page link %s", ctx.enumNextPageLink));
        List<Disk> diskList = results.value;
        if (diskList == null || diskList.size() == 0) {
            ctx.subStage = DiskEnumStages.DISASSOCIATE_ENDPOINT_LINKS;
            handleSubStage(ctx);
            return;
        }
        logInfo(() -> String.format("Retrieved %d managed disks from Azure", diskList.size()));
        // save all disks from Azure to process further
        diskList.forEach(disk -> ctx.managedDisks.put(disk.id, disk));
        // filter all un-attached disks from diskList
        List<Disk> unattachedDisks = diskList.stream().filter(dk -> dk.properties.diskState.equals(DISK_STATUS_UNATTACHED)).collect(Collectors.toList());
        // TODO - Remove toLowerCase() after https://github.com/Azure/azure-sdk-for-java/issues/2014 is fixed.
        // save all unattached disks in managedDisks map for further processing
        unattachedDisks.forEach(disk -> ctx.unattachedDisks.put(disk.id.toLowerCase(), disk));
        logInfo(() -> String.format("Processing %d independent disks", ctx.managedDisks.size()));
        if (ctx.enumNextPageLink != null) {
            ctx.subStage = DiskEnumStages.GET_DISKS;
            logFine(() -> String.format("Transition to same stage" + ctx.subStage));
        } else {
            ctx.subStage = nextStage;
            logFine(() -> String.format("Transition to " + nextStage));
        }
        handleSubStage(ctx);
    });
    sendRequest(operation);
}
Also used : QUERY_PARAM_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.QUERY_PARAM_API_VERSION) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) DISK_STATUS_UNATTACHED(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_STATUS_UNATTACHED) QueryTask(com.vmware.xenon.services.common.QueryTask) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) Disk(com.vmware.photon.controller.model.adapters.azure.model.storage.Disk) URI(java.net.URI) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) AdapterUtils.getDeletionState(com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState) Collectors(java.util.stream.Collectors) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) TagService(com.vmware.photon.controller.model.resources.TagService) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) AzureUtils.getAzureConfig(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getAzureConfig) DiskService(com.vmware.photon.controller.model.resources.DiskService) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) LIST_DISKS_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_DISKS_URI) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) DISK_REST_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_REST_API_VERSION) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) Query(com.vmware.xenon.services.common.QueryTask.Query) AUTH_HEADER_BEARER_PREFIX(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTH_HEADER_BEARER_PREFIX) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) DiskStatus(com.vmware.photon.controller.model.resources.DiskService.DiskStatus) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ManagedDiskList(com.vmware.photon.controller.model.adapters.azure.model.storage.ManagedDiskList) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) Operation(com.vmware.xenon.common.Operation) ManagedDiskList(com.vmware.photon.controller.model.adapters.azure.model.storage.ManagedDiskList) URI(java.net.URI) LIST_DISKS_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_DISKS_URI) Disk(com.vmware.photon.controller.model.adapters.azure.model.storage.Disk)

Aggregations

ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)1 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)1 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)1 AzureUriPaths (com.vmware.photon.controller.model.adapters.azure.AzureUriPaths)1 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)1 AUTH_HEADER_BEARER_PREFIX (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTH_HEADER_BEARER_PREFIX)1 AZURE_MANAGED_DISK_TYPE (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE)1 DISK_CONTROLLER_NUMBER (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER)1 DISK_REST_API_VERSION (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_REST_API_VERSION)1 DISK_STATUS_UNATTACHED (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_STATUS_UNATTACHED)1 LIST_DISKS_URI (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_DISKS_URI)1 QUERY_PARAM_API_VERSION (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.QUERY_PARAM_API_VERSION)1 Disk (com.vmware.photon.controller.model.adapters.azure.model.storage.Disk)1 ManagedDiskList (com.vmware.photon.controller.model.adapters.azure.model.storage.ManagedDiskList)1 AzureUtils (com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils)1 AzureUtils.getAzureConfig (com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getAzureConfig)1 AdapterUriUtil (com.vmware.photon.controller.model.adapters.util.AdapterUriUtil)1 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)1 AdapterUtils.getDeletionState (com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState)1 ComputeEnumerateAdapterRequest (com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest)1