Search in sources :

Example 11 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 12 with TTransportException

use of org.apache.thrift.transport.TTransportException in project presto by prestodb.

the class Transport method create.

public static TTransport create(String host, int port, HostAndPort socksProxy, int timeoutMillis, HiveMetastoreAuthentication authentication) throws TTransportException {
    try {
        TTransport rawTransport = createRaw(host, port, socksProxy, timeoutMillis);
        TTransport authenticatedTransport = authentication.authenticate(rawTransport, host);
        if (!authenticatedTransport.isOpen()) {
            authenticatedTransport.open();
        }
        return new TTransportWrapper(authenticatedTransport, host);
    } catch (TTransportException e) {
        throw rewriteException(e, host);
    }
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport)

Example 13 with TTransportException

use of org.apache.thrift.transport.TTransportException in project brisk by riptano.

the class CassandraStorage method createConnection.

private static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws IOException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to server", e);
    }
    return new Cassandra.Client(new TBinaryProtocol(trans));
}
Also used : TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 14 with TTransportException

use of org.apache.thrift.transport.TTransportException in project scale7-pelops by s7.

the class CommonsBackedPool method getConnectionExcept.

@Override
public IPooledConnection getConnectionExcept(Set<String> avoidNodes) throws NoConnectionsAvailableException {
    PooledNode node = null;
    IPooledConnection connection = null;
    long timeout = -1;
    while (connection == null) {
        if (timeout == -1) {
            // first run through calc the timeout for the next loop
            // (this makes debugging easier)
            int maxWait = getPolicy().getMaxWaitForConnection();
            timeout = maxWait > 0 ? System.currentTimeMillis() + maxWait : Long.MAX_VALUE;
        } else if (timeout < System.currentTimeMillis()) {
            logger.debug("Max wait time for connection exceeded");
            break;
        }
        node = nodeSelectionStrategy.select(this, nodes.keySet(), avoidNodes);
        // if the strategy was unable to choose a node (all suspended?) then sleep for a bit and loop
        if (node == null) {
            logger.debug("The node selection strategy was unable to choose a node, sleeping before trying again...");
            try {
                Thread.sleep(DEFAULT_WAIT_PERIOD);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            continue;
        }
        try {
            logger.debug("Attempting to borrow free connection for node '{}'", node.getAddress());
            // note that if no connections are currently available for this node then the pool will sleep for
            // DEFAULT_WAIT_PERIOD milliseconds
            connection = pool.borrowObject(node.getAddress());
        } catch (IllegalStateException e) {
            throw new PelopsException("The pool has been shutdown", e);
        } catch (Exception e) {
            if (e instanceof NoSuchElementException) {
                logger.debug("No free connections available for node '{}'.  Trying another node...", node.getAddress());
            } else if (e instanceof TTransportException) {
                logger.warn(String.format("A TTransportException was thrown while attempting to create a connection to '%s'.  " + "This node will be suspended for %sms.  Trying another node...", node.getAddress(), this.policy.getNodeDownSuspensionMillis()));
                node.suspendForMillis(this.policy.getNodeDownSuspensionMillis());
            } else
                logger.warn(String.format("An exception was thrown while attempting to create a connection to '%s'.  " + "Trying another node...", node.getAddress()), e);
            // try and avoid this node on the next trip through the loop
            if (avoidNodes == null)
                avoidNodes = new HashSet<String>(10);
            avoidNodes.add(node.getAddress());
        }
    }
    if (node == null) {
        logger.error("Failed to get a connection within the configured wait time because there are no available nodes. " + "This possibly indicates that either the suspension strategy is too aggressive or that your " + "cluster is in a bad way.");
        throw new NoConnectionsAvailableException("Failed to get a connection within the configured max wait time.");
    }
    if (connection == null) {
        logger.error("Failed to get a connection within the maximum allowed wait time.  " + "Try increasing the either the number of allowed connections or the max wait time.");
        throw new NoConnectionsAvailableException("Failed to get a connection within the configured max wait time.");
    }
    logger.debug("Borrowing connection '{}'", connection);
    statistics.connectionsActive.incrementAndGet();
    reportConnectionBorrowed(connection.getNode().getAddress());
    return connection;
}
Also used : NoConnectionsAvailableException(org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException) TTransportException(org.apache.thrift.transport.TTransportException) PelopsException(org.scale7.cassandra.pelops.exceptions.PelopsException) TTransportException(org.apache.thrift.transport.TTransportException) NoConnectionsAvailableException(org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) SocketException(java.net.SocketException) NoSuchElementException(java.util.NoSuchElementException) TException(org.apache.thrift.TException) PelopsException(org.scale7.cassandra.pelops.exceptions.PelopsException) NoSuchElementException(java.util.NoSuchElementException)

Example 15 with TTransportException

use of org.apache.thrift.transport.TTransportException in project jstorm by alibaba.

the class BlobStoreUtils method downloadResourcesAsSupervisor.

/**
     * Meant to be called only by the supervisor for stormjar/stormconf/stormcode files.
     *
     * @param key
     * @param localFile
     * @param cb
     * @throws KeyNotFoundException
     * @throws IOException
     */
public static void downloadResourcesAsSupervisor(String key, String localFile, ClientBlobStore cb, Map conf) throws KeyNotFoundException, IOException {
    if (cb instanceof NimbusBlobStore) {
        List<NimbusInfo> nimbusInfos = null;
        CuratorFramework zkClient = null;
        try {
            zkClient = BlobStoreUtils.createZKClient(conf);
            nimbusInfos = Lists.newArrayList(BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, key));
            Collections.shuffle(nimbusInfos);
        } catch (Exception e) {
            LOG.error("get available nimbus for blob key:{} error", e);
            return;
        } finally {
            if (zkClient != null) {
                zkClient.close();
                zkClient = null;
            }
        }
        if (nimbusInfos != null) {
            for (NimbusInfo nimbusInfo : nimbusInfos) {
                try {
                    NimbusClient nimbusClient = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort());
                    cb.setClient(conf, nimbusClient);
                } catch (TTransportException e) {
                    // ignore
                    continue;
                }
                LOG.info("download blob {} from nimbus {}:{}", key, nimbusInfo.getHost(), nimbusInfo.getPort());
                downloadResourcesAsSupervisorDirect(key, localFile, cb);
            }
        }
    } else {
        downloadResourcesAsSupervisorDirect(key, localFile, cb);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TTransportException(org.apache.thrift.transport.TTransportException) NimbusClient(backtype.storm.utils.NimbusClient) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) IOException(java.io.IOException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) NimbusInfo(backtype.storm.nimbus.NimbusInfo)

Aggregations

TTransportException (org.apache.thrift.transport.TTransportException)67 IOException (java.io.IOException)23 TException (org.apache.thrift.TException)22 TTransport (org.apache.thrift.transport.TTransport)18 TSocket (org.apache.thrift.transport.TSocket)14 Test (org.junit.Test)13 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)8 TProtocol (org.apache.thrift.protocol.TProtocol)8 TFramedTransport (org.apache.thrift.transport.TFramedTransport)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)4 Map (java.util.Map)4 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)3 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)3 NimbusInfo (backtype.storm.nimbus.NimbusInfo)3 NimbusClient (backtype.storm.utils.NimbusClient)3 SocketException (java.net.SocketException)3 PrivilegedActionException (java.security.PrivilegedActionException)3 LoginException (javax.security.auth.login.LoginException)3