Search in sources :

Example 71 with LoadBalancer

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

the class GatewayPublicEndpointManagementServiceTest method testGenerateCertAndSaveForStackWithLoadBalancerWithCloudDns.

@Test
void testGenerateCertAndSaveForStackWithLoadBalancerWithCloudDns() throws IOException {
    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));
    InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance();
    String endpointName = primaryGatewayInstance.getShortHostname();
    String lbEndpointName = loadBalancer.getEndpoint();
    String environmentDomain = "anenvname.xcu2-8y8x.dev.cldr.work";
    String commonName = "hashofshorthostname." + environmentDomain;
    String fqdn = endpointName + "." + environmentDomain;
    String lbfqdn = lbEndpointName + "." + environmentDomain;
    String envName = "anEnvName";
    String cloudDns = loadBalancer.getDns();
    String hostedZoneId = loadBalancer.getHostedZoneId();
    DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).withEnvironmentDomain(environmentDomain).build();
    when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
    when(domainNameProvider.getCommonName(endpointName, environment)).thenReturn(commonName);
    when(domainNameProvider.getFullyQualifiedEndpointName(Set.of(), endpointName, environment)).thenReturn(fqdn);
    when(domainNameProvider.getFullyQualifiedEndpointName(Set.of(), lbEndpointName, environment)).thenReturn(lbfqdn);
    when(certificateCreationService.create(eq("123"), eq(endpointName), eq(envName), any(PKCS10CertificationRequest.class), eq(stack.getResourceCrn()))).thenReturn(List.of());
    when(dnsManagementService.createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(primaryGatewayInstance.getPublicIpWrapper())))).thenReturn(Boolean.TRUE);
    when(dnsManagementService.createOrUpdateDnsEntryWithCloudDns(eq("123"), eq(lbEndpointName), eq(envName), eq(cloudDns), eq(hostedZoneId))).thenReturn(Boolean.TRUE);
    when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
    when(loadBalancerConfigService.selectLoadBalancerForFrontend(any(), any())).thenReturn(Optional.of(loadBalancer));
    boolean result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.generateCertAndSaveForStackAndUpdateDnsEntry(stack));
    verify(environmentClientService, times(3)).getByCrn(anyString());
    verify(domainNameProvider, times(1)).getCommonName(endpointName, environment);
    verify(domainNameProvider, times(2)).getFullyQualifiedEndpointName(Set.of(), endpointName, environment);
    verify(certificateCreationService, times(1)).create(eq("123"), eq(endpointName), eq(envName), any(PKCS10CertificationRequest.class), eq(stack.getResourceCrn()));
    verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(primaryGatewayInstance.getPublicIpWrapper())));
    verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithCloudDns(eq("123"), eq(lbEndpointName), eq(envName), eq(cloudDns), eq(hostedZoneId));
    verify(securityConfigService, times(2)).save(any(SecurityConfig.class));
    Assertions.assertEquals(Boolean.TRUE, result);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) 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)

Example 72 with LoadBalancer

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

the class GatewayPublicEndpointManagementServiceTest method testGenerateCertAndSaveForStackWithLoadBalancerWithIpAddress.

