Search in sources :

Example 56 with LoadBalancer

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

the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertAws.

@Test
public void testConvertAws() {
    LoadBalancer source = getSource();
    // GIVEN
    getSource().setProviderConfig(createAwsLoadBalancerConfig());
    given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAwsTargetGroups());
    // WHEN
    LoadBalancerResponse response = underTest.convert(source);
    // THEN
    assertAllFieldsNotNull(response, List.of("azureResourceId", "gcpResourceId"));
    assertEquals(LB_ARN, response.getAwsResourceId().getArn());
    assertEquals(1, response.getTargets().size());
    TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
    assertEquals(PORT, targetGroupResponse.getPort());
    assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
    AwsTargetGroupResponse awsTargetGroupResponse = targetGroupResponse.getAwsResourceIds();
    assertNotNull(awsTargetGroupResponse);
    assertEquals(LISTENER_ARN, awsTargetGroupResponse.getListenerArn());
    assertEquals(TG_ARN, awsTargetGroupResponse.getTargetGroupArn());
}
Also used : LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 57 with LoadBalancer

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

the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertAzure.

@Test
public void testConvertAzure() {
    LoadBalancer source = getSource();
    // GIVEN
    getSource().setProviderConfig(createAzureLoadBalancerConfig());
    given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAzureTargetGroups());
    // WHEN
    LoadBalancerResponse response = underTest.convert(source);
    // THEN
    assertAllFieldsNotNull(response, List.of("awsResourceId", "gcpResourceId"));
    assertEquals(AZURE_LB_NAME, response.getAzureResourceId().getName());
    assertEquals(1, response.getTargets().size());
    TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
    assertEquals(PORT, targetGroupResponse.getPort());
    assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
    AzureTargetGroupResponse azureTargetGroupResponse = targetGroupResponse.getAzureResourceId();
    assertNotNull(azureTargetGroupResponse);
    assertEquals(List.of(AZURE_AS_NAME), azureTargetGroupResponse.getAvailabilitySet());
}
Also used : LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 58 with LoadBalancer

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

the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertGcp.

@Test
public void testConvertGcp() {
    LoadBalancer source = getSource();
    // GIVEN
    getSource().setProviderConfig(createGcpLoadBalancerConfig());
    given(targetGroupService.findByLoadBalancerId(any())).willReturn(creatGcpTargetGroups());
    // WHEN
    LoadBalancerResponse response = underTest.convert(source);
    // THEN
    assertAllFieldsNotNull(response, List.of("awsResourceId", "azureResourceId"));
    assertEquals(GCP_LB_NAME, response.getGcpResourceId().getName());
    assertEquals(1, response.getTargets().size());
    TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
    assertEquals(PORT, targetGroupResponse.getPort());
    assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
    GcpTargetGroupResponse gcpTargetGroupResponse = targetGroupResponse.getGcpResourceId();
    assertNotNull(gcpTargetGroupResponse);
    assertEquals(GCP_INSTANCE_GROUP_NAME, gcpTargetGroupResponse.getGcpInstanceGroupName());
    assertEquals(GCP_BACKEND_SERVICE_NAME, gcpTargetGroupResponse.getGcpBackendServiceName());
}
Also used : LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 59 with LoadBalancer

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

the class LoadBalancerToLoadBalancerResponseConverterTest method createSource.

@Override
public LoadBalancer createSource() {
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setType(LoadBalancerType.PRIVATE);
    loadBalancer.setFqdn(LB_FQDN);
    loadBalancer.setIp(LB_IP);
    loadBalancer.setDns(LB_DNS);
    return loadBalancer;
}
Also used : LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)

Example 60 with LoadBalancer

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer 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)

Aggregations

LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)74 Test (org.junit.Test)48 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)46 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)39 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)37 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)32 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)26 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)16 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)12 Test (org.junit.jupiter.api.Test)12 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 LoadBalancerPersistenceService (com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService)9 HashSet (java.util.HashSet)9 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)8 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)8 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)8 Map (java.util.Map)8 Optional (java.util.Optional)8 Json (com.sequenceiq.cloudbreak.common.json.Json)7