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 eiger by wlloyd.
the class TCustomServerSocket method acceptImpl.
@Override
protected TCustomSocket acceptImpl() throws TTransportException {
if (serverSocket_ == null)
throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
TCustomSocket tsocket = null;
Socket socket = null;
try {
socket = serverSocket_.accept();
tsocket = new TCustomSocket(socket);
tsocket.setTimeout(0);
} catch (IOException iox) {
throw new TTransportException(iox);
}
try {
socket.setKeepAlive(this.keepAlive);
} catch (SocketException se) {
logger.warn("Failed to set keep-alive on Thrift socket.", se);
}
if (this.sendBufferSize != null) {
try {
socket.setSendBufferSize(this.sendBufferSize.intValue());
} catch (SocketException se) {
logger.warn("Failed to set send buffer size on Thrift socket.", se);
}
}
if (this.recvBufferSize != null) {
try {
socket.setReceiveBufferSize(this.recvBufferSize.intValue());
} catch (SocketException se) {
logger.warn("Failed to set receive buffer size on Thrift socket.", se);
}
}
return tsocket;
}
use of org.apache.thrift.transport.TTransportException in project zeppelin by apache.
the class RemoteInterpreterEventServer method start.
public void start() throws IOException {
Thread startingThread = new Thread() {
@Override
public void run() {
try (TServerSocket tSocket = new TServerSocket(RemoteInterpreterUtils.findAvailablePort(portRange))) {
port = tSocket.getServerSocket().getLocalPort();
host = RemoteInterpreterUtils.findAvailableHostAddress();
LOGGER.info("InterpreterEventServer is starting at {}:{}", host, port);
RemoteInterpreterEventService.Processor<RemoteInterpreterEventServer> processor = new RemoteInterpreterEventService.Processor<>(RemoteInterpreterEventServer.this);
thriftServer = new TThreadPoolServer(new TThreadPoolServer.Args(tSocket).processor(processor));
thriftServer.serve();
} catch (IOException | TTransportException e) {
throw new RuntimeException("Fail to create TServerSocket", e);
}
LOGGER.info("ThriftServer-Thread finished");
}
};
startingThread.start();
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < 30 * 1000) {
if (thriftServer != null && thriftServer.isServing()) {
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
if (thriftServer != null && !thriftServer.isServing()) {
throw new IOException("Fail to start InterpreterEventServer in 30 seconds.");
}
LOGGER.info("RemoteInterpreterEventServer is started");
runner = new AppendOutputRunner(listener);
appendFuture = appendService.scheduleWithFixedDelay(runner, 0, AppendOutputRunner.BUFFER_TIME_MS, TimeUnit.MILLISECONDS);
}
use of org.apache.thrift.transport.TTransportException in project zeppelin by apache.
the class ClusterMockTest method startCluster.
public static void startCluster() throws IOException, InterruptedException {
LOGGER.info("startCluster >>>");
zconf = ZeppelinConfiguration.create();
// Set the cluster IP and port
zServerHost = RemoteInterpreterUtils.findAvailableHostAddress();
zServerPort = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
zconf.setClusterAddress(zServerHost + ":" + zServerPort);
// mock cluster manager server
clusterServer = ClusterManagerServer.getInstance(zconf);
clusterServer.start();
// mock cluster manager client
clusterClient = ClusterManagerClient.getInstance(zconf);
clusterClient.start(metaKey);
// Waiting for cluster startup
int wait = 0;
while (wait++ < 100) {
if (clusterServer.isClusterLeader() && clusterServer.raftInitialized() && clusterClient.raftInitialized()) {
LOGGER.info("wait {}(ms) found cluster leader", wait * 3000);
break;
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
assertEquals(true, clusterServer.isClusterLeader());
try {
tSocket = new TServerSocket(0);
} catch (TTransportException e) {
throw new IOException("Fail to create TServerSocket", e);
}
LOGGER.info("startCluster <<<");
}
use of org.apache.thrift.transport.TTransportException in project hive by apache.
the class TSubjectAssumingTransport method open.
@Override
public void open() throws TTransportException {
try {
AccessControlContext context = AccessController.getContext();
Subject subject = Subject.getSubject(context);
Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {
public Void run() {
try {
wrapped.open();
} catch (TTransportException tte) {
// more time in our catch clause to get back the TTE. (ugh)
throw new RuntimeException(tte);
}
return null;
}
});
} catch (PrivilegedActionException ioe) {
throw new RuntimeException("Received an ioe we never threw!", ioe);
} catch (RuntimeException rte) {
if (rte.getCause() instanceof TTransportException) {
throw (TTransportException) rte.getCause();
} else {
throw rte;
}
}
}
Aggregations