Search in sources :

Example 6 with AzureDeferredResultServiceCallback

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();
}
Also used : AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 7 with AzureDeferredResultServiceCallback

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);
}
Also used : OperationStatusResponseInner(com.microsoft.azure.management.compute.implementation.OperationStatusResponseInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl)

Example 8 with AzureDeferredResultServiceCallback

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);
}
Also used : NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner)

Aggregations

AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)8 PublicIPAddressInner (com.microsoft.azure.management.network.implementation.PublicIPAddressInner)3 AzureSdkClients (com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients)3 NetworkInterfaceInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)2 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)2 StorageAccountInner (com.microsoft.azure.management.storage.implementation.StorageAccountInner)2 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)2 AzureUtils (com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils)2 DiskService (com.vmware.photon.controller.model.resources.DiskService)2 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)2 StorageDescription (com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)2 DeferredResult (com.vmware.xenon.common.DeferredResult)2 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)2 List (java.util.List)2 Map (java.util.Map)2 Level (java.util.logging.Level)2 Collectors (java.util.stream.Collectors)2 Azure (com.microsoft.azure.management.Azure)1 AvailabilitySet (com.microsoft.azure.management.compute.AvailabilitySet)1 Disk (com.microsoft.azure.management.compute.Disk)1