无法从WildFly连接到HBase

时间:2014-10-09 09:13:24

标签: java-ee ejb hbase wildfly

我尝试从部署到WildFly 8.1.0.Final上的EJB连接到HBase 0.98.5-hadoop2数据库时遇到了奇怪的问题。

此代码完全可以作为独立应用程序使用:

public static void main(String[] args) throws IOException {
   Configuration config = getConfiguration();
   HConnection connection = HConnectionManager.createConnection(config);
} 
private static Configuration getConfiguration() {
   Configuration config = HBaseConfiguration.create();
   config.set("hbase.zookeeper.quorum", "hbase");  // 
   config.set("hbase.client.retries.number", "3");  // 
   config.set("hbase.cluster.distributed", "true");
   return config;
}

但是当我将它包含在EJB中并从服务器运行时,我遇到了以下异常:

  

2014-10-09 11:58:57,537错误[org.jboss.as.ejb3.invocation](EJB   default - 2)JBAS014134:组件上的EJB调用失败   方法public abstract void的HbaseExecutorImpl   hbasetest.HbaseExecutor.testConnect():javax.ejb.EJBException:   java.lang.RuntimeException:java.io.IOException:登录失败   org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:340)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:79)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory $ 1.processInvocation(ShutDownInterceptorFactory.java:64)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)     在   org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:448)     在   org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)     在   org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)     在   org.jboss.as.ee.component.ViewService $ View.invoke(ViewService.java:185)     在   org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:330)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access $ 100(MethodInvocationMessageHandler.java:70)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler $ 1.run(MethodInvocationMessageHandler.java:203)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)   [rt.jar:1.7.0_67] at   java.util.concurrent.FutureTask.run(FutureTask.java:262)   [rt.jar:1.7.0_67] at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)   [rt.jar:1.7.0_67] at   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)   [rt.jar:1.7.0_67]在java.lang.Thread.run(Thread.java:745)   [rt.jar:1.7.0_67] at   org.jboss.threads.JBossThread.run(JBossThread.java:122)引起:   java.lang.RuntimeException:java.io.IOException:登录失败   hbasetest.HbaseExecutorImpl.testConnect(HbaseExecutorImpl.java:21)   [db2test-1.0-SNAPSHOT.jar:] at   sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)   [rt.jar:1.7.0_67] at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)   [rt.jar:1.7.0_67] at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   [rt.jar:1.7.0_67] at java.lang.reflect.Method.invoke(Method.java:606)   [rt.jar:1.7.0_67] at   org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)     在   org.jboss.as.ee.component.interceptors.UserInterceptorFactory $ 1.processInvocation(UserInterceptorFactory.java:63)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.InterceptorContext $ Invocation.proceed(InterceptorContext.java:407)     在   org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)   [wildfly-weld-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)   [wildfly-weld-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.as.ee.component.interceptors.UserInterceptorFactory $ 1.processInvocation(UserInterceptorFactory.java:63)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)     在   org.jboss.as.ee.component.interceptors.UserInterceptorFactory $ 1.processInvocation(UserInterceptorFactory.java:63)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.InterceptorContext $ Invocation.proceed(InterceptorContext.java:407)     在   org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)   [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at   org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)   [wildfly-weld-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)   [wildfly-ee-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)     在   org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)     在   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] at   org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)     在   org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273)   [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final] ... 39更多引起:   java.io.IOException:登录失败   org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:700)   [hadoop-common-2.2.0.jar:] at   org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:571)   [hadoop-common-2.2.0.jar:] at   hbasetest.HbaseExecutorImpl.testConnect(HbaseExecutorImpl.java:19)   [db2test-1.0-SNAPSHOT.jar:] ... 74更多引起:   javax.security.auth.login.LoginException:无法找到LoginModule   class:com.sun.security.auth.module.NTLoginModule来自[Module   " com.something.hbaseclient:主"来自本地模块加载器@ 64f40c1f   (发现者:本地模块查找器@ 5247fb00(根:   C:\选择\ DTV \ wildfly-8.1.0.Final \模块,C:\选择\ DTV \ wildfly-8.1.0.Final \模块\ SYSTEM \层\基))]     在   javax.security.auth.login.LoginContext.invoke(LoginContext.java:800)   [rt.jar:1.7.0_67] at   javax.security.auth.login.LoginContext.access $ 000(LoginContext.java:203)   [rt.jar:1.7.0_67] at   javax.security.auth.login.LoginContext中$ 4.run(LoginContext.java:690)   [rt.jar:1.7.0_67] at   javax.security.auth.login.LoginContext中$ 4.run(LoginContext.java:688)   [rt.jar:1.7.0_67] at   java.security.AccessController.doPrivileged(本机方法)   [rt.jar:1.7.0_67] at   javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:687)   [rt.jar:1.7.0_67] at   javax.security.auth.login.LoginContext.login(LoginContext.java:595)   [rt.jar:1.7.0_67] at   org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:675)   [hadoop-common-2.2.0.jar:] ... 76更多

在Linux机器上也是如此,除了它无法找到的UnixLoginModule。

来自org.apache.hadoop.hbase.security.User的这一行发生了实际异常

