use of com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback in project photon-model by vmware.
the class AzureLoadBalancerService method getNetworkInterfaceInner.
/**
* Fetch single Network Interface from Azure
*
* @param context Azure load balancer context
* @param networkInterfaceState state of the network interface to be fetched from Azure
* @return DeferredResult
*/
private DeferredResult<NetworkInterfaceInner> getNetworkInterfaceInner(AzureLoadBalancerContext context, NetworkInterfaceState networkInterfaceState) {
String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceState.id);
final String msg = "Getting network Interface [" + networkInterfaceState.name + "] in resource group [" + networkInterfaceResGrp + "].";
logInfo(() -> msg);
AzureDeferredResultServiceCallback<NetworkInterfaceInner> callback = new AzureDeferredResultServiceCallback<NetworkInterfaceInner>(this, msg) {
@Override
protected DeferredResult<NetworkInterfaceInner> consumeSuccess(NetworkInterfaceInner networkInterface) {
if (networkInterface == null) {
logWarning("Failed to get information for network interface: %s", networkInterfaceState.name);
}
return DeferredResult.completed(networkInterface);
}
};
NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceState.name, null, /* expand */
callback);
return callback.toDeferredResult();
}
use of com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback in project photon-model by vmware.
the class AzureInstanceService method deleteVirtualMachine.
private DeferredResult<AzureInstanceContext> deleteVirtualMachine(AzureInstanceContext ctx) {
String msg = "Deleting virtual machine [" + ctx.vmName + "]";
ComputeManagementClientImpl computeManager = getComputeManagementClientImpl(ctx);
AzureDeferredResultServiceCallback<OperationStatusResponseInner> deleteVirtualMachineCallback = new AzureDeferredResultServiceCallback<OperationStatusResponseInner>(this, msg) {
@Override
protected DeferredResult<OperationStatusResponseInner> consumeSuccess(OperationStatusResponseInner result) {
logInfo("Successfully deleted VM: " + ctx.vmName);
return DeferredResult.completed(result);
}
};
computeManager.virtualMachines().deleteAsync(ctx.resourceGroupName, ctx.vmName, deleteVirtualMachineCallback);
return deleteVirtualMachineCallback.toDeferredResult().thenApply(result -> ctx);
}
use of com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback in project photon-model by vmware.
the class AzureLoadBalancerService method getPublicIPAddress.
/**
* Fetch public IP address after an address has been assigned
*/
private DeferredResult<AzureLoadBalancerContext> getPublicIPAddress(AzureLoadBalancerContext ctx) {
if (ctx.publicIPAddressInner == null) {
// No public IP address created -> do nothing.
return DeferredResult.completed(ctx);
}
NetworkManagementClientImpl client = ctx.azureSdkClients.getNetworkManagementClientImpl();
String msg = "Get public IP address for resource group [" + ctx.resourceGroupName + "] and name [" + ctx.publicIPAddressInner.name() + "].";
AzureDeferredResultServiceCallback<PublicIPAddressInner> callback = new AzureDeferredResultServiceCallback<PublicIPAddressInner>(ctx.service, msg) {
@Override
protected DeferredResult<PublicIPAddressInner> consumeSuccess(PublicIPAddressInner result) {
ctx.publicIPAddressInner = result;
ctx.loadBalancerStateExpanded.address = result.ipAddress();
return DeferredResult.completed(result);
}
};
client.publicIPAddresses().getByResourceGroupAsync(ctx.resourceGroupName, ctx.publicIPAddressInner.name(), null, callback);
return callback.toDeferredResult().thenApply(ignored -> ctx);
}
Aggregations