1

我有一个 Java Web 服务(使用我公司的专有技术制作),用于为请求/响应提供服务,在处理请求时,它试图与 Hadoop 的 Hive 对话并执行查询。但是,当我只是尝试初始化连接时,它会立即失败。

这是它失败的代码行。我主要使用来自https://cwiki.apache.org/confluence/display/Hive/HiveClient的代码示例:

String connString = "jdbc:hive://";
Connection con = DriverManager.getConnection(connString, "", "");

这是堆栈跟踪:

javax.jdo.JDOFatalInternalException: Unexpected exception caught.
    at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1186)
    at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:803)
    at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:698)
    at org.apache.hadoop.hive.metastore.ObjectStore.getPMF(ObjectStore.java:246)
    at org.apache.hadoop.hive.metastore.ObjectStore.getPersistenceManager(ObjectStore.java:275)
    at org.apache.hadoop.hive.metastore.ObjectStore.initialize(ObjectStore.java:208)
    at org.apache.hadoop.hive.metastore.ObjectStore.setConf(ObjectStore.java:183)
    at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:70)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:130)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMS(HiveMetaStore.java:407)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.executeWithRetry(HiveMetaStore.java:359)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:504)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:266)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.<init>(HiveMetaStore.java:228)
    at org.apache.hadoop.hive.service.HiveServer$HiveServerHandler.<init>(HiveServer.java:131)
    at org.apache.hadoop.hive.service.HiveServer$HiveServerHandler.<init>(HiveServer.java:121)
    at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:76)
    at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at (...my package...).RemoteCtrbTest.kickOffRemoteTest(RemoteCtrbTest.java:52)

NestedThrowablesStackTrace:
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.jdo.JDOHelper$16.run(JDOHelper.java:1958)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.jdo.JDOHelper.invoke(JDOHelper.java:1953)
    at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1159)
    at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:803)
    at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:698)
    at org.apache.hadoop.hive.metastore.ObjectStore.getPMF(ObjectStore.java:246)
    at org.apache.hadoop.hive.metastore.ObjectStore.getPersistenceManager(ObjectStore.java:275)
    at org.apache.hadoop.hive.metastore.ObjectStore.initialize(ObjectStore.java:208)
    at org.apache.hadoop.hive.metastore.ObjectStore.setConf(ObjectStore.java:183)
    at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:70)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:130)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMS(HiveMetaStore.java:407)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.executeWithRetry(HiveMetaStore.java:359)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:504)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:266)
    at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.<init>(HiveMetaStore.java:228)
    at org.apache.hadoop.hive.service.HiveServer$HiveServerHandler.<init>(HiveServer.java:131)
    at org.apache.hadoop.hive.service.HiveServer$HiveServerHandler.<init>(HiveServer.java:121)
    at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:76)
    at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at (...my package...).RemoteCtrbTest.kickOffRemoteTest(RemoteCtrbTest.java:52)

Caused by: org.datanucleus.exceptions.NucleusUserException: Persistence process has been specified to use a ClassLoaderResolver of name "jdo" yet this has not been found by the DataNucleus plugin mechanism. Please check your CLASSPATH and plugin specification.
    at org.datanucleus.OMFContext.getClassLoaderResolver(OMFContext.java:319)
    at org.datanucleus.OMFContext.<init>(OMFContext.java:165)
    at org.datanucleus.OMFContext.<init>(OMFContext.java:137)
    at org.datanucleus.ObjectManagerFactoryImpl.initialiseOMFContext(ObjectManagerFactoryImpl.java:132)
    at org.datanucleus.jdo.JDOPersistenceManagerFactory.initialiseProperties(JDOPersistenceManagerFactory.java:363)
    at org.datanucleus.jdo.JDOPersistenceManagerFactory.<init>(JDOPersistenceManagerFactory.java:307)
    at org.datanucleus.jdo.JDOPersistenceManagerFactory.createPersistenceManagerFactory(JDOPersistenceManagerFactory.java:255)
    at org.datanucleus.jdo.JDOPersistenceManagerFactory.getPersistenceManagerFactory(JDOPersistenceManagerFactory.java:182)
    ... 35 more

我发现另一个问题有类似的错误消息,但它是关于 Maven 并且不包含 Hive(这是在其代码中使用 DataNucleus 的那个): Datanucleus、JDO 和可执行 jar - 怎么做?

我正在使用 hive-site.xml 文件为 hive 和 datanucleus 指定一些属性。数据核如下。最后两个我试图解决这个问题,当我更改我为 datanucleus.classLoaderResolverName 指定的任何内容时,它会更改引号中的错误消息。

<property>
  <name>datanucleus.autoCreateSchema</name>
  <value>false</value>
</property>

<property>
  <name>datanucleus.fixedDatastore</name>
  <value>true</value>
</property>

<property>
  <name>datanucleus.classLoaderResolverName</name>
  <value>jdo</value>
</property>

<property>
  <name>javax.jdo.PersistenceManagerFactoryClass</name>
  <value>org.datanucleus.jdo.JDOPersistenceManagerFactory</value>
</property>

我无法弄清楚的部分是该服务是否以某种方式重新捆绑了 jar,就像我在上面链接到的另一个 stackoverflow 问题一样,弄乱了 plugin.xml 和/或 Manifest.mf 文件的位置。我也不确定插件文件如何与配置单元站点文件交互。

这里的类路径需要添加特定的 jar,而不仅仅是一个类路径。我正在使用以下 datanucleus jar: * datanucleus-connectionpool-2.0.3.jar * datanucleus-enhancer-2.0.3.jar * datanucelus-rdbms-2.0.3.jar * datanucleus-core-2.0.3.jar

您可以提供任何帮助我的意见将不胜感激。如果您需要,我可以提供更多信息,所以请询问。

4

2 回答 2

1

如果您在您的公司使用专有技术制作的应用程序中使用Spring框架,那么您可以利用Spring-Hadoop支持。

您所要做的就是在您的以下配置中添加applicationContext

<hdp:configuration>
    fs.default.name=${fs.default.name.url}
    mapred.job.tracker=${mapred.job.tracker.url}
</hdp:configuration>

<hdp:hive-client-factory host="${hadoop.hive.host.url}" port="10000"
    xmlns="http://www.springframework.org/schema/hadoop" />

<hdp:hive-template />

之后, autowire HiveTemplate

@Autowired
HiveTemplate hiveTemplate;

然后查询Hive,如下图:

List<String> list = hiveTemplate.query(queryString, parameterMap);
于 2014-03-28T12:31:28.923 回答
0

DataNucleus 显然使用了基于 OSGi 的插件机制。如果您没有在 OSGi 容器中运行它并且只是使用标准的 maven 项目,那么可能发生的情况是插件位于类路径上,但由于清单问题而未注册。你可以尝试这样的事情:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/jars</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是以前回答过的。

于 2014-03-28T04:26:53.153 回答