use of com.microsoft.azure.management.network.TransportProtocol 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;
}
Aggregations