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();
}
}
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);
}
}
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));
}
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;
}
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);
}
}
Aggregations