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