Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with TTransportException

use of org.apache.thrift.transport.TTransportException in project alluxio by Alluxio.

the class ThriftClientPool method createNewResource.

/**
   * Creates a thrift client instance.
   *
   * @return the thrift client created
   * @throws IOException if it fails to create a thrift client
   */
@Override
protected T createNewResource() throws IOException {
    TTransport transport = mTransportProvider.getClientTransport(mParentSubject, mAddress);
    TProtocol binaryProtocol = new TBinaryProtocol(transport);
    T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName));
    TException exception;
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
    do {
        LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, mServiceName, mAddress);
        try {
            if (!transport.isOpen()) {
                transport.open();
            }
            if (transport.isOpen()) {
                checkVersion(client);
            }
            LOG.info("Client registered with {} @ {}", mServiceName, mAddress);
            return client;
        } catch (TTransportException e) {
            if (e.getCause() instanceof java.net.SocketTimeoutException) {
                // Do not retry if socket timeout.
                String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
                throw new IOException(message, e);
            }
            LOG.warn("Failed to connect ({}) to {} @ {}: {}", retryPolicy.getRetryCount(), mServiceName, mAddress, e.getMessage());
            exception = e;
        }
    } while (retryPolicy.attemptRetry());
    LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
    Preconditions.checkNotNull(exception);
    throw new IOException(exception);
}
Also used : TException(org.apache.thrift.TException) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) RetryPolicy(alluxio.retry.RetryPolicy)

Aggregations

TTransportException (org.apache.thrift.transport.TTransportException)154 TException (org.apache.thrift.TException)45 TTransport (org.apache.thrift.transport.TTransport)44 IOException (java.io.IOException)43 TSocket (org.apache.thrift.transport.TSocket)39 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)30 TProtocol (org.apache.thrift.protocol.TProtocol)27 Test (org.junit.Test)22 TServerSocket (org.apache.thrift.transport.TServerSocket)15 ArrayList (java.util.ArrayList)12 TFramedTransport (org.apache.thrift.transport.TFramedTransport)12 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 HostAndPort (org.apache.accumulo.core.util.HostAndPort)10 InetSocketAddress (java.net.InetSocketAddress)9 AccumuloException (org.apache.accumulo.core.client.AccumuloException)9 UnknownHostException (java.net.UnknownHostException)8 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)8 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)8 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)8 List (java.util.List)7