Search in sources :

Example 1 with LoadBalancerInner

use of com.microsoft.azure.management.network.implementation.LoadBalancerInner in project photon-model by vmware.

the class AzureLoadBalancerService method createOrUpdateLoadBalancer.

/**
 * Create or update load balancer in Azure
 *
 * @param context Azure load balancer context
 * @param msg     message to log
 * @return DeferredResult
 */
private DeferredResult<LoadBalancerInner> createOrUpdateLoadBalancer(AzureLoadBalancerContext context, String msg) {
    LoadBalancersInner azureLoadBalancerClient = context.azureSdkClients.getNetworkManagementClientImpl().loadBalancers();
    logInfo(() -> msg);
    AzureProvisioningCallback<LoadBalancerInner> handler = new AzureProvisioningCallback<LoadBalancerInner>(this, msg) {

        @Override
        protected DeferredResult<LoadBalancerInner> consumeProvisioningSuccess(LoadBalancerInner loadBalancer) {
            // Populate the load balancer id with Azure Load Balancer ID
            context.loadBalancerStateExpanded.id = loadBalancer.id();
            return DeferredResult.completed(loadBalancer);
        }

        @Override
        protected String getProvisioningState(LoadBalancerInner loadBalancer) {
            return loadBalancer.provisioningState();
        }

        @Override
        protected Runnable checkProvisioningStateCall(ServiceCallback<LoadBalancerInner> checkProvisioningStateCallback) {
            return () -> azureLoadBalancerClient.getByResourceGroupAsync(context.resourceGroupName, context.loadBalancerAzure.name(), null, /* expand */
            checkProvisioningStateCallback);
        }
    };
    azureLoadBalancerClient.createOrUpdateAsync(context.resourceGroupName, context.loadBalancerStateExpanded.name, context.loadBalancerAzure, handler);
    return handler.toDeferredResult();
}
Also used : LoadBalancerInner(com.microsoft.azure.management.network.implementation.LoadBalancerInner) ServiceCallback(com.microsoft.rest.ServiceCallback) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) LoadBalancersInner(com.microsoft.azure.management.network.implementation.LoadBalancersInner) AzureProvisioningCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback)

Example 2 with LoadBalancerInner

use of com.microsoft.azure.management.network.implementation.LoadBalancerInner in project photon-model by vmware.

the class AzureLoadBalancerService method createLoadBalancer.

/**
 * Creates a load balancer in Azure
 *
 * @param context Azure load balancer context
 * @return DeferredResult
 */
private DeferredResult<AzureLoadBalancerContext> createLoadBalancer(AzureLoadBalancerContext context) {
    context.loadBalancerAzure = new LoadBalancerInner();
    context.loadBalancerAzure.withLocation(context.loadBalancerStateExpanded.regionId);
    context.loadBalancerAzure.withFrontendIPConfigurations(buildFrontendIPConfiguration(context));
    context.loadBalancerAzure.withBackendAddressPools(buildBackendPools(context));
    final String msg = String.format("Creating Azure Load Balancer [%s] in resource group [%s].", context.loadBalancerStateExpanded.name, context.resourceGroupName);
    return createOrUpdateLoadBalancer(context, msg).thenApply(lb -> {
        // Populate the load balancer id with Azure Load Balancer ID
        context.loadBalancerStateExpanded.id = lb.id();
        // We have to update the load balancer with health probes and load balancing rules in a separate update call to Azure
        // So storing the create load balancer in context to use in update call
        context.loadBalancerAzure = lb;
        return context;
    });
}
Also used : LoadBalancerInner(com.microsoft.azure.management.network.implementation.LoadBalancerInner)

Example 3 with LoadBalancerInner

use of com.microsoft.azure.management.network.implementation.LoadBalancerInner in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method testCreateLoadBalancerWithMixedTarget.

