Search in sources :

Example 36 with CloudLoadBalancerMetadata

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

the class AzureMetadataCollectorTest method testCollectSinglePublicLoadBalancer.

@Test
public void testCollectSinglePublicLoadBalancer() {
    List<CloudResource> resources = new ArrayList<>();
    CloudResource cloudResource = createCloudResource();
    when(authenticatedContext.getCloudContext()).thenReturn(mockCloudContext);
    when(mockCloudContext.getName()).thenReturn(RESOURCE_GROUP_NAME);
    when(azureUtils.getTemplateResource(resources)).thenReturn(cloudResource);
    when(azureUtils.getStackName(any())).thenReturn(STACK_NAME);
    final String loadBalancerName = AzureLoadBalancer.getLoadBalancerName(LoadBalancerType.PUBLIC, STACK_NAME);
    when(azureClient.getLoadBalancerIps(RESOURCE_GROUP_NAME, loadBalancerName, LoadBalancerType.PUBLIC)).thenReturn(List.of(PUBLIC_IP));
    when(authenticatedContext.getParameter(AzureClient.class)).thenReturn(azureClient);
    when(azureLbMetadataCollector.getParameters(any(), anyString(), anyString())).thenReturn(Map.of());
    List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
    assertEquals(1, result.size());
    assertEquals(PUBLIC_IP, result.get(0).getIp());
    assertEquals(LoadBalancerType.PUBLIC, result.get(0).getType());
}
Also used : ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 37 with CloudLoadBalancerMetadata

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

the class LoadBalancerMetadataService method collectMetadata.

public List<CloudLoadBalancerMetadata> collectMetadata(CloudContext cloudContext, CloudCredential cloudCredential, List<LoadBalancerType> types, List<CloudResource> cloudResources) {
    LOGGER.debug("Initiating load balancer metadata collection");
    CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
    AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
    List<CloudLoadBalancerMetadata> loadBalancerStatuses = connector.metadata().collectLoadBalancer(ac, types, cloudResources);
    LOGGER.debug("Load balancer metadata collection successfully finished. Collected metadata: {}", loadBalancerStatuses);
    return loadBalancerStatuses;
}
Also used : AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)

Example 38 with CloudLoadBalancerMetadata

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

the class AwsMetaDataCollectorTest method testCollectLoadBalancers.

@Test
public void testCollectLoadBalancers() {
    setupMethodsForLoadBalancer(true);
    AuthenticatedContext ac = authenticatedContext();
    List<CloudLoadBalancerMetadata> metadata = awsMetadataCollector.collectLoadBalancer(ac, List.of(LoadBalancerType.PRIVATE, LoadBalancerType.PUBLIC), null);
    assertEquals(2, metadata.size());
    Optional<CloudLoadBalancerMetadata> internalMetadata = metadata.stream().filter(m -> m.getType() == LoadBalancerType.PRIVATE).findFirst();
    assertTrue(internalMetadata.isPresent());
    assertEquals(INTERNAL_LB_DNS, internalMetadata.get().getCloudDns());
    assertEquals(ZONE_1, internalMetadata.get().getHostedZoneId());
    Optional<CloudLoadBalancerMetadata> externalMetadata = metadata.stream().filter(m -> m.getType() == LoadBalancerType.PUBLIC).findFirst();
    assertTrue(externalMetadata.isPresent());
    assertEquals(EXTERNAL_LB_DNS, externalMetadata.get().getCloudDns());
    assertEquals(ZONE_2, externalMetadata.get().getHostedZoneId());
}
Also used : Arrays(java.util.Arrays) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Reservation(com.amazonaws.services.ec2.model.Reservation) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Collectors(java.util.stream.Collectors) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) Test(org.junit.jupiter.api.Test) List(java.util.List) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) AwsLifeCycleMapper(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsLifeCycleMapper) Captor(org.mockito.Captor) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) ArgumentCaptor(org.mockito.ArgumentCaptor) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Subnet(com.amazonaws.services.ec2.model.Subnet) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) Instance(com.amazonaws.services.ec2.model.Instance) InjectMocks(org.mockito.InjectMocks) CloudInstanceLifeCycle(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceLifeCycle) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) Collections(java.util.Collections) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 39 with CloudLoadBalancerMetadata

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

