Search in sources :

Example 6 with LoadBalancer

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.

the class LoadBalancerToLoadBalancerResponseConverterTest method testNoSavedCloudConfig.

@Test
public void testNoSavedCloudConfig() {
    LoadBalancer source = getSource();
    // GIVEN
    given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAwsTargetGroups());
    // WHEN
    LoadBalancerResponse response = underTest.convert(source);
    // THEN
    assertAllFieldsNotNull(response, List.of("awsResourceId", "azureResourceId", "gcpResourceId"));
    assertNull(response.getAwsResourceId());
    assertNull(response.getAzureResourceId());
}
Also used : LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 7 with LoadBalancer

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.

the class LoadBalancerSANProviderTest method loadBalancerSetUp.

private void loadBalancerSetUp(String dns, String ip) {
    LoadBalancer loadBalancer = new LoadBalancer();
    if (dns != null) {
        loadBalancer.setDns("foobar.timbuk2.com");
    }
    if (ip != null) {
        loadBalancer.setIp("10.10.10.10");
    }
    Set<LoadBalancer> loadBalancers = new HashSet<>();
    loadBalancers.add(loadBalancer);
    when(loadBalancerPersistenceService.findByStackId(ID)).thenReturn(loadBalancers);
    when(loadBalancerConfigService.selectLoadBalancerForFrontend(loadBalancers, LoadBalancerType.PUBLIC)).thenReturn(Optional.of(loadBalancer));
}
Also used : LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) HashSet(java.util.HashSet)

Example 8 with LoadBalancer

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer 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)

Example 9 with LoadBalancer

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.

the class FreeIPAEndpointManagementServiceTest method testRegisterLoadBalancerWithIP.

@Test
public void testRegisterLoadBalancerWithIP() {
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setType(LoadBalancerType.PUBLIC);
    loadBalancer.setIp(LB_IP);
    loadBalancer.setEndpoint(LB_ENDPOINT);
    when(loadBalancerPersistenceService.findByStackId(any())).thenReturn(Set.of(loadBalancer));
    when(loadBalancerConfigService.selectLoadBalancerForFrontend(any(), any())).thenReturn(Optional.of(loadBalancer));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.registerLoadBalancerDomainWithFreeIPA(stack));
    ArgumentCaptor<AddDnsARecordRequest> requestCaptor = ArgumentCaptor.forClass(AddDnsARecordRequest.class);
    verify(dnsV1Endpoint, times(1)).addDnsARecordInternal(any(), requestCaptor.capture());
    assertEquals(LB_IP, requestCaptor.getValue().getIp());
    assertEquals(LB_ENDPOINT, requestCaptor.getValue().getHostname());
}
Also used : AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Test(org.junit.Test)

Example 10 with LoadBalancer

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.

the class GatewayPublicEndpointManagementServiceTest method testUpdateDnsEntryForLoadBalancers.

@Test
void testUpdateDnsEntryForLoadBalancers() {
    SecurityConfig securityConfig = new SecurityConfig();
    Cluster cluster = TestUtil.cluster();
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setEndpoint("gateway");
    loadBalancer.setDns("http://cloud.dns");
    loadBalancer.setHostedZoneId("1");
    loadBalancer.setType(LoadBalancerType.PUBLIC);
    Stack stack = cluster.getStack();
    stack.setSecurityConfig(securityConfig);
    stack.setCluster(cluster);
    stack.setLoadBalancers(Set.of(loadBalancer));
    String envName = "anEnvName";
    DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).build();
    when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
    when(loadBalancerConfigService.selectLoadBalancerForFrontend(any(), any())).thenReturn(Optional.of(loadBalancer));
    when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
    when(dnsManagementService.createOrUpdateDnsEntryWithCloudDns(any(), any(), any(), any(), any())).thenReturn(Boolean.TRUE);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        boolean result = underTest.updateDnsEntryForLoadBalancers(stack);
        assert result;
    });
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)74 Test (org.junit.Test)48 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)46 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)39 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)37 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)32 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)26 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)16 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)12 Test (org.junit.jupiter.api.Test)12 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 LoadBalancerPersistenceService (com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService)9 HashSet (java.util.HashSet)9 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)8 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)8 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)8 Map (java.util.Map)8 Optional (java.util.Optional)8 Json (com.sequenceiq.cloudbreak.common.json.Json)7