@Test
void testGenerateCertAndSaveForStackWithLoadBalancerWithIpAddress() throws IOException {
    SecurityConfig securityConfig = new SecurityConfig();
    Cluster cluster = TestUtil.cluster();
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setEndpoint("gateway");
    loadBalancer.setIp("1.2.3.4");
    loadBalancer.setType(LoadBalancerType.PUBLIC);
    Stack stack = cluster.getStack();
    stack.setSecurityConfig(securityConfig);
    stack.setCluster(cluster);
    stack.setLoadBalancers(Set.of(loadBalancer));
    InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance();
    String endpointName = primaryGatewayInstance.getShortHostname();
    String lbEndpointName = loadBalancer.getEndpoint();
    String environmentDomain = "anenvname.xcu2-8y8x.dev.cldr.work";
    String commonName = "hashofshorthostname." + environmentDomain;
    String fqdn = endpointName + "." + environmentDomain;
    String lbfqdn = lbEndpointName + "." + environmentDomain;
    String envName = "anEnvName";
    String lbIp = loadBalancer.getIp();
    DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).withEnvironmentDomain(environmentDomain).build();
    when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
    when(domainNameProvider.getCommonName(endpointName, environment)).thenReturn(commonName);
    when(domainNameProvider.getFullyQualifiedEndpointName(Set.of(), endpointName, environment)).thenReturn(fqdn);
    when(domainNameProvider.getFullyQualifiedEndpointName(Set.of(), lbEndpointName, environment)).thenReturn(lbfqdn);
    when(certificateCreationService.create(eq("123"), eq(endpointName), eq(envName), any(PKCS10CertificationRequest.class), eq(stack.getResourceCrn()))).thenReturn(List.of());
    when(dnsManagementService.createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(primaryGatewayInstance.getPublicIpWrapper())))).thenReturn(Boolean.TRUE);
    when(dnsManagementService.createOrUpdateDnsEntryWithIp(eq("123"), eq(lbEndpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(lbIp)))).thenReturn(Boolean.TRUE);
    when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
    when(loadBalancerConfigService.selectLoadBalancerForFrontend(any(), any())).thenReturn(Optional.of(loadBalancer));
    boolean result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.generateCertAndSaveForStackAndUpdateDnsEntry(stack));
    verify(environmentClientService, times(3)).getByCrn(anyString());
    verify(domainNameProvider, times(1)).getCommonName(endpointName, environment);
    verify(domainNameProvider, times(2)).getFullyQualifiedEndpointName(Set.of(), endpointName, environment);
    verify(certificateCreationService, times(1)).create(eq("123"), eq(endpointName), eq(envName), any(PKCS10CertificationRequest.class), eq(stack.getResourceCrn()));
    verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(primaryGatewayInstance.getPublicIpWrapper())));
    verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithIp(eq("123"), eq(lbEndpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(lbIp)));
    verify(securityConfigService, times(2)).save(any(SecurityConfig.class));
    Assertions.assertEquals(Boolean.TRUE, result);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) 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)

Example 73 with LoadBalancer

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

the class GatewayPublicEndpointManagementServiceTest method testSkipLoadBalancersWithMissingEndpoints.

@Test
void testSkipLoadBalancersWithMissingEndpoints() {
    String validEndpoint = "valid-endpoint";
    LoadBalancer nullEndpointLb = new LoadBalancer();
    LoadBalancer emptyEndpointLb = new LoadBalancer();
    emptyEndpointLb.setEndpoint("");
    LoadBalancer validEndpointLb = new LoadBalancer();
    emptyEndpointLb.setEndpoint(validEndpoint);
    Stack stack = new Stack();
    stack.setId(1L);
    when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(nullEndpointLb, emptyEndpointLb, validEndpointLb));
    Set<String> loadBalancerEndpoints = underTest.getLoadBalancerNamesForStack(stack);
    Assertions.assertEquals(Set.of(validEndpoint), loadBalancerEndpoints);
}
Also used : 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)

Example 74 with LoadBalancer

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

the class LoadBalancerConfigServiceTest method testCreateAzureLoadBalancerWithSkuSet.

@Test
public void testCreateAzureLoadBalancerWithSkuSet() {
    Stack stack = createAzureStack(StackType.DATALAKE, PRIVATE_ID_1, true);
    CloudSubnet subnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
    DetailedEnvironmentResponse environment = createEnvironment(subnet, false);
    AzureStackV4Parameters azureParameters = new AzureStackV4Parameters();
    azureParameters.setLoadBalancerSku(LoadBalancerSku.STANDARD);
    StackV4Request request = new StackV4Request();
    request.setEnableLoadBalancer(false);
    request.setAzure(azureParameters);
    when(entitlementService.datalakeLoadBalancerEnabled(anyString())).thenReturn(true);
    when(blueprint.getBlueprintText()).thenReturn(getBlueprintText("input/clouderamanager-knox.bp"));
    when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(subnet));
    when(availabilitySetNameService.generateName(any(), any())).thenReturn("");
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        Set<LoadBalancer> loadBalancers = underTest.createLoadBalancers(stack, environment, request);
        assertEquals(1, loadBalancers.size());
        LoadBalancer loadBalancer = loadBalancers.iterator().next();
        assertEquals(LoadBalancerType.PRIVATE, loadBalancer.getType());
        InstanceGroup masterInstanceGroup = stack.getInstanceGroups().stream().filter(ig -> "master".equals(ig.getGroupName())).findFirst().get();
        assertEquals(1, masterInstanceGroup.getTargetGroups().size());
        assertEquals(LoadBalancerSku.STANDARD, loadBalancer.getSku());
        checkAvailabilitySetAttributes(loadBalancers);
    });
}
Also used : AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) Test(org.junit.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