Search in sources :

Example 6 with RouteConfiguration

use of com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration in project photon-model by vmware.

the class LoadBalancerDescriptionService method getDocumentTemplate.

@Override
public ServiceDocument getDocumentTemplate() {
    ServiceDocument td = super.getDocumentTemplate();
    // enable metadata indexing
    td.documentDescription.documentIndexingOptions = EnumSet.of(DocumentIndexingOption.INDEX_METADATA);
    ServiceUtils.setRetentionLimit(td);
    LoadBalancerDescription template = (LoadBalancerDescription) td;
    template.id = UUID.randomUUID().toString();
    template.name = "load-balancer";
    template.endpointLink = UriUtils.buildUriPath(EndpointService.FACTORY_LINK, "my-endpoint");
    template.networkName = "lb-net";
    RouteConfiguration routeConfiguration = new RouteConfiguration();
    routeConfiguration.protocol = Protocol.HTTP.name();
    routeConfiguration.port = "80";
    routeConfiguration.instanceProtocol = Protocol.HTTP.name();
    routeConfiguration.instancePort = "80";
    routeConfiguration.healthCheckConfiguration = new HealthCheckConfiguration();
    routeConfiguration.healthCheckConfiguration.protocol = Protocol.HTTP.name();
    routeConfiguration.healthCheckConfiguration.port = "80";
    template.routes = Arrays.asList(routeConfiguration);
    return template;
}
Also used : HealthCheckConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration) ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Example 7 with RouteConfiguration

use of com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration 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 8 with RouteConfiguration

use of com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration 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)

Example 9 with RouteConfiguration

use of com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method createLoadBalancerState.

private LoadBalancerState createLoadBalancerState(String name, LoadBalancerTargetType loadBalancerTargetType) throws Throwable {
    LoadBalancerState loadBalancerState = new LoadBalancerState();
    loadBalancerState.id = name;
    loadBalancerState.name = name;
    loadBalancerState.instanceAdapterReference = UriUtils.buildUri(this.host, AzureLoadBalancerService.SELF_LINK);
    loadBalancerState.endpointLink = endpointState.documentSelfLink;
    loadBalancerState.tenantLinks = endpointState.tenantLinks;
    loadBalancerState.regionId = this.regionId;
    loadBalancerState.internetFacing = true;
    loadBalancerState.subnetLinks = Stream.of(subnetState.documentSelfLink).collect(Collectors.toSet());
    RouteConfiguration route = createRouteConfiguration();
    loadBalancerState.routes = Stream.of(route).collect(Collectors.toList());
    loadBalancerState.computeLinks = vmStates.stream().map(cs -> cs.documentSelfLink).collect(Collectors.toSet());
    if (loadBalancerTargetType != null) {
        switch(loadBalancerTargetType) {
            case COMPUTE:
                loadBalancerState.targetLinks = vmStates.stream().map(cs -> cs.documentSelfLink).collect(Collectors.toSet());
                break;
            case NIC:
                loadBalancerState.targetLinks = vmStates.stream().map(cs -> cs.networkInterfaceLinks.stream().findFirst().get()).collect(Collectors.toSet());
                break;
            case BOTH:
                // use boolean to toggle between compute link and NIC link
                AtomicBoolean typeToggle = new AtomicBoolean(true);
                loadBalancerState.targetLinks = vmStates.stream().map(cs -> {
                    typeToggle.set(!typeToggle.get());
                    if (typeToggle.get()) {
                        return cs.documentSelfLink;
                    } else {
                        return cs.networkInterfaceLinks.stream().findFirst().get();
                    }
                }).collect(Collectors.toSet());
                break;
            case INVALID:
                loadBalancerState.targetLinks = new HashSet<>();
                loadBalancerState.targetLinks.add("123");
                break;
            default:
                break;
        }
    }
    if (securityGroupState != null) {
        loadBalancerState.securityGroupLinks = Stream.of(securityGroupState.documentSelfLink).collect(Collectors.toList());
    }
    loadBalancerState.address = "1.1.1.1";
    return postServiceSynchronously(LoadBalancerService.FACTORY_LINK, loadBalancerState, LoadBalancerState.class);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState)

Example 10 with RouteConfiguration

use of com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration in project photon-model by vmware.

the class LoadBalancerServiceTest method buildValidStartState.

public static LoadBalancerState buildValidStartState() {
    LoadBalancerState loadBalancerState = new LoadBalancerState();
    loadBalancerState.descriptionLink = LoadBalancerDescriptionService.FACTORY_LINK + "/lb-desc";
    loadBalancerState.id = UUID.randomUUID().toString();
    loadBalancerState.name = "lbName";
    loadBalancerState.endpointLink = EndpointService.FACTORY_LINK + "/my-endpoint";
    loadBalancerState.computeLinks = new HashSet<>();
    loadBalancerState.computeLinks.add(ComputeService.FACTORY_LINK + "/a-compute");
    loadBalancerState.targetLinks = new HashSet<>();
    loadBalancerState.targetLinks.add(ComputeService.FACTORY_LINK + "/a-compute");
    loadBalancerState.targetLinks.add(NetworkInterfaceService.FACTORY_LINK + "/a-nic");
    loadBalancerState.subnetLinks = new HashSet<>();
    loadBalancerState.subnetLinks.add(SubnetService.FACTORY_LINK + "/a-subnet");
    loadBalancerState.securityGroupLinks = new ArrayList<>();
    loadBalancerState.securityGroupLinks.add(SecurityGroupService.FACTORY_LINK + "/a-sg");
    loadBalancerState.regionId = "regionId";
    loadBalancerState.tenantLinks = new ArrayList<>();
    loadBalancerState.tenantLinks.add("tenant-linkA");
    RouteConfiguration route1 = new RouteConfiguration();
    route1.protocol = Protocol.HTTP.name();
    route1.port = "80";
    route1.instanceProtocol = Protocol.HTTP.name();
    route1.instancePort = "80";
    route1.healthCheckConfiguration = new HealthCheckConfiguration();
    route1.healthCheckConfiguration.protocol = Protocol.HTTP.name();
    route1.healthCheckConfiguration.port = "80";
    RouteConfiguration route2 = new RouteConfiguration();
    route2.protocol = Protocol.HTTPS.name();
    route2.port = "443";
    route2.instanceProtocol = Protocol.HTTP.name();
    route2.instancePort = "443";
    loadBalancerState.routes = Arrays.asList(route1, route2);
    return loadBalancerState;
}
Also used : HealthCheckConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState)

Aggregations

RouteConfiguration (com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration)10 HealthCheckConfiguration (com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration)7 LoadBalancerState (com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState)4 ProbeInner (com.microsoft.azure.management.network.implementation.ProbeInner)2 ServiceDocument (com.vmware.xenon.common.ServiceDocument)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 LoadBalancerDescription (com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1