Search in sources :

Example 36 with TThreadPoolServer

use of org.apache.thrift.server.TThreadPoolServer in project jstorm by alibaba.

the class SaslTransportPlugin method getServer.

@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
    int port = type.getPort(storm_conf);
    TTransportFactory serverTransportFactory = getServerTransportFactory();
    TServerSocket serverTransport = new TServerSocket(port);
    int numWorkerThreads = type.getNumThreads(storm_conf);
    Integer queueSize = type.getQueueSize(storm_conf);
    TThreadPoolServer.Args server_args = new TThreadPoolServer.Args(serverTransport).processor(new TUGIWrapProcessor(processor)).minWorkerThreads(numWorkerThreads).maxWorkerThreads(numWorkerThreads).protocolFactory(new TBinaryProtocol.Factory(false, true));
    if (serverTransportFactory != null) {
        server_args.transportFactory(serverTransportFactory);
    }
    BlockingQueue workQueue = new SynchronousQueue();
    if (queueSize != null) {
        workQueue = new ArrayBlockingQueue(queueSize);
    }
    ThreadPoolExecutor executorService = new ExtendedThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, workQueue);
    server_args.executorService(executorService);
    return new TThreadPoolServer(server_args);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) TTransportFactory(org.apache.thrift.transport.TTransportFactory) ExtendedThreadPoolExecutor(backtype.storm.utils.ExtendedThreadPoolExecutor) TServerSocket(org.apache.thrift.transport.TServerSocket) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ExtendedThreadPoolExecutor(backtype.storm.utils.ExtendedThreadPoolExecutor) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Example 37 with TThreadPoolServer

use of org.apache.thrift.server.TThreadPoolServer in project zeppelin by apache.

the class RemoteInterpreterServer method run.

@Override
public void run() {
    RemoteInterpreterService.Processor<RemoteInterpreterServer> processor = new RemoteInterpreterService.Processor<>(this);
    try (TServerSocket tSocket = new TServerSocket(port)) {
        server = new TThreadPoolServer(new TThreadPoolServer.Args(tSocket).stopTimeoutVal(DEFAULT_SHUTDOWN_TIMEOUT).stopTimeoutUnit(TimeUnit.MILLISECONDS).processor(processor));
        if (null != intpEventServerHost && !isTest) {
            Thread registerThread = new Thread(new RegisterRunnable());
            registerThread.setName("RegisterThread");
            registerThread.start();
        }
        LOGGER.info("Launching ThriftServer at {}:{}", this.host, this.port);
        server.serve();
    } catch (TTransportException e) {
        LOGGER.error("Failure in TTransport", e);
    }
    LOGGER.info("RemoteInterpreterServer-Thread finished");
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) RemoteInterpreterService(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService) TTransportException(org.apache.thrift.transport.TTransportException) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Example 38 with TThreadPoolServer

use of org.apache.thrift.server.TThreadPoolServer in project accumulo by apache.

the class TServerUtils method createSaslThreadPoolServer.

