2017-11-23 8 views
0

Kerberized HDP-2.6.3.0。HiveMetaStoreClient(それによってHiveConf)を使用してHiveメタデータを取得する

WindowsマシンからHive JDBCドライバを使用してHiveに接続できますが、HiveMetaStoreClientのいくつかのメソッドを使用する必要があります。私はAPIを飛ばし、私がIDEから実行しているテストコードを書いた。ポンポンファイル内

private static void connectHiveMetastore() throws MetaException, MalformedURLException { 
     //System.setProperty("javax.security.auth.useSubjectCredsOnly","false"); 
     //System.setProperty("java.security.krb5.conf","C:\\kerb5.conf"); 
     Configuration configuration = new Configuration(); 
     //configuration.addResource("E:\\hdp\\client_config\\HDFS_CLIENT\\core-site.xml"); 
     //configuration.addResource("E:\\hdp\\client_config\\HDFS_CLIENT\\hdfs-site.xml"); 
     HiveConf hiveConf = new HiveConf(configuration,Configuration.class); 
     //URL url = new File("E:\\hdp\\client_config\\HDFS_CLIENT\\hive-site.xml").toURI().toURL(); 
     //hiveConf.setHiveSiteLocation(url); 
     //hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS,"thrift://l4283t.sss.com:9083,thrift://l4284t.sss.com:9083"); 
     HiveMetaStoreClient hiveMetaStoreClient = new HiveMetaStoreClient(hiveConf); 
    } 

依存関係:

かかわらず、私はコメントしたり設定やKerberosに関連する行のコメントを解除するかどうかの
</dependencies> 
<dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-metastore --> 
    <dependency> 
     <groupId>org.apache.hive</groupId> 
     <artifactId>hive-metastore</artifactId> 
     <version>2.3.2</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec --> 
    <dependency> 
     <groupId>org.apache.hive</groupId> 
     <artifactId>hive-exec</artifactId> 
     <version>2.3.2</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common --> 
    <dependency> 
     <groupId>org.apache.hadoop</groupId> 
     <artifactId>hadoop-common</artifactId> 
     <version>2.9.0</version> 
    </dependency> 
</dependencies> 

、私はHive wikiに説明されている次の例外を受け取ります。

15:35:27.139 [main] ERROR org.apache.hadoop.hive.metastore.RetryingHMSHandler - MetaException(message:Version information not found in metastore.) 
at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:7564) 
at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:7542) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:101) 
at com.sun.proxy.$Proxy8.verifySchema(Unknown Source) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMSForConf(HiveMetaStore.java:591) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMS(HiveMetaStore.java:584) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:651) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:427) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invokeInternal(RetryingHMSHandler.java:148) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:107) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.<init>(RetryingHMSHandler.java:79) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.getProxy(RetryingHMSHandler.java:92) 
at org.apache.hadoop.hive.metastore.HiveMetaStore.newRetryingHMSHandler(HiveMetaStore.java:6893) 
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:164) 
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:129) 
at com.my.App.connectHiveMetastore(App.java:58) 
at com.my.App.main(App.java:37) 
15:35:27.141 [main] ERROR org.apache.hadoop.hive.metastore.RetryingHMSHandler - HMSHandler Fatal error: MetaException(message:Version information not found in metastore.) 
at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:7564) 
at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:7542) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:101) 
at com.sun.proxy.$Proxy8.verifySchema(Unknown Source) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMSForConf(HiveMetaStore.java:591) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMS(HiveMetaStore.java:584) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:651) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:427) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invokeInternal(RetryingHMSHandler.java:148) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:107) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.<init>(RetryingHMSHandler.java:79) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.getProxy(RetryingHMSHandler.java:92) 
at org.apache.hadoop.hive.metastore.HiveMetaStore.newRetryingHMSHandler(HiveMetaStore.java:6893) 
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:164) 
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:129) 
at com.my.App.connectHiveMetastore(App.java:58) 
at com.my.App.main(App.java:37) 
Exception in thread "main" MetaException(message:Version information not found in metastore.) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.<init>(RetryingHMSHandler.java:83) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.getProxy(RetryingHMSHandler.java:92) 
at org.apache.hadoop.hive.metastore.HiveMetaStore.newRetryingHMSHandler(HiveMetaStore.java:6893) 
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:164) 
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:129) 
at com.my.App.connectHiveMetastore(App.java:58) 
at com.my.App.main(App.java:37) 
Caused by: MetaException(message:Version information not found in metastore.) 
at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:7564) 
at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:7542) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:101) 
at com.sun.proxy.$Proxy8.verifySchema(Unknown Source) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMSForConf(HiveMetaStore.java:591) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMS(HiveMetaStore.java:584) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:651) 
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:427) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invokeInternal(RetryingHMSHandler.java:148) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:107) 
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.<init>(RetryingHMSHandler.java:79) 
... 6 more 
Process finished with exit code 1 

