Search in sources :

Example 6 with CloudLoadBalancerMetadata

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

the class GCPLoadBalancerMetadataCollectorTest method testCollectLoadBalancerWithNoIps.

@Test
public void testCollectLoadBalancerWithNoIps() {
    List<CloudResource> resources = new ArrayList<>();
    resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
    ForwardingRule forwardingRule = new ForwardingRule();
    forwardingRule.setLoadBalancingScheme("EXTERNAL");
    forwardingRule.setName(FORWARDING_RULE_NAME_1);
    when(forwardingRuleListResponse.getItems()).thenReturn(List.of(forwardingRule));
    List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
    assertEquals(1, result.size());
    assertEquals(null, result.get(0).getIp());
    assertEquals(LoadBalancerType.PUBLIC, result.get(0).getType());
    assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getName());
    assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
    assertNull(result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
    assertNull(result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 7 with CloudLoadBalancerMetadata

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

the class GCPLoadBalancerMetadataCollectorTest method testCollectSinglePublicLoadBalancerWithMultipleForwardingRules.

@Test
public void testCollectSinglePublicLoadBalancerWithMultipleForwardingRules() {
    List<CloudResource> resources = new ArrayList<>();
    resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
    resources.add(createCloudResource(FORWARDING_RULE_NAME_2, ResourceType.GCP_FORWARDING_RULE));
    ForwardingRule publicFowardingRule = createPublicFowardingRule();
    ForwardingRule publicFowardingRule2 = createPublicFowardingRule();
    publicFowardingRule2.setIPAddress(PUBLIC_IP2);
    publicFowardingRule2.setName(FORWARDING_RULE_NAME_2);
    when(forwardingRuleListResponse.getItems()).thenReturn(List.of(publicFowardingRule, publicFowardingRule2));
    List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
    assertEquals(2, result.size());
    assertEquals(PUBLIC_IP, result.get(0).getIp());
    assertEquals(PUBLIC_IP2, result.get(1).getIp());
    assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getName());
    assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
    assertEquals(FORWARDING_RULE_NAME_2, result.get(1).getName());
    assertEquals(FORWARDING_RULE_NAME_2, result.get(1).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
    assertEquals(LoadBalancerType.PUBLIC, result.get(0).getType());
    assertEquals(BACKEND_SERVICE_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
    assertEquals(INSTANCE_GROUP_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
    assertEquals(BACKEND_SERVICE_NAME, result.get(1).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
    assertEquals(INSTANCE_GROUP_NAME, result.get(1).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 8 with CloudLoadBalancerMetadata

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

the class GCPLoadBalancerMetadataCollectorTest method testCollectPrivateLoadBalancer.

@Test
public void testCollectPrivateLoadBalancer() {
    List<CloudResource> resources = new ArrayList<>();
    resources.add(createCloudResource(FORWARDING_RULE_NAME_2, ResourceType.GCP_FORWARDING_RULE));
    ForwardingRule privateForwardingRule = createPrivateFowardingRule();
    when(forwardingRuleListResponse.getItems()).thenReturn(List.of(privateForwardingRule));
    List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PRIVATE), resources);
    assertEquals(1, result.size());
    assertEquals(PRIVATE_IP, result.get(0).getIp());
    assertEquals(LoadBalancerType.PRIVATE, result.get(0).getType());
    assertEquals(FORWARDING_RULE_NAME_2, result.get(0).getName());
    assertEquals(FORWARDING_RULE_NAME_2, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
    assertEquals(BACKEND_SERVICE_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(443)));
    assertEquals(INSTANCE_GROUP_NAME, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(443)));
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 9 with CloudLoadBalancerMetadata

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

the class GCPLoadBalancerMetadataCollectorTest method testCollectOtherType.

@Test
public void testCollectOtherType() {
    List<CloudResource> resources = new ArrayList<>();
    resources.add(createCloudResource(FORWARDING_RULE_NAME_2, ResourceType.GCP_FORWARDING_RULE));
    ForwardingRule privateForwardingRule = createPrivateFowardingRule();
    when(forwardingRuleListResponse.getItems()).thenReturn(List.of(privateForwardingRule));
    List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
    assertEquals(0, result.size());
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 10 with CloudLoadBalancerMetadata

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

the class MetadataSetupServiceTest method saveLoadBalancerMetadataAndSetEndpointToOldStack.

@Test
public void saveLoadBalancerMetadataAndSetEndpointToOldStack() {
    Stack oldStack = new Stack();
    oldStack.setId(OLD_STACK_ID);
    oldStack.setName(OLD_STACK_NAME);
    oldStack.setCloudPlatform("DEFAULT");
    oldStack.setEnvironmentCrn(STACK_CRN);
    oldStack.setDisplayName(STACK_DISPLAY_NAME);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setId(INSTANCE_GROUP_ID);
    instanceGroup.setGroupName(GROUP_NAME);
    instanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
    pgwInstanceMetadata.setInstanceStatus(STOPPED);
    pgwInstanceMetadata.setDiscoveryFQDN("master0.subdomain.cldr.work");
    pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
    instanceGroup.setInstanceMetaData(Set.of(pgwInstanceMetadata));
    oldStack.setInstanceGroups(Set.of(instanceGroup));
    stack.setName(STACK_NAME);
    stack.setCloudPlatform("DEFAULT");
    stack.setEnvironmentCrn(STACK_CRN);
    stack.setDisplayName(STACK_DISPLAY_NAME);
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setStack(stack);
    loadBalancer.setType(LoadBalancerType.PUBLIC);
    Set<LoadBalancer> loadBalancerSet = new HashSet<>();
    loadBalancerSet.add(loadBalancer);
    when(loadBalancerPersistenceService.findByStackId(STACK_ID)).thenReturn(loadBalancerSet);
    when(loadBalancerPersistenceService.findByStackId(OLD_STACK_ID)).thenReturn(new HashSet<>());
    when(loadBalancerConfigService.generateLoadBalancerEndpoint(stack)).thenCallRealMethod();
    StackIdView stackIdView = new StackIdViewImpl(STACK_ID, STACK_NAME, "no");
    StackStatus stackStatus = new StackStatus();
    stackStatus.setStatus(Status.AVAILABLE);
    stackStatus.setStack(stack);
    StackIdView stackIdViewOld = new StackIdViewImpl(OLD_STACK_ID, OLD_STACK_NAME, "old_no");
    StackStatus stoppedStackStatus = new StackStatus();
    stoppedStackStatus.setStatus(Status.STOPPED);
    stoppedStackStatus.setStack(oldStack);
    when(stackService.getByEnvironmentCrnAndStackType(STACK_CRN, StackType.DATALAKE)).thenReturn(List.of(stackIdView, stackIdViewOld));
    when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(STACK_ID)).thenReturn(Optional.of(stackStatus));
    when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(OLD_STACK_ID)).thenReturn(Optional.of(stoppedStackStatus));
    when(stackService.getByIdWithGatewayInTransaction(OLD_STACK_ID)).thenReturn(oldStack);
    when(targetGroupPersistenceService.findByLoadBalancerId(any())).thenReturn(Set.of());
    Iterable<CloudLoadBalancerMetadata> cloudLoadBalancerMetaDataStatuses = getCloudLoadBalancerMetaDataStatuses();
    underTest.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetaDataStatuses);
    verify(loadBalancerPersistenceService).save(loadBalancerCaptor.capture());
    LoadBalancer loadBalancerValue = loadBalancerCaptor.getValue();
    assertThat(loadBalancerValue.getHostedZoneId()).isSameAs(HOSTED_ZONE);
    assertThat(loadBalancerValue.getIp()).isSameAs(PUBLIC_IP);
    assertThat(loadBalancerValue.getDns()).isSameAs(CLOUD_DNS);
    assertThat(loadBalancerValue.getEndpoint()).isEqualTo("master0");
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackIdViewImpl(com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) HashSet(java.util.HashSet) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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