Search in sources :

Example 11 with CloudLoadBalancerMetadata

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

the class LoadBalancerConfigConverterTest method testConvertGcpLoadBalancer.

@Test
public void testConvertGcpLoadBalancer() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(creatGcpParams(0)).build();
    LoadBalancerConfigDbWrapper cloudLoadBalancerConfigDbWrapper = underTest.convertLoadBalancer(GCP, cloudLoadBalancerMetadata);
    assertNotNull(cloudLoadBalancerConfigDbWrapper.getGcpConfig());
    GcpLoadBalancerConfigDb gcpLoadBalancerConfigDb = cloudLoadBalancerConfigDbWrapper.getGcpConfig();
    assertEquals(LB_NAME, gcpLoadBalancerConfigDb.getName());
}
Also used : LoadBalancerConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancerConfigDbWrapper) GcpLoadBalancerConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpLoadBalancerConfigDb) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 12 with CloudLoadBalancerMetadata

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

the class AwsMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
    LOGGER.debug("Collect AWS load balancer metadata, for cluster {}", ac.getCloudContext().getName());
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = new ArrayList<>();
    for (LoadBalancerType type : loadBalancerTypes) {
        AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(type);
        String loadBalancerName = AwsLoadBalancer.getLoadBalancerName(scheme);
        LOGGER.debug("Attempting to collect metadata for load balancer {}, type {}", loadBalancerName, type);
        try {
            LoadBalancer loadBalancer = cloudFormationStackUtil.getLoadBalancerByLogicalId(ac, loadBalancerName);
            LOGGER.debug("Parsing all listener and target group information for load balancer {}", loadBalancerName);
            Map<String, Object> parameters = awsLoadBalancerMetadataCollector.getParameters(ac, loadBalancer, scheme);
            CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(type).withCloudDns(loadBalancer.getDNSName()).withHostedZoneId(loadBalancer.getCanonicalHostedZoneId()).withName(loadBalancerName).withParameters(parameters).build();
            cloudLoadBalancerMetadata.add(loadBalancerMetadata);
            LOGGER.debug("Saved metadata for load balancer {}: DNS {}, zone id {}", loadBalancerName, loadBalancer.getDNSName(), loadBalancer.getCanonicalHostedZoneId());
        } catch (RuntimeException e) {
            LOGGER.debug("Unable to find metadata for load balancer " + loadBalancerName, e);
        }
    }
    return cloudLoadBalancerMetadata;
}
Also used : ArrayList(java.util.ArrayList) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Example 13 with CloudLoadBalancerMetadata

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

the class AwsNativeMetadataCollector method describeLoadBalancer.

private Optional<CloudLoadBalancerMetadata> describeLoadBalancer(String loadBalancerArn, AmazonElasticLoadBalancingClient loadBalancingClient, List<CloudResource> resources) {
    DescribeLoadBalancersRequest describeLoadBalancersRequest = new DescribeLoadBalancersRequest().withLoadBalancerArns(loadBalancerArn);
    DescribeLoadBalancersResult describeLoadBalancersResult = loadBalancingClient.describeLoadBalancers(describeLoadBalancersRequest);
    return describeLoadBalancersResult.getLoadBalancers().stream().findFirst().map(loadBalancer -> {
        LoadBalancerType type = loadBalancerTypeConverter.convert(loadBalancer.getScheme());
        Map<String, Object> parameters = awsNativeLbMetadataCollector.getParameters(loadBalancerArn, resources);
        CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(type).withCloudDns(loadBalancer.getDNSName()).withHostedZoneId(loadBalancer.getCanonicalHostedZoneId()).withName(loadBalancer.getLoadBalancerName()).withParameters(parameters).build();
        LOGGER.info("Saved metadata for load balancer {}: DNS {}, zone ID {}", loadBalancer.getLoadBalancerName(), loadBalancer.getDNSName(), loadBalancer.getCanonicalHostedZoneId());
        return loadBalancerMetadata;
    });
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)

Example 14 with CloudLoadBalancerMetadata

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

the class AzureMetadataCollectorTest method testCollectPrivateLoadBalancer.

@Test
public void testCollectPrivateLoadBalancer() {
    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 privateLoadBalancerName = AzureLoadBalancer.getLoadBalancerName(LoadBalancerType.PRIVATE, STACK_NAME);
    when(azureClient.getLoadBalancerIps(RESOURCE_GROUP_NAME, privateLoadBalancerName, LoadBalancerType.PRIVATE)).thenReturn(List.of(PRIVATE_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.PRIVATE), resources);
    assertEquals(1, result.size());
    assertEquals(LoadBalancerType.PRIVATE, result.get(0).getType());
    assertEquals(PRIVATE_IP, result.get(0).getIp());
}
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 15 with CloudLoadBalancerMetadata

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

the class AzureMetadataCollectorTest method testCollectPublicAndPrivateLoadBalancer.

@Test
public void testCollectPublicAndPrivateLoadBalancer() {
    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 publicLoadBalancerName = AzureLoadBalancer.getLoadBalancerName(LoadBalancerType.PUBLIC, STACK_NAME);
    when(azureClient.getLoadBalancerIps(RESOURCE_GROUP_NAME, publicLoadBalancerName, LoadBalancerType.PUBLIC)).thenReturn(List.of(PUBLIC_IP));
    final String privateLoadBalancerName = AzureLoadBalancer.getLoadBalancerName(LoadBalancerType.PRIVATE, STACK_NAME);
    when(azureClient.getLoadBalancerIps(RESOURCE_GROUP_NAME, privateLoadBalancerName, LoadBalancerType.PRIVATE)).thenReturn(List.of(PRIVATE_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, LoadBalancerType.PRIVATE), resources);
    assertEquals(2, result.size());
    Optional<CloudLoadBalancerMetadata> publicLoadBalancerMetadata = result.stream().filter(metadata -> metadata.getType() == LoadBalancerType.PUBLIC).findAny();
    assertTrue(publicLoadBalancerMetadata.isPresent());
    assertEquals(PUBLIC_IP, publicLoadBalancerMetadata.get().getIp());
    Optional<CloudLoadBalancerMetadata> privateLoadBalancerMetadata = result.stream().filter(metadata -> metadata.getType() == LoadBalancerType.PRIVATE).findAny();
    assertTrue(privateLoadBalancerMetadata.isPresent());
    assertEquals(PRIVATE_IP, privateLoadBalancerMetadata.get().getIp());
}
Also used : NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) InjectMocks(org.mockito.InjectMocks) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration) ResourceType(com.sequenceiq.common.api.type.ResourceType) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Optional(java.util.Optional) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) Mockito.any(org.mockito.Mockito.any) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) 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)

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