use of com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_STATUS_UNATTACHED 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);
}
Aggregations