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();
}
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;
});
}
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);
}
}
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);
}
}
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);
}
}
Aggregations