1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase;
19
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23
24 import org.apache.commons.cli.CommandLine;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.io.hfile.HFile;
27 import org.apache.hadoop.hbase.security.access.AccessController;
28 import org.apache.hadoop.hbase.util.LoadTestTool;
29 import org.apache.hadoop.hbase.util.test.LoadTestDataGeneratorWithACL;
30 import org.apache.hadoop.util.ToolRunner;
31 import org.junit.experimental.categories.Category;
32
33
34
35
36
37
38
39
40 @Category(IntegrationTests.class)
41 public class IntegrationTestIngestWithACL extends IntegrationTestIngest {
42
43 private static final char COLON = ':';
44 public static final char HYPHEN = '-';
45 private static final int SPECIAL_PERM_CELL_INSERTION_FACTOR = 100;
46 public static final String OPT_SUPERUSER = "superuser";
47 public static final String OPT_USERS = "userlist";
48 private String superUser = "owner";
49 private String userNames = "user1,user2,user3,user4";
50 @Override
51 public void setUpCluster() throws Exception {
52 util = getTestingUtil(null);
53 Configuration conf = util.getConfiguration();
54 conf.setInt(HFile.FORMAT_VERSION_KEY, 3);
55 conf.set("hbase.coprocessor.master.classes", AccessController.class.getName());
56 conf.set("hbase.coprocessor.region.classes", AccessController.class.getName());
57
58 super.setUpCluster();
59 }
60
61 @Override
62 protected String[] getArgsForLoadTestTool(String mode, String modeSpecificArg, long startKey,
63 long numKeys) {
64 String[] args = super.getArgsForLoadTestTool(mode, modeSpecificArg, startKey, numKeys);
65 List<String> tmp = new ArrayList<String>(Arrays.asList(args));
66 tmp.add(HYPHEN + LoadTestTool.OPT_GENERATOR);
67 StringBuilder sb = new StringBuilder(LoadTestDataGeneratorWithACL.class.getName());
68 sb.append(COLON);
69 sb.append(superUser);
70 sb.append(COLON);
71 sb.append(userNames);
72 sb.append(COLON);
73 sb.append(Integer.toString(SPECIAL_PERM_CELL_INSERTION_FACTOR));
74 tmp.add(sb.toString());
75 return tmp.toArray(new String[tmp.size()]);
76 }
77 @Override
78 protected void addOptions() {
79 super.addOptions();
80 super.addOptWithArg(OPT_SUPERUSER,
81 "Super user name used to add the ACL permissions");
82 super.addOptWithArg(OPT_USERS,
83 "List of users to be added with the ACLs. Should be comma seperated.");
84 }
85
86 @Override
87 protected void processOptions(CommandLine cmd) {
88 super.processOptions(cmd);
89 if (cmd.hasOption(OPT_SUPERUSER)) {
90 superUser = cmd.getOptionValue(OPT_SUPERUSER);
91 }
92 if (cmd.hasOption(OPT_USERS)) {
93 userNames = cmd.getOptionValue(OPT_USERS);
94 }
95 }
96
97 public static void main(String[] args) throws Exception {
98 Configuration conf = HBaseConfiguration.create();
99 IntegrationTestingUtility.setUseDistributedCluster(conf);
100 int ret = ToolRunner.run(conf, new IntegrationTestIngestWithACL(), args);
101 System.exit(ret);
102 }
103 }