the class AwsMetaDataCollectorTest method testCollectLoadBalancerMissingMetadata.

@Test
public void testCollectLoadBalancerMissingMetadata() {
    setupMethodsForLoadBalancer(false);
    when(awsLoadBalancerMetadataCollector.getParameters(any(), any(), any())).thenReturn(Map.of());
    AuthenticatedContext ac = authenticatedContext();
    List<CloudLoadBalancerMetadata> metadata = awsMetadataCollector.collectLoadBalancer(ac, List.of(LoadBalancerType.PRIVATE, LoadBalancerType.PUBLIC), null);
    assertEquals(1, metadata.size());
    Optional<CloudLoadBalancerMetadata> externalMetadata = metadata.stream().filter(m -> m.getType() == LoadBalancerType.PUBLIC).findFirst();
    assertTrue(externalMetadata.isPresent());
    assertEquals(LoadBalancerType.PUBLIC, metadata.iterator().next().getType());
    assertEquals(EXTERNAL_LB_DNS, metadata.iterator().next().getCloudDns());
    assertEquals(ZONE_2, metadata.iterator().next().getHostedZoneId());
}
Also used : Arrays(java.util.Arrays) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Reservation(com.amazonaws.services.ec2.model.Reservation) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Collectors(java.util.stream.Collectors) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) Test(org.junit.jupiter.api.Test) List(java.util.List) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) AwsLifeCycleMapper(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsLifeCycleMapper) Captor(org.mockito.Captor) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) ArgumentCaptor(org.mockito.ArgumentCaptor) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Subnet(com.amazonaws.services.ec2.model.Subnet) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) Instance(com.amazonaws.services.ec2.model.Instance) InjectMocks(org.mockito.InjectMocks) CloudInstanceLifeCycle(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceLifeCycle) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) Collections(java.util.Collections) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 40 with CloudLoadBalancerMetadata

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

the class AwsMetaDataCollectorTest method testCollectLoadBalancerOnlyEndpointAccessGateway.

@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void testCollectLoadBalancerOnlyEndpointAccessGateway() {
    setupMethodsForLoadBalancer(true);
    when(awsLoadBalancerMetadataCollector.getParameters(any(), any(), any())).thenReturn(Map.of());
    AuthenticatedContext ac = authenticatedContext();
    List<CloudLoadBalancerMetadata> metadata = awsMetadataCollector.collectLoadBalancer(ac, List.of(LoadBalancerType.PUBLIC), null);
    assertEquals(1, metadata.size());
    Optional<CloudLoadBalancerMetadata> externalMetadata = metadata.stream().filter(m -> m.getType() == LoadBalancerType.PUBLIC).findFirst();
    assertTrue(externalMetadata.isPresent());
    assertEquals(EXTERNAL_LB_DNS, externalMetadata.get().getCloudDns());
    assertEquals(ZONE_2, externalMetadata.get().getHostedZoneId());
}
Also used : Arrays(java.util.Arrays) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Reservation(com.amazonaws.services.ec2.model.Reservation) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Collectors(java.util.stream.Collectors) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) Test(org.junit.jupiter.api.Test) List(java.util.List) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) AwsLifeCycleMapper(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsLifeCycleMapper) Captor(org.mockito.Captor) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) ArgumentCaptor(org.mockito.ArgumentCaptor) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Subnet(com.amazonaws.services.ec2.model.Subnet) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) Instance(com.amazonaws.services.ec2.model.Instance) InjectMocks(org.mockito.InjectMocks) CloudInstanceLifeCycle(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceLifeCycle) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) Collections(java.util.Collections) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings)

Aggregations

CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)45 ArrayList (java.util.ArrayList)22 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)18 Test (org.junit.jupiter.api.Test)17 Test (org.junit.Test)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 List (java.util.List)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)8 Optional (java.util.Optional)8 LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)7 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)7 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)7 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)7 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ForwardingRule (com.google.api.services.compute.model.ForwardingRule)6