squall
squall

Reputation: 61

how to create symbolic link for file saved on hadoop 2.5 version

I am a freshmen about HDFS,my question is how to create symbolic link for file saved on hadoop 2.5 version.I used java API to access hdfs to create symbolic link(symlink) and an exception as follow:

Exception in thread "main" java.lang.UnsupportedOperationException: Symlinks not supported at org.apache.hadoop.hdfs.DistributedFileSystem.createSymlink(DistributedFileSystem.java:1328)

My java code as follow:

1st, add some content in hdfs-site.xml.

<property>
    <name>test.SymlinkEnabledForTesting</name>
    <value>true</value>
</property>   

2nd, call java API.

Configuration conf = new Configuration();
conf.set("mapred.create.symlink", "yes");
conf.set("fs.defaultFS", HdfsServer);
URI uri = URI.create(HdfsServer);
String target = "/tmp/target.csv";
Path targetPath = new Path(target);
String uriWithLink = "/tmp/link.csv";
Path linkPath= new Path(uriWithLink );
FileContext fc = FileContext.getFileContext(uri,conf);
fc.createSymlink(targetPath, linkPath, true);

Is there someone could give me some suggestion?

Upvotes: 2

Views: 2827

Answers (1)

charan tej
charan tej

Reputation: 1054

java.lang.UnsupportedOperationException: Symlinks not supported

The Above exception may occur due to not enabling the symlink even you gave in hdfs-site.xml. Refer this link for more understanding link for Reason to Exception

So before FileContext, enable the symlink first.

something like this

FileSystem.enableSymlinks();  // See linked patch: https://issues.apache.org/jira/browse/HADOOP-10020

Hope this helps.

Upvotes: 2

Related Questions