Search in sources :

Example 11 with TargetGroup

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.

the class LoadBalancerConfigConverterTest method testConvertGcpTargetGroup.

@Test
public void testConvertGcpTargetGroup() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(creatGcpParams(1)).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair = new TargetGroupPortPair(PORT1, PORT2);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(GCP, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getGcpConfig());
    GcpTargetGroupConfigDb gcpTargetGroupConfigDb = targetGroupConfigDbWrapper.getGcpConfig();
    assertEquals(1, gcpTargetGroupConfigDb.getPortMapping().size());
    assertEquals(PORT1, gcpTargetGroupConfigDb.getPortMapping().keySet().iterator().next());
    GcpLoadBalancerNamesDb gcpLoadBalancerNamesDb = gcpTargetGroupConfigDb.getPortMapping().get(PORT1);
    assertEquals(BACKEND_SERVICE_NAME, gcpLoadBalancerNamesDb.getBackendServiceName());
    assertEquals(INSTANCE_GROUP_NAME, gcpLoadBalancerNamesDb.getInstanceGroupName());
}
Also used : GcpLoadBalancerNamesDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpLoadBalancerNamesDb) TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) GcpTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpTargetGroupConfigDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 12 with TargetGroup

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.

the class StackToCloudStackConverter method buildLoadBalancers.

private List<CloudLoadBalancer> buildLoadBalancers(Stack stack, List<Group> instanceGroups) {
    List<CloudLoadBalancer> cloudLoadBalancers = new ArrayList<>();
    for (LoadBalancer loadBalancer : loadBalancerPersistenceService.findByStackId(stack.getId())) {
        CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(loadBalancer.getType(), loadBalancer.getSku());
        for (TargetGroup targetGroup : targetGroupPersistenceService.findByLoadBalancerId(loadBalancer.getId())) {
            Set<TargetGroupPortPair> portPairs = loadBalancerConfigService.getTargetGroupPortPairs(targetGroup);
            Set<String> targetInstanceGroupName = instanceGroupService.findByTargetGroupId(targetGroup.getId()).stream().map(InstanceGroup::getGroupName).collect(Collectors.toSet());
            for (TargetGroupPortPair portPair : portPairs) {
                cloudLoadBalancer.addPortToTargetGroupMapping(portPair, instanceGroups.stream().filter(ig -> targetInstanceGroupName.contains(ig.getName())).collect(Collectors.toSet()));
            }
        }
        cloudLoadBalancers.add(cloudLoadBalancer);
    }
    return cloudLoadBalancers;
}
Also used : CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) ArrayList(java.util.ArrayList) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)

Example 13 with TargetGroup

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.

the class LoadBalancerConfigService method setupOozieHATargetGroup.

private Optional<TargetGroup> setupOozieHATargetGroup(Stack stack, boolean dryRun) {
    Optional<InstanceGroup> oozieInstanceGroup = getOozieHAInstanceGroup(stack);
    if (oozieInstanceGroup.isPresent()) {
        LOGGER.info("Oozie HA instance group found; enabling Oozie load balancer configuration.");
        TargetGroup oozieTargetGroup = new TargetGroup();
        if (CloudPlatform.GCP.equalsIgnoreCase(stack.getCloudPlatform())) {
            oozieTargetGroup.setType(TargetGroupType.OOZIE_GCP);
        } else {
            oozieTargetGroup.setType(TargetGroupType.OOZIE);
        }
        oozieTargetGroup.setInstanceGroups(Set.of(oozieInstanceGroup.get()));
        if (!dryRun) {
            LOGGER.debug("Adding target group to Oozie HA instance group.");
            oozieInstanceGroup.get().addTargetGroup(oozieTargetGroup);
        } else {
            LOGGER.debug("Dry run, skipping instance group/target group linkage for Oozie.");
        }
        return Optional.of(oozieTargetGroup);
    } else {
        LOGGER.info("Oozie HA instance group not found; not enabling Oozie load balancer configuration.");
        return Optional.empty();
    }
}
Also used : TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 14 with TargetGroup

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.

the class LoadBalancerToLoadBalancerResponseConverterTest method creatGcpTargetGroups.

private Set<TargetGroup> creatGcpTargetGroups() {
    GcpTargetGroupConfigDb gcpTargetGroupConfigDb = new GcpTargetGroupConfigDb();
    GcpLoadBalancerNamesDb gcpLoadBalancerNamesDb = new GcpLoadBalancerNamesDb();
    gcpLoadBalancerNamesDb.setBackendServiceName(GCP_BACKEND_SERVICE_NAME);
    gcpLoadBalancerNamesDb.setInstanceGroupName(GCP_INSTANCE_GROUP_NAME);
    gcpTargetGroupConfigDb.addPortNameMapping(PORT, gcpLoadBalancerNamesDb);
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = new TargetGroupConfigDbWrapper();
    targetGroupConfigDbWrapper.setGcpConfig(gcpTargetGroupConfigDb);
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setProviderConfig(targetGroupConfigDbWrapper);
    return Set.of(targetGroup);
}
Also used : GcpLoadBalancerNamesDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpLoadBalancerNamesDb) TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) GcpTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpTargetGroupConfigDb)

Example 15 with TargetGroup

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.

the class LoadBalancerToLoadBalancerResponseConverterTest method createAzureTargetGroups.

private Set<TargetGroup> createAzureTargetGroups() {
    AzureTargetGroupConfigDb azureTargetGroupConfigDb = new AzureTargetGroupConfigDb();
    azureTargetGroupConfigDb.setPortAvailabilitySetMapping(Map.of(PORT, List.of(AZURE_AS_NAME)));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = new TargetGroupConfigDbWrapper();
    targetGroupConfigDbWrapper.setAzureConfig(azureTargetGroupConfigDb);
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setProviderConfig(targetGroupConfigDbWrapper);
    return Set.of(targetGroup);
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AzureTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb)

Aggregations

TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)19 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)12 TargetGroupConfigDbWrapper (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper)10 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)9 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)7 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)7 Test (org.junit.Test)6 AwsTargetGroupConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 AwsTargetGroupArnsDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb)4 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)3 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)3 Json (com.sequenceiq.cloudbreak.common.json.Json)3 AzureTargetGroupConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb)3 LoadBalancerSku (com.sequenceiq.common.api.type.LoadBalancerSku)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3