Search in sources :

Example 6 with AwsLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerNewPrivate.

@Test
public void testConvertLoadBalancerNewPrivate() {
    when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PRIVATE))).thenReturn(AwsLoadBalancerScheme.INTERNAL);
    AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(), LoadBalancerType.PRIVATE, PRIVATE_ID_1);
    assertNotNull(awsLoadBalancer);
    assertEquals(AwsLoadBalancerScheme.INTERNAL, awsLoadBalancer.getScheme());
    assertEquals(Set.of(PRIVATE_ID_1), awsLoadBalancer.getSubnetIds());
    assertEquals(1, awsLoadBalancer.getListeners().size());
    AwsListener listener = awsLoadBalancer.getListeners().get(0);
    assertEquals(PORT, listener.getPort());
    assertNotNull(listener.getTargetGroup());
    AwsTargetGroup targetGroup = listener.getTargetGroup();
    assertEquals(PORT, targetGroup.getPort());
    assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
Also used : AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Test(org.junit.jupiter.api.Test)

Example 7 with AwsLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerNewPublic.

@Test
public void testConvertLoadBalancerNewPublic() {
    when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PUBLIC))).thenReturn(AwsLoadBalancerScheme.INTERNET_FACING);
    AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(), LoadBalancerType.PUBLIC, PUBLIC_ID_1);
    assertNotNull(awsLoadBalancer);
    assertEquals(AwsLoadBalancerScheme.INTERNET_FACING, awsLoadBalancer.getScheme());
    assertEquals(Set.of(PUBLIC_ID_1), awsLoadBalancer.getSubnetIds());
    assertEquals(1, awsLoadBalancer.getListeners().size());
    AwsListener listener = awsLoadBalancer.getListeners().get(0);
    assertEquals(PORT, listener.getPort());
    assertNotNull(listener.getTargetGroup());
    AwsTargetGroup targetGroup = listener.getTargetGroup();
    assertEquals(PORT, targetGroup.getPort());
    assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
Also used : AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Test(org.junit.jupiter.api.Test)

Example 8 with AwsLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerExistingPublic.

@Test
public void testConvertLoadBalancerExistingPublic() {
    AwsLoadBalancer existingLoadBalancer = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNET_FACING);
    when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PUBLIC))).thenReturn(AwsLoadBalancerScheme.INTERNET_FACING);
    AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(existingLoadBalancer), LoadBalancerType.PUBLIC, PUBLIC_ID_1);
    assertNotNull(awsLoadBalancer);
    assertEquals(existingLoadBalancer, awsLoadBalancer);
    assertEquals(AwsLoadBalancerScheme.INTERNET_FACING, awsLoadBalancer.getScheme());
    assertEquals(Set.of(PUBLIC_ID_1), awsLoadBalancer.getSubnetIds());
    assertEquals(1, awsLoadBalancer.getListeners().size());
    AwsListener listener = awsLoadBalancer.getListeners().get(0);
    assertEquals(PORT, listener.getPort());
    assertNotNull(listener.getTargetGroup());
    AwsTargetGroup targetGroup = listener.getTargetGroup();
    assertEquals(PORT, targetGroup.getPort());
    assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
Also used : AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Test(org.junit.jupiter.api.Test)

Example 9 with AwsLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestHealthCheckPortDifferentFromTrafficPort.

public void buildTestHealthCheckPortDifferentFromTrafficPort() {
    // GIVEN
    AwsLoadBalancer awsLoadBalancer = setupLoadBalancer(AwsLoadBalancerScheme.INTERNAL, 443, true);
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withLoadBalancers(List.of(awsLoadBalancer));
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("\"Port\" : 443").contains("\"HealthCheckPort\" : \"8443\"");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil)

Example 10 with AwsLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestWithSingleLoadBalancerAfterUpdate.

@Test
public void buildTestWithSingleLoadBalancerAfterUpdate() {
    // GIVEN
    AwsLoadBalancer awsLoadBalancer = setupLoadBalancer(AwsLoadBalancerScheme.INTERNAL, 443, true);
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withLoadBalancers(List.of(awsLoadBalancer));
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("\"LoadBalancerInternal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::LoadBalancer\"").contains("\"Scheme\" : \"internal\"").contains("\"TargetGroupPort443Internal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::TargetGroup\"").contains("\"ListenerPort443Internal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::Listener\"");
    assert templateString.contains("\"Targets\" : [{ \"Id\" : \"instance1-443\" },{ \"Id\" : \"instance2-443\" }]}}") || templateString.contains("\"Targets\" : [{ \"Id\" : \"instance2-443\" },{ \"Id\" : \"instance1-443\" }]}}");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Test(org.junit.jupiter.api.Test)

Aggregations

AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)23 AwsListener (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener)14 ArrayList (java.util.ArrayList)8 AwsTargetGroup (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup)7 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)7 List (java.util.List)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)6 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)6 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Test (org.junit.jupiter.api.Test)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Service (org.springframework.stereotype.Service)6 ModelContext (com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext)5 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)4