Search in sources :

Example 71 with TTransportException

use of org.apache.thrift.transport.TTransportException in project accumulo by apache.

the class TServerUtils method startTServer.

/**
 * Start the appropriate Thrift server (SSL or non-blocking server) for the given parameters. Non-null SSL parameters will cause an SSL server to be started.
 *
 * @return A ServerAddress encapsulating the Thrift server created and the host/port which it is bound to.
 */
public static ServerAddress startTServer(ThriftServerType serverType, TimedProcessor processor, TProtocolFactory protocolFactory, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize, SslConnectionParams sslParams, SaslServerConnectionParams saslParams, long serverSocketTimeout, HostAndPort... addresses) throws TTransportException {
    // This is presently not supported. It's hypothetically possible, I believe, to work, but it would require changes in how the transports
    // work at the Thrift layer to ensure that both the SSL and SASL handshakes function. SASL's quality of protection addresses privacy issues.
    checkArgument(!(sslParams != null && saslParams != null), "Cannot start a Thrift server using both SSL and SASL");
    ServerAddress serverAddress = null;
    for (HostAndPort address : addresses) {
        try {
            switch(serverType) {
                case SSL:
                    log.debug("Instantiating SSL Thrift server");
                    serverAddress = createSslThreadPoolServer(address, processor, protocolFactory, serverSocketTimeout, sslParams, serverName, numThreads, numSTThreads, timeBetweenThreadChecks);
                    break;
                case SASL:
                    log.debug("Instantiating SASL Thrift server");
                    serverAddress = createSaslThreadPoolServer(address, processor, protocolFactory, serverSocketTimeout, saslParams, serverName, threadName, numThreads, numSTThreads, timeBetweenThreadChecks);
                    break;
                case THREADPOOL:
                    log.debug("Instantiating unsecure TThreadPool Thrift server");
                    serverAddress = createBlockingServer(address, processor, protocolFactory, maxMessageSize, serverName, numThreads, numSTThreads, timeBetweenThreadChecks);
                    break;
                // Intentional passthrough -- Our custom wrapper around HsHa is the default
                case CUSTOM_HS_HA:
                default:
                    log.debug("Instantiating default, unsecure custom half-async Thrift server");
                    serverAddress = createNonBlockingServer(address, processor, protocolFactory, serverName, threadName, numThreads, numSTThreads, timeBetweenThreadChecks, maxMessageSize);
            }
            break;
        } catch (TTransportException e) {
            log.warn("Error attempting to create server at {}. Error: {}", address.toString(), e.getMessage());
        }
    }
    if (null == serverAddress) {
        throw new TTransportException("Unable to create server on addresses: " + Arrays.toString(addresses));
    }
    final TServer finalServer = serverAddress.server;
    Runnable serveTask = new Runnable() {

        @Override
        public void run() {
            try {
                finalServer.serve();
            } catch (Error e) {
                Halt.halt("Unexpected error in TThreadPoolServer " + e + ", halting.", 1);
            }
        }
    };
    serveTask = new LoggingRunnable(TServerUtils.log, serveTask);
    Thread thread = new Daemon(serveTask, threadName);
    thread.start();
    // check for the special "bind to everything address"
    if (serverAddress.address.getHost().equals("0.0.0.0")) {
        // can't get the address from the bind, so we'll do our best to invent our hostname
        try {
            serverAddress = new ServerAddress(finalServer, HostAndPort.fromParts(InetAddress.getLocalHost().getHostName(), serverAddress.address.getPort()));
        } catch (UnknownHostException e) {
            throw new TTransportException(e);
        }
    }
    return serverAddress;
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) LoggingRunnable(org.apache.accumulo.fate.util.LoggingRunnable) Daemon(org.apache.accumulo.core.util.Daemon) UnknownHostException(java.net.UnknownHostException) TServer(org.apache.thrift.server.TServer) LoggingRunnable(org.apache.accumulo.fate.util.LoggingRunnable) TTransportException(org.apache.thrift.transport.TTransportException)

Example 72 with TTransportException

use of org.apache.thrift.transport.TTransportException in project accumulo by apache.

the class TServerUtils method startServer.