public static ServerAddress createSaslThreadPoolServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, long socketTimeout, SaslServerConnectionParams params, final String serverName, final int numThreads, final long threadTimeOut, final AccumuloConfiguration conf, long timeBetweenThreadChecks) throws TTransportException {
    // We'd really prefer to use THsHaServer (or similar) to avoid 1 RPC == 1 Thread that the
    // TThreadPoolServer does,
    // but sadly this isn't the case. Because TSaslTransport needs to issue a handshake when it
    // open()'s which will fail
    // when the server does an accept() to (presumably) wake up the eventing system.
    log.info("Creating SASL thread pool thrift server on listening on {}:{}", address.getHost(), address.getPort());
    InetSocketAddress isa = new InetSocketAddress(address.getHost(), address.getPort());
    // Must use an ISA, providing only a port would ignore the hostname given
    TServerSocket transport = new TServerSocket(isa, (int) socketTimeout);
    String hostname, fqdn;
    try {
        hostname = InetAddress.getByName(address.getHost()).getCanonicalHostName();
        fqdn = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        transport.close();
        throw new TTransportException(e);
    }
    // localhost
    if ("0.0.0.0".equals(hostname)) {
        hostname = fqdn;
    }
    // their configuration.
    if (!hostname.equals(fqdn)) {
        log.error("Expected hostname of '{}' but got '{}'. Ensure the entries in" + " the Accumulo hosts files (e.g. managers, tservers) are the FQDN for" + " each host when using SASL.", fqdn, hostname);
        transport.close();
        throw new RuntimeException("SASL requires that the address the thrift" + " server listens on is the same as the FQDN for this host");
    }
    final UserGroupInformation serverUser;
    try {
        serverUser = UserGroupInformation.getLoginUser();
    } catch (IOException e) {
        transport.close();
        throw new TTransportException(e);
    }
    log.debug("Logged in as {}, creating TSaslServerTransport factory with {}/{}", serverUser, params.getKerberosServerPrimary(), hostname);
    // Make the SASL transport factory with the instance and primary from the kerberos server
    // principal, SASL properties
    // and the SASL callback handler from Hadoop to ensure authorization ID is the authentication
    // ID. Despite the 'protocol' argument seeming to be useless, it
    // *must* be the primary of the server.
    TSaslServerTransport.Factory saslTransportFactory = new TSaslServerTransport.Factory();
    saslTransportFactory.addServerDefinition(ThriftUtil.GSSAPI, params.getKerberosServerPrimary(), hostname, params.getSaslProperties(), new SaslRpcServer.SaslGssCallbackHandler());
    if (params.getSecretManager() != null) {
        log.info("Adding DIGEST-MD5 server definition for delegation tokens");
        saslTransportFactory.addServerDefinition(ThriftUtil.DIGEST_MD5, params.getKerberosServerPrimary(), hostname, params.getSaslProperties(), new SaslServerDigestCallbackHandler(params.getSecretManager()));
    } else {
        log.info("SecretManager is null, not adding support for delegation token authentication");
    }
    // Make sure the TTransportFactory is performing a UGI.doAs
    TTransportFactory ugiTransportFactory = new UGIAssumingTransportFactory(saslTransportFactory, serverUser);
    if (address.getPort() == 0) {
        // If we chose a port dynamically, make a new use it (along with the proper hostname)
        address = HostAndPort.fromParts(address.getHost(), transport.getServerSocket().getLocalPort());
        log.info("SASL thrift server bound on {}", address);
    }
    ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, threadTimeOut, conf, timeBetweenThreadChecks);
    final TThreadPoolServer server = createTThreadPoolServer(transport, processor, ugiTransportFactory, protocolFactory, pool);
    return new ServerAddress(server, address);
}
Also used : SaslRpcServer(org.apache.hadoop.security.SaslRpcServer) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) TTransportException(org.apache.thrift.transport.TTransportException) LoggerFactory(org.slf4j.LoggerFactory) UGIAssumingTransportFactory(org.apache.accumulo.core.rpc.UGIAssumingTransportFactory) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TProcessorFactory(org.apache.thrift.TProcessorFactory) TTransportFactory(org.apache.thrift.transport.TTransportFactory) IOException(java.io.IOException) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TServerSocket(org.apache.thrift.transport.TServerSocket) UGIAssumingTransportFactory(org.apache.accumulo.core.rpc.UGIAssumingTransportFactory) TSaslServerTransport(org.apache.thrift.transport.TSaslServerTransport) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)38 TServerSocket (org.apache.thrift.transport.TServerSocket)33 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)17 TServerTransport (org.apache.thrift.transport.TServerTransport)15 TTransportFactory (org.apache.thrift.transport.TTransportFactory)15 InetSocketAddress (java.net.InetSocketAddress)12 TTransportException (org.apache.thrift.transport.TTransportException)12 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)9 TServer (org.apache.thrift.server.TServer)9 IOException (java.io.IOException)7 TTransport (org.apache.thrift.transport.TTransport)7 TProtocol (org.apache.thrift.protocol.TProtocol)6 ArrayList (java.util.ArrayList)5 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)5 ServerContext (org.apache.thrift.server.ServerContext)5 TServerEventHandler (org.apache.thrift.server.TServerEventHandler)5 UnknownHostException (java.net.UnknownHostException)4 TProcessorFactory (org.apache.thrift.TProcessorFactory)4 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)4 TSSLTransportFactory (org.apache.thrift.transport.TSSLTransportFactory)4