Hi Nick,
if you are using secure HDFS cluster:
you can try getting the FileSystem instance by using following code
template:


*Configuration conf = new HdfsConfiguration();**
**
UserGroupInformation ugi = UserGroupInformation
          .loginUserFromKeytabAndReturnUGI(<USERNAME>, <PATH OF THE KEYTAB
FILE>);
      FileSystem fs = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() {
        @Override
        public FileSystem run() throws Exception {
          return FileSystem.get(conf);**
        }
      });*


- Thanks
  Jaimin

~

On Wed, May 16, 2012 at 11:59 AM, IGZ Nick <igznic...@gmail.com> wrote:

> I am trying to access some file in a secure HDFS cluster through java like
> this:
>
> private static Configuration conf = new Configuration();
> FileSystem fs = FileSystem.get(conf);
>
> However, this fails on the FileSystem.get() line with this exception:
>
> May 16, 2012 11:33:31 AM org.apache.hadoop.security.UserGroupInformation
> doAs
> SEVERE: PriviledgedActionException as:griduser
> cause:javax.security.sasl.SaslException: GSS initiate failed [Caused by
> GSSException: No valid credentials provided (Mechanism level: Failed to
> find any Kerberos tgt)]
> May 16, 2012 11:33:31 AM org.apache.hadoop.ipc.Client$Connection$1 run
> WARNING: Exception encountered while connecting to the server :
> javax.security.sasl.SaslException: GSS initiate failed [Caused by
> GSSException: No valid credentials provided (Mechanism level: Failed to
> find any Kerberos tgt)]
> May 16, 2012 11:33:31 AM org.apache.hadoop.security.UserGroupInformation
> doAs
> SEVERE: PriviledgedActionException as:griduser cause:java.io.IOException:
> javax.security.sasl.SaslException: GSS initiate failed [Caused by
> GSSException: No valid credentials provided (Mechanism level: Failed to
> find any Kerberos tgt)]
>
> I am running it like
> java -cp <jars> <classname>
>
> I am able to access the files using the normal command line as the same
> user. e.g,
> hadoop dfs -get <file> <dest> works perfectly.
>
> I think this is because I have added this line to the hadoop executable:
> kinit -k -t <keytab file> <username>
>
> But how can I do this from the java code?
>
> Thanks in advance for your help,
>

Reply via email to