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..920a659 100644 --- hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java +++ hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java @@ -104,7 +104,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..c4a9b0f 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,11 @@ 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" }; - + private String userNames; + private String superUser; + public static final String OPT_SUPERUSER = "superuser"; + public static final String OPT_USERS = "userlist"; @Override public void setUpCluster() throws Exception { util = getTestingUtil(null); @@ -64,12 +66,29 @@ 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(superUser); + sb.append(COLON); + sb.append(userNames); sb.append(COLON); sb.append(Integer.toString(SPECIAL_PERM_CELL_INSERTION_FACTOR)); tmp.add(sb.toString()); return tmp.toArray(new String[tmp.size()]); } + @Override + protected void addOptions() { + super.addOptions(); + super.addOptWithArg(OPT_SUPERUSER, + "Super user name used to add the ACL permissions"); + super.addOptWithArg(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(OPT_SUPERUSER); + userNames = cmd.getOptionValue(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..1dcf25c 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; @@ -180,6 +179,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; @@ -454,14 +457,21 @@ 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]); - if(dataGen instanceof LoadTestDataGeneratorWithACL) { + String args[]; + if (dataGen instanceof LoadTestDataGeneratorWithACL) { LOG.info("ACL is on"); - userOwner = User.createUserForTesting(conf, "owner", new String[0]); + if (clazzAndArgs[1] != null) { + superUser = clazzAndArgs[1]; + } + if (clazzAndArgs[2] != null) { + userNames = clazzAndArgs[2]; + } + userOwner = User.createUserForTesting(conf, superUser, new String[0]); } - String[] args = clazzAndArgs.length == 1 ? new String[0] : Arrays.copyOfRange(clazzAndArgs, - 1, clazzAndArgs.length); + args = clazzAndArgs.length == 1 ? new String[0] : Arrays.copyOfRange(clazzAndArgs, 1, + clazzAndArgs.length); dataGen.initialize(args); } else { // Default DataGenerator is MultiThreadedAction.DefaultDataGenerator @@ -499,7 +509,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 +519,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..0067003 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 @@ -97,7 +97,7 @@ public class MultiThreadedReaderWithACL extends MultiThreadedReader { try { get.setACLStrategy(true); Result result = null; - int specialPermCellInsertionFactor = Integer.parseInt(dataGenerator.getArgs()[1]); + int specialPermCellInsertionFactor = Integer.parseInt(dataGenerator.getArgs()[2]); int mod = ((int) keyToRead % userNames.length); if (userVsTable.get(userNames[mod]) == null) { localTable = new HTable(conf, tableName); diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdater.java hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdater.java index 0f5df88..12c585d 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdater.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/util/MultiThreadedUpdater.java @@ -174,7 +174,7 @@ public class MultiThreadedUpdater extends MultiThreadedWriterBase { Map columnValues = result != null ? result.getFamilyMap(cf) : null; if (columnValues == null) { - int specialPermCellInsertionFactor = Integer.parseInt(dataGenerator.getArgs()[1]); + int specialPermCellInsertionFactor = Integer.parseInt(dataGenerator.getArgs()[2]); if (((int) rowKeyBase % specialPermCellInsertionFactor == 0)) { LOG.info("Null result expected for the rowkey " + Bytes.toString(rowKey)); } else { 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 diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/util/test/LoadTestDataGeneratorWithACL.java hbase-server/src/test/java/org/apache/hadoop/hbase/util/test/LoadTestDataGeneratorWithACL.java index b2988cf..cd137f9 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/util/test/LoadTestDataGeneratorWithACL.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/util/test/LoadTestDataGeneratorWithACL.java @@ -41,17 +41,17 @@ public class LoadTestDataGeneratorWithACL extends DefaultDataGenerator { @Override public void initialize(String[] args) { super.initialize(args); - if (args.length != 2) { + if (args.length != 3) { throw new IllegalArgumentException( "LoadTestDataGeneratorWithACL can have " - + "1st arguement which would be the user list and the 2nd argument " - + "should be the factor representing " + + "1st arguement which would be super user, the 2nd argument " + + "would be the user list and the 3rd argument should be the factor representing " + "the row keys for which only write ACLs will be added."); } - String temp = args[0]; + String temp = args[1]; // This will be comma separated list of expressions. this.userNames = temp.split(COMMA); - this.specialPermCellInsertionFactor = Integer.parseInt(args[1]); + this.specialPermCellInsertionFactor = Integer.parseInt(args[2]); } @Override