Search in sources :

Example 1 with AwsTargetGroup

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

the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerExistingPrivate.

@Test
public void testConvertLoadBalancerExistingPrivate() {
    AwsLoadBalancer existingLoadBalancer = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNAL);
    when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PRIVATE))).thenReturn(AwsLoadBalancerScheme.INTERNAL);
    AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(existingLoadBalancer), LoadBalancerType.PRIVATE, PRIVATE_ID_1);
    assertNotNull(awsLoadBalancer);
    assertEquals(existingLoadBalancer, 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 2 with AwsTargetGroup

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup 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 3 with AwsTargetGroup

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup 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 4 with AwsTargetGroup

use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup 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 5 with AwsTargetGroup

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

the class AwsNativeLoadBalancerLaunchService method registerTarget.

private void registerTarget(AmazonElasticLoadBalancingClient loadBalancingClient, Long stackId, AwsTargetGroup targetGroup) {
    LOGGER.debug("Registering targets to target group '{}'", targetGroup.getArn());
    Set<TargetDescription> targetDescriptions = targetGroup.getInstanceIds().stream().map(privateId -> {
        String instanceId = persistenceRetriever.notifyRetrieve(stackId, privateId, CommonStatus.CREATED, ResourceType.AWS_INSTANCE).orElseThrow(() -> {
            String notFoundMsg = String.format("No AWS instance resource found with private id('%s') for stack('%s')", privateId, stackId);
            return new CloudConnectorException(notFoundMsg);
        }).getInstanceId();
        return new TargetDescription().withPort(targetGroup.getPort()).withId(instanceId);
    }).collect(toSet());
    RegisterTargetsRequest registerTargetsRequest = new RegisterTargetsRequest().withTargetGroupArn(targetGroup.getArn()).withTargets(targetDescriptions);
    LOGGER.info("Registering target group of load balancer('{}') to instances: '{}'", targetGroup.getArn(), String.join(",", targetGroup.getInstanceIds()));
    loadBalancingClient.registerTargets(registerTargetsRequest);
}
Also used : AwsResourceNameService(com.sequenceiq.cloudbreak.cloud.aws.common.service.AwsResourceNameService) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreateTargetGroupResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupResult) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) LoggerFactory(org.slf4j.LoggerFactory) DescribeListenersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) CreateListenerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult) StringUtils(org.apache.commons.lang3.StringUtils) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Collectors.toSet(java.util.stream.Collectors.toSet) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) Action(com.amazonaws.services.elasticloadbalancingv2.model.Action) Collection(java.util.Collection) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Set(java.util.Set) LoadBalancerTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerTypeEnum) Collectors(java.util.stream.Collectors) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerRequest) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) IpAddressType(com.amazonaws.services.elasticloadbalancingv2.model.IpAddressType) Tag(com.amazonaws.services.elasticloadbalancingv2.model.Tag) Group(com.sequenceiq.cloudbreak.cloud.model.Group) DescribeListenersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest) Optional(java.util.Optional) CreateListenerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerRequest) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) ArrayList(java.util.ArrayList) TargetTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.TargetTypeEnum) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) PersistenceRetriever(com.sequenceiq.cloudbreak.cloud.notification.PersistenceRetriever) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) AwsLoadBalancerCommonService(com.sequenceiq.cloudbreak.cloud.aws.common.connector.resource.AwsLoadBalancerCommonService) Service(org.springframework.stereotype.Service) CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) ActionTypeEnum(com.amazonaws.services.elasticloadbalancingv2.model.ActionTypeEnum) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CreateTargetGroupRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupRequest) ProtocolEnum(com.amazonaws.services.elasticloadbalancingv2.model.ProtocolEnum) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors.toList(java.util.stream.Collectors.toList) AwsCloudStackView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCloudStackView) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AwsTaggingService(com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription)

Aggregations

AwsListener (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener)8 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)8 AwsTargetGroup (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup)8 Test (org.junit.jupiter.api.Test)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 Action (com.amazonaws.services.elasticloadbalancingv2.model.Action)3 ActionTypeEnum (com.amazonaws.services.elasticloadbalancingv2.model.ActionTypeEnum)3 CreateListenerRequest (com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerRequest)3 CreateListenerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult)3 CreateLoadBalancerRequest (com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerRequest)3 CreateLoadBalancerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult)3 CreateTargetGroupRequest (com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupRequest)3 CreateTargetGroupResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupResult)3 DescribeListenersRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest)3 DescribeListenersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersResult)3 DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest)3 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)3 DescribeTargetGroupsRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest)3 DescribeTargetGroupsResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult)3 IpAddressType (com.amazonaws.services.elasticloadbalancingv2.model.IpAddressType)3