Search in sources :

Example 36 with TTransportException

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

the class TSubjectAssumingTransport method open.

@Override
public void open() throws TTransportException {
    try {
        AccessControlContext context = AccessController.getContext();
        Subject subject = Subject.getSubject(context);
        Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {

            public Void run() {
                try {
                    wrapped.open();
                } catch (TTransportException tte) {
                    // more time in our catch clause to get back the TTE. (ugh)
                    throw new RuntimeException(tte);
                }
                return null;
            }
        });
    } catch (PrivilegedActionException ioe) {
        throw new RuntimeException("Received an ioe we never threw!", ioe);
    } catch (RuntimeException rte) {
        if (rte.getCause() instanceof TTransportException) {
            throw (TTransportException) rte.getCause();
        } else {
            throw rte;
        }
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedActionException(java.security.PrivilegedActionException) TTransportException(org.apache.thrift.transport.TTransportException) Subject(javax.security.auth.Subject)

Example 37 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 = conf.getBoolVar(ConfVars.HIVE_METASTORE_USE_SSL);
    boolean useSasl = conf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_SASL);
    boolean useFramedTransport = conf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_FRAMED_TRANSPORT);
    boolean useCompactProtocol = conf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_COMPACT_PROTOCOL);
    int clientSocketTimeout = (int) conf.getTimeVar(ConfVars.METASTORE_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 (useSasl) {
                    // Wrap thrift connection with SASL for secure connection.
                    try {
                        HadoopThriftAuthBridge.Client authBridge = ShimLoader.getHadoopThriftAuthBridge().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 = conf.getVar(ConfVars.METASTORE_TOKEN_SIGNATURE);
                        // tokenSig could be null
                        tokenStrForm = Utils.getTokenStrForm(tokenSig);
                        transport = new TSocket(store.getHost(), store.getPort(), clientSocketTimeout);
                        if (tokenStrForm != null) {
                            // authenticate using delegation tokens via the "DIGEST" mechanism
                            transport = authBridge.createClientTransport(null, store.getHost(), "DIGEST", tokenStrForm, transport, MetaStoreUtils.getMetaStoreSaslProperties(conf));
                        } else {
                            String principalConfig = conf.getVar(HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL);
                            transport = authBridge.createClientTransport(principalConfig, store.getHost(), "KERBEROS", null, transport, MetaStoreUtils.getMetaStoreSaslProperties(conf));
                        }
                    } catch (IOException ioe) {
                        LOG.error("Couldn't create client transport", ioe);
                        throw new MetaException(ioe.toString());
                    }
                } else {
                    if (useSSL) {
                        try {
                            String trustStorePath = conf.getVar(ConfVars.HIVE_METASTORE_SSL_TRUSTSTORE_PATH).trim();
                            if (trustStorePath.isEmpty()) {
                                throw new IllegalArgumentException(ConfVars.HIVE_METASTORE_SSL_TRUSTSTORE_PATH.varname + " Not configured for SSL connection");
                            }
                            String trustStorePassword = ShimLoader.getHadoopShims().getPassword(conf, HiveConf.ConfVars.HIVE_METASTORE_SSL_TRUSTSTORE_PASSWORD.varname);
                            // Create an SSL socket and connect
                            transport = HiveAuthUtils.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 (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 && conf.getBoolVar(ConfVars.METASTORE_EXECUTE_SET_UGI)) {
                    // Call set_ugi, only in unsecure mode.
                    try {
                        UserGroupInformation ugi = Utils.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.thrift.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)

Example 38 with TTransportException

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

the class StaticHiveCluster method createMetastoreClient.

/**
     * Create a metastore client connected to the Hive metastore.
     * <p>
     * As per Hive HA metastore behavior, return the first metastore in the list
     * list of available metastores (i.e. the default metastore) if a connection
     * can be made, else try another of the metastores at random, until either a
     * connection succeeds or there are no more fallback metastores.
     */
@Override
public HiveMetastoreClient createMetastoreClient() {
    List<HostAndPort> metastores = new ArrayList<>(addresses);
    Collections.shuffle(metastores.subList(1, metastores.size()));
    TTransportException lastException = null;
    for (HostAndPort metastore : metastores) {
        try {
            return clientFactory.create(metastore.getHostText(), metastore.getPort());
        } catch (TTransportException e) {
            lastException = e;
        }
    }
    throw new PrestoException(HIVE_METASTORE_ERROR, "Failed connecting to Hive metastore: " + addresses, lastException);
}
Also used : HostAndPort(com.google.common.net.HostAndPort) ArrayList(java.util.ArrayList) TTransportException(org.apache.thrift.transport.TTransportException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 39 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 40 with TTransportException

use of org.apache.thrift.transport.TTransportException in project brisk by riptano.

the class BriskTool method getConnection.

private Brisk.Iface getConnection() throws IOException {
    TTransport trans = new TFramedTransport(new TSocket(host, port));
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to brisk server");
    }
    Brisk.Iface client = new Brisk.Client(new TBinaryProtocol(trans));
    return client;
}
Also used : TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) Brisk(org.apache.cassandra.thrift.Brisk) Iface(org.apache.cassandra.thrift.Brisk.Iface) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

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