Search in sources :

Example 1 with LoadBalancingRuleInner

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

the class AzureLoadBalancerService method buildLoadBalancingRules.

/**
 * Build Azure load balancing rule model
 *
 * @param context Azure load balancer context
 * @return List of LoadBalancingRuleInner objects
 */
private List<LoadBalancingRuleInner> buildLoadBalancingRules(AzureLoadBalancerContext context) {
    List<LoadBalancingRuleInner> loadBalancingRules = Lists.newArrayList();
    int index = 1;
    for (RouteConfiguration routes : context.loadBalancerStateExpanded.routes) {
        ProbeInner probeInner = findMatchingProbe(context, index);
        LoadBalancingRuleInner loadBalancingRule = new LoadBalancingRuleInner();
        loadBalancingRule.withName(String.format("%s-lb-rule-%s", context.loadBalancerStateExpanded.name, index++));
        loadBalancingRule.withBackendPort(Integer.valueOf(routes.instancePort));
        loadBalancingRule.withFrontendPort(Integer.valueOf(routes.port));
        loadBalancingRule.withBackendAddressPool(new SubResource().withId(context.loadBalancerAzure.backendAddressPools().get(0).id()));
        // Converting HTTP and HTTPS to TCP to send to Azure as Azure only supports TCP or UCP
        if (StringUtils.equalsIgnoreCase("HTTP", routes.protocol) || StringUtils.equalsIgnoreCase("HTTPS", routes.protocol)) {
            routes.protocol = TransportProtocol.TCP.toString();
        }
        boolean isTcpProtocol = StringUtils.equalsIgnoreCase(TransportProtocol.TCP.toString(), routes.protocol);
        boolean isUdpProtocol = StringUtils.equalsIgnoreCase(TransportProtocol.UDP.toString(), routes.protocol);
        AssertUtil.assertTrue(isTcpProtocol || isUdpProtocol, String.format("Unsupported protocol %s. Only UDP and TCP are supported.", routes.protocol));
        loadBalancingRule.withProtocol(new TransportProtocol(routes.protocol));
        // TODO support more than one frontend case
        loadBalancingRule.withFrontendIPConfiguration(new SubResource().withId(context.loadBalancerAzure.frontendIPConfigurations().get(0).id()));
        if (probeInner != null) {
            loadBalancingRule.withProbe(new SubResource().withId(probeInner.id()));
        }
        loadBalancingRules.add(loadBalancingRule);
    }
    return loadBalancingRules;
}
Also used : SubResource(com.microsoft.azure.SubResource) ProbeInner(com.microsoft.azure.management.network.implementation.ProbeInner) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration) TransportProtocol(com.microsoft.azure.management.network.TransportProtocol) LoadBalancingRuleInner(com.microsoft.azure.management.network.implementation.LoadBalancingRuleInner)

Aggregations

SubResource (com.microsoft.azure.SubResource)1 TransportProtocol (com.microsoft.azure.management.network.TransportProtocol)1 LoadBalancingRuleInner (com.microsoft.azure.management.network.implementation.LoadBalancingRuleInner)1 ProbeInner (com.microsoft.azure.management.network.implementation.ProbeInner)1 RouteConfiguration (com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration)1