Search in sources :

Example 16 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMultiplePorts.

@Test
public void testCollectLoadBalancerMultiplePorts() {
    int numPorts = 3;
    AuthenticatedContext ac = authenticatedContext();
    LoadBalancer loadBalancer = createLoadBalancer();
    List<StackResourceSummary> summaries = createSummaries(numPorts, true);
    ListStackResourcesResult result = new ListStackResourcesResult();
    result.setStackResourceSummaries(summaries);
    Map<String, Object> expectedParameters = Map.of(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN, AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, TARGET_GROUP_ARN + "0Internal", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 1, LISTENER_ARN + "1Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 1, TARGET_GROUP_ARN + "1Internal", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 2, LISTENER_ARN + "2Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 2, TARGET_GROUP_ARN + "2Internal");
    when(awsClient.createCloudFormationClient(any(), any())).thenReturn(cfRetryClient);
    when(cloudFormationStackUtil.getCfStackName(ac)).thenReturn("stackName");
    when(awsStackRequestHelper.createListStackResourcesRequest(eq("stackName"))).thenReturn(new ListStackResourcesRequest());
    when(cfRetryClient.listStackResources(any())).thenReturn(result);
    Map<String, Object> parameters = underTest.getParameters(ac, loadBalancer, AwsLoadBalancerScheme.INTERNAL);
    assertEquals(expectedParameters, parameters);
}
Also used : ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) Test(org.junit.jupiter.api.Test)

Example 17 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project cloudbreak by hortonworks.

the class AwsMetaDataCollectorTest method setupMethodsForLoadBalancer.

private void setupMethodsForLoadBalancer(boolean canFindInternalLB) {
    LoadBalancer internalLoadBalancer = new LoadBalancer().withDNSName(INTERNAL_LB_DNS).withCanonicalHostedZoneId(ZONE_1);
    LoadBalancer externalLoadBalancer = new LoadBalancer().withDNSName(EXTERNAL_LB_DNS).withCanonicalHostedZoneId(ZONE_2);
    if (canFindInternalLB) {
        when(cloudFormationStackUtil.getLoadBalancerByLogicalId(any(), eq(INTERNAL_LB_ID))).thenReturn(internalLoadBalancer);
    } else {
        when(cloudFormationStackUtil.getLoadBalancerByLogicalId(any(), eq(INTERNAL_LB_ID))).thenThrow(new RuntimeException("missing metadata"));
    }
    when(cloudFormationStackUtil.getLoadBalancerByLogicalId(any(), eq(EXTERNAL_LB_ID))).thenReturn(externalLoadBalancer);
    when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PRIVATE))).thenReturn(AwsLoadBalancerScheme.INTERNAL);
    when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PUBLIC))).thenReturn(AwsLoadBalancerScheme.INTERNET_FACING);
}
Also used : LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)

Example 18 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project cloudbreak by hortonworks.

the class CloudFormationStackUtil method getLoadBalancerByLogicalId.

public LoadBalancer getLoadBalancerByLogicalId(AuthenticatedContext ac, String logicalId) {
    String region = ac.getCloudContext().getLocation().getRegion().value();
    AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
    String loadBalancerArn = getResourceArnByLogicalId(ac, logicalId, region);
    DescribeLoadBalancersResult loadBalancersResult = amazonElbClient.describeLoadBalancers(new DescribeLoadBalancersRequest().withLoadBalancerArns(Collections.singletonList(loadBalancerArn)));
    return loadBalancersResult.getLoadBalancers().get(0);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest)

Example 19 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMissingTargetGroup.

@Test
public void testCollectLoadBalancerMissingTargetGroup() {
    int numPorts = 1;
    AuthenticatedContext ac = authenticatedContext();
    LoadBalancer loadBalancer = createLoadBalancer();
    List<StackResourceSummary> summaries = createSummaries(numPorts, false);
    ListStackResourcesResult result = new ListStackResourcesResult();
    result.setStackResourceSummaries(summaries);
    Map<String, Object> expectedParameters = new HashMap<>();
    expectedParameters.put(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN);
    expectedParameters.put(AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal");
    expectedParameters.put(AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, null);
    when(awsClient.createCloudFormationClient(any(), any())).thenReturn(cfRetryClient);
    when(cloudFormationStackUtil.getCfStackName(ac)).thenReturn("stackName");
    when(awsStackRequestHelper.createListStackResourcesRequest(eq("stackName"))).thenReturn(new ListStackResourcesRequest());
    when(cfRetryClient.listStackResources(any())).thenReturn(result);
    Map<String, Object> parameters = underTest.getParameters(ac, loadBalancer, AwsLoadBalancerScheme.INTERNAL);
    assertEquals(expectedParameters, parameters);
}
Also used : HashMap(java.util.HashMap) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) Test(org.junit.jupiter.api.Test)

Example 20 with LoadBalancer

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerMetadataCollectorTest method createLoadBalancer.

private LoadBalancer createLoadBalancer() {
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setLoadBalancerArn(LOAD_BALANCER_ARN);
    return loadBalancer;
}
Also used : LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)

Aggregations

LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)20 Test (org.junit.jupiter.api.Test)16 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)14 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)14 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)13 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)12 AmazonServiceException (com.amazonaws.AmazonServiceException)10 AmazonElasticLoadBalancingClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient)10 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)10 ArrayList (java.util.ArrayList)10 AmazonElasticLoadBalancingException (com.amazonaws.services.elasticloadbalancingv2.model.AmazonElasticLoadBalancingException)9 RegisterTargetsResult (com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsResult)9 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 CommonStatus (com.sequenceiq.common.api.type.CommonStatus)9 ResourceType (com.sequenceiq.common.api.type.ResourceType)9 List (java.util.List)9 Map (java.util.Map)9 CreateLoadBalancerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult)8 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 CreateListenerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult)7