diff --git hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java index 6717933..d47ca84 100644 --- hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java +++ hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java @@ -53,6 +53,8 @@ public class IntegrationTestIngest extends IntegrationTestBase { protected IntegrationTestingUtility util; protected HBaseCluster cluster; protected LoadTestTool loadTool; + protected String userNames; + protected String superUser; @Override public void setUpCluster() throws Exception { @@ -104,7 +106,6 @@ public class IntegrationTestIngest extends IntegrationTestBase { util.deleteTable(Bytes.toBytes(getTablename())); } } - protected void runIngestTest(long defaultRunTime, int keysPerServerPerIter, int colsPerKey, int recordSize, int writeThreads) throws Exception { LOG.info("Running ingest"); diff --git hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngestWithACL.java hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngestWithACL.java index 77d81d5..ea38c4d 100644 --- hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngestWithACL.java +++ hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngestWithACL.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.commons.cli.CommandLine; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.io.hfile.HFile; import org.apache.hadoop.hbase.security.access.AccessController; @@ -41,10 +42,7 @@ public class IntegrationTestIngestWithACL extends IntegrationTestIngest { private static final char COLON = ':'; public static final char HYPHEN = '-'; - private static final char COMMA = ','; private static final int SPECIAL_PERM_CELL_INSERTION_FACTOR = 100; - public static final String[] userNames = { "user1", "user2", "user3", "user4" }; - @Override public void setUpCluster() throws Exception { util = getTestingUtil(null); @@ -64,12 +62,33 @@ public class IntegrationTestIngestWithACL extends IntegrationTestIngest { tmp.add(HYPHEN + LoadTestTool.OPT_GENERATOR); StringBuilder sb = new StringBuilder(LoadTestDataGeneratorWithACL.class.getName()); sb.append(COLON); - sb.append(asCommaSeperatedString(userNames)); - sb.append(COLON); sb.append(Integer.toString(SPECIAL_PERM_CELL_INSERTION_FACTOR)); tmp.add(sb.toString()); + if (superUser != null) { + tmp.add(HYPHEN + LoadTestTool.OPT_SUPERUSER); + tmp.add(superUser); + } + if (userNames != null) { + tmp.add(HYPHEN + LoadTestTool.OPT_USERS); + tmp.add(userNames); + } return tmp.toArray(new String[tmp.size()]); } + @Override + protected void addOptions() { + super.addOptions(); + super.addOptWithArg(LoadTestTool.OPT_SUPERUSER, + "Super user name used to add the ACL permissions"); + super.addOptWithArg(LoadTestTool.OPT_USERS, + "List of users to be added with the ACLs. Should be comma seperated."); + } + + @Override + protected void processOptions(CommandLine cmd) { + super.processOptions(cmd); + superUser = cmd.getOptionValue(LoadTestTool.OPT_SUPERUSER); + userNames = cmd.getOptionValue(LoadTestTool.OPT_USERS); + } public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); @@ -77,17 +96,4 @@ public class IntegrationTestIngestWithACL extends IntegrationTestIngest { int ret = ToolRunner.run(conf, new IntegrationTestIngestWithACL(), args); System.exit(ret); } - - private static String asCommaSeperatedString(String[] list) { - StringBuilder sb = new StringBuilder(); - for (String item : list) { - sb.append(item); - sb.append(COMMA); - } - if (sb.length() > 0) { - // Remove the trailing , - sb.deleteCharAt(sb.length() - 1); - } - return sb.toString(); - } } diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/util/LoadTestTool.java hbase-server/src/test/java/org/apache/hadoop/hbase/util/LoadTestTool.java index 629944b..93b2be7 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/util/LoadTestTool.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/util/LoadTestTool.java @@ -39,7 +39,6 @@ import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.PerformanceEvaluation; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.io.crypto.Cipher; import org.apache.hadoop.hbase.io.crypto.Encryption; @@ -142,6 +141,9 @@ public class LoadTestTool extends AbstractHBaseTool { protected static final long DEFAULT_START_KEY = 0; + public static final String OPT_SUPERUSER = "superuser"; + public static final String OPT_USERS = "userlist"; + /** This will be removed as we factor out the dependency on command line */ protected CommandLine cmd; @@ -180,6 +182,10 @@ public class LoadTestTool extends AbstractHBaseTool { private int numTables = 1; + private String superUser = "owner"; + + private String userNames = "user1,user2,user3,user4"; + // TODO: refactor LoadTestToolImpl somewhere to make the usage from tests less bad, // console tool itself should only be used from console. protected boolean isSkipInit = false; @@ -290,6 +296,10 @@ public class LoadTestTool extends AbstractHBaseTool { + "table name prefix. Each table name is in format _1..._n"); addOptWithArg(OPT_ENCRYPTION, OPT_ENCRYPTION_USAGE); + addOptWithArg(LoadTestTool.OPT_SUPERUSER, + "Super user name used to add the ACL permissions"); + addOptWithArg(LoadTestTool.OPT_USERS, + "List of users to be added with the ACLs. Should be comma seperated."); } @Override @@ -399,6 +409,12 @@ public class LoadTestTool extends AbstractHBaseTool { if(cmd.hasOption(NUM_TABLES)) { numTables = parseInt(cmd.getOptionValue(NUM_TABLES), 1, Short.MAX_VALUE); } + if(cmd.hasOption(OPT_SUPERUSER)) { + superUser = cmd.getOptionValue(OPT_SUPERUSER); + } + if(cmd.hasOption(OPT_USERS)) { + userNames = cmd.getOptionValue(OPT_USERS); + } } private void parseColumnFamilyOptions(CommandLine cmd) { @@ -454,14 +470,20 @@ public class LoadTestTool extends AbstractHBaseTool { } LoadTestDataGenerator dataGen = null; if (cmd.hasOption(OPT_GENERATOR)) { - String[] clazzAndArgs = cmd.getOptionValue(OPT_GENERATOR).split(COLON); + String[] clazzAndArgs = cmd.getOptionValue(OPT_GENERATOR).split(COLON); dataGen = getLoadGeneratorInstance(clazzAndArgs[0]); + String args[]; if(dataGen instanceof LoadTestDataGeneratorWithACL) { LOG.info("ACL is on"); - userOwner = User.createUserForTesting(conf, "owner", new String[0]); - } - String[] args = clazzAndArgs.length == 1 ? new String[0] : Arrays.copyOfRange(clazzAndArgs, + userOwner = User.createUserForTesting(conf, superUser, new String[0]); + // Create an args with 2 elements + args = new String[2]; + args[0] = userNames; + args[1] = clazzAndArgs[1]; + } else { + args = clazzAndArgs.length == 1 ? new String[0] : Arrays.copyOfRange(clazzAndArgs, 1, clazzAndArgs.length); + } dataGen.initialize(args); } else { // Default DataGenerator is MultiThreadedAction.DefaultDataGenerator @@ -499,7 +521,7 @@ public class LoadTestTool extends AbstractHBaseTool { if (isUpdate) { if (userOwner != null) { updaterThreads = new MultiThreadedUpdaterWithACL(dataGen, conf, tableName, updatePercent, - userOwner); + userOwner, userNames); } else { updaterThreads = new MultiThreadedUpdater(dataGen, conf, tableName, updatePercent); } @@ -509,7 +531,8 @@ public class LoadTestTool extends AbstractHBaseTool { if (isRead) { if (userOwner != null) { - readerThreads = new MultiThreadedReaderWithACL(dataGen, conf, tableName, verifyPercent); + readerThreads = new MultiThreadedReaderWithACL(dataGen, conf, tableName, verifyPercent, + userNames); } else { readerThreads = new MultiThreadedReader(dataGen, conf, tableName, verifyPercent); } diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedReaderWithACL.java hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedReaderWithACL.java index b71ff6d..f0f15a5 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedReaderWithACL.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedReaderWithACL.java @@ -48,9 +48,9 @@ public class MultiThreadedReaderWithACL extends MultiThreadedReader { private String[] userNames; public MultiThreadedReaderWithACL(LoadTestDataGenerator dataGen, Configuration conf, - TableName tableName, double verifyPercent) { + TableName tableName, double verifyPercent, String userNames) { super(dataGen, conf, tableName, verifyPercent); - userNames = dataGenerator.getArgs()[0].split(COMMA); + this.userNames = userNames.split(COMMA); } @Override diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdaterWithACL.java hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdaterWithACL.java index 996bf55..b4e24e5 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdaterWithACL.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdaterWithACL.java @@ -22,7 +22,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.security.PrivilegedExceptionAction; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; @@ -59,10 +58,10 @@ public class MultiThreadedUpdaterWithACL extends MultiThreadedUpdater { private String[] userNames; public MultiThreadedUpdaterWithACL(LoadTestDataGenerator dataGen, Configuration conf, - TableName tableName, double updatePercent, User userOwner) { + TableName tableName, double updatePercent, User userOwner, String userNames) { super(dataGen, conf, tableName, updatePercent); this.userOwner = userOwner; - userNames = dataGenerator.getArgs()[0].split(COMMA); + this.userNames = userNames.split(COMMA); } @Override