Search in sources :

Example 6 with DataSourceProperties

use of com.thinkbiganalytics.db.DataSourceProperties in project kylo by Teradata.

the class PostgreSqlSchemaParserTest method prepareDataSourceWithBasicUrl.

/**
 * Verify updating data source URL with a catalog name.
 */
@Test
public void prepareDataSourceWithBasicUrl() throws SQLException {
    // Test preparing data source with no catalog
    DataSourceProperties dataSource = new DataSourceProperties("user", "password", "jdbc:postgresql://localhost:5432");
    final JdbcSchemaParser parser = new PostgreSqlSchemaParser();
    DataSourceProperties prepared = parser.prepareDataSource(dataSource, null);
    Assert.assertNotEquals(dataSource, prepared);
    Assert.assertEquals("jdbc:postgresql://localhost:5432/postgres", prepared.getUrl());
    // Test preparing data source with user-defined catalog
    dataSource = new DataSourceProperties("user", "password", "jdbc:postgresql://localhost:5432?flag=true");
    prepared = parser.prepareDataSource(dataSource, "kylo");
    Assert.assertNotEquals(dataSource, prepared);
    Assert.assertEquals("jdbc:postgresql://localhost:5432/kylo?flag=true", prepared.getUrl());
}
Also used : JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) Test(org.junit.Test)

Example 7 with DataSourceProperties

use of com.thinkbiganalytics.db.DataSourceProperties in project kylo by Teradata.

the class DefaultCatalogTableManager method isolatedFunction.

/**
 * Executes the specified function in a separate class loader containing the jars of the specified template.
 */
@VisibleForTesting
protected <R> R isolatedFunction(@Nonnull final DataSetTemplate template, @Nullable final String catalog, @Nonnull final SqlSchemaFunction<R> function) throws SQLException {
    // Get Hadoop configuration
    final Configuration conf = DataSetUtil.getConfiguration(template, defaultConf);
    final HadoopClassLoader classLoader = new HadoopClassLoader(conf);
    if (template.getJars() != null) {
        log.debug("Adding jars to HadoopClassLoader: {}", template.getJars());
        classLoader.addJars(template.getJars());
    }
    // Get data source configuration
    DataSourceProperties properties = getDataSourceProperties(template, classLoader);
    final JdbcSchemaParser schemaParser = schemaParserProvider.getSchemaParser(properties.getUrl());
    properties = schemaParser.prepareDataSource(properties, catalog);
    // Connect to data source
    final javax.sql.DataSource dataSource = PoolingDataSourceService.getDataSource(properties);
    try (final Connection connection = KerberosUtil.getConnectionWithOrWithoutKerberos(dataSource, new KerberosTicketConfiguration())) {
        return function.apply(connection, schemaParser);
    }
}
Also used : HadoopClassLoader(com.thinkbiganalytics.kylo.util.HadoopClassLoader) Configuration(org.apache.hadoop.conf.Configuration) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) Connection(java.sql.Connection) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

DataSourceProperties (com.thinkbiganalytics.db.DataSourceProperties)7 JdbcSchemaParser (com.thinkbiganalytics.discovery.schema.JdbcSchemaParser)5 Properties (java.util.Properties)4 Test (org.junit.Test)4 Nonnull (javax.annotation.Nonnull)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 KerberosTicketConfiguration (com.thinkbiganalytics.kerberos.KerberosTicketConfiguration)1 HadoopClassLoader (com.thinkbiganalytics.kylo.util.HadoopClassLoader)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Configuration (org.apache.hadoop.conf.Configuration)1