/**
 * Start a server, at the given port, or higher, if that port is not available.
 *
 * @param service
 *          RPC configuration
 * @param portHintProperty
 *          the port to attempt to open, can be zero, meaning "any available port"
 * @param processor
 *          the service to be started
 * @param serverName
 *          the name of the class that is providing the service
 * @param threadName
 *          name this service's thread for better debugging
 * @param portSearchProperty
 *          A boolean Property to control if port-search should be used, or null to disable
 * @param minThreadProperty
 *          A Property to control the minimum number of threads in the pool
 * @param timeBetweenThreadChecksProperty
 *          A Property to control the amount of time between checks to resize the thread pool
 * @param maxMessageSizeProperty
 *          A Property to control the maximum Thrift message size accepted
 * @return the server object created, and the port actually used
 * @throws UnknownHostException
 *           when we don't know our own address
 */
public static ServerAddress startServer(AccumuloServerContext service, String hostname, Property portHintProperty, TProcessor processor, String serverName, String threadName, Property portSearchProperty, Property minThreadProperty, Property timeBetweenThreadChecksProperty, Property maxMessageSizeProperty) throws UnknownHostException {
    final AccumuloConfiguration config = service.getConfiguration();
    final int[] portHint = config.getPort(portHintProperty);
    int minThreads = 2;
    if (minThreadProperty != null)
        minThreads = config.getCount(minThreadProperty);
    long timeBetweenThreadChecks = 1000;
    if (timeBetweenThreadChecksProperty != null)
        timeBetweenThreadChecks = config.getTimeInMillis(timeBetweenThreadChecksProperty);
    long maxMessageSize = 10 * 1000 * 1000;
    if (maxMessageSizeProperty != null)
        maxMessageSize = config.getAsBytes(maxMessageSizeProperty);
    boolean portSearch = false;
    if (portSearchProperty != null)
        portSearch = config.getBoolean(portSearchProperty);
    final int simpleTimerThreadpoolSize = config.getCount(Property.GENERAL_SIMPLETIMER_THREADPOOL_SIZE);
    final ThriftServerType serverType = service.getThriftServerType();
    if (ThriftServerType.SASL == serverType) {
        processor = updateSaslProcessor(serverType, processor);
    }
    // create the TimedProcessor outside the port search loop so we don't try to register the same metrics mbean more than once
    TimedProcessor timedProcessor = new TimedProcessor(config, processor, serverName, threadName);
    HostAndPort[] addresses = getHostAndPorts(hostname, portHint);
    try {
        return TServerUtils.startTServer(serverType, timedProcessor, serverName, threadName, minThreads, simpleTimerThreadpoolSize, timeBetweenThreadChecks, maxMessageSize, service.getServerSslParams(), service.getSaslParams(), service.getClientTimeoutInMillis(), addresses);
    } catch (TTransportException e) {
        if (portSearch) {
            HostAndPort last = addresses[addresses.length - 1];
            // Search sequentially over the next 1000 ports
            for (int i = last.getPort() + 1; i < last.getPort() + 1001; i++) {
                int port = i;
                if (port > 65535) {
                    break;
                }
                try {
                    HostAndPort addr = HostAndPort.fromParts(hostname, port);
                    return TServerUtils.startTServer(serverType, timedProcessor, serverName, threadName, minThreads, simpleTimerThreadpoolSize, timeBetweenThreadChecks, maxMessageSize, service.getServerSslParams(), service.getSaslParams(), service.getClientTimeoutInMillis(), addr);
                } catch (TTransportException tte) {
                    log.info("Unable to use port {}, retrying. (Thread Name = {})", port, threadName);
                }
            }
            log.error("Unable to start TServer", e);
            throw new UnknownHostException("Unable to find a listen port");
        } else {
            log.error("Unable to start TServer", e);
            throw new UnknownHostException("Unable to find a listen port");
        }
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) UnknownHostException(java.net.UnknownHostException) TTransportException(org.apache.thrift.transport.TTransportException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 73 with TTransportException

use of org.apache.thrift.transport.TTransportException in project Honu by jboulon.

the class TServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("application/x-thrift");
    InputStream in = request.getInputStream();
    OutputStream out = response.getOutputStream();
    TTransport client = new TIOStreamTransport(in, out);
    TProcessor processor = null;
    TTransport inputTransport = null;
    TTransport outputTransport = null;
    TProtocol inputProtocol = null;
    TProtocol outputProtocol = null;
    try {
        processor = processor_;
        inputTransport = inputTransportFactory_.getTransport(client);
        outputTransport = outputTransportFactory_.getTransport(client);
        inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
        outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
        while (processor.process(inputProtocol, outputProtocol)) {
        }
    } catch (TTransportException ttx) {
    // Client died, just move on
    } catch (TException tx) {
        tx.printStackTrace();
    } catch (Exception x) {
        x.printStackTrace();
    }
    if (inputTransport != null) {
        inputTransport.close();
    }
    if (outputTransport != null) {
        outputTransport.close();
    }
}
Also used : TException(org.apache.thrift.TException) TProcessor(org.apache.thrift.TProcessor) TProtocol(org.apache.thrift.protocol.TProtocol) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TTransportException(org.apache.thrift.transport.TTransportException) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport) ServletException(javax.servlet.ServletException) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 74 with TTransportException

