1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.hadoop.hbase.util.test;
18
19 import java.io.IOException;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.client.Delete;
25 import org.apache.hadoop.hbase.client.Mutation;
26 import org.apache.hadoop.hbase.security.access.Permission;
27 import org.apache.hadoop.hbase.util.MultiThreadedAction.DefaultDataGenerator;
28
29 @InterfaceAudience.Private
30 public class LoadTestDataGeneratorWithACL extends DefaultDataGenerator {
31 private static final Log LOG = LogFactory.getLog(LoadTestDataGeneratorWithACL.class);
32 private String[] userNames = null;
33 private static final String COMMA = ",";
34 private int specialPermCellInsertionFactor = 100;
35
36 public LoadTestDataGeneratorWithACL(int minValueSize, int maxValueSize, int minColumnsPerKey,
37 int maxColumnsPerKey, byte[]... columnFamilies) {
38 super(minValueSize, maxValueSize, minColumnsPerKey, maxColumnsPerKey, columnFamilies);
39 }
40
41 @Override
42 public void initialize(String[] args) {
43 super.initialize(args);
44 if (args.length != 3) {
45 throw new IllegalArgumentException(
46 "LoadTestDataGeneratorWithACL can have "
47 + "1st arguement which would be super user, the 2nd argument "
48 + "would be the user list and the 3rd argument should be the factor representing "
49 + "the row keys for which only write ACLs will be added.");
50 }
51 String temp = args[1];
52
53 this.userNames = temp.split(COMMA);
54 this.specialPermCellInsertionFactor = Integer.parseInt(args[2]);
55 }
56
57 @Override
58 public Mutation beforeMutate(long rowkeyBase, Mutation m) throws IOException {
59 if (!(m instanceof Delete)) {
60 if (userNames != null && userNames.length > 0) {
61 int mod = ((int) rowkeyBase % this.userNames.length);
62 if (((int) rowkeyBase % specialPermCellInsertionFactor) == 0) {
63
64 if (LOG.isTraceEnabled()) {
65 LOG.trace("Adding special perm " + rowkeyBase);
66 }
67 m.setACL(userNames[mod], new Permission(Permission.Action.WRITE));
68 } else {
69 m.setACL(userNames[mod], new Permission(Permission.Action.READ));
70 }
71 }
72 }
73 return m;
74 }
75 }