@Test
public void testCreateLoadBalancerWithMixedTarget() throws Throwable {
    LoadBalancerState loadBalancerState = provisionLoadBalancer(TaskStage.FINISHED, LoadBalancerTargetType.BOTH);
    assertNotNull(loadBalancerState.id);
    assertNotEquals(loadBalancerState.id, this.loadBalancerName);
    if (!this.isMock) {
        // Verify that the load balancer was created.
        LoadBalancerInner lbResponse = this.loadBalancerClient.getByResourceGroup(this.rgName, this.loadBalancerName);
        assertEquals(this.loadBalancerName, lbResponse.name());
        assertEquals(loadBalancerState.id, lbResponse.id());
        // delete the load balancer
        startLoadBalancerProvisioning(LoadBalancerInstanceRequest.InstanceRequestType.DELETE, loadBalancerState, TaskStage.FINISHED);
    }
}
Also used : LoadBalancerInner(com.microsoft.azure.management.network.implementation.LoadBalancerInner) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 4 with LoadBalancerInner

use of com.microsoft.azure.management.network.implementation.LoadBalancerInner in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method testCreateLoadBalancerWithComputeTarget.

@Test
public void testCreateLoadBalancerWithComputeTarget() throws Throwable {
    securityGroupState = createSecurityGroupState(this.host, endpointState, this.securityGroupName, Lists.newArrayList(), Lists.newArrayList());
    kickOffSecurityGroupProvision(SecurityGroupInstanceRequest.InstanceRequestType.CREATE, TaskStage.FINISHED);
    LoadBalancerState loadBalancerState = provisionLoadBalancer(TaskStage.FINISHED, LoadBalancerTargetType.COMPUTE);
    assertNotNull(loadBalancerState.id);
    assertNotEquals(loadBalancerState.id, this.loadBalancerName);
    if (!this.isMock) {
        // Verify that the load balancer was created.
        LoadBalancerInner lbResponse = this.loadBalancerClient.getByResourceGroup(this.rgName, this.loadBalancerName);
        assertEquals(this.loadBalancerName, lbResponse.name());
        assertEquals(loadBalancerState.id, lbResponse.id());
        assertNotNull(loadBalancerState.address);
        // delete the load balancer
        startLoadBalancerProvisioning(LoadBalancerInstanceRequest.InstanceRequestType.DELETE, loadBalancerState, TaskStage.FINISHED);
    }
}
Also used : LoadBalancerInner(com.microsoft.azure.management.network.implementation.LoadBalancerInner) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 5 with LoadBalancerInner

use of com.microsoft.azure.management.network.implementation.LoadBalancerInner in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method testCreateLoadBalancerWithNICTarget.

@Test
public void testCreateLoadBalancerWithNICTarget() throws Throwable {
    LoadBalancerState loadBalancerState = provisionLoadBalancer(TaskStage.FINISHED, LoadBalancerTargetType.NIC);
    assertNotNull(loadBalancerState.id);
    assertNotEquals(loadBalancerState.id, this.loadBalancerName);
    if (!this.isMock) {
        // Verify that the load balancer was created.
        LoadBalancerInner lbResponse = this.loadBalancerClient.getByResourceGroup(this.rgName, this.loadBalancerName);
        assertEquals(this.loadBalancerName, lbResponse.name());
        assertEquals(loadBalancerState.id, lbResponse.id());
        // delete the load balancer
        startLoadBalancerProvisioning(LoadBalancerInstanceRequest.InstanceRequestType.DELETE, loadBalancerState, TaskStage.FINISHED);
    }
}
Also used : LoadBalancerInner(com.microsoft.azure.management.network.implementation.LoadBalancerInner) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Aggregations

LoadBalancerInner (com.microsoft.azure.management.network.implementation.LoadBalancerInner)6 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)4 LoadBalancerState (com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState)4 Test (org.junit.Test)4 LoadBalancersInner (com.microsoft.azure.management.network.implementation.LoadBalancersInner)1 ServiceCallback (com.microsoft.rest.ServiceCallback)1 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)1 AzureProvisioningCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback)1