Search in sources :

Example 1 with ReadTimeoutHandler

use of org.apache.hbase.thirdparty.io.netty.handler.timeout.ReadTimeoutHandler in project hbase by apache.

the class NettyRpcConnection method saslNegotiate.

private void saslNegotiate(final Channel ch) {
    assert eventLoop.inEventLoop();
    UserGroupInformation ticket = provider.getRealUser(remoteId.getTicket());
    if (ticket == null) {
        failInit(ch, new FatalConnectionException("ticket/user is null"));
        return;
    }
    Promise<Boolean> saslPromise = ch.eventLoop().newPromise();
    final NettyHBaseSaslRpcClientHandler saslHandler;
    try {
        saslHandler = new NettyHBaseSaslRpcClientHandler(saslPromise, ticket, provider, token, ((InetSocketAddress) ch.remoteAddress()).getAddress(), securityInfo, rpcClient.fallbackAllowed, this.rpcClient.conf);
    } catch (IOException e) {
        failInit(ch, e);
        return;
    }
    ch.pipeline().addFirst(new SaslChallengeDecoder(), saslHandler);
    saslPromise.addListener(new FutureListener<Boolean>() {

        @Override
        public void operationComplete(Future<Boolean> future) throws Exception {
            if (future.isSuccess()) {
                ChannelPipeline p = ch.pipeline();
                p.remove(SaslChallengeDecoder.class);
                p.remove(NettyHBaseSaslRpcClientHandler.class);
                // check if negotiate with server for connection header is necessary
                if (saslHandler.isNeedProcessConnectionHeader()) {
                    Promise<Boolean> connectionHeaderPromise = ch.eventLoop().newPromise();
                    // create the handler to handle the connection header
                    ChannelHandler chHandler = new NettyHBaseRpcConnectionHeaderHandler(connectionHeaderPromise, conf, connectionHeaderWithLength);
                    // add ReadTimeoutHandler to deal with server doesn't response connection header
                    // because of the different configuration in client side and server side
                    p.addFirst(new ReadTimeoutHandler(RpcClient.DEFAULT_SOCKET_TIMEOUT_READ, TimeUnit.MILLISECONDS));
                    p.addLast(chHandler);
                    connectionHeaderPromise.addListener(new FutureListener<Boolean>() {

                        @Override
                        public void operationComplete(Future<Boolean> future) throws Exception {
                            if (future.isSuccess()) {
                                ChannelPipeline p = ch.pipeline();
                                p.remove(ReadTimeoutHandler.class);
                                p.remove(NettyHBaseRpcConnectionHeaderHandler.class);
                                // don't send connection header, NettyHbaseRpcConnectionHeaderHandler
                                // sent it already
                                established(ch);
                            } else {
                                final Throwable error = future.cause();
                                scheduleRelogin(error);
                                failInit(ch, toIOE(error));
                            }
                        }
                    });
                } else {
                    // send the connection header to server
                    ch.write(connectionHeaderWithLength.retainedDuplicate());
                    established(ch);
                }
            } else {
                final Throwable error = future.cause();
                scheduleRelogin(error);
                failInit(ch, toIOE(error));
            }
        }
    });
}
Also used : ChannelFutureListener(org.apache.hbase.thirdparty.io.netty.channel.ChannelFutureListener) FutureListener(org.apache.hbase.thirdparty.io.netty.util.concurrent.FutureListener) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) ChannelHandler(org.apache.hbase.thirdparty.io.netty.channel.ChannelHandler) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ChannelPipeline(org.apache.hbase.thirdparty.io.netty.channel.ChannelPipeline) Promise(org.apache.hbase.thirdparty.io.netty.util.concurrent.Promise) NettyHBaseRpcConnectionHeaderHandler(org.apache.hadoop.hbase.security.NettyHBaseRpcConnectionHeaderHandler) SaslChallengeDecoder(org.apache.hadoop.hbase.security.SaslChallengeDecoder) NettyHBaseSaslRpcClientHandler(org.apache.hadoop.hbase.security.NettyHBaseSaslRpcClientHandler) ReadTimeoutHandler(org.apache.hbase.thirdparty.io.netty.handler.timeout.ReadTimeoutHandler) Future(org.apache.hbase.thirdparty.io.netty.util.concurrent.Future) ChannelFuture(org.apache.hbase.thirdparty.io.netty.channel.ChannelFuture) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 NettyHBaseRpcConnectionHeaderHandler (org.apache.hadoop.hbase.security.NettyHBaseRpcConnectionHeaderHandler)1 NettyHBaseSaslRpcClientHandler (org.apache.hadoop.hbase.security.NettyHBaseSaslRpcClientHandler)1 SaslChallengeDecoder (org.apache.hadoop.hbase.security.SaslChallengeDecoder)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 ChannelFuture (org.apache.hbase.thirdparty.io.netty.channel.ChannelFuture)1 ChannelFutureListener (org.apache.hbase.thirdparty.io.netty.channel.ChannelFutureListener)1 ChannelHandler (org.apache.hbase.thirdparty.io.netty.channel.ChannelHandler)1 ChannelPipeline (org.apache.hbase.thirdparty.io.netty.channel.ChannelPipeline)1 ReadTimeoutHandler (org.apache.hbase.thirdparty.io.netty.handler.timeout.ReadTimeoutHandler)1 Future (org.apache.hbase.thirdparty.io.netty.util.concurrent.Future)1 FutureListener (org.apache.hbase.thirdparty.io.netty.util.concurrent.FutureListener)1 Promise (org.apache.hbase.thirdparty.io.netty.util.concurrent.Promise)1