use of org.apache.thrift.transport.TTransportException in project titan by thinkaurelius.

the class CTConnectionFactory method makeRawConnection.

/**
 * Create a Cassandra-Thrift connection, but do not attempt to
 * set a keyspace on the connection.
 *
 * @return A CTConnection ready to talk to a Cassandra cluster
 * @throws TTransportException on any Thrift transport failure
 */
public CTConnection makeRawConnection() throws TTransportException {
    final Config cfg = cfgRef.get();
    String hostname = cfg.getRandomHost();
    if (log.isDebugEnabled())
        log.debug("Creating TSocket({}, {}, {}, {}, {})", hostname, cfg.port, cfg.username, cfg.password, cfg.timeoutMS);
    TTransport transport = new TFramedTransport(new TSocket(hostname, cfg.port, cfg.timeoutMS), cfg.frameSize);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    Cassandra.Client client = new Cassandra.Client(protocol);
    transport.open();
    if (cfg.username != null) {
        Map<String, String> credentials = new HashMap<String, String>() {

            {
                put(IAuthenticator.USERNAME_KEY, cfg.username);
                put(IAuthenticator.PASSWORD_KEY, cfg.password);
            }
        };
        try {
            client.login(new AuthenticationRequest(credentials));
        } catch (Exception e) {
            // TTransportException will propagate authentication/authorization failure
            throw new TTransportException(e);
        }
    }
    return new CTConnection(transport, client, cfg);
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) TTransportException(org.apache.thrift.transport.TTransportException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 75 with TTransportException

use of org.apache.thrift.transport.TTransportException in project titan by thinkaurelius.

the class CassandraKiller method waitForClusterSize.

public void waitForClusterSize(int minSize) throws InterruptedException, StorageException {
    CTConnectionFactory f = new CTConnectionFactory(new String[] { address }, port, // username, password
    null, // username, password
    null, GraphDatabaseConfiguration.CONNECTION_TIMEOUT_DEFAULT, AbstractCassandraStoreManager.THRIFT_DEFAULT_FRAME_SIZE);
    CTConnection conn = null;
    try {
        conn = f.makeRawConnection();
        CTConnectionFactory.waitForClusterSize(conn.getClient(), minSize);
    } catch (TTransportException e) {
        throw new TemporaryStorageException(e);
    } finally {
        if (null != conn)
            if (conn.getTransport().isOpen())
                conn.getTransport().close();
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TTransportException(org.apache.thrift.transport.TTransportException) CTConnectionFactory(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory)

Aggregations

TTransportException (org.apache.thrift.transport.TTransportException)165 TTransport (org.apache.thrift.transport.TTransport)43 TException (org.apache.thrift.TException)42 Test (org.junit.Test)39 IOException (java.io.IOException)38 TSocket (org.apache.thrift.transport.TSocket)38 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 TProtocol (org.apache.thrift.protocol.TProtocol)26 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)24 TServerSocket (org.apache.thrift.transport.TServerSocket)15 ArrayList (java.util.ArrayList)13 TFramedTransport (org.apache.thrift.transport.TFramedTransport)13 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 HostAndPort (org.apache.accumulo.core.util.HostAndPort)10 InetSocketAddress (java.net.InetSocketAddress)9 AccumuloException (org.apache.accumulo.core.client.AccumuloException)9 Function (org.apache.hadoop.hive.metastore.api.Function)9 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)8 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)8 Partition (org.apache.hadoop.hive.metastore.api.Partition)8