SpringBoot DataSource集成Hive、Phoenix、Presto数据源(带Kerberos校验)

在数据中台的落地过程中,元数据管理经常需要和多个数据源进行交互,下面我们延时几个数据源

1. HiveDataSource

@Configuration
@EnableTransactionManagement
public class HiveDataSource {

    @Value("${spring.datasource.hive.url}")
    private String url;

    @Value("${project.release.principal}")
    private String principal;

    @Value("${project.release.keytab}")
    private String keytab;

    @Bean(name = "hiveJdbcDataSource")
    @Qualifier("hiveJdbcDataSource")
    public DataSource dataSource() throws IOException {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(url);
        org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
        conf.set("hadoop.security.authentication", "Kerberos");
        UserGroupInformation.setConfiguration(conf);
        UserGroupInformation.loginUserFromKeytab(principal, keytab);
        return dataSource;
    }

    @Bean(name = "hiveJdbcTemplate")
    public JdbcTemplate hiveJdbcTemplate(@Qualifier("hiveJdbcDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}

2.PhoenixDataSource

@Configuration
@EnableTransactionManagement
public class PhoenixDataSource {

    @Value("${spring.datasource.phoenix.url}")
    private String url;

    @Value("${project.release.principal}")
    private String principal;

    @Value("${project.release.keytab}")
    private String keytab;

    @Bean(name = "phoenixJdbcDataSource")
    @Qualifier("phoenixJdbcDataSource")
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(url);
        dataSource.setDriverClassName("org.apache.phoenix.queryserver.client.Driver");
        Properties properties = new Properties();
        properties.setProperty("serialization", "PROTOBUF");
        properties.setProperty("authentication", "SPNEGO");
        properties.setProperty("principal", principal);
        properties.setProperty("keytab", keytab);
        dataSource.setConnectProperties(properties);
        return dataSource;
    }

    @Bean(name = "phoenixJdbcTemplate")
    public JdbcTemplate phoenixJdbcTemplate(@Qualifier("phoenixJdbcDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}

3.PrestoDataSource

@Configuration
@EnableTransactionManagement
public class PrestoDataSource {

    @Value("${spring.datasource.presto.url}")
    private String url;

    @Value("${project.release.principal}")
    private String principal;

    @Value("${project.release.keytab}")
    private String keytab;

    @Bean(name = "prestoJdbcDataSource")
    @Qualifier("prestoJdbcDataSource")
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(url);
        String driver = "com.facebook.presto.jdbc.PrestoDriver";
        dataSource.setDriverClassName(driver);
        dataSource.setUsername("wumii-data");
//        Properties properties=new Properties();
//        properties.setProperty("KerberosPrincipal",principal);
//        properties.setProperty("KerberosKeytabPath",keytab);
//        dataSource.setConnectProperties(properties);
        return dataSource;
    }

    @Bean(name = "prestoJdbcTemplate")
    public JdbcTemplate phoenixJdbcTemplate(@Qualifier("prestoJdbcDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}

涉及到的Properties

spring.datasource.hive.url=jdbc:hive2://host1:2181,host2.wumii.net:2181,host3:2181/default;principal=hive/_HOST@WUMII.NET;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-interactive
spring.datasource.phoenix.url=jdbc:phoenix:thin:url=http://host3:8765
spring.datasource.presto.url=jdbc:presto://hive@host2:8999/hive/default
project.release.keytab=XXX.keytab
project.release.principal=XX@WUMII.NET
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值