use of org.apache.hadoop.hive.thrift.TUGIContainingTransport in project hive by apache.
the class TUGIBasedProcessor method process.
@SuppressWarnings("unchecked")
@Override
public boolean 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 true;
}
TUGIContainingTransport ugiTrans = (TUGIContainingTransport) in.getTransport();
// Store ugi in transport if the rpc is set_ugi
if (msg.name.equalsIgnoreCase("set_ugi")) {
try {
handleSetUGI(ugiTrans, (set_ugi<Iface>) fn, msg, in, out);
} catch (TException e) {
throw e;
} catch (Exception e) {
throw new TException(e.getCause());
}
return true;
}
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 true;
} 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 true;
} 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);
}
}
}
}
use of org.apache.hadoop.hive.thrift.TUGIContainingTransport in project hive by apache.
the class TUGIBasedProcessor method setIpAddress.
@Override
protected void setIpAddress(final TProtocol in) {
TUGIContainingTransport ugiTrans = (TUGIContainingTransport) in.getTransport();
Socket socket = ugiTrans.getSocket();
if (socket != null) {
setIpAddress(socket);
}
}
Aggregations