|
| 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 | +} |
0 commit comments