Search in sources :

Example 21 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class LoadBalancerConfigConverterTest method testConvertAwsTargetGroupMissingPortInMetadata.

@Test
public void testConvertAwsTargetGroupMissingPortInMetadata() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAwsParams(1)).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT1);
    TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AWS, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAwsConfig());
    AwsTargetGroupConfigDb awsTargetGroupConfigDb = targetGroupConfigDbWrapper.getAwsConfig();
    assertEquals(2, awsTargetGroupConfigDb.getPortArnMapping().size());
    assertEquals(Set.of(PORT1, PORT2), awsTargetGroupConfigDb.getPortArnMapping().keySet());
    AwsTargetGroupArnsDb targetGroupArns = awsTargetGroupConfigDb.getPortArnMapping().get(PORT1);
    assertEquals(LISTENER_ARN, targetGroupArns.getListenerArn());
    assertEquals(TARGET_ARN, targetGroupArns.getTargetGroupArn());
    targetGroupArns = awsTargetGroupConfigDb.getPortArnMapping().get(PORT2);
    assertEquals(MISSING_CLOUD_RESOURCE, targetGroupArns.getListenerArn());
    assertEquals(MISSING_CLOUD_RESOURCE, targetGroupArns.getTargetGroupArn());
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) AwsTargetGroupArnsDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 22 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair 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 23 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair 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 24 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class StackToCloudStackConverterTest method testConvertWithKnoxLoadBalancer.

@Test
public void testConvertWithKnoxLoadBalancer() {
    Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
    InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
    InstanceGroup instanceGroup2 = mock(InstanceGroup.class);
    when(instanceGroup1.getGroupName()).thenReturn("group1");
    when(instanceGroup2.getGroupName()).thenReturn("group2");
    instanceGroups.add(instanceGroup1);
    instanceGroups.add(instanceGroup2);
    when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
    Template template = new Template();
    template.setVolumeTemplates(Sets.newHashSet());
    when(instanceGroup1.getTemplate()).thenReturn(template);
    when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
    when(instanceGroup1.getStack()).thenReturn(stack);
    when(instanceGroup2.getTemplate()).thenReturn(template);
    when(instanceGroup2.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
    when(instanceGroup2.getStack()).thenReturn(stack);
    TargetGroup targetGroup = mock(TargetGroup.class);
    when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
    LoadBalancer loadBalancer = mock(LoadBalancer.class);
    when(loadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
    when(loadBalancer.getId()).thenReturn(1L);
    when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
    when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
    when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1, instanceGroup2));
    TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(443, 8443);
    when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(targetGroupPortPair));
    CloudStack result = underTest.convert(stack);
    assertEquals(1, result.getLoadBalancers().size());
    CloudLoadBalancer cloudLoadBalancer = result.getLoadBalancers().iterator().next();
    assertEquals(LoadBalancerType.PRIVATE, cloudLoadBalancer.getType());
    assertEquals(Set.of(targetGroupPortPair), cloudLoadBalancer.getPortToTargetGroupMapping().keySet());
    Set<String> groupNames = cloudLoadBalancer.getPortToTargetGroupMapping().values().stream().flatMap(Collection::stream).collect(Collectors.toSet()).stream().map(Group::getName).collect(Collectors.toSet());
    assertEquals(Set.of("group1", "group2"), groupNames);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Collection(java.util.Collection) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class StackToCloudStackConverterTest method testConvertWithLoadBalancerSkuSet.

@Test
public void testConvertWithLoadBalancerSkuSet() {
    Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
    InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
    instanceGroups.add(instanceGroup1);
    Template template = new Template();
    template.setVolumeTemplates(Sets.newHashSet());
    TargetGroup targetGroup = mock(TargetGroup.class);
    LoadBalancer loadBalancer = mock(LoadBalancer.class);
    TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(443, 8443);
    when(instanceGroup1.getGroupName()).thenReturn("group1");
    when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
    when(instanceGroup1.getTemplate()).thenReturn(template);
    when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
    when(instanceGroup1.getStack()).thenReturn(stack);
    when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
    when(loadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
    when(loadBalancer.getId()).thenReturn(1L);
    when(loadBalancer.getSku()).thenReturn(LoadBalancerSku.STANDARD);
    when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
    when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
    when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1));
    when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(targetGroupPortPair));
    CloudStack result = underTest.convert(stack);
    assertEquals(1, result.getLoadBalancers().size());
    CloudLoadBalancer cloudLoadBalancer = result.getLoadBalancers().iterator().next();
    assertEquals(LoadBalancerSku.STANDARD, cloudLoadBalancer.getSku());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)36 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)24 Group (com.sequenceiq.cloudbreak.cloud.model.Group)19 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)14 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)11 Set (java.util.Set)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)8 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)8 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)8 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)8 Network (com.sequenceiq.cloudbreak.cloud.model.Network)8 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)8 List (java.util.List)7