Search in sources :

Example 21 with TTransport

use of org.apache.thrift.transport.TTransport in project pinpoint by naver.

the class TProtocolReadMessageEndInterceptor method recordRootSpan.

private void recordRootSpan(final Trace trace, final ThriftRequestProperty parentTraceInfo, Object target) {
    // begin root span
    SpanRecorder recorder = trace.getSpanRecorder();
    recorder.recordServiceType(ThriftConstants.THRIFT_SERVER);
    recorder.recordApi(this.thriftServerEntryMethodDescriptor);
    if (!trace.isRoot()) {
        recordParentInfo(recorder, parentTraceInfo);
    }
    // record connection information here as the socket may be closed by the time the Span is popped in
    // TBaseAsyncProcessorProcessInterceptor's after section.
    TTransport transport = ((TProtocol) target).getTransport();
    recordConnection(recorder, transport);
}
Also used : SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport)

Example 22 with TTransport

use of org.apache.thrift.transport.TTransport in project pinpoint by naver.

the class WrappedTTransportConstructInterceptor method after.

@Override
public final void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (validateTransport(target)) {
        TTransport wrappedTransport = getWrappedTransport(args);
        if (validateTransport(wrappedTransport)) {
            Socket socket = ((SocketFieldAccessor) wrappedTransport)._$PINPOINT$_getSocket();
            ((SocketFieldAccessor) target)._$PINPOINT$_setSocket(socket);
        }
    }
}
Also used : SocketFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor) TTransport(org.apache.thrift.transport.TTransport) Socket(java.net.Socket)

Example 23 with TTransport

use of org.apache.thrift.transport.TTransport in project alluxio by Alluxio.

the class ThriftClientPool method createNewResource.

/**
   * Creates a thrift client instance.
   *
   * @return the thrift client created
   * @throws IOException if it fails to create a thrift client
   */
@Override
protected T createNewResource() throws IOException {
    TTransport transport = mTransportProvider.getClientTransport(mParentSubject, mAddress);
    TProtocol binaryProtocol = new TBinaryProtocol(transport);
    T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName));
    TException exception;
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
    do {
        LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, mServiceName, mAddress);
        try {
            if (!transport.isOpen()) {
                transport.open();
            }
            if (transport.isOpen()) {
                checkVersion(client);
            }
            LOG.info("Client registered with {} @ {}", mServiceName, mAddress);
            return client;
        } catch (TTransportException e) {
            if (e.getCause() instanceof java.net.SocketTimeoutException) {
                // Do not retry if socket timeout.
                String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
                throw new IOException(message, e);
            }
            LOG.warn("Failed to connect ({}) to {} @ {}: {}", retryPolicy.getRetryCount(), mServiceName, mAddress, e.getMessage());
            exception = e;
        }
    } while (retryPolicy.attemptRetry());
    LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
    Preconditions.checkNotNull(exception);
    throw new IOException(exception);
}
Also used : TException(org.apache.thrift.TException) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) RetryPolicy(alluxio.retry.RetryPolicy)

Example 24 with TTransport

use of org.apache.thrift.transport.TTransport in project alluxio by Alluxio.

the class TransportProviderTest method customAuthenticationEmptyPassword.

/**
   * In CUSTOM mode, if client's password is empty, an exception should be thrown in server side.
   */
@Test
public void customAuthenticationEmptyPassword() throws Exception {
    Configuration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName());
    Configuration.set(PropertyKey.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, ExactlyMatchAuthenticationProvider.class.getName());
    mTransportProvider = TransportProvider.Factory.create();
    // start server
    startServerThread();
    // check case that password is empty
    mThrown.expect(TTransportException.class);
    mThrown.expectMessage("Peer indicated failure: Plain authentication failed: No password provided");
    TTransport client = ((PlainSaslTransportProvider) mTransportProvider).getClientTransport(ExactlyMatchAuthenticationProvider.USERNAME, "", mServerAddress);
    try {
        client.open();
    } finally {
        mServer.stop();
    }
}
Also used : TTransport(org.apache.thrift.transport.TTransport) Test(org.junit.Test)

Example 25 with TTransport

use of org.apache.thrift.transport.TTransport in project alluxio by Alluxio.

the class TransportProviderTest method customAuthenticationExactNamePasswordMatch.

/**
   * In CUSTOM mode, the TTransport mechanism is PLAIN. When server authenticate the connected
   * client user, it use configured AuthenticationProvider. If the username:password pair matches, a
   * connection should be built.
   */
@Test
public void customAuthenticationExactNamePasswordMatch() throws Exception {
    Configuration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName());
    Configuration.set(PropertyKey.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, ExactlyMatchAuthenticationProvider.class.getName());
    mTransportProvider = TransportProvider.Factory.create();
    // start server
    startServerThread();
    // when connecting, authentication happens. User's name:pwd pair matches and auth pass.
    TTransport client = ((PlainSaslTransportProvider) mTransportProvider).getClientTransport(ExactlyMatchAuthenticationProvider.USERNAME, ExactlyMatchAuthenticationProvider.PASSWORD, mServerAddress);
    client.open();
    Assert.assertTrue(client.isOpen());
    // clean up
    client.close();
    mServer.stop();
}
Also used : TTransport(org.apache.thrift.transport.TTransport) Test(org.junit.Test)

Aggregations

TTransport (org.apache.thrift.transport.TTransport)99 TSocket (org.apache.thrift.transport.TSocket)43 TProtocol (org.apache.thrift.protocol.TProtocol)42 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)28 TTransportException (org.apache.thrift.transport.TTransportException)20 Test (org.junit.Test)20 TException (org.apache.thrift.TException)18 IOException (java.io.IOException)12 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 ArrayList (java.util.ArrayList)9 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)8 HashMap (java.util.HashMap)6 Socket (java.net.Socket)5 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)5 THttpClient (org.apache.thrift.transport.THttpClient)4 TSaslClientTransport (org.apache.thrift.transport.TSaslClientTransport)4 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)3