I use the following program to rename a directory, but I got the exception, which seems that it only assumes that I am using the local file system. Actually, in my core-site.xml, i have already set the fs.default.name to the hdfs, instead of local file system.
So, I want to know the loading order of the configuration files, and why it think that I am using local file system. How to fix it? thanks
`
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://xiliu:54310</value>
<final>true</final>`
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/data1/hadoop/hdfs/tmp</value>
<final>true</final>
</property>
</configuration>
public class FSUtil extends Configured
{
private static Configuration conf;
static
{
conf = new Configuration( );
}
public static void rename( Path srcPath, Path tgtPath)
throws IOException
{
FileSystem fs = FileSystem.get( conf);
fs.rename( srcPath, tgtPath);
}
public static void main(String[]args){
try {
FSUtil.rename(new Path("hdfs://xiliu:54310/user/warehouse/test"), new Path("hdfs://xiliu:54310/user/warehouse/testtmp"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://xiliu:54310/user/warehouse/test, expected: file:///
at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:354)
at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:54)
at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:367)
at org.apache.hadoop.fs.FileSystem.isDirectory(FileSystem.java:702)
at org.apache.hadoop.fs.ChecksumFileSystem.rename(ChecksumFileSystem.java:402)
at com.business.cloudbase.hadoop.fs.FSUtil.rename(FSUtil.java:251)
at com.business.cloudbase.hadoop.fs.FSUtil.main(FSUtil.java:602)
Looks like the configuration files are not in the class path and the fs.default.name parameter is defaulting to file:///.
Two options
Put the configuration files in the classpath, so that the code picks it.
Use Configuration.set() to set the required parameters in the code.