use of com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallbackWithRetry in project photon-model by vmware.
the class AzureInstanceService method createNetwork.
private void createNetwork(AzureInstanceContext ctx, AzureInstanceStage nextStage, List<SubnetInner> subnetsToCreate) {
// All NICs MUST be at the same vNet (no cross vNet VMs),
// so we select the Primary vNet.
final AzureNicContext primaryNic = ctx.getPrimaryNic();
final VirtualNetworkInner vNetToCreate = newAzureVirtualNetwork(ctx, primaryNic, subnetsToCreate);
final String vNetName = primaryNic.networkState.name;
final String vNetRGName = primaryNic.networkRGState != null ? primaryNic.networkRGState.name : ctx.resourceGroup.name();
VirtualNetworksInner azureClient = getNetworkManagementClientImpl(ctx).virtualNetworks();
final String subnetNames = vNetToCreate.subnets().stream().map(SubnetInner::name).collect(Collectors.joining(","));
final String msg = "Creating Azure vNet-Subnet [v=" + vNetName + "; s=" + subnetNames + "] for [" + ctx.vmName + "] VM";
AzureProvisioningCallbackWithRetry<VirtualNetworkInner> handler = new AzureProvisioningCallbackWithRetry<VirtualNetworkInner>(this, msg) {
@Override
protected DeferredResult<VirtualNetworkInner> consumeProvisioningSuccess(VirtualNetworkInner vNet) {
// Populate NICs with Azure Subnet
for (AzureNicContext nicCtx : ctx.nics) {
if (nicCtx.subnet == null) {
nicCtx.subnet = vNet.subnets().stream().filter(subnet -> subnet.name().equals(nicCtx.subnetState.name)).findFirst().get();
}
}
return DeferredResult.completed(vNet);
}
@Override
protected String getProvisioningState(VirtualNetworkInner vNet) {
// or PROVISIONING_STATE_SUCCEEDED if all are Succeeded
if (vNet.subnets().size() == 0) {
return PROVISIONING_STATE_FAILED_NO_SUBNET;
}
String subnetPS = vNet.subnets().stream().map(SubnetInner::provisioningState).filter(ps -> !PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(ps)).findFirst().orElse(PROVISIONING_STATE_SUCCEEDED);
if (PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(vNet.provisioningState()) && PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(subnetPS)) {
return PROVISIONING_STATE_SUCCEEDED;
}
return vNet.provisioningState() + ":" + subnetPS;
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<VirtualNetworkInner> checkProvisioningStateCallback) {
return () -> azureClient.getByResourceGroupAsync(vNetRGName, vNetName, null, /* expand */
checkProvisioningStateCallback);
}
@Override
protected Runnable retryServiceCall(ServiceCallback<VirtualNetworkInner> retryCallback) {
return () -> azureClient.createOrUpdateAsync(vNetRGName, vNetName, vNetToCreate, retryCallback);
}
};
azureClient.createOrUpdateAsync(vNetRGName, vNetName, vNetToCreate, handler);
handler.toDeferredResult().thenApply(ignore -> ctx).whenComplete(thenAllocation(ctx, nextStage, NETWORK_NAMESPACE));
}
use of com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallbackWithRetry in project photon-model by vmware.
the class AzureLoadBalancerService method createOrUpdateNetworkInterface.
/**
* Create or Update network interface in Azure
*
* @param context Azure load balancer context
* @param networkInterfaceInner Azure network interface construct
* @return DeferredResult
*/
private DeferredResult<NetworkInterfaceInner> createOrUpdateNetworkInterface(AzureLoadBalancerContext context, NetworkInterfaceInner networkInterfaceInner) {
String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceInner.id());
final String msg = "Update network Interface [" + networkInterfaceInner.name() + "] in resource group [" + networkInterfaceResGrp + "].";
logInfo(() -> msg);
NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
AzureProvisioningCallbackWithRetry<NetworkInterfaceInner> handler = new AzureProvisioningCallbackWithRetry<NetworkInterfaceInner>(this, msg) {
@Override
protected DeferredResult<NetworkInterfaceInner> consumeProvisioningSuccess(NetworkInterfaceInner networkInterfaceInner) {
return DeferredResult.completed(networkInterfaceInner);
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<NetworkInterfaceInner> checkProvisioningStateCallback) {
return () -> azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceInner.name(), null, /* expand */
checkProvisioningStateCallback);
}
@Override
protected String getProvisioningState(NetworkInterfaceInner body) {
return body.provisioningState();
}
@Override
protected Runnable retryServiceCall(ServiceCallback<NetworkInterfaceInner> retryCallback) {
return () -> azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, retryCallback);
}
};
azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, handler);
return handler.toDeferredResult();
}
Aggregations