私は、次の質問/懸念があります。

  1. HiveMetaStoreClientを正しく考えて接続する方法はありますか?そうでない場合、HiveMetaStoreClientのメソッドで提供されているメタデータ情報を取得するにはどうすればよいですか?
  2. コードは確かにクラスタに到達していません。依存関係のバージョンに関する上記の例外はありますか?そうでない場合、根本原因は何か?
+0

有効な 'hive-site.xml'ファイルをローカルディレクトリにドロップし、**ディレクトリ**をCLASSPATHに追加して、単に新しいHiveConf(...)をビルドします。次に、 'hive.metastore.uris'が正しく初期化されていることを確認します - HadoopクライアントがCLASSPATHで設定ファイルを見つけられなかった場合、それらはhard-cdedのデフォルトに戻ります。つまり、揮発性ダービーデータベース。 –

+1

また、POMファイルを使用しています。 Kerberos auth _(例えば、hadoop-authとcommons-configuration)のために、あなたのクラスタに存在するHive JARだけでなく、いくつかのHadoop JARを入手してください。 –

+0

Kerberosと言えば、JavaスタイルのKerberosチケットを入手するか、プリンシパル&keytab ... _(JDBCはJAAS設定から直接principal/keytabを取得できます)の静的 'UserGroupInformation'を明示的に初期化する必要があります_ –

答えて

0

@Samsonのコメント(コメント)の後、私はMavenのアプローチを採用し、単にクラスタから必要なjarをコピーし続けました。はい、これはソートされたものを取得するために長い時間がかかりましたが、私はいくつかの進歩をしました。 以下は私が使っているクラスですが、まだSASL関連の例外がありますが、少なくともリクエストがサーバーに届いています。

private static void connectHiveMetastore() throws MetaException, MalformedURLException { 

     System.setProperty("hadoop.home.dir", "E:\\Software\\Virtualization"); 

     /*Start : Commented or un-commented, immaterial ...*/ 
     System.setProperty("javax.security.auth.useSubjectCredsOnly","false"); 
     System.setProperty("java.security.auth.login.config","E:\\lib\\hdp\\loginconf.ini"); 
     System.setProperty("java.security.krb5.conf","E:\\lib\\hdp\\krb5.conf"); 
     /*End : Commented or un-commented, immaterial ...*/ 

     Configuration configuration = new Configuration(); 
     /*Start : Commented or un-commented, immaterial ...*/ 
     configuration.addResource("E:\\lib\\hdp\\client_config\\HDFS_CLIENT\\core-site.xml"); 
     configuration.addResource("E:\\lib\\hdp\\client_config\\HDFS_CLIENT\\hdfs-site.xml"); 
     configuration.addResource("E:\\lib\\hdp\\client_config\\HIVE_CLIENT\\hive-site.xml"); 
     configuration.set("hive.server2.authentication","KERBEROS"); 
     configuration.set("hadoop.security.authentication", "Kerberos"); 
     /*End : Commented or un-commented, immaterial ...*/ 

     HiveConf hiveConf = new HiveConf(configuration,Configuration.class); 
     URL url = new File("E:\\lib\\hdp\\client_config\\HIVE_CLIENT\\hive-site.xml").toURI().toURL(); 
     HiveConf.setHiveSiteLocation(url); 
     hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS,"thrift://l4283t.sss.se.com:9083,thrift://l4284t.sss.se.com:9083"); 
     /*Start : Commented or un-commented, immaterial ...*/ 
     hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_AUTHENTICATION,"KERBEROS"); 
     /*End : Commented or un-commented, immaterial ...*/ 

     HiveMetaStoreClient hiveMetaStoreClient = new HiveMetaStoreClient(hiveConf); 

     System.out.println("Metastore client : "+hiveMetaStoreClient); 
     System.out.println("Is local metastore ? "+hiveMetaStoreClient.isLocalMetaStore()); 
     System.out.println(hiveMetaStoreClient.getAllDatabases()); 

     hiveMetaStoreClient.close(); 
    }