private SecureHadoopUser() throws IOException {
   ugi = UserGroupInformation.getCurrentUser();
}

非常简单的EJB代码说明了主题如下。无论HBase服务器是否存在,它都会失败。

package hbasetest;
import java.io.IOException;
import javax.ejb.Stateless;
import org.apache.hadoop.security.UserGroupInformation;
@Stateless
public class HbaseExecutorImpl implements HbaseExecutor {
    public void test() {
        try {
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}

我已将HBase客户端设置为模块,此处的module.xml内容

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.something.hbaseclient">
    <resources>
        <resource-root path="activation-1.1.jar"/>
        <resource-root path="aopalliance-1.0.jar"/>
        <resource-root path="asm-3.1.jar"/>
        <resource-root path="avro-1.7.7.jar"/>
        <resource-root path="commons-beanutils-1.7.0.jar"/>
        <resource-root path="commons-beanutils-core-1.8.0.jar"/>
        <resource-root path="commons-cli-1.2.jar"/>
        <resource-root path="commons-codec-1.7.jar"/>
        <resource-root path="commons-collections-3.2.1.jar"/>
        <resource-root path="commons-compress-1.4.1.jar"/>
        <resource-root path="commons-configuration-1.6.jar"/>
        <resource-root path="commons-digester-1.8.jar"/>
        <resource-root path="commons-httpclient-3.1.jar"/>
        <resource-root path="commons-io-2.4.jar"/>
        <resource-root path="commons-lang-2.6.jar"/>
        <resource-root path="commons-logging-1.1.1.jar"/>
        <resource-root path="commons-math-2.1.jar"/>
        <resource-root path="commons-net-3.1.jar"/>
        <resource-root path="findbugs-annotations-1.3.9-1.jar"/>
        <resource-root path="guava-12.0.1.jar"/>
        <resource-root path="guice-3.0.jar"/>
        <resource-root path="guice-servlet-3.0.jar"/>
        <resource-root path="hadoop-auth-2.2.0.jar"/>
        <resource-root path="hadoop-common-2.2.0.jar"/>
        <resource-root path="hadoop-mapreduce-client-core-2.2.0.jar"/>
        <resource-root path="hadoop-yarn-api-2.2.0.jar"/>
        <resource-root path="hadoop-yarn-common-2.2.0.jar"/>
        <resource-root path="hbase-client-0.98.5-hadoop2.jar"/>
        <resource-root path="hbase-common-0.98.5-hadoop2.jar"/>
        <resource-root path="hbase-protocol-0.98.5-hadoop2.jar"/>
        <resource-root path="htrace-core-2.04.jar"/>
        <resource-root path="jackson-core-asl-1.8.8.jar"/>
        <resource-root path="jackson-jaxrs-1.8.8.jar"/>
        <resource-root path="jackson-mapper-asl-1.8.8.jar"/>
        <resource-root path="jackson-xc-1.8.8.jar"/>
        <resource-root path="javax.inject-1.jar"/>
        <resource-root path="jaxb-api-2.2.2.jar"/>
        <resource-root path="jaxb-impl-2.2.3-1.jar"/>
        <resource-root path="jboss-ejb-api_3.2_spec-1.0.0.Final.jar"/>
        <resource-root path="jersey-core-1.8.jar"/>
        <resource-root path="jersey-guice-1.9.jar"/>
        <resource-root path="jersey-json-1.8.jar"/>
        <resource-root path="jersey-server-1.8.jar"/>
        <resource-root path="jets3t-0.6.1.jar"/>
        <resource-root path="jettison-1.3.1.jar"/>
        <resource-root path="jetty-6.1.26.jar"/>
        <resource-root path="jetty-util-6.1.26.jar"/>
        <resource-root path="jsch-0.1.42.jar"/>
        <resource-root path="jsr305-1.3.9.jar"/>
        <resource-root path="log4j-1.2.17.jar"/>
        <resource-root path="netty-3.6.6.Final.jar"/>
        <resource-root path="paranamer-2.3.jar"/>
        <resource-root path="protobuf-java-2.5.0.jar"/>
        <resource-root path="slf4j-api-1.6.4.jar"/>
        <resource-root path="slf4j-log4j12-1.6.4.jar"/>
        <resource-root path="snappy-java-1.0.4.1.jar"/>
        <resource-root path="xmlenc-0.52.jar"/>
        <resource-root path="xz-1.0.jar"/>
        <resource-root path="zookeeper-3.4.6.jar"/>
    </resources>
    <dependencies>
        <module name="javaee.api"/>
    </dependencies>
</module>

jboss-deployment-structure.xml如下所示:

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="com.something.hbaseclient"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

我想知道会发生什么。看起来驻留在WildFly上的代码有错误的安全上下文,因此一些WildFly设置应该会有所帮助,但我真的不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

万一有人对此感兴趣我已经通过添加此

解决了这个问题
<system export="true">
   <paths>
      <path name="com/sun/security/auth/module"/>
   </paths>
</system>

进入module.xml的部分

由于WildFly加载类的方式,它必须添加到module.xml而不是jboss-deployment-structure.xml。