Search in sources :

Example 1 with Iface

use of org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface in project hive by apache.

the class TUGIBasedProcessor method process.

@SuppressWarnings("unchecked")
@Override
public void process(final TProtocol in, final TProtocol out) throws TException {
    setIpAddress(in);
    final TMessage msg = in.readMessageBegin();
    final ProcessFunction<Iface, ? extends TBase> fn = functions.get(msg.name);
    if (fn == null) {
        TProtocolUtil.skip(in, TType.STRUCT);
        in.readMessageEnd();
        TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '" + msg.name + "'");
        out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
        x.write(out);
        out.writeMessageEnd();
        out.getTransport().flush();
        return;
    }
    TUGIContainingTransport ugiTrans = (TUGIContainingTransport) in.getTransport();
    // Store ugi in transport if the rpc is set_ugi
    if (msg.name.equalsIgnoreCase("set_ugi")) {
        try {
            handleSetUGI(ugiTrans, (ThriftHiveMetastore.Processor.set_ugi<Iface>) fn, msg, in, out);
        } catch (TException e) {
            throw e;
        } catch (Exception e) {
            throw new TException(e.getCause());
        }
        return;
    }
    UserGroupInformation clientUgi = ugiTrans.getClientUGI();
    if (null == clientUgi) {
        // At this point, transport must contain client ugi, if it doesn't then its an old client.
        fn.process(msg.seqid, in, out, iface);
        return;
    } else {
        // Found ugi, perform doAs().
        PrivilegedExceptionAction<Void> pvea = new PrivilegedExceptionAction<Void>() {

            @Override
            public Void run() {
                try {
                    fn.process(msg.seqid, in, out, iface);
                    return null;
                } catch (TException te) {
                    throw new RuntimeException(te);
                }
            }
        };
        try {
            clientUgi.doAs(pvea);
            return;
        } catch (RuntimeException rte) {
            if (rte.getCause() instanceof TException) {
                throw (TException) rte.getCause();
            }
            throw rte;
        } catch (InterruptedException ie) {
            // unexpected!
            throw new RuntimeException(ie);
        } catch (IOException ioe) {
            // unexpected!
            throw new RuntimeException(ioe);
        } finally {
            try {
                FileSystem.closeAllForUGI(clientUgi);
            } catch (IOException e) {
                LOG.error("Could not clean up file-system handles for UGI: " + clientUgi, e);
            }
        }
    }
}
Also used : TException(org.apache.thrift.TException) TUGIContainingTransport(org.apache.hadoop.hive.metastore.security.TUGIContainingTransport) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) TProtocolException(org.apache.thrift.protocol.TProtocolException) TApplicationException(org.apache.thrift.TApplicationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TApplicationException(org.apache.thrift.TApplicationException) Iface(org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface) TMessage(org.apache.thrift.protocol.TMessage) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Iface (org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface)1 TUGIContainingTransport (org.apache.hadoop.hive.metastore.security.TUGIContainingTransport)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 TApplicationException (org.apache.thrift.TApplicationException)1 TException (org.apache.thrift.TException)1 TMessage (org.apache.thrift.protocol.TMessage)1 TProtocolException (org.apache.thrift.protocol.TProtocolException)1