Search in sources :

Example 96 with Cluster

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");
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Before(org.junit.Before)

Example 97 with Cluster

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)));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 98 with Cluster

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)));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 99 with Cluster

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)));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 100 with Cluster

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);
}
Also used : 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)407 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)248 Test (org.junit.jupiter.api.Test)125 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)63 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)60 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)58 Optional (java.util.Optional)51 Test (org.junit.Test)50 List (java.util.List)49 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)47 Set (java.util.Set)43 Json (com.sequenceiq.cloudbreak.common.json.Json)39 Map (java.util.Map)39 Collectors (java.util.stream.Collectors)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)36 Inject (javax.inject.Inject)36 Logger (org.slf4j.Logger)36 LoggerFactory (org.slf4j.LoggerFactory)36 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)35