use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ProxyConfigProviderTest method init.
@Before
public void init() {
cluster = new Cluster();
servicePillar = new HashMap<>();
cluster.setWorkspace(workspace);
cluster.setStack(stack);
when(workspace.getTenant().getName()).thenReturn("tenantId");
when(stack.getCreator().getUserCrn()).thenReturn("aUserCrn");
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class GatewayPublicEndpointManagementServiceTest method testUpdateDnsEntryShouldCallDnsManagementServiceWithGatewayInstanceShortHostnameAsEndpointName.
@Test
void testUpdateDnsEntryShouldCallDnsManagementServiceWithGatewayInstanceShortHostnameAsEndpointName() {
String gatewayIp = "10.191.192.193";
Cluster cluster = TestUtil.cluster();
Stack stack = cluster.getStack();
stack.setCluster(cluster);
InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance();
String endpointName = primaryGatewayInstance.getShortHostname();
String envName = "anEnvName";
String environmentDomain = "anenvname.xcu2-8y8x.dev.cldr.work";
DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).withEnvironmentDomain(environmentDomain).build();
when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment);
when(dnsManagementService.createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)))).thenReturn(Boolean.TRUE);
String fqdn = endpointName + ".anenvname.xcu2-8y8x.dev.cldr.work";
when(domainNameProvider.getFullyQualifiedEndpointName(Set.of(), endpointName, environment)).thenReturn(fqdn);
String result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.updateDnsEntry(stack, gatewayIp));
Assertions.assertNotNull(result);
Assertions.assertEquals(fqdn, result);
verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)));
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class GatewayPublicEndpointManagementServiceTest method testUpdateDnsEntryShouldReturnWithFqdnInCaseOfSuccessAndSetEntryToGatewayIpWhenGatewayIpIsSpecified.
@Test
void testUpdateDnsEntryShouldReturnWithFqdnInCaseOfSuccessAndSetEntryToGatewayIpWhenGatewayIpIsSpecified() {
String gatewayIp = "10.191.192.193";
Cluster cluster = TestUtil.cluster();
Stack stack = cluster.getStack();
stack.setCluster(cluster);
InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance();
String endpointName = primaryGatewayInstance.getShortHostname();
String envName = "anEnvName";
String environmentDomain = "anenvname.xcu2-8y8x.dev.cldr.work";
DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).withEnvironmentDomain(environmentDomain).build();
when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment);
when(dnsManagementService.createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)))).thenReturn(Boolean.TRUE);
String fqdn = endpointName + "." + environmentDomain;
when(domainNameProvider.getFullyQualifiedEndpointName(Set.of(), endpointName, environment)).thenReturn(fqdn);
String result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.updateDnsEntry(stack, gatewayIp));
Assertions.assertNotNull(result);
Assertions.assertEquals(fqdn, result);
verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)));
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class GatewayPublicEndpointManagementServiceTest method testDeleteDnsEntryShouldCallDnsManagementServiceWithGatewayInstanceShortHostnameAsEndpointNameWhenEnvNameIsNotSpecified.
@Test
void testDeleteDnsEntryShouldCallDnsManagementServiceWithGatewayInstanceShortHostnameAsEndpointNameWhenEnvNameIsNotSpecified() {
Cluster cluster = TestUtil.cluster();
Stack stack = cluster.getStack();
stack.setCluster(cluster);
InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance();
String endpointName = primaryGatewayInstance.getShortHostname();
String gatewayIp = primaryGatewayInstance.getPublicIpWrapper();
String envName = "anEnvName";
DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).build();
when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment);
when(dnsManagementService.deleteDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)))).thenReturn(Boolean.TRUE);
String result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.deleteDnsEntry(stack, null));
Assertions.assertNotNull(result);
Assertions.assertEquals(gatewayIp, result);
verify(dnsManagementService, times(1)).deleteDnsEntryWithIp(eq("123"), eq(endpointName), eq(envName), eq(Boolean.FALSE), eq(List.of(gatewayIp)));
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class GatewayPublicEndpointManagementServiceTest method testRenewCertificateWhenCertGenerationIsTriggerableAndDnsEntryShouldBeCreated.
@Test
void testRenewCertificateWhenCertGenerationIsTriggerableAndDnsEntryShouldBeCreated() throws IOException {
SecurityConfig securityConfig = new SecurityConfig();
securityConfig.setUserFacingCert("CERT");
securityConfig.setUserFacingKey(USER_FACING_PRIVATE_KEY);
Cluster cluster = TestUtil.cluster();
Stack stack = cluster.getStack();
stack.setSecurityConfig(securityConfig);
stack.setCluster(cluster);
String envName = "anEnvName";
String environmentDomain = "anenvname.xcu2-8y8x.dev.cldr.work";
DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withName(envName).withEnvironmentDomain(environmentDomain).build();
when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment);
String endpointName = stack.getPrimaryGatewayInstance().getShortHostname();
String commonName = "hashofshorthostname.anenvname.xcu2-8y8x.dev.cldr.work";
when(domainNameProvider.getCommonName(endpointName, environment)).thenReturn(commonName);
String fqdn = endpointName + "." + environmentDomain;
when(domainNameProvider.getFullyQualifiedEndpointName(Set.of(), endpointName, environment)).thenReturn(fqdn);
when(certificateCreationService.create(eq("123"), eq(endpointName), eq(envName), any(PKCS10CertificationRequest.class), eq(stack.getResourceCrn()))).thenReturn(List.of());
when(dnsManagementService.createOrUpdateDnsEntryWithIp(anyString(), anyString(), anyString(), anyBoolean(), any())).thenReturn(true);
boolean result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.renewCertificate(stack));
verify(environmentClientService, times(2)).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(securityConfigService, times(1)).save(any(SecurityConfig.class));
verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithIp(anyString(), anyString(), anyString(), anyBoolean(), any());
verify(clusterService, times(1)).save(cluster);
Assertions.assertEquals(Boolean.TRUE, result);
}
Aggregations