Search in sources :

Example 41 with DatabaseServerV4Response

use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.

the class RedbeamsDbCertificateProvider method getDatabaseRootCerts.

private Set<String> getDatabaseRootCerts(Cluster cluster) {
    Set<String> result = new HashSet<>();
    if (dbServerConfigurer.isRemoteDatabaseNeeded(cluster)) {
        String stackResourceCrn = cluster.getStack().getResourceCrn();
        String clusterName = cluster.getName();
        LOGGER.info("Gathering cluster's(crn:'{}', name: '{}') remote database root certificates", stackResourceCrn, clusterName);
        String databaseServerCrn = cluster.getDatabaseServerCrn();
        DatabaseServerV4Response databaseServer = dbServerConfigurer.getDatabaseServer(databaseServerCrn);
        SslConfigV4Response sslConfig = databaseServer.getSslConfig();
        if (sslConfig != null) {
            if (SslMode.isEnabled(sslConfig.getSslMode())) {
                Set<String> sslCertificates = sslConfig.getSslCertificates();
                result.addAll(sslCertificates);
                LOGGER.info("Number of certificates found:'{}' for cluster(crn:'{}', name: '{}')", sslCertificates.size(), stackResourceCrn, clusterName);
            }
        } else {
            LOGGER.info("There no SSL config could be found for the remote database('{}').", databaseServerCrn);
        }
    }
    return result;
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) HashSet(java.util.HashSet)

Example 42 with DatabaseServerV4Response

use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.

the class RedbeamsDbCertificateProviderTest method getRelatedSslCertsWhenTheClusterDistroXAndRdsConfiguredAndRelatedSdxHasRdsConfigured.

@Test
void getRelatedSslCertsWhenTheClusterDistroXAndRdsConfiguredAndRelatedSdxHasRdsConfigured() {
    String dbServerCrn = "dbservercrn-A";
    String dbServerCrnB = "dbservercrn-B";
    String certificateA = "certificate-A";
    String certificateB = "certificate-B";
    Cluster sdxCluster = TestUtil.cluster();
    sdxCluster.setId(2L);
    sdxCluster.setDatabaseServerCrn(dbServerCrnB);
    Stack sdxStack = sdxCluster.getStack();
    sdxStack.setCluster(sdxCluster);
    sdxStack.setType(StackType.DATALAKE);
    sdxStack.setId(2L);
    Cluster cluster = TestUtil.cluster();
    cluster.setDatabaseServerCrn(dbServerCrn);
    Stack stack = cluster.getStack();
    stack.setCluster(cluster);
    stack.setType(StackType.WORKLOAD);
    when(datalakeService.getDatalakeStackByDatahubStack(any())).thenReturn(Optional.of(sdxStack));
    when(dbServerConfigurer.isRemoteDatabaseNeeded(any())).thenReturn(Boolean.TRUE);
    DatabaseServerV4Response databaseServerV4Response = new DatabaseServerV4Response();
    databaseServerV4Response.setSslConfig(getSslConfigV4ResponseWithCertificate(Set.of(certificateA)));
    when(dbServerConfigurer.getDatabaseServer(dbServerCrn)).thenReturn(databaseServerV4Response);
    DatabaseServerV4Response databaseServerV4ResponseB = new DatabaseServerV4Response();
    databaseServerV4ResponseB.setSslConfig(getSslConfigV4ResponseWithCertificate(Set.of(certificateB)));
    when(dbServerConfigurer.getDatabaseServer(dbServerCrnB)).thenReturn(databaseServerV4ResponseB);
    Set<String> actual = underTest.getRelatedSslCerts(stack, cluster);
    assertThat(actual).isNotEmpty();
    assertThat(actual).contains(certificateA, certificateB);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 43 with DatabaseServerV4Response

use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.

the class RedbeamsDbCertificateProviderTest method getRelatedSslCertsWhenTheClusterDistroXAndNoRdsConfiguredAndThereIsNoRelatedSdx.

@Test
void getRelatedSslCertsWhenTheClusterDistroXAndNoRdsConfiguredAndThereIsNoRelatedSdx() {
    String dbServerCrn = "adbservercrn";
    String certificateA = "certificate-A";
    Cluster cluster = TestUtil.cluster();
    cluster.setDatabaseServerCrn(dbServerCrn);
    Stack stack = cluster.getStack();
    stack.setCluster(cluster);
    stack.setType(StackType.WORKLOAD);
    when(dbServerConfigurer.isRemoteDatabaseNeeded(cluster)).thenReturn(Boolean.TRUE);
    DatabaseServerV4Response databaseServerV4Response = new DatabaseServerV4Response();
    databaseServerV4Response.setSslConfig(getSslConfigV4ResponseWithCertificate(Set.of(certificateA)));
    when(dbServerConfigurer.getDatabaseServer(dbServerCrn)).thenReturn(databaseServerV4Response);
    Set<String> actual = underTest.getRelatedSslCerts(stack, cluster);
    assertThat(actual).isNotEmpty();
    assertThat(actual).contains(certificateA);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 44 with DatabaseServerV4Response

use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.

the class RedbeamsDbCertificateProviderTest method getRelatedSslCertsWhenTheClusterDistroXAndNoRdsConfiguredButRelatedSdxHasRdsConfigured.

@Test
void getRelatedSslCertsWhenTheClusterDistroXAndNoRdsConfiguredButRelatedSdxHasRdsConfigured() {
    String dbServerCrnB = "dbservercrn-B";
    String certificateB = "certificate-B";
    Cluster sdxCluster = TestUtil.cluster();
    sdxCluster.setId(2L);
    sdxCluster.setDatabaseServerCrn(dbServerCrnB);
    Stack sdxStack = sdxCluster.getStack();
    sdxStack.setCluster(sdxCluster);
    sdxStack.setType(StackType.DATALAKE);
    sdxStack.setId(2L);
    Cluster cluster = TestUtil.cluster();
    cluster.setDatabaseServerCrn(null);
    Stack stack = cluster.getStack();
    stack.setCluster(cluster);
    stack.setType(StackType.WORKLOAD);
    when(datalakeService.getDatalakeStackByDatahubStack(any())).thenReturn(Optional.of(sdxStack));
    when(dbServerConfigurer.isRemoteDatabaseNeeded(cluster)).thenReturn(Boolean.FALSE);
    when(dbServerConfigurer.isRemoteDatabaseNeeded(sdxCluster)).thenReturn(Boolean.TRUE);
    DatabaseServerV4Response databaseServerV4ResponseB = new DatabaseServerV4Response();
    databaseServerV4ResponseB.setSslConfig(getSslConfigV4ResponseWithCertificate(Set.of(certificateB)));
    when(dbServerConfigurer.getDatabaseServer(dbServerCrnB)).thenReturn(databaseServerV4ResponseB);
    Set<String> actual = underTest.getRelatedSslCerts(stack, cluster);
    assertThat(actual).isNotEmpty();
    assertThat(actual).contains(certificateB);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 45 with DatabaseServerV4Response

use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.

the class RedbeamsDbCertificateProviderTest method getRelatedSslCertsWhenTheClusterSdxAndRdsConfiguredWithSSL.

@Test
void getRelatedSslCertsWhenTheClusterSdxAndRdsConfiguredWithSSL() {
    String dbServerCrn = "adbservercrn";
    String certificateA = "certificate-A";
    Cluster cluster = TestUtil.cluster();
    cluster.setDatabaseServerCrn(dbServerCrn);
    Stack stack = cluster.getStack();
    stack.setCluster(cluster);
    stack.setType(StackType.DATALAKE);
    when(dbServerConfigurer.isRemoteDatabaseNeeded(cluster)).thenReturn(Boolean.TRUE);
    DatabaseServerV4Response databaseServerV4Response = new DatabaseServerV4Response();
    SslConfigV4Response sslConfig = getSslConfigV4ResponseWithCertificate(Set.of(certificateA));
    databaseServerV4Response.setSslConfig(sslConfig);
    when(dbServerConfigurer.getDatabaseServer(dbServerCrn)).thenReturn(databaseServerV4Response);
    Set<String> actual = underTest.getRelatedSslCerts(stack, cluster);
    assertThat(actual).isNotEmpty();
    assertThat(actual).contains(certificateA);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)54 Test (org.junit.jupiter.api.Test)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)16 SslConfigV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)9 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)7 Test (org.junit.Test)6 StackDatabaseServerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.StackDatabaseServerResponse)5 AllocateDatabaseServerV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request)5 DatabaseServerSslConfig (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseServerSslConfig)4 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)4 DatabaseServerStatusV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response)4 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)4 Date (java.util.Date)4 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)3 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)3 NotFoundException (javax.ws.rs.NotFoundException)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3