Search in sources :

Example 1 with ProbeInner

use of com.microsoft.azure.management.network.implementation.ProbeInner 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)

Example 2 with ProbeInner

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

the class AzureLoadBalancerService method buildLoadBalancingProbes.

/**
 * Build Azure health probe model
 *
 * @param context Azure load balancer context
 * @return List of ProbeInner objects
 */
private List<ProbeInner> buildLoadBalancingProbes(AzureLoadBalancerContext context) {
    List<ProbeInner> loadBalancingProbes = Lists.newArrayList();
    int index = 1;
    for (RouteConfiguration routes : context.loadBalancerStateExpanded.routes) {
        HealthCheckConfiguration healthCheckConfiguration = routes.healthCheckConfiguration;
        if (healthCheckConfiguration != null) {
            ProbeInner probeInner = new ProbeInner();
            String healthProbeName = String.format("%s-probe-%s", context.loadBalancerStateExpanded.name, index);
            probeInner.withName(healthProbeName);
            probeInner.withIntervalInSeconds(healthCheckConfiguration.intervalSeconds);
            probeInner.withPort(Integer.parseInt(healthCheckConfiguration.port));
            boolean isHttpProtocol = StringUtils.equalsIgnoreCase(ProbeProtocol.HTTP.toString(), healthCheckConfiguration.protocol);
            boolean isTcpProtocol = StringUtils.equalsIgnoreCase(ProbeProtocol.TCP.toString(), healthCheckConfiguration.protocol);
            AssertUtil.assertTrue(isHttpProtocol || isTcpProtocol, String.format("Unsupported protocol %s. Only HTTP and TCP are supported.", healthCheckConfiguration.protocol));
            probeInner.withProtocol(new ProbeProtocol(healthCheckConfiguration.protocol));
            if (isHttpProtocol) {
                probeInner.withRequestPath(healthCheckConfiguration.urlPath);
            }
            probeInner.withNumberOfProbes(healthCheckConfiguration.unhealthyThreshold);
            loadBalancingProbes.add(probeInner);
            index++;
        }
    }
    return loadBalancingProbes;
}
Also used : ProbeProtocol(com.microsoft.azure.management.network.ProbeProtocol) HealthCheckConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration) ProbeInner(com.microsoft.azure.management.network.implementation.ProbeInner) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration)

Aggregations

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