Search in sources :

Example 1 with DatabaseCommon

use of com.sequenceiq.cloudbreak.common.database.DatabaseCommon in project cloudbreak by hortonworks.

the class DatabaseServerConfigTest method testCreateDatabaseConfig.

@Test
public void testCreateDatabaseConfig() {
    config.setId(1L);
    config.setAccountId("myaccount");
    Crn crn = TestData.getTestCrn("databaseServer", "myserver");
    config.setResourceCrn(crn);
    config.setWorkspaceId(0L);
    config.setName("myserver");
    config.setDescription("mine not yours");
    config.setHost("myserver.db.example.com");
    config.setPort(5432);
    config.setDatabaseVendor(DatabaseVendor.POSTGRES);
    config.setConnectionDriver("org.postgresql.Driver");
    config.setConnectionUserName("root");
    config.setConnectionPassword("cloudera");
    long now = System.currentTimeMillis();
    config.setCreationDate(now);
    config.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
    config.setDeletionTimestamp(2L);
    config.setArchived(true);
    config.setEnvironmentId("myenvironment");
    DatabaseConfig db = config.createDatabaseConfig("mydb", "hive", Optional.empty(), ResourceStatus.USER_MANAGED, "dbuser", "dbpass");
    assertEquals(config.getDatabaseVendor(), db.getDatabaseVendor());
    assertEquals("mydb", db.getName());
    assertEquals(config.getDescription(), db.getDescription());
    String connectionUrl = new DatabaseCommon().getJdbcConnectionUrl(config.getDatabaseVendor().jdbcUrlDriverId(), config.getHost(), config.getPort(), Optional.of("mydb"));
    assertEquals(connectionUrl, db.getConnectionURL());
    assertEquals(config.getConnectionDriver(), db.getConnectionDriver());
    assertEquals("dbuser", db.getConnectionUserName().getRaw());
    assertEquals("dbpass", db.getConnectionPassword().getRaw());
    assertEquals(ResourceStatus.USER_MANAGED, db.getStatus());
    assertEquals("hive", db.getType());
    assertEquals(config.getEnvironmentId(), db.getEnvironmentId());
    assertEquals(config, db.getServer());
}
Also used : DatabaseCommon(com.sequenceiq.cloudbreak.common.database.DatabaseCommon) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Test(org.junit.Test)

Example 2 with DatabaseCommon

use of com.sequenceiq.cloudbreak.common.database.DatabaseCommon in project cloudbreak by hortonworks.

the class DriverWithConnectivity method connect.

public Connection connect(DatabaseServerConfig databaseServerConfig) throws SQLException {
    String connectionUrl = new DatabaseCommon().getJdbcConnectionUrl(databaseServerConfig.getDatabaseVendor().jdbcUrlDriverId(), databaseServerConfig.getHost(), databaseServerConfig.getPort(), Optional.empty());
    Properties connectionProps = new Properties();
    connectionProps.setProperty("user", databaseServerConfig.getConnectionUserName());
    connectionProps.setProperty("password", databaseServerConfig.getConnectionPassword());
    connectionProps.setProperty("sslmode", "allow");
    return connect(connectionUrl, connectionProps);
}
Also used : DatabaseCommon(com.sequenceiq.cloudbreak.common.database.DatabaseCommon) Properties(java.util.Properties)

Example 3 with DatabaseCommon

use of com.sequenceiq.cloudbreak.common.database.DatabaseCommon in project cloudbreak by hortonworks.

the class DatabaseVendorAndServiceValidatorTest method testIsValid.

@Test
public void testIsValid() {
    DatabaseV4Request request = new DatabaseV4Request();
    request.setType(serviceName);
    request.setConnectionURL(new DatabaseCommon().getJdbcConnectionUrl(databaseVendor.jdbcUrlDriverId(), "mydb.example.com", 1234, Optional.of(serviceName)));
    assertEquals(expectedResult, underTest.isValid(request, context));
    int expectedTimes = expectedResult ? 0 : 1;
    verify(context, times(expectedTimes)).buildConstraintViolationWithTemplate(any(String.class));
}
Also used : DatabaseCommon(com.sequenceiq.cloudbreak.common.database.DatabaseCommon) DatabaseV4Request(com.sequenceiq.redbeams.api.endpoint.v4.database.request.DatabaseV4Request) Test(org.junit.Test)

Aggregations

DatabaseCommon (com.sequenceiq.cloudbreak.common.database.DatabaseCommon)3 Test (org.junit.Test)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 DatabaseV4Request (com.sequenceiq.redbeams.api.endpoint.v4.database.request.DatabaseV4Request)1 Properties (java.util.Properties)1