Forráskód Böngészése

Make Hue file upload work even if it's talking to a secure cluster.

Aaron T. Myers 15 éve
szülő
commit
d25a0c73f1

+ 7 - 0
desktop/libs/hadoop/gen-py/hadoop/api/hdfs/Namenode-remote

@@ -43,6 +43,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
   print '  void utime(RequestContext ctx, string path, i64 atime, i64 mtime)'
   print '  void datanodeUp(string name, string storage, i32 thriftPort)'
   print '  void datanodeDown(string name, string storage, i32 thriftPort)'
+  print '  ThriftHdfsDelegationToken getDelegationToken(RequestContext ctx, string renewer)'
   print ''
   sys.exit(0)
 
@@ -223,4 +224,10 @@ elif cmd == 'datanodeDown':
     sys.exit(1)
   pp.pprint(client.datanodeDown(args[0],args[1],eval(args[2]),))
 
+elif cmd == 'getDelegationToken':
+  if len(args) != 2:
+    print 'getDelegationToken requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.getDelegationToken(eval(args[0]),args[1],))
+
 transport.close()

+ 203 - 0
desktop/libs/hadoop/gen-py/hadoop/api/hdfs/Namenode.py

@@ -300,6 +300,14 @@ class Iface(hadoop.api.common.HadoopServiceBase.Iface):
     """
     pass
 
+  def getDelegationToken(self, ctx, renewer):
+    """
+    Parameters:
+     - ctx
+     - renewer
+    """
+    pass
+
 
 class Client(hadoop.api.common.HadoopServiceBase.Client, Iface):
   """
@@ -1144,6 +1152,40 @@ class Client(hadoop.api.common.HadoopServiceBase.Client, Iface):
     self._iprot.readMessageEnd()
     return
 
+  def getDelegationToken(self, ctx, renewer):
+    """
+    Parameters:
+     - ctx
+     - renewer
+    """
+    self.send_getDelegationToken(ctx, renewer)
+    return self.recv_getDelegationToken()
+
+  def send_getDelegationToken(self, ctx, renewer):
+    self._oprot.writeMessageBegin('getDelegationToken', TMessageType.CALL, self._seqid)
+    args = getDelegationToken_args()
+    args.ctx = ctx
+    args.renewer = renewer
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_getDelegationToken(self, ):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = getDelegationToken_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success != None:
+      return result.success
+    if result.err != None:
+      raise result.err
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "getDelegationToken failed: unknown result");
+
 
 class Processor(hadoop.api.common.HadoopServiceBase.Processor, Iface, TProcessor):
   def __init__(self, handler):
@@ -1170,6 +1212,7 @@ class Processor(hadoop.api.common.HadoopServiceBase.Processor, Iface, TProcessor
     self._processMap["utime"] = Processor.process_utime
     self._processMap["datanodeUp"] = Processor.process_datanodeUp
     self._processMap["datanodeDown"] = Processor.process_datanodeDown
+    self._processMap["getDelegationToken"] = Processor.process_getDelegationToken
 
   def process(self, iprot, oprot):
     (name, type, seqid) = iprot.readMessageBegin()
@@ -1485,6 +1528,20 @@ class Processor(hadoop.api.common.HadoopServiceBase.Processor, Iface, TProcessor
     oprot.writeMessageEnd()
     oprot.trans.flush()
 
+  def process_getDelegationToken(self, seqid, iprot, oprot):
+    args = getDelegationToken_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = getDelegationToken_result()
+    try:
+      result.success = self._handler.getDelegationToken(args.ctx, args.renewer)
+    except hadoop.api.common.ttypes.IOException, err:
+      result.err = err
+    oprot.writeMessageBegin("getDelegationToken", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
 
 # HELPER FUNCTIONS AND STRUCTURES
 
@@ -4666,4 +4723,150 @@ class datanodeDown_result(object):
   def __ne__(self, other):
     return not (self == other)
 
+class getDelegationToken_args(object):
+  """
+  Attributes:
+   - ctx
+   - renewer
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'renewer', None, None, ), # 1
+    None, # 2
+    None, # 3
+    None, # 4
+    None, # 5
+    None, # 6
+    None, # 7
+    None, # 8
+    None, # 9
+    (10, TType.STRUCT, 'ctx', (hadoop.api.common.ttypes.RequestContext, hadoop.api.common.ttypes.RequestContext.thrift_spec), None, ), # 10
+  )
+
+  def __init__(self, ctx=None, renewer=None,):
+    self.ctx = ctx
+    self.renewer = renewer
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 10:
+        if ftype == TType.STRUCT:
+          self.ctx = hadoop.api.common.ttypes.RequestContext()
+          self.ctx.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRING:
+          self.renewer = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('getDelegationToken_args')
+    if self.renewer != None:
+      oprot.writeFieldBegin('renewer', TType.STRING, 1)
+      oprot.writeString(self.renewer)
+      oprot.writeFieldEnd()
+    if self.ctx != None:
+      oprot.writeFieldBegin('ctx', TType.STRUCT, 10)
+      self.ctx.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class getDelegationToken_result(object):
+  """
+  Attributes:
+   - success
+   - err
+  """
+
+  thrift_spec = (
+    (0, TType.STRUCT, 'success', (ThriftHdfsDelegationToken, ThriftHdfsDelegationToken.thrift_spec), None, ), # 0
+    (1, TType.STRUCT, 'err', (hadoop.api.common.ttypes.IOException, hadoop.api.common.ttypes.IOException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, err=None,):
+    self.success = success
+    self.err = err
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRUCT:
+          self.success = ThriftHdfsDelegationToken()
+          self.success.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.err = hadoop.api.common.ttypes.IOException()
+          self.err.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('getDelegationToken_result')
+    if self.success != None:
+      oprot.writeFieldBegin('success', TType.STRUCT, 0)
+      self.success.write(oprot)
+      oprot.writeFieldEnd()
+    if self.err != None:
+      oprot.writeFieldBegin('err', TType.STRUCT, 1)
+      self.err.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
 

+ 56 - 0
desktop/libs/hadoop/gen-py/hadoop/api/hdfs/ttypes.py

@@ -903,6 +903,62 @@ class DFSHealthReport(object):
   def __ne__(self, other):
     return not (self == other)
 
+class ThriftHdfsDelegationToken(object):
+  """
+  Attributes:
+   - delegationTokenBytes
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'delegationTokenBytes', None, None, ), # 1
+  )
+
+  def __init__(self, delegationTokenBytes=None,):
+    self.delegationTokenBytes = delegationTokenBytes
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.delegationTokenBytes = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftHdfsDelegationToken')
+    if self.delegationTokenBytes != None:
+      oprot.writeFieldBegin('delegationTokenBytes', TType.STRING, 1)
+      oprot.writeString(self.delegationTokenBytes)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
 class QuotaException(Exception):
   """
   Quota-related error

+ 776 - 0
desktop/libs/hadoop/java/gen-java/org/apache/hadoop/thriftfs/api/Namenode.java

@@ -283,6 +283,8 @@ public class Namenode {
      */
     public void datanodeDown(String name, String storage, int thriftPort) throws TException;
 
+    public ThriftHdfsDelegationToken getDelegationToken(org.apache.hadoop.thriftfs.api.RequestContext ctx, String renewer) throws org.apache.hadoop.thriftfs.api.IOException, TException;
+
   }
 
   public static class Client extends org.apache.hadoop.thriftfs.api.HadoopServiceBase.Client implements Iface {
@@ -1081,6 +1083,43 @@ public class Namenode {
       return;
     }
 
+    public ThriftHdfsDelegationToken getDelegationToken(org.apache.hadoop.thriftfs.api.RequestContext ctx, String renewer) throws org.apache.hadoop.thriftfs.api.IOException, TException
+    {
+      send_getDelegationToken(ctx, renewer);
+      return recv_getDelegationToken();
+    }
+
+    public void send_getDelegationToken(org.apache.hadoop.thriftfs.api.RequestContext ctx, String renewer) throws TException
+    {
+      oprot_.writeMessageBegin(new TMessage("getDelegationToken", TMessageType.CALL, seqid_));
+      getDelegationToken_args args = new getDelegationToken_args();
+      args.ctx = ctx;
+      args.renewer = renewer;
+      args.write(oprot_);
+      oprot_.writeMessageEnd();
+      oprot_.getTransport().flush();
+    }
+
+    public ThriftHdfsDelegationToken recv_getDelegationToken() throws org.apache.hadoop.thriftfs.api.IOException, TException
+    {
+      TMessage msg = iprot_.readMessageBegin();
+      if (msg.type == TMessageType.EXCEPTION) {
+        TApplicationException x = TApplicationException.read(iprot_);
+        iprot_.readMessageEnd();
+        throw x;
+      }
+      getDelegationToken_result result = new getDelegationToken_result();
+      result.read(iprot_);
+      iprot_.readMessageEnd();
+      if (result.isSetSuccess()) {
+        return result.success;
+      }
+      if (result.err != null) {
+        throw result.err;
+      }
+      throw new TApplicationException(TApplicationException.MISSING_RESULT, "getDelegationToken failed: unknown result");
+    }
+
   }
   public static class Processor extends org.apache.hadoop.thriftfs.api.HadoopServiceBase.Processor implements TProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName());
@@ -1110,6 +1149,7 @@ public class Namenode {
       processMap_.put("utime", new utime());
       processMap_.put("datanodeUp", new datanodeUp());
       processMap_.put("datanodeDown", new datanodeDown());
+      processMap_.put("getDelegationToken", new getDelegationToken());
     }
 
     private Iface iface_;
@@ -1718,6 +1758,34 @@ public class Namenode {
 
     }
 
+    private class getDelegationToken implements ProcessFunction {
+      public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException
+      {
+        getDelegationToken_args args = new getDelegationToken_args();
+        args.read(iprot);
+        iprot.readMessageEnd();
+        getDelegationToken_result result = new getDelegationToken_result();
+        try {
+          result.success = iface_.getDelegationToken(args.ctx, args.renewer);
+        } catch (org.apache.hadoop.thriftfs.api.IOException err) {
+          result.err = err;
+        } catch (Throwable th) {
+          LOGGER.error("Internal error processing getDelegationToken", th);
+          TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing getDelegationToken");
+          oprot.writeMessageBegin(new TMessage("getDelegationToken", TMessageType.EXCEPTION, seqid));
+          x.write(oprot);
+          oprot.writeMessageEnd();
+          oprot.getTransport().flush();
+          return;
+        }
+        oprot.writeMessageBegin(new TMessage("getDelegationToken", TMessageType.REPLY, seqid));
+        result.write(oprot);
+        oprot.writeMessageEnd();
+        oprot.getTransport().flush();
+      }
+
+    }
+
   }
 
   public static class chmod_args implements TBase<chmod_args._Fields>, java.io.Serializable, Cloneable   {
@@ -17571,4 +17639,712 @@ public class Namenode {
 
   }
 
+  public static class getDelegationToken_args implements TBase<getDelegationToken_args._Fields>, java.io.Serializable, Cloneable   {
+    private static final TStruct STRUCT_DESC = new TStruct("getDelegationToken_args");
+
+    private static final TField CTX_FIELD_DESC = new TField("ctx", TType.STRUCT, (short)10);
+    private static final TField RENEWER_FIELD_DESC = new TField("renewer", TType.STRING, (short)1);
+
+    public org.apache.hadoop.thriftfs.api.RequestContext ctx;
+    public String renewer;
+
+    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+    public enum _Fields implements TFieldIdEnum {
+      CTX((short)10, "ctx"),
+      RENEWER((short)1, "renewer");
+
+      private static final Map<Integer, _Fields> byId = new HashMap<Integer, _Fields>();
+      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+      static {
+        for (_Fields field : EnumSet.allOf(_Fields.class)) {
+          byId.put((int)field._thriftId, field);
+          byName.put(field.getFieldName(), field);
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, or null if its not found.
+       */
+      public static _Fields findByThriftId(int fieldId) {
+        return byId.get(fieldId);
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, throwing an exception
+       * if it is not found.
+       */
+      public static _Fields findByThriftIdOrThrow(int fieldId) {
+        _Fields fields = findByThriftId(fieldId);
+        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+        return fields;
+      }
+
+      /**
+       * Find the _Fields constant that matches name, or null if its not found.
+       */
+      public static _Fields findByName(String name) {
+        return byName.get(name);
+      }
+
+      private final short _thriftId;
+      private final String _fieldName;
+
+      _Fields(short thriftId, String fieldName) {
+        _thriftId = thriftId;
+        _fieldName = fieldName;
+      }
+
+      public short getThriftFieldId() {
+        return _thriftId;
+      }
+
+      public String getFieldName() {
+        return _fieldName;
+      }
+    }
+
+    // isset id assignments
+
+    public static final Map<_Fields, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new EnumMap<_Fields, FieldMetaData>(_Fields.class) {{
+      put(_Fields.CTX, new FieldMetaData("ctx", TFieldRequirementType.DEFAULT, 
+          new StructMetaData(TType.STRUCT, org.apache.hadoop.thriftfs.api.RequestContext.class)));
+      put(_Fields.RENEWER, new FieldMetaData("renewer", TFieldRequirementType.DEFAULT, 
+          new FieldValueMetaData(TType.STRING)));
+    }});
+
+    static {
+      FieldMetaData.addStructMetaDataMap(getDelegationToken_args.class, metaDataMap);
+    }
+
+    public getDelegationToken_args() {
+    }
+
+    public getDelegationToken_args(
+      org.apache.hadoop.thriftfs.api.RequestContext ctx,
+      String renewer)
+    {
+      this();
+      this.ctx = ctx;
+      this.renewer = renewer;
+    }
+
+    /**
+     * Performs a deep copy on <i>other</i>.
+     */
+    public getDelegationToken_args(getDelegationToken_args other) {
+      if (other.isSetCtx()) {
+        this.ctx = new org.apache.hadoop.thriftfs.api.RequestContext(other.ctx);
+      }
+      if (other.isSetRenewer()) {
+        this.renewer = other.renewer;
+      }
+    }
+
+    public getDelegationToken_args deepCopy() {
+      return new getDelegationToken_args(this);
+    }
+
+    @Deprecated
+    public getDelegationToken_args clone() {
+      return new getDelegationToken_args(this);
+    }
+
+    public org.apache.hadoop.thriftfs.api.RequestContext getCtx() {
+      return this.ctx;
+    }
+
+    public getDelegationToken_args setCtx(org.apache.hadoop.thriftfs.api.RequestContext ctx) {
+      this.ctx = ctx;
+      return this;
+    }
+
+    public void unsetCtx() {
+      this.ctx = null;
+    }
+
+    /** Returns true if field ctx is set (has been asigned a value) and false otherwise */
+    public boolean isSetCtx() {
+      return this.ctx != null;
+    }
+
+    public void setCtxIsSet(boolean value) {
+      if (!value) {
+        this.ctx = null;
+      }
+    }
+
+    public String getRenewer() {
+      return this.renewer;
+    }
+
+    public getDelegationToken_args setRenewer(String renewer) {
+      this.renewer = renewer;
+      return this;
+    }
+
+    public void unsetRenewer() {
+      this.renewer = null;
+    }
+
+    /** Returns true if field renewer is set (has been asigned a value) and false otherwise */
+    public boolean isSetRenewer() {
+      return this.renewer != null;
+    }
+
+    public void setRenewerIsSet(boolean value) {
+      if (!value) {
+        this.renewer = null;
+      }
+    }
+
+    public void setFieldValue(_Fields field, Object value) {
+      switch (field) {
+      case CTX:
+        if (value == null) {
+          unsetCtx();
+        } else {
+          setCtx((org.apache.hadoop.thriftfs.api.RequestContext)value);
+        }
+        break;
+
+      case RENEWER:
+        if (value == null) {
+          unsetRenewer();
+        } else {
+          setRenewer((String)value);
+        }
+        break;
+
+      }
+    }
+
+    public void setFieldValue(int fieldID, Object value) {
+      setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
+    }
+
+    public Object getFieldValue(_Fields field) {
+      switch (field) {
+      case CTX:
+        return getCtx();
+
+      case RENEWER:
+        return getRenewer();
+
+      }
+      throw new IllegalStateException();
+    }
+
+    public Object getFieldValue(int fieldId) {
+      return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
+    }
+
+    /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */
+    public boolean isSet(_Fields field) {
+      switch (field) {
+      case CTX:
+        return isSetCtx();
+      case RENEWER:
+        return isSetRenewer();
+      }
+      throw new IllegalStateException();
+    }
+
+    public boolean isSet(int fieldID) {
+      return isSet(_Fields.findByThriftIdOrThrow(fieldID));
+    }
+
+    @Override
+    public boolean equals(Object that) {
+      if (that == null)
+        return false;
+      if (that instanceof getDelegationToken_args)
+        return this.equals((getDelegationToken_args)that);
+      return false;
+    }
+
+    public boolean equals(getDelegationToken_args that) {
+      if (that == null)
+        return false;
+
+      boolean this_present_ctx = true && this.isSetCtx();
+      boolean that_present_ctx = true && that.isSetCtx();
+      if (this_present_ctx || that_present_ctx) {
+        if (!(this_present_ctx && that_present_ctx))
+          return false;
+        if (!this.ctx.equals(that.ctx))
+          return false;
+      }
+
+      boolean this_present_renewer = true && this.isSetRenewer();
+      boolean that_present_renewer = true && that.isSetRenewer();
+      if (this_present_renewer || that_present_renewer) {
+        if (!(this_present_renewer && that_present_renewer))
+          return false;
+        if (!this.renewer.equals(that.renewer))
+          return false;
+      }
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return 0;
+    }
+
+    public void read(TProtocol iprot) throws TException {
+      TField field;
+      iprot.readStructBegin();
+      while (true)
+      {
+        field = iprot.readFieldBegin();
+        if (field.type == TType.STOP) { 
+          break;
+        }
+        _Fields fieldId = _Fields.findByThriftId(field.id);
+        if (fieldId == null) {
+          TProtocolUtil.skip(iprot, field.type);
+        } else {
+          switch (fieldId) {
+            case CTX:
+              if (field.type == TType.STRUCT) {
+                this.ctx = new org.apache.hadoop.thriftfs.api.RequestContext();
+                this.ctx.read(iprot);
+              } else { 
+                TProtocolUtil.skip(iprot, field.type);
+              }
+              break;
+            case RENEWER:
+              if (field.type == TType.STRING) {
+                this.renewer = iprot.readString();
+              } else { 
+                TProtocolUtil.skip(iprot, field.type);
+              }
+              break;
+          }
+          iprot.readFieldEnd();
+        }
+      }
+      iprot.readStructEnd();
+
+      // check for required fields of primitive type, which can't be checked in the validate method
+      validate();
+    }
+
+    public void write(TProtocol oprot) throws TException {
+      validate();
+
+      oprot.writeStructBegin(STRUCT_DESC);
+      if (this.renewer != null) {
+        oprot.writeFieldBegin(RENEWER_FIELD_DESC);
+        oprot.writeString(this.renewer);
+        oprot.writeFieldEnd();
+      }
+      if (this.ctx != null) {
+        oprot.writeFieldBegin(CTX_FIELD_DESC);
+        this.ctx.write(oprot);
+        oprot.writeFieldEnd();
+      }
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+
+    @Override
+    public String toString() {
+      StringBuilder sb = new StringBuilder("getDelegationToken_args(");
+      boolean first = true;
+
+      sb.append("ctx:");
+      if (this.ctx == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.ctx);
+      }
+      first = false;
+      if (!first) sb.append(", ");
+      sb.append("renewer:");
+      if (this.renewer == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.renewer);
+      }
+      first = false;
+      sb.append(")");
+      return sb.toString();
+    }
+
+    public void validate() throws TException {
+      // check for required fields
+    }
+
+  }
+
+  public static class getDelegationToken_result implements TBase<getDelegationToken_result._Fields>, java.io.Serializable, Cloneable, Comparable<getDelegationToken_result>   {
+    private static final TStruct STRUCT_DESC = new TStruct("getDelegationToken_result");
+
+    private static final TField SUCCESS_FIELD_DESC = new TField("success", TType.STRUCT, (short)0);
+    private static final TField ERR_FIELD_DESC = new TField("err", TType.STRUCT, (short)1);
+
+    public ThriftHdfsDelegationToken success;
+    public org.apache.hadoop.thriftfs.api.IOException err;
+
+    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+    public enum _Fields implements TFieldIdEnum {
+      SUCCESS((short)0, "success"),
+      ERR((short)1, "err");
+
+      private static final Map<Integer, _Fields> byId = new HashMap<Integer, _Fields>();
+      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+      static {
+        for (_Fields field : EnumSet.allOf(_Fields.class)) {
+          byId.put((int)field._thriftId, field);
+          byName.put(field.getFieldName(), field);
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, or null if its not found.
+       */
+      public static _Fields findByThriftId(int fieldId) {
+        return byId.get(fieldId);
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, throwing an exception
+       * if it is not found.
+       */
+      public static _Fields findByThriftIdOrThrow(int fieldId) {
+        _Fields fields = findByThriftId(fieldId);
+        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+        return fields;
+      }
+
+      /**
+       * Find the _Fields constant that matches name, or null if its not found.
+       */
+      public static _Fields findByName(String name) {
+        return byName.get(name);
+      }
+
+      private final short _thriftId;
+      private final String _fieldName;
+
+      _Fields(short thriftId, String fieldName) {
+        _thriftId = thriftId;
+        _fieldName = fieldName;
+      }
+
+      public short getThriftFieldId() {
+        return _thriftId;
+      }
+
+      public String getFieldName() {
+        return _fieldName;
+      }
+    }
+
+    // isset id assignments
+
+    public static final Map<_Fields, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new EnumMap<_Fields, FieldMetaData>(_Fields.class) {{
+      put(_Fields.SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, 
+          new StructMetaData(TType.STRUCT, ThriftHdfsDelegationToken.class)));
+      put(_Fields.ERR, new FieldMetaData("err", TFieldRequirementType.DEFAULT, 
+          new FieldValueMetaData(TType.STRUCT)));
+    }});
+
+    static {
+      FieldMetaData.addStructMetaDataMap(getDelegationToken_result.class, metaDataMap);
+    }
+
+    public getDelegationToken_result() {
+    }
+
+    public getDelegationToken_result(
+      ThriftHdfsDelegationToken success,
+      org.apache.hadoop.thriftfs.api.IOException err)
+    {
+      this();
+      this.success = success;
+      this.err = err;
+    }
+
+    /**
+     * Performs a deep copy on <i>other</i>.
+     */
+    public getDelegationToken_result(getDelegationToken_result other) {
+      if (other.isSetSuccess()) {
+        this.success = new ThriftHdfsDelegationToken(other.success);
+      }
+      if (other.isSetErr()) {
+        this.err = new org.apache.hadoop.thriftfs.api.IOException(other.err);
+      }
+    }
+
+    public getDelegationToken_result deepCopy() {
+      return new getDelegationToken_result(this);
+    }
+
+    @Deprecated
+    public getDelegationToken_result clone() {
+      return new getDelegationToken_result(this);
+    }
+
+    public ThriftHdfsDelegationToken getSuccess() {
+      return this.success;
+    }
+
+    public getDelegationToken_result setSuccess(ThriftHdfsDelegationToken success) {
+      this.success = success;
+      return this;
+    }
+
+    public void unsetSuccess() {
+      this.success = null;
+    }
+
+    /** Returns true if field success is set (has been asigned a value) and false otherwise */
+    public boolean isSetSuccess() {
+      return this.success != null;
+    }
+
+    public void setSuccessIsSet(boolean value) {
+      if (!value) {
+        this.success = null;
+      }
+    }
+
+    public org.apache.hadoop.thriftfs.api.IOException getErr() {
+      return this.err;
+    }
+
+    public getDelegationToken_result setErr(org.apache.hadoop.thriftfs.api.IOException err) {
+      this.err = err;
+      return this;
+    }
+
+    public void unsetErr() {
+      this.err = null;
+    }
+
+    /** Returns true if field err is set (has been asigned a value) and false otherwise */
+    public boolean isSetErr() {
+      return this.err != null;
+    }
+
+    public void setErrIsSet(boolean value) {
+      if (!value) {
+        this.err = null;
+      }
+    }
+
+    public void setFieldValue(_Fields field, Object value) {
+      switch (field) {
+      case SUCCESS:
+        if (value == null) {
+          unsetSuccess();
+        } else {
+          setSuccess((ThriftHdfsDelegationToken)value);
+        }
+        break;
+
+      case ERR:
+        if (value == null) {
+          unsetErr();
+        } else {
+          setErr((org.apache.hadoop.thriftfs.api.IOException)value);
+        }
+        break;
+
+      }
+    }
+
+    public void setFieldValue(int fieldID, Object value) {
+      setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
+    }
+
+    public Object getFieldValue(_Fields field) {
+      switch (field) {
+      case SUCCESS:
+        return getSuccess();
+
+      case ERR:
+        return getErr();
+
+      }
+      throw new IllegalStateException();
+    }
+
+    public Object getFieldValue(int fieldId) {
+      return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
+    }
+
+    /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */
+    public boolean isSet(_Fields field) {
+      switch (field) {
+      case SUCCESS:
+        return isSetSuccess();
+      case ERR:
+        return isSetErr();
+      }
+      throw new IllegalStateException();
+    }
+
+    public boolean isSet(int fieldID) {
+      return isSet(_Fields.findByThriftIdOrThrow(fieldID));
+    }
+
+    @Override
+    public boolean equals(Object that) {
+      if (that == null)
+        return false;
+      if (that instanceof getDelegationToken_result)
+        return this.equals((getDelegationToken_result)that);
+      return false;
+    }
+
+    public boolean equals(getDelegationToken_result that) {
+      if (that == null)
+        return false;
+
+      boolean this_present_success = true && this.isSetSuccess();
+      boolean that_present_success = true && that.isSetSuccess();
+      if (this_present_success || that_present_success) {
+        if (!(this_present_success && that_present_success))
+          return false;
+        if (!this.success.equals(that.success))
+          return false;
+      }
+
+      boolean this_present_err = true && this.isSetErr();
+      boolean that_present_err = true && that.isSetErr();
+      if (this_present_err || that_present_err) {
+        if (!(this_present_err && that_present_err))
+          return false;
+        if (!this.err.equals(that.err))
+          return false;
+      }
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return 0;
+    }
+
+    public int compareTo(getDelegationToken_result other) {
+      if (!getClass().equals(other.getClass())) {
+        return getClass().getName().compareTo(other.getClass().getName());
+      }
+
+      int lastComparison = 0;
+      getDelegationToken_result typedOther = (getDelegationToken_result)other;
+
+      lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(isSetSuccess());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      lastComparison = TBaseHelper.compareTo(success, typedOther.success);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      lastComparison = Boolean.valueOf(isSetErr()).compareTo(isSetErr());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      lastComparison = TBaseHelper.compareTo(err, typedOther.err);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      return 0;
+    }
+
+    public void read(TProtocol iprot) throws TException {
+      TField field;
+      iprot.readStructBegin();
+      while (true)
+      {
+        field = iprot.readFieldBegin();
+        if (field.type == TType.STOP) { 
+          break;
+        }
+        _Fields fieldId = _Fields.findByThriftId(field.id);
+        if (fieldId == null) {
+          TProtocolUtil.skip(iprot, field.type);
+        } else {
+          switch (fieldId) {
+            case SUCCESS:
+              if (field.type == TType.STRUCT) {
+                this.success = new ThriftHdfsDelegationToken();
+                this.success.read(iprot);
+              } else { 
+                TProtocolUtil.skip(iprot, field.type);
+              }
+              break;
+            case ERR:
+              if (field.type == TType.STRUCT) {
+                this.err = new org.apache.hadoop.thriftfs.api.IOException();
+                this.err.read(iprot);
+              } else { 
+                TProtocolUtil.skip(iprot, field.type);
+              }
+              break;
+          }
+          iprot.readFieldEnd();
+        }
+      }
+      iprot.readStructEnd();
+
+      // check for required fields of primitive type, which can't be checked in the validate method
+      validate();
+    }
+
+    public void write(TProtocol oprot) throws TException {
+      oprot.writeStructBegin(STRUCT_DESC);
+
+      if (this.isSetSuccess()) {
+        oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
+        this.success.write(oprot);
+        oprot.writeFieldEnd();
+      } else if (this.isSetErr()) {
+        oprot.writeFieldBegin(ERR_FIELD_DESC);
+        this.err.write(oprot);
+        oprot.writeFieldEnd();
+      }
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+
+    @Override
+    public String toString() {
+      StringBuilder sb = new StringBuilder("getDelegationToken_result(");
+      boolean first = true;
+
+      sb.append("success:");
+      if (this.success == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.success);
+      }
+      first = false;
+      if (!first) sb.append(", ");
+      sb.append("err:");
+      if (this.err == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.err);
+      }
+      first = false;
+      sb.append(")");
+      return sb.toString();
+    }
+
+    public void validate() throws TException {
+      // check for required fields
+    }
+
+  }
+
 }

+ 314 - 0
desktop/libs/hadoop/java/gen-java/org/apache/hadoop/thriftfs/api/ThriftHdfsDelegationToken.java

@@ -0,0 +1,314 @@
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package org.apache.hadoop.thriftfs.api;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.EnumMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.EnumSet;
+import java.util.Collections;
+import java.util.BitSet;
+import java.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.thrift.*;
+import org.apache.thrift.meta_data.*;
+import org.apache.thrift.protocol.*;
+
+public class ThriftHdfsDelegationToken implements TBase<ThriftHdfsDelegationToken._Fields>, java.io.Serializable, Cloneable, Comparable<ThriftHdfsDelegationToken> {
+  private static final TStruct STRUCT_DESC = new TStruct("ThriftHdfsDelegationToken");
+
+  private static final TField DELEGATION_TOKEN_BYTES_FIELD_DESC = new TField("delegationTokenBytes", TType.STRING, (short)1);
+
+  public byte[] delegationTokenBytes;
+
+  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+  public enum _Fields implements TFieldIdEnum {
+    DELEGATION_TOKEN_BYTES((short)1, "delegationTokenBytes");
+
+    private static final Map<Integer, _Fields> byId = new HashMap<Integer, _Fields>();
+    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+    static {
+      for (_Fields field : EnumSet.allOf(_Fields.class)) {
+        byId.put((int)field._thriftId, field);
+        byName.put(field.getFieldName(), field);
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, or null if its not found.
+     */
+    public static _Fields findByThriftId(int fieldId) {
+      return byId.get(fieldId);
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, throwing an exception
+     * if it is not found.
+     */
+    public static _Fields findByThriftIdOrThrow(int fieldId) {
+      _Fields fields = findByThriftId(fieldId);
+      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+      return fields;
+    }
+
+    /**
+     * Find the _Fields constant that matches name, or null if its not found.
+     */
+    public static _Fields findByName(String name) {
+      return byName.get(name);
+    }
+
+    private final short _thriftId;
+    private final String _fieldName;
+
+    _Fields(short thriftId, String fieldName) {
+      _thriftId = thriftId;
+      _fieldName = fieldName;
+    }
+
+    public short getThriftFieldId() {
+      return _thriftId;
+    }
+
+    public String getFieldName() {
+      return _fieldName;
+    }
+  }
+
+  // isset id assignments
+
+  public static final Map<_Fields, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new EnumMap<_Fields, FieldMetaData>(_Fields.class) {{
+    put(_Fields.DELEGATION_TOKEN_BYTES, new FieldMetaData("delegationTokenBytes", TFieldRequirementType.DEFAULT, 
+        new FieldValueMetaData(TType.STRING)));
+  }});
+
+  static {
+    FieldMetaData.addStructMetaDataMap(ThriftHdfsDelegationToken.class, metaDataMap);
+  }
+
+  public ThriftHdfsDelegationToken() {
+  }
+
+  public ThriftHdfsDelegationToken(
+    byte[] delegationTokenBytes)
+  {
+    this();
+    this.delegationTokenBytes = delegationTokenBytes;
+  }
+
+  /**
+   * Performs a deep copy on <i>other</i>.
+   */
+  public ThriftHdfsDelegationToken(ThriftHdfsDelegationToken other) {
+    if (other.isSetDelegationTokenBytes()) {
+      this.delegationTokenBytes = new byte[other.delegationTokenBytes.length];
+      System.arraycopy(other.delegationTokenBytes, 0, delegationTokenBytes, 0, other.delegationTokenBytes.length);
+    }
+  }
+
+  public ThriftHdfsDelegationToken deepCopy() {
+    return new ThriftHdfsDelegationToken(this);
+  }
+
+  @Deprecated
+  public ThriftHdfsDelegationToken clone() {
+    return new ThriftHdfsDelegationToken(this);
+  }
+
+  public byte[] getDelegationTokenBytes() {
+    return this.delegationTokenBytes;
+  }
+
+  public ThriftHdfsDelegationToken setDelegationTokenBytes(byte[] delegationTokenBytes) {
+    this.delegationTokenBytes = delegationTokenBytes;
+    return this;
+  }
+
+  public void unsetDelegationTokenBytes() {
+    this.delegationTokenBytes = null;
+  }
+
+  /** Returns true if field delegationTokenBytes is set (has been asigned a value) and false otherwise */
+  public boolean isSetDelegationTokenBytes() {
+    return this.delegationTokenBytes != null;
+  }
+
+  public void setDelegationTokenBytesIsSet(boolean value) {
+    if (!value) {
+      this.delegationTokenBytes = null;
+    }
+  }
+
+  public void setFieldValue(_Fields field, Object value) {
+    switch (field) {
+    case DELEGATION_TOKEN_BYTES:
+      if (value == null) {
+        unsetDelegationTokenBytes();
+      } else {
+        setDelegationTokenBytes((byte[])value);
+      }
+      break;
+
+    }
+  }
+
+  public void setFieldValue(int fieldID, Object value) {
+    setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
+  }
+
+  public Object getFieldValue(_Fields field) {
+    switch (field) {
+    case DELEGATION_TOKEN_BYTES:
+      return getDelegationTokenBytes();
+
+    }
+    throw new IllegalStateException();
+  }
+
+  public Object getFieldValue(int fieldId) {
+    return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
+  }
+
+  /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */
+  public boolean isSet(_Fields field) {
+    switch (field) {
+    case DELEGATION_TOKEN_BYTES:
+      return isSetDelegationTokenBytes();
+    }
+    throw new IllegalStateException();
+  }
+
+  public boolean isSet(int fieldID) {
+    return isSet(_Fields.findByThriftIdOrThrow(fieldID));
+  }
+
+  @Override
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof ThriftHdfsDelegationToken)
+      return this.equals((ThriftHdfsDelegationToken)that);
+    return false;
+  }
+
+  public boolean equals(ThriftHdfsDelegationToken that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_delegationTokenBytes = true && this.isSetDelegationTokenBytes();
+    boolean that_present_delegationTokenBytes = true && that.isSetDelegationTokenBytes();
+    if (this_present_delegationTokenBytes || that_present_delegationTokenBytes) {
+      if (!(this_present_delegationTokenBytes && that_present_delegationTokenBytes))
+        return false;
+      if (!java.util.Arrays.equals(this.delegationTokenBytes, that.delegationTokenBytes))
+        return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return 0;
+  }
+
+  public int compareTo(ThriftHdfsDelegationToken other) {
+    if (!getClass().equals(other.getClass())) {
+      return getClass().getName().compareTo(other.getClass().getName());
+    }
+
+    int lastComparison = 0;
+    ThriftHdfsDelegationToken typedOther = (ThriftHdfsDelegationToken)other;
+
+    lastComparison = Boolean.valueOf(isSetDelegationTokenBytes()).compareTo(isSetDelegationTokenBytes());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    lastComparison = TBaseHelper.compareTo(delegationTokenBytes, typedOther.delegationTokenBytes);
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    return 0;
+  }
+
+  public void read(TProtocol iprot) throws TException {
+    TField field;
+    iprot.readStructBegin();
+    while (true)
+    {
+      field = iprot.readFieldBegin();
+      if (field.type == TType.STOP) { 
+        break;
+      }
+      _Fields fieldId = _Fields.findByThriftId(field.id);
+      if (fieldId == null) {
+        TProtocolUtil.skip(iprot, field.type);
+      } else {
+        switch (fieldId) {
+          case DELEGATION_TOKEN_BYTES:
+            if (field.type == TType.STRING) {
+              this.delegationTokenBytes = iprot.readBinary();
+            } else { 
+              TProtocolUtil.skip(iprot, field.type);
+            }
+            break;
+        }
+        iprot.readFieldEnd();
+      }
+    }
+    iprot.readStructEnd();
+
+    // check for required fields of primitive type, which can't be checked in the validate method
+    validate();
+  }
+
+  public void write(TProtocol oprot) throws TException {
+    validate();
+
+    oprot.writeStructBegin(STRUCT_DESC);
+    if (this.delegationTokenBytes != null) {
+      oprot.writeFieldBegin(DELEGATION_TOKEN_BYTES_FIELD_DESC);
+      oprot.writeBinary(this.delegationTokenBytes);
+      oprot.writeFieldEnd();
+    }
+    oprot.writeFieldStop();
+    oprot.writeStructEnd();
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("ThriftHdfsDelegationToken(");
+    boolean first = true;
+
+    sb.append("delegationTokenBytes:");
+    if (this.delegationTokenBytes == null) {
+      sb.append("null");
+    } else {
+        int __delegationTokenBytes_size = Math.min(this.delegationTokenBytes.length, 128);
+        for (int i = 0; i < __delegationTokenBytes_size; i++) {
+          if (i != 0) sb.append(" ");
+          sb.append(Integer.toHexString(this.delegationTokenBytes[i]).length() > 1 ? Integer.toHexString(this.delegationTokenBytes[i]).substring(Integer.toHexString(this.delegationTokenBytes[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.delegationTokenBytes[i]).toUpperCase());
+        }
+        if (this.delegationTokenBytes.length > 128) sb.append(" ...");
+    }
+    first = false;
+    sb.append(")");
+    return sb.toString();
+  }
+
+  public void validate() throws TException {
+    // check for required fields
+  }
+
+}
+

+ 5 - 0
desktop/libs/hadoop/java/if/hdfs.thrift

@@ -236,6 +236,9 @@ struct DFSHealthReport {
   8: i32 httpPort
 }
 
+struct ThriftHdfsDelegationToken {
+  1: binary delegationTokenBytes
+}
 
 /** Quota-related error */
 exception QuotaException {
@@ -486,6 +489,8 @@ service Namenode extends common.HadoopServiceBase {
                     2:  string storage,
                     /** Thrift port of the datanode */
                     3:  i32 thriftPort),
+
+  ThriftHdfsDelegationToken getDelegationToken(10:common.RequestContext ctx, 1:string renewer) throws(1: common.IOException err)
 }
 
 /** Encapsulates a block data transfer with its CRC */

+ 32 - 0
desktop/libs/hadoop/java/src/java/org/apache/hadoop/thriftfs/NamenodePlugin.java

@@ -18,6 +18,7 @@
 package org.apache.hadoop.thriftfs;
 
 import java.io.FileNotFoundException;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
@@ -40,8 +41,14 @@ import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
 import org.apache.hadoop.hdfs.protocol.LocatedBlock;
 import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
 import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction;
+import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.apache.hadoop.io.Text;
 import org.apache.hadoop.net.NetUtils;
+import org.apache.hadoop.security.Credentials;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
 import org.apache.hadoop.thriftfs.api.Block;
 import org.apache.hadoop.thriftfs.api.Constants;
 import org.apache.hadoop.thriftfs.api.ContentSummary;
@@ -49,6 +56,7 @@ import org.apache.hadoop.thriftfs.api.IOException;
 import org.apache.hadoop.thriftfs.api.Namenode;
 import org.apache.hadoop.thriftfs.api.RequestContext;
 import org.apache.hadoop.thriftfs.api.Stat;
+import org.apache.hadoop.thriftfs.api.ThriftHdfsDelegationToken;
 import org.apache.thrift.TException;
 import org.apache.thrift.TProcessor;
 import org.apache.thrift.TProcessorFactory;
@@ -401,6 +409,30 @@ public class NamenodePlugin extends org.apache.hadoop.hdfs.server.namenode.Namen
       LOG.info("Datanode " + dnId + ": " + "Thrift port " + thriftPort + " open");
       thriftPorts.put(dnId, thriftPort);
     }
+
+    @Override
+    public ThriftHdfsDelegationToken getDelegationToken(RequestContext ctx, final String renewer) throws IOException,
+        TException {
+      return assumeUserContextAndExecute(ctx, new PrivilegedExceptionAction<ThriftHdfsDelegationToken>() {
+        public ThriftHdfsDelegationToken run() throws java.io.IOException {
+          UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
+          Token<DelegationTokenIdentifier> delegationToken = namenode.getDelegationToken(new Text(renewer));
+
+          InetSocketAddress address = namenode.getNameNodeAddress();
+          String nnAddress = InetAddress.getByName(address.getHostName()).getHostAddress() + ":" + address.getPort();
+          delegationToken.setService(new Text(nnAddress));
+
+          DataOutputBuffer out = new DataOutputBuffer();
+          Credentials ts = new Credentials();
+          ts.addToken(new Text(ugi.getShortUserName()), delegationToken);
+          ts.writeTokenStorageToStream(out);
+
+          byte[] tokenData = new byte[out.getLength()];
+          System.arraycopy(out.getData(), 0, tokenData, 0, tokenData.length);
+          return new ThriftHdfsDelegationToken(tokenData);
+        }
+      });
+    }
   }
 
   public NamenodePlugin() {

+ 2 - 1
desktop/libs/hadoop/src/hadoop/cluster.py

@@ -38,7 +38,8 @@ def _make_filesystem(identifier):
       cluster_conf.NN_HOST.get(),
       cluster_conf.NN_THRIFT_PORT.get(),
       cluster_conf.NN_HDFS_PORT.get(),
-      hadoop_bin_path=conf.HADOOP_BIN.get())
+      conf.HADOOP_BIN.get(),
+      cluster_conf.SECURITY_ENABLED.get())
     raise Exception("Unknown choice: %s" % choice)
 
 def _make_mrcluster(identifier):

+ 8 - 3
desktop/libs/hadoop/src/hadoop/conf.py

@@ -15,7 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 """Settings to configure your Hadoop cluster."""
-from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, validate_path
+from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, validate_path, coerce_bool
 import glob
 import os
 import logging
@@ -114,7 +114,8 @@ HDFS_CLUSTERS = UnspecifiedConfigSection(
       NN_THRIFT_PORT=Config("thrift_port", help="Thrift port for name node", default=9090,
                             type=int),
       NN_HDFS_PORT=Config("hdfs_port", help="Hadoop IPC port for the name node", default=8020,
-                            type=int)
+                            type=int),
+      SECURITY_ENABLED=Config('security_enabled', help='True if security is enabled for this HDFS cluster', type=coerce_bool, default=False)
     )
   )
 )
@@ -127,7 +128,11 @@ MR_CLUSTERS = UnspecifiedConfigSection(
     members=dict(
       JT_HOST=Config("jobtracker_host", help="IP for JobTracker"),
       JT_THRIFT_PORT=Config("thrift_port", help="Thrift port for JobTracker", default=9290,
-                            type=int))))
+                            type=int),
+      SECURITY_ENABLED=Config('security_enabled', help='True if security is enabled for this MR cluster', type=coerce_bool, default=False)
+    )
+  )
+)
 
 
 def config_validator():

+ 33 - 10
desktop/libs/hadoop/src/hadoop/fs/hadoopfs.py

@@ -27,6 +27,7 @@ import stat as statconsts
 import subprocess
 import sys
 import urlparse
+import tempfile
 import threading
 
 from thrift.transport import TTransport
@@ -176,7 +177,7 @@ class HadoopFileSystem(object):
   Implementation of Filesystem APIs through Thrift to a Hadoop cluster.
   """
 
-  def __init__(self, host, thrift_port, hdfs_port=8020, hadoop_bin_path="hadoop"):
+  def __init__(self, host, thrift_port, hdfs_port=8020, hadoop_bin_path="hadoop", security_enabled=False):
     """
     @param host hostname or IP of the namenode
     @param thrift_port port on which the Thrift plugin is listening
@@ -190,6 +191,7 @@ class HadoopFileSystem(object):
     self.hdfs_port = hdfs_port
     self.hadoop_bin_path = hadoop_bin_path
     self._resolve_hadoop_path()
+    self.security_enabled = security_enabled
 
     self.nn_client = thrift_util.get_client(Namenode.Client, host, thrift_port,
         service_name="HDFS Namenode HUE Plugin",
@@ -550,6 +552,12 @@ class HadoopFileSystem(object):
       ret["space_quota"] = summary.spaceQuota
     return ret
 
+  @_coerce_exceptions
+  def get_delegation_token(self):
+    # TODO(atm): The second argument here should really be the Hue kerberos
+    # principal, which doesn't exist yet. Todd's working on that.
+    return self.nn_client.getDelegationToken(self.request_context, '')
+
   def _connect_dn(self, node):
     sock = TSocket.TSocket(node.host, node.thriftPort)
     sock.setTimeout(int(DN_THRIFT_TIMEOUT * 1000))
@@ -759,11 +767,19 @@ class FileUpload(object):
                            "-Dfs.default.name=" + self.fs.uri] + \
                            extra_confs + \
                            ["-put", "-", encode_fs_path(path)]
-    env = i18n.make_utf8_env()
-    if env.has_key('HADOOP_CLASSPATH'):
-      env['HADOOP_CLASSPATH'] += ':' + hadoop.conf.HADOOP_STATIC_GROUP_MAPPING_CLASSPATH.get()
+    self.subprocess_env = i18n.make_utf8_env()
+
+    if self.fs.security_enabled:
+      token = self.fs.get_delegation_token()
+      self.token_file = tempfile.NamedTemporaryFile()
+      self.token_file.write(token.delegationTokenBytes)
+      self.token_file.flush()
+      self.subprocess_env['HADOOP_TOKEN_FILE_LOCATION'] = self.token_file.name
+
+    if self.subprocess_env.has_key('HADOOP_CLASSPATH'):
+      self.subprocess_env['HADOOP_CLASSPATH'] += ':' + hadoop.conf.HADOOP_STATIC_GROUP_MAPPING_CLASSPATH.get()
     else:
-      env['HADOOP_CLASSPATH'] = hadoop.conf.HADOOP_STATIC_GROUP_MAPPING_CLASSPATH.get()
+      self.subprocess_env['HADOOP_CLASSPATH'] = hadoop.conf.HADOOP_STATIC_GROUP_MAPPING_CLASSPATH.get()
 
     self.path = path
     self.putter = subprocess.Popen(self.subprocess_cmd,
@@ -771,7 +787,7 @@ class FileUpload(object):
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    close_fds=True,
-                                   env=env,
+                                   env=self.subprocess_env,
                                    bufsize=WRITE_BUFFER_SIZE)
   @require_open
   def write(self, data):
@@ -785,13 +801,20 @@ class FileUpload(object):
       logging.debug("Saw IOError writing %r" % self.path, exc_info=1)
       if ioe.errno == errno.EPIPE:
         stdout, stderr = self.putter.communicate()
+
+    if self.fs.security_enabled and self.token_file:
+      try:
+        self.token_file.close()
+      except:
+        LOG.warn('Failed to close HDFS delegation token file %s' % (self.token_file.name(),))
+
     self.closed = True
     if stderr:
-      LOG.warn("HDFS FileUpload (cmd='%s')outputted stderr:\n%s" %
-                   (repr(self.subprocess_cmd), stderr))
+      LOG.warn("HDFS FileUpload (cmd='%s', env='%s') outputted stderr:\n%s" %
+                   (repr(self.subprocess_cmd), repr(self.subprocess_env), stderr))
     if stdout:
-      LOG.info("HDFS FileUpload (cmd='%s')outputted stdout:\n%s" %
-                   (repr(self.subprocess_cmd), stdout))
+      LOG.info("HDFS FileUpload (cmd='%s', env='%s') outputted stdout:\n%s" %
+                   (repr(self.subprocess_cmd), repr(self.subprocess_env), stdout))
     if self.putter.returncode != 0:
       raise IOError("hdfs put returned bad code: %d\nstderr: %s" %
                     (self.putter.returncode, stderr))