Search in sources :

Example 1 with HadoopClassLoader

use of com.thinkbiganalytics.kylo.util.HadoopClassLoader in project kylo by Teradata.

the class DefaultCatalogFileManager 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, @Nonnull final Path path, @Nonnull final FileSystemFunction<R> function) throws IOException {
    final Configuration conf = DataSetUtil.getConfiguration(template, defaultConf);
    try (final HadoopClassLoader classLoader = new HadoopClassLoader(conf)) {
        if (template.getJars() != null) {
            log.debug("Adding jars to HadoopClassLoader: {}", template.getJars());
            classLoader.addJars(template.getJars());
        }
        log.debug("Creating FileSystem from path: {}", path);
        try (final FileSystem fs = FileSystem.newInstance(path.toUri(), conf)) {
            return function.apply(fs);
        }
    }
}
Also used : HadoopClassLoader(com.thinkbiganalytics.kylo.util.HadoopClassLoader) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with HadoopClassLoader

use of com.thinkbiganalytics.kylo.util.HadoopClassLoader 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

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HadoopClassLoader (com.thinkbiganalytics.kylo.util.HadoopClassLoader)2 Configuration (org.apache.hadoop.conf.Configuration)2 DataSourceProperties (com.thinkbiganalytics.db.DataSourceProperties)1 JdbcSchemaParser (com.thinkbiganalytics.discovery.schema.JdbcSchemaParser)1 KerberosTicketConfiguration (com.thinkbiganalytics.kerberos.KerberosTicketConfiguration)1 Connection (java.sql.Connection)1 FileSystem (org.apache.hadoop.fs.FileSystem)1