Skip to content

Commit d7a0613

Browse files
committed
Working Directory patch to force hadoop < 1.2 to use /user/{user.name}/ as starting working dir instead of {user.dir}
Also some minor logging updates.
1 parent 0df4777 commit d7a0613

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

src/main/java/org/apache/hadoop/fs/glusterfs/GlusterVolume.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public class GlusterVolume extends RawLocalFileSystem{
4949

5050
protected static GlusterFSXattr attr = null;
5151

52-
public GlusterVolume(){}
52+
public GlusterVolume(){
53+
}
5354

5455
public GlusterVolume(Configuration conf){
5556
this();
@@ -65,6 +66,7 @@ public void setConf(Configuration conf){
6566

6667
try{
6768
root=conf.get("fs.glusterfs.mount", null);
69+
log.info("Root of Gluster file system is " + root);
6870
getfattrcmd = conf.get("fs.glusterfs.getfattrcmd", null);
6971
if(getfattrcmd!=null){
7072
attr = new GlusterFSXattr(getfattrcmd);
@@ -85,13 +87,18 @@ public void setConf(Configuration conf){
8587
}
8688

8789
superUser = conf.get("gluster.daemon.user", null);
90+
log.info("Gluster Daemon for ACLs is: " + superUser);
8891

8992
aclFilter = new AclPathFilter(conf);
9093

9194
/* ensure the initial working directory exists */
92-
Path workingDirectory = getInitialWorkingDirectory();
95+
final Path workingDirectory = getInitialWorkingDirectory();
9396
mkdirs(workingDirectory);
97+
//For hadoop < 1.2.0, when RawLocalFileSystem used
98+
//user.dir instead of user.home
99+
setWorkingDirectory(workingDirectory);
94100

101+
log.info("Working directory is : "+ getWorkingDirectory());
95102
//volName=conf.get("fs.glusterfs.volname", null);
96103
//remoteGFSServer=conf.get("fs.glusterfs.server", null);
97104

@@ -110,7 +117,10 @@ public File pathToFile(Path path) {
110117
return new File(root + path.toUri().getPath());
111118
}
112119

113-
@Override
120+
/**
121+
* Note this method doesn't override anything in hadoop 1.2.0 and
122+
* below.
123+
*/
114124
protected Path getInitialWorkingDirectory() {
115125
/* apache's unit tests use a default working direcotry like this: */
116126
return new Path(this.NAME + "user/" + System.getProperty("user.name"));
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.apache.hadoop.fs.test.unit;
2+
3+
import static org.apache.hadoop.fs.FileSystemTestHelper.getTestRootPath;
4+
5+
import java.io.File;
6+
7+
import junit.framework.Assert;
8+
9+
import org.apache.hadoop.fs.FileSystem;
10+
import org.apache.hadoop.fs.FileUtil;
11+
import org.apache.hadoop.fs.Path;
12+
import org.apache.hadoop.fs.test.connector.HcfsTestConnectorFactory;
13+
import org.apache.hadoop.fs.test.connector.HcfsTestConnectorInterface;
14+
import org.junit.After;
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
20+
public class HCFSTestWorkingDir{
21+
22+
Logger log = LoggerFactory.getLogger(HCFSTestWorkingDir.class);
23+
FileSystem fSys;
24+
25+
@Before
26+
public void setUp() throws Exception{
27+
HcfsTestConnectorInterface connector=
28+
HcfsTestConnectorFactory.getHcfsTestConnector();
29+
fSys=connector.create();
30+
}
31+
32+
/**
33+
* This test fails in hadoop 1.2.0, if we do not have
34+
* logic in the GlusterVolume to use "getInitialWorkingDirectory"
35+
* as the starting working directory.
36+
*/
37+
@Test
38+
public void test() throws Exception {
39+
Path outpath = new Path("to_");
40+
if(fSys.exists(outpath)){
41+
fSys.delete(outpath,true);
42+
}
43+
File tmpfile = new File("/tmp/test_copyfromlocal");
44+
tmpfile.createNewFile();
45+
log.info(tmpfile.getAbsolutePath());
46+
Assert.assertTrue(tmpfile.exists());
47+
48+
fSys.copyFromLocalFile(false, false,
49+
new Path(tmpfile.getPath()),
50+
outpath);
51+
52+
Assert.assertTrue(fSys.exists(outpath));
53+
fSys.delete(outpath,true);
54+
}
55+
56+
@After
57+
public void tearDown() throws Exception{
58+
fSys.delete(getTestRootPath(fSys, "test"), true);
59+
}
60+
}

0 commit comments

Comments
 (0)