use of org.apache.thrift.transport.TTransportException in project storm by apache.
the class NimbusClient method getConfiguredClientAs.
public static NimbusClient getConfiguredClientAs(Map conf, String asUser) {
if (conf.containsKey(Config.STORM_DO_AS_USER)) {
if (asUser != null && !asUser.isEmpty()) {
LOG.warn("You have specified a doAsUser as param {} and a doAsParam as config, config will take precedence.", asUser, conf.get(Config.STORM_DO_AS_USER));
}
asUser = (String) conf.get(Config.STORM_DO_AS_USER);
}
List<String> seeds;
if (conf.containsKey(Config.NIMBUS_HOST)) {
LOG.warn("Using deprecated config {} for backward compatibility. Please update your storm.yaml so it only has config {}", Config.NIMBUS_HOST, Config.NIMBUS_SEEDS);
seeds = Lists.newArrayList(conf.get(Config.NIMBUS_HOST).toString());
} else {
seeds = (List<String>) conf.get(Config.NIMBUS_SEEDS);
}
for (String host : seeds) {
int port = Integer.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT).toString());
NimbusSummary nimbusSummary;
NimbusClient client = null;
try {
client = new NimbusClient(conf, host, port, null, asUser);
nimbusSummary = client.getClient().getLeader();
if (nimbusSummary != null) {
String leaderNimbus = nimbusSummary.get_host() + ":" + nimbusSummary.get_port();
LOG.info("Found leader nimbus : {}", leaderNimbus);
if (nimbusSummary.get_host().equals(host) && nimbusSummary.get_port() == port) {
NimbusClient ret = client;
client = null;
return ret;
}
try {
return new NimbusClient(conf, nimbusSummary.get_host(), nimbusSummary.get_port(), null, asUser);
} catch (TTransportException e) {
throw new RuntimeException("Failed to create a nimbus client for the leader " + leaderNimbus, e);
}
}
} catch (Exception e) {
LOG.warn("Ignoring exception while trying to get leader nimbus info from " + host + ". will retry with a different seed host.", e);
continue;
} finally {
if (client != null) {
client.close();
}
}
throw new NimbusLeaderNotFoundException("Could not find a nimbus leader, please try " + "again after some time.");
}
throw new NimbusLeaderNotFoundException("Could not find leader nimbus from seed hosts " + seeds + ". " + "Did you specify a valid list of nimbus hosts for config " + Config.NIMBUS_SEEDS + "?");
}
use of org.apache.thrift.transport.TTransportException in project zeppelin by apache.
the class JDBCInterpreter method executeSql.
private InterpreterResult executeSql(String propertyKey, String sql, InterpreterContext interpreterContext) {
Connection connection;
Statement statement;
ResultSet resultSet = null;
String paragraphId = interpreterContext.getParagraphId();
String user = interpreterContext.getAuthenticationInfo().getUser();
InterpreterResult interpreterResult = new InterpreterResult(InterpreterResult.Code.SUCCESS);
try {
connection = getConnection(propertyKey, interpreterContext);
if (connection == null) {
return new InterpreterResult(Code.ERROR, "Prefix not found.");
}
ArrayList<String> multipleSqlArray = splitSqlQueries(sql);
for (int i = 0; i < multipleSqlArray.size(); i++) {
String sqlToExecute = multipleSqlArray.get(i);
statement = connection.createStatement();
if (statement == null) {
return new InterpreterResult(Code.ERROR, "Prefix not found.");
}
try {
getJDBCConfiguration(user).saveStatement(paragraphId, statement);
boolean isResultSetAvailable = statement.execute(sqlToExecute);
getJDBCConfiguration(user).setConnectionInDBDriverPoolSuccessful(propertyKey);
if (isResultSetAvailable) {
resultSet = statement.getResultSet();
// Regards that the command is DDL.
if (isDDLCommand(statement.getUpdateCount(), resultSet.getMetaData().getColumnCount())) {
interpreterResult.add(InterpreterResult.Type.TEXT, "Query executed successfully.");
} else {
interpreterResult.add(getResults(resultSet, !containsIgnoreCase(sqlToExecute, EXPLAIN_PREDICATE)));
}
} else {
// Response contains either an update count or there are no results.
int updateCount = statement.getUpdateCount();
interpreterResult.add(InterpreterResult.Type.TEXT, "Query executed successfully. Affected rows : " + updateCount);
}
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
/*ignored*/
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
/*ignored*/
}
}
}
}
//In case user ran an insert/update/upsert statement
if (connection != null) {
try {
if (!connection.getAutoCommit()) {
connection.commit();
}
connection.close();
} catch (SQLException e) {
/*ignored*/
}
}
getJDBCConfiguration(user).removeStatement(paragraphId);
} catch (Throwable e) {
if (e.getCause() instanceof TTransportException && Throwables.getStackTraceAsString(e).contains("GSS") && getJDBCConfiguration(user).isConnectionInDBDriverPoolSuccessful(propertyKey)) {
return reLoginFromKeytab(propertyKey, sql, interpreterContext, interpreterResult);
} else {
logger.error("Cannot run " + sql, e);
String errorMsg = Throwables.getStackTraceAsString(e);
try {
closeDBPool(user, propertyKey);
} catch (SQLException e1) {
logger.error("Cannot close DBPool for user, propertyKey: " + user + propertyKey, e1);
}
interpreterResult.add(errorMsg);
return new InterpreterResult(Code.ERROR, interpreterResult.message());
}
}
return interpreterResult;
}
use of org.apache.thrift.transport.TTransportException in project zeppelin by apache.
the class ClientFactory method create.
@Override
public Client create() throws Exception {
TSocket transport = new TSocket(host, port);
try {
transport.open();
} catch (TTransportException e) {
throw new InterpreterException(e);
}
TProtocol protocol = new TBinaryProtocol(transport);
Client client = new RemoteInterpreterService.Client(protocol);
synchronized (clientSocketMap) {
clientSocketMap.put(client, transport);
}
return client;
}
use of org.apache.thrift.transport.TTransportException in project buck by facebook.
the class ThriftCoordinatorClient method start.
public ThriftCoordinatorClient start() throws IOException {
transport = new TFramedTransport(new TSocket(remoteHost, remotePort));
Stopwatch stopwatch = Stopwatch.createStarted();
while (true) {
try {
transport.open();
break;
} catch (TTransportException e) {
if (stopwatch.elapsed(TimeUnit.SECONDS) > MAX_CONNECT_TIMEOUT_SECONDS) {
throw new IOException(String.format("Failed to connect. Coordinator is still not healthy after [%d] seconds.", MAX_CONNECT_TIMEOUT_SECONDS));
}
LOG.debug("Coordinator server currently not available. Retrying in a bit...");
try {
Thread.sleep(TimeUnit.SECONDS.toMillis(RETRY_TIMEOUT_SECONDS));
} catch (InterruptedException innerException) {
throw new RuntimeException(innerException);
}
}
}
TProtocol protocol = new TBinaryProtocol(transport);
client = new CoordinatorService.Client(protocol);
return this;
}
use of org.apache.thrift.transport.TTransportException in project buck by facebook.
the class ThriftCoordinatorServer method start.
public ThriftCoordinatorServer start() throws IOException {
synchronized (lock) {
try {
transport = new TNonblockingServerSocket(this.port);
} catch (TTransportException e) {
throw new ThriftException(e);
}
TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(transport);
serverArgs.processor(processor);
server = new TThreadedSelectorServer(serverArgs);
serverThread = new Thread(() -> Preconditions.checkNotNull(server).serve());
serverThread.start();
}
return this;
}
Aggregations