Skip to content

Commit 748cba3

Browse files
committed
Staging directory filter. Uses 2 regular expressions to filter out the stating directory based on the apache core classes algorithm (LocalJobRunner.java & JobTracker.java)
1 parent fe14eac commit 748cba3

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.apache.hadoop.fs.glusterfs;
2+
3+
import java.io.IOException;
4+
import java.util.ListIterator;
5+
import java.util.Vector;
6+
import org.apache.hadoop.conf.Configuration;
7+
import org.apache.hadoop.fs.Path;
8+
import org.apache.hadoop.security.UserGroupInformation;
9+
10+
11+
public class AclPathFilter {
12+
13+
Vector<String> paths = null;
14+
15+
public AclPathFilter(){
16+
paths = new Vector<String>();
17+
}
18+
/* generates a white list of ACL path regular expressions */
19+
public AclPathFilter(Configuration conf){
20+
this();
21+
UserGroupInformation ugi = null;
22+
try {
23+
ugi = UserGroupInformation.getCurrentUser();
24+
} catch (IOException e) {
25+
26+
}
27+
String stagingRootDir = new Path(conf.get("mapreduce.jobtracker.staging.root.dir", "/tmp/hadoop/mapred/staging")).toString();
28+
String user;
29+
String randid = "\\d*";
30+
if (ugi != null) {
31+
user = ugi.getShortUserName();
32+
} else {
33+
user = "dummy";
34+
}
35+
paths.add("^" + new Path(stagingRootDir, user + randid +"/.staging").toString() + ".*");
36+
stagingRootDir = new Path(conf.get("mapreduce.jobtracker.staging.root.dir","/tmp/hadoop/mapred/staging")).toString();
37+
paths.add("^" + new Path(stagingRootDir, user+"/.staging").toString() + ".*");
38+
39+
}
40+
41+
public boolean matches(String path){
42+
43+
boolean needsAcl = false;
44+
ListIterator<String> list = paths.listIterator();
45+
String filterPath = null;
46+
while(list.hasNext() && !needsAcl){
47+
filterPath = list.next();
48+
if(path.matches(filterPath)){
49+
needsAcl = true;
50+
}
51+
}
52+
return needsAcl;
53+
}
54+
public boolean matches(Path path){
55+
return matches(path.toString());
56+
}
57+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class GlusterVolume extends RawLocalFileSystem{
4343

4444
protected String root=null;
4545
protected String superUser=null;
46+
protected AclPathFilter aclFilter = null;
4647

4748
protected static GlusterFSXattr attr = null;
4849

@@ -83,6 +84,7 @@ public void setConf(Configuration conf){
8384

8485
superUser = conf.get("gluster.daemon.user", null);
8586

87+
aclFilter = new AclPathFilter(conf);
8688
//volName=conf.get("fs.glusterfs.volname", null);
8789
//remoteGFSServer=conf.get("fs.glusterfs.server", null);
8890

@@ -165,7 +167,7 @@ public long getBlockSize(Path path) throws IOException{
165167
*/
166168

167169
private void updateAcl(Path p){
168-
if(superUser!=null){
170+
if(superUser!=null && aclFilter.matches(p) ){
169171
File f = pathToFile(p);
170172
String path = f.getAbsolutePath();
171173
String command = "setfacl -m u:" + superUser + ":rwx " + path;

0 commit comments

Comments
 (0)