Search in sources :

Example 11 with HiveConnection

use of org.apache.hive.jdbc.HiveConnection in project incubator-gobblin by apache.

the class HiveProxyQueryExecutor method setProxiedConnection.

private synchronized void setProxiedConnection(final List<String> proxies) throws IOException, InterruptedException, TException {
    Preconditions.checkArgument(this.state.contains(ConfigurationKeys.SUPER_USER_KEY_TAB_LOCATION), "Missing required property " + ConfigurationKeys.SUPER_USER_KEY_TAB_LOCATION);
    String superUser = this.state.getProp(ComplianceConfigurationKeys.GOBBLIN_COMPLIANCE_SUPER_USER);
    String keytabLocation = this.state.getProp(ConfigurationKeys.SUPER_USER_KEY_TAB_LOCATION);
    String realm = this.state.getProp(ConfigurationKeys.KERBEROS_REALM);
    UserGroupInformation loginUser = UserGroupInformation.loginUserFromKeytabAndReturnUGI(HostUtils.getPrincipalUsingHostname(superUser, realm), keytabLocation);
    loginUser.doAs(new PrivilegedExceptionAction<Void>() {

        @Override
        public Void run() throws MetaException, SQLException, ClassNotFoundException {
            for (String proxy : proxies) {
                HiveConnection hiveConnection = getHiveConnection(Optional.fromNullable(proxy));
                Statement statement = hiveConnection.createStatement();
                statementMap.put(proxy, statement);
                connectionMap.put(proxy, hiveConnection);
                for (String setting : settings) {
                    statement.execute(setting);
                }
            }
            return null;
        }
    });
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveConnection(org.apache.hive.jdbc.HiveConnection)

Example 12 with HiveConnection

use of org.apache.hive.jdbc.HiveConnection in project incubator-gobblin by apache.

the class HiveProxyQueryExecutor method setConnection.

private synchronized void setConnection() throws ClassNotFoundException, SQLException {
    HiveConnection hiveConnection = getHiveConnection(Optional.<String>absent());
    Statement statement = hiveConnection.createStatement();
    this.statementMap.put(DEFAULT, statement);
    this.connectionMap.put(DEFAULT, hiveConnection);
    for (String setting : settings) {
        statement.execute(setting);
    }
}
Also used : Statement(java.sql.Statement) HiveConnection(org.apache.hive.jdbc.HiveConnection)

Aggregations

HiveConnection (org.apache.hive.jdbc.HiveConnection)12 Test (org.junit.Test)6 Statement (java.sql.Statement)5 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)5 SQLException (java.sql.SQLException)3 Properties (java.util.Properties)3 IOException (java.io.IOException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 Connection (java.sql.Connection)2 Field (java.lang.reflect.Field)1 ResultSet (java.sql.ResultSet)1 Configuration (org.apache.hadoop.conf.Configuration)1 DelegationTokenIdentifier (org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 Token (org.apache.hadoop.security.token.Token)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1 CookieStore (org.apache.http.client.CookieStore)1 HttpClient (org.apache.http.client.HttpClient)1 TException (org.apache.thrift.TException)1