Search in sources :

Example 16 with CloudLoadBalancerMetadata

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

the class CollectLoadBalancerMetadataHandler method accept.

@Override
public void accept(Event<CollectLoadBalancerMetadataRequest> collectLBMetadataRequestEvent) {
    LOGGER.debug("Received event: {}", collectLBMetadataRequestEvent);
    CollectLoadBalancerMetadataRequest request = collectLBMetadataRequestEvent.getData();
    try {
        List<CloudLoadBalancerMetadata> loadBalancerStatuses = loadBalancerMetadataService.collectMetadata(request.getCloudContext(), request.getCloudCredential(), request.getTypesPresentInStack(), request.getCloudResources());
        CollectLoadBalancerMetadataResult collectLBMetadataResult = new CollectLoadBalancerMetadataResult(request.getResourceId(), loadBalancerStatuses);
        request.getResult().onNext(collectLBMetadataResult);
        eventBus.notify(collectLBMetadataResult.selector(), new Event<>(collectLBMetadataRequestEvent.getHeaders(), collectLBMetadataResult));
        LOGGER.debug("Load balancer metadata collection successfully finished");
    } catch (RuntimeException e) {
        LOGGER.error("Collecting load balancer metadata failed", e);
        CollectLoadBalancerMetadataResult failure = new CollectLoadBalancerMetadataResult(e, request.getResourceId());
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(collectLBMetadataRequestEvent.getHeaders(), failure));
    }
}
Also used : CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) Event(reactor.bus.Event) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)

Example 17 with CloudLoadBalancerMetadata

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

the class YarnMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
    List<CloudLoadBalancerMetadata> loadBalancerMetadata = Lists.newArrayList();
    if (loadBalancerTypes.size() == 0) {
        return loadBalancerMetadata;
    }
    YarnClient yarnClient = yarnClientUtil.createYarnClient(ac);
    String loadBalancerApplicationName = applicationNameUtil.createLoadBalancerName(ac);
    Iterable<Container> loadBalancerContainers = yarnLoadBalancerLaunchService.getContainers(loadBalancerApplicationName, yarnClient);
    Iterator<Container> containerIterator = loadBalancerContainers.iterator();
    for (LoadBalancerType loadBalancerType : loadBalancerTypes) {
        Container container = containerIterator.next();
        CloudLoadBalancerMetadata metadata = new CloudLoadBalancerMetadata.Builder().withType(loadBalancerType).withName(applicationNameUtil.createLoadBalancerComponentName(loadBalancerApplicationName, loadBalancerType)).withIp(container.getIp()).build();
        loadBalancerMetadata.add(metadata);
    }
    return loadBalancerMetadata;
}
Also used : Container(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Container) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType)

Example 18 with CloudLoadBalancerMetadata

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

the class AwsMetaDataCollectorTest method testCollectLoadBalancerOnlyDefaultGateway.

@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void testCollectLoadBalancerOnlyDefaultGateway() {
    setupMethodsForLoadBalancer(true);
    when(awsLoadBalancerMetadataCollector.getParameters(any(), any(), any())).thenReturn(Map.of());
    AuthenticatedContext ac = authenticatedContext();
    List<CloudLoadBalancerMetadata> metadata = awsMetadataCollector.collectLoadBalancer(ac, List.of(LoadBalancerType.PRIVATE), null);
    assertEquals(1, 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());
}
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)

Example 19 with CloudLoadBalancerMetadata

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

the class LoadBalancerConfigConverterTest method testConvertAwsTargetGroupExtraPortsInMetadata.

@Test
public void testConvertAwsTargetGroupExtraPortsInMetadata() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAwsParams(3)).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT1);
    TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AWS, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAwsConfig());
    AwsTargetGroupConfigDb awsTargetGroupConfigDb = targetGroupConfigDbWrapper.getAwsConfig();
    assertEquals(2, awsTargetGroupConfigDb.getPortArnMapping().size());
    assertEquals(Set.of(PORT1, PORT2), awsTargetGroupConfigDb.getPortArnMapping().keySet());
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Example 20 with CloudLoadBalancerMetadata

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

the class LoadBalancerConfigConverterTest method testConvertAzureTargetGroupMissingAvailabilitySetInMetadata.

@Test
public void testConvertAzureTargetGroupMissingAvailabilitySetInMetadata() {
    Map<String, Object> azureParams = createAzureParams(1);
    azureParams.put(AzureLoadBalancerMetadataView.getAvailabilitySetParam(PORT2), null);
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(azureParams).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT2);
    TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
    TargetGroupPortPair portPair3 = new TargetGroupPortPair(PORT3, PORT3);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2, portPair3));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AZURE, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAzureConfig());
    AzureTargetGroupConfigDb azureTargetGroupConfigDb = targetGroupConfigDbWrapper.getAzureConfig();
    assertEquals(Set.of(PORT1, PORT2, PORT3), azureTargetGroupConfigDb.getPortAvailabilitySetMapping().keySet());
    List<String> availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT1);
    assertEquals(List.of(AVAILABILITY_SET_NAME), availabilitySets);
    availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT2);
    assertEquals(List.of(MISSING_CLOUD_RESOURCE), availabilitySets);
    availabilitySets = azureTargetGroupConfigDb.getPortAvailabilitySetMapping().get(PORT3);
    assertEquals(List.of(MISSING_CLOUD_RESOURCE), availabilitySets);
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AzureTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) 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