Search in sources :

Example 96 with TTransportException

use of org.apache.thrift.transport.TTransportException in project presto by prestodb.

the class Transport method createRaw.

private static TTransport createRaw(String host, int port, HostAndPort socksProxy, int timeoutMillis) throws TTransportException {
    if (socksProxy == null) {
        return new TSocket(host, port, timeoutMillis);
    }
    Socket socks = createSocksSocket(socksProxy);
    try {
        try {
            socks.connect(InetSocketAddress.createUnresolved(host, port), timeoutMillis);
            socks.setSoTimeout(timeoutMillis);
            return new TSocket(socks);
        } catch (Throwable t) {
            closeQuietly(socks);
            throw t;
        }
    } catch (IOException e) {
        throw new TTransportException(e);
    }
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) Socket(java.net.Socket) TSocket(org.apache.thrift.transport.TSocket) TSocket(org.apache.thrift.transport.TSocket)

Example 97 with TTransportException

use of org.apache.thrift.transport.TTransportException in project jena by apache.

the class BinRDF method apply.

/**
     * Send the contents of a RDF-encoded Thrift file to an "action" 
     * @param protocol TProtocol
     * @param action   Code to act on the row.
     */
public static void apply(TProtocol protocol, Consumer<RDF_StreamRow> action) {
    RDF_StreamRow row = new RDF_StreamRow();
    while (protocol.getTransport().isOpen()) {
        try {
            row.read(protocol);
        } catch (TTransportException e) {
            if (e.getType() == TTransportException.END_OF_FILE)
                break;
        } catch (TException ex) {
            TRDF.exception(ex);
        }
        action.accept(row);
        row.clear();
    }
}
Also used : TException(org.apache.thrift.TException) TTransportException(org.apache.thrift.transport.TTransportException) RDF_StreamRow(org.apache.jena.riot.thrift.wire.RDF_StreamRow)

Example 98 with TTransportException

use of org.apache.thrift.transport.TTransportException in project jena by apache.

the class Thift2Binding method moveToNext.

@Override
protected Binding moveToNext() {
    try {
        row.read(protocol);
    } catch (TTransportException e) {
        return null;
    } catch (TException e) {
        TRDF.exception(e);
    }
    if (row.getRowSize() != vars.size())
        throw new RiotThriftException(String.format("Vars %d : Row length : %d", vars.size(), row.getRowSize()));
    BindingMap b = BindingFactory.create();
    for (int i = 0; i < vars.size(); i++) {
        // Old school
        Var v = vars.get(i);
        RDF_Term rt = row.getRow().get(i);
        if (rt.isSetUndefined())
            continue;
        Node n = ThriftConvert.convert(rt);
        b.add(v, n);
    }
    row.clear();
    return b;
}
Also used : TException(org.apache.thrift.TException) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TTransportException(org.apache.thrift.transport.TTransportException) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 99 with TTransportException

use of org.apache.thrift.transport.TTransportException in project simba-os by cegeka.

the class SimbaGateway method isSimbaAlive.

public boolean isSimbaAlive() {
    THttpClient tHttpClient = null;
    try {
        tHttpClient = getTHttpClient();
        tHttpClient.flush();
    } catch (TTransportException e) {
        if (e.getCause() != null && e.getCause().getClass().isAssignableFrom(SocketException.class)) {
            if (tHttpClient != null) {
                tHttpClient.close();
            }
            return false;
        }
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
    return true;
}
Also used : THttpClient(org.apache.thrift.transport.THttpClient) TTransportException(org.apache.thrift.transport.TTransportException)

Example 100 with TTransportException

use of org.apache.thrift.transport.TTransportException in project hive by apache.

the class HiveMetaStoreClient method open.

private void open() throws MetaException {
    isConnected = false;
    TTransportException tte = null;
    boolean useSSL = MetastoreConf.getBoolVar(conf, ConfVars.USE_SSL);
    boolean useSasl = MetastoreConf.getBoolVar(conf, ConfVars.USE_THRIFT_SASL);
    boolean useFramedTransport = MetastoreConf.getBoolVar(conf, ConfVars.USE_THRIFT_FRAMED_TRANSPORT);
    boolean useCompactProtocol = MetastoreConf.getBoolVar(conf, ConfVars.USE_THRIFT_COMPACT_PROTOCOL);
    int clientSocketTimeout = (int) MetastoreConf.getTimeVar(conf, ConfVars.CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
    for (int attempt = 0; !isConnected && attempt < retries; ++attempt) {
        for (URI store : metastoreUris) {
            LOG.info("Trying to connect to metastore with URI " + store);
            try {
                if (useSSL) {
                    try {
                        String trustStorePath = MetastoreConf.getVar(conf, ConfVars.SSL_TRUSTSTORE_PATH).trim();
                        if (trustStorePath.isEmpty()) {
                            throw new IllegalArgumentException(ConfVars.SSL_TRUSTSTORE_PATH.toString() + " Not configured for SSL connection");
                        }
                        String trustStorePassword = MetastoreConf.getPassword(conf, MetastoreConf.ConfVars.SSL_TRUSTSTORE_PASSWORD);
                        // Create an SSL socket and connect
                        transport = SecurityUtils.getSSLSocket(store.getHost(), store.getPort(), clientSocketTimeout, trustStorePath, trustStorePassword);
                        LOG.info("Opened an SSL connection to metastore, current connections: " + connCount.incrementAndGet());
                    } catch (IOException e) {
                        throw new IllegalArgumentException(e);
                    } catch (TTransportException e) {
                        tte = e;
                        throw new MetaException(e.toString());
                    }
                } else {
                    transport = new TSocket(store.getHost(), store.getPort(), clientSocketTimeout);
                }
                if (useSasl) {
                    // Wrap thrift connection with SASL for secure connection.
                    try {
                        HadoopThriftAuthBridge.Client authBridge = HadoopThriftAuthBridge.getBridge().createClient();
                        // check if we should use delegation tokens to authenticate
                        // the call below gets hold of the tokens if they are set up by hadoop
                        // this should happen on the map/reduce tasks if the client added the
                        // tokens into hadoop's credential store in the front end during job
                        // submission.
                        String tokenSig = MetastoreConf.getVar(conf, ConfVars.TOKEN_SIGNATURE);
                        // tokenSig could be null
                        tokenStrForm = SecurityUtils.getTokenStrForm(tokenSig);
                        if (tokenStrForm != null) {
                            LOG.info("HMSC::open(): Found delegation token. Creating DIGEST-based thrift connection.");
                            // authenticate using delegation tokens via the "DIGEST" mechanism
                            transport = authBridge.createClientTransport(null, store.getHost(), "DIGEST", tokenStrForm, transport, MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
                        } else {
                            LOG.info("HMSC::open(): Could not find delegation token. Creating KERBEROS-based thrift connection.");
                            String principalConfig = MetastoreConf.getVar(conf, ConfVars.KERBEROS_PRINCIPAL);
                            transport = authBridge.createClientTransport(principalConfig, store.getHost(), "KERBEROS", null, transport, MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
                        }
                    } catch (IOException ioe) {
                        LOG.error("Couldn't create client transport", ioe);
                        throw new MetaException(ioe.toString());
                    }
                } else {
                    if (useFramedTransport) {
                        transport = new TFramedTransport(transport);
                    }
                }
                final TProtocol protocol;
                if (useCompactProtocol) {
                    protocol = new TCompactProtocol(transport);
                } else {
                    protocol = new TBinaryProtocol(transport);
                }
                client = new ThriftHiveMetastore.Client(protocol);
                try {
                    if (!transport.isOpen()) {
                        transport.open();
                        LOG.info("Opened a connection to metastore, current connections: " + connCount.incrementAndGet());
                    }
                    isConnected = true;
                } catch (TTransportException e) {
                    tte = e;
                    if (LOG.isDebugEnabled()) {
                        LOG.warn("Failed to connect to the MetaStore Server...", e);
                    } else {
                        // Don't print full exception trace if DEBUG is not on.
                        LOG.warn("Failed to connect to the MetaStore Server...");
                    }
                }
                if (isConnected && !useSasl && MetastoreConf.getBoolVar(conf, ConfVars.EXECUTE_SET_UGI)) {
                    // Call set_ugi, only in unsecure mode.
                    try {
                        UserGroupInformation ugi = SecurityUtils.getUGI();
                        client.set_ugi(ugi.getUserName(), Arrays.asList(ugi.getGroupNames()));
                    } catch (LoginException e) {
                        LOG.warn("Failed to do login. set_ugi() is not successful, " + "Continuing without it.", e);
                    } catch (IOException e) {
                        LOG.warn("Failed to find ugi of client set_ugi() is not successful, " + "Continuing without it.", e);
                    } catch (TException e) {
                        LOG.warn("set_ugi() not successful, Likely cause: new client talking to old server. " + "Continuing without it.", e);
                    }
                }
            } catch (MetaException e) {
                LOG.error("Unable to connect to metastore with URI " + store + " in attempt " + attempt, e);
            }
            if (isConnected) {
                break;
            }
        }
        // Wait before launching the next round of connection retries.
        if (!isConnected && retryDelaySeconds > 0) {
            try {
                LOG.info("Waiting " + retryDelaySeconds + " seconds before next connection attempt.");
                Thread.sleep(retryDelaySeconds * 1000);
            } catch (InterruptedException ignore) {
            }
        }
    }
    if (!isConnected) {
        throw new MetaException("Could not connect to meta store using any of the URIs provided." + " Most recent failure: " + StringUtils.stringifyException(tte));
    }
    snapshotActiveConf();
    LOG.info("Connected to metastore.");
}
Also used : TException(org.apache.thrift.TException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) URI(java.net.URI) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) HadoopThriftAuthBridge(org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) LoginException(javax.security.auth.login.LoginException) TSocket(org.apache.thrift.transport.TSocket) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

TTransportException (org.apache.thrift.transport.TTransportException)165 TTransport (org.apache.thrift.transport.TTransport)43 TException (org.apache.thrift.TException)42 Test (org.junit.Test)39 IOException (java.io.IOException)38 TSocket (org.apache.thrift.transport.TSocket)38 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 TProtocol (org.apache.thrift.protocol.TProtocol)26 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)24 TServerSocket (org.apache.thrift.transport.TServerSocket)15 ArrayList (java.util.ArrayList)13 TFramedTransport (org.apache.thrift.transport.TFramedTransport)13 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 Function (org.apache.hadoop.hive.metastore.api.Function)9 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)8 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)8 Partition (org.apache.hadoop.hive.metastore.api.Partition)8