Search in sources :

Example 6 with TTransportException

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 + "?");
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) NimbusSummary(org.apache.storm.generated.NimbusSummary) TTransportException(org.apache.thrift.transport.TTransportException)

Example 7 with TTransportException

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;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) TTransportException(org.apache.thrift.transport.TTransportException)

Example 8 with TTransportException

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;
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) TTransportException(org.apache.thrift.transport.TTransportException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TSocket(org.apache.thrift.transport.TSocket)

Example 9 with TTransportException

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;
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) Stopwatch(com.google.common.base.Stopwatch) TTransportException(org.apache.thrift.transport.TTransportException) CoordinatorService(com.facebook.buck.distributed.thrift.CoordinatorService) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 10 with TTransportException

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;
}
Also used : ThriftException(com.facebook.buck.slb.ThriftException) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) TThreadedSelectorServer(org.apache.thrift.server.TThreadedSelectorServer) TTransportException(org.apache.thrift.transport.TTransportException)

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