use of com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallbackWithRetry in project photon-model by vmware.
the class AzureInstanceService method createAvailabilitySet.
private void createAvailabilitySet(AzureInstanceContext ctx, AzureInstanceStage nextStage) {
String availabilitySetName = AzureUtils.getAvailabilitySetName(ctx);
String msg = "Creating Azure Availability Set [" + availabilitySetName + "] for [" + ctx.vmName + "] VM";
AvailabilitySetSkuTypes skuType = ctx.useManagedDisks() ? AvailabilitySetSkuTypes.MANAGED : AvailabilitySetSkuTypes.UNMANAGED;
AvailabilitySet.DefinitionStages.WithCreate availabilitySetDefinition = ctx.azureSdkClients.getComputeManager().availabilitySets().define(availabilitySetName).withRegion(ctx.child.description.regionId).withExistingResourceGroup(ctx.resourceGroup.name()).withSku(skuType);
AzureDeferredResultServiceCallbackWithRetry<AvailabilitySet> callback = new AzureDeferredResultServiceCallbackWithRetry<AvailabilitySet>(this, msg) {
@Override
protected DeferredResult<AvailabilitySet> consumeSuccess(AvailabilitySet availabilitySet) {
logInfo("Successfully created AvailabilitySet: " + availabilitySet.name());
ctx.availabilitySet = availabilitySet;
return DeferredResult.completed(availabilitySet);
}
@Override
protected Runnable retryServiceCall(ServiceCallback<AvailabilitySet> retryCallback) {
return () -> availabilitySetDefinition.createAsync(retryCallback);
}
};
availabilitySetDefinition.createAsync(callback);
callback.toDeferredResult().thenApply(ignore -> ctx).whenComplete(thenAllocation(ctx, nextStage, NETWORK_NAMESPACE));
}
use of com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallbackWithRetry in project photon-model by vmware.
the class AzureInstanceService method getAvailabilitySets.
private DeferredResult<AzureInstanceContext> getAvailabilitySets(AzureInstanceContext ctx) {
String msg = "Getting availability sets. ResourceGroup [" + ctx.resourceGroupName + "]";
ComputeManagementClientImpl computeManager = getComputeManagementClientImpl(ctx);
AzureDeferredResultServiceCallbackWithRetry<List<AvailabilitySetInner>> getAvailabilitySetsCallback = new AzureDeferredResultServiceCallbackWithRetry<List<AvailabilitySetInner>>(this, msg) {
@Override
protected DeferredResult<List<AvailabilitySetInner>> consumeSuccess(List<AvailabilitySetInner> result) {
ctx.availabilitySetInners = result;
return DeferredResult.completed(result);
}
@Override
protected Runnable retryServiceCall(ServiceCallback<List<AvailabilitySetInner>> retryCallback) {
return () -> computeManager.availabilitySets().listByResourceGroupAsync(ctx.resourceGroupName, retryCallback);
}
};
computeManager.availabilitySets().listByResourceGroupAsync(ctx.resourceGroupName, getAvailabilitySetsCallback);
return getAvailabilitySetsCallback.toDeferredResult().thenApply(result -> ctx);
}
Aggregations