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);
}
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);
}
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);
}
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);
});
}
Aggregations