HBASE-10675 - IntegrationTestIngestWithACL should allow User to be passed as Parameter (Ram)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1576016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6dab763850
commit
829c3725c7
|
@ -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");
|
||||
|
|
|
@ -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" };
|
||||
|
||||
public static final String OPT_SUPERUSER = "superuser";
|
||||
public static final String OPT_USERS = "userlist";
|
||||
private String superUser = "owner";
|
||||
private String userNames = "user1,user2,user3,user4";
|
||||
@Override
|
||||
public void setUpCluster() throws Exception {
|
||||
util = getTestingUtil(null);
|
||||
|
@ -64,12 +66,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(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);
|
||||
if (cmd.hasOption(OPT_SUPERUSER)) {
|
||||
superUser = cmd.getOptionValue(OPT_SUPERUSER);
|
||||
}
|
||||
if (cmd.hasOption(OPT_USERS)) {
|
||||
userNames = cmd.getOptionValue(OPT_USERS);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
|
@ -77,17 +100,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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
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;
|
||||
|
@ -456,12 +459,18 @@ public class LoadTestTool extends AbstractHBaseTool {
|
|||
if (cmd.hasOption(OPT_GENERATOR)) {
|
||||
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]);
|
||||
superUser = clazzAndArgs[1];
|
||||
userNames = clazzAndArgs[2];
|
||||
args = Arrays.copyOfRange(clazzAndArgs, 1,
|
||||
clazzAndArgs.length);
|
||||
userOwner = User.createUserForTesting(conf, superUser, new String[0]);
|
||||
} else {
|
||||
args = clazzAndArgs.length == 1 ? new String[0] : Arrays.copyOfRange(clazzAndArgs, 1,
|
||||
clazzAndArgs.length);
|
||||
}
|
||||
String[] args = clazzAndArgs.length == 1 ? new String[0] : Arrays.copyOfRange(clazzAndArgs,
|
||||
1, clazzAndArgs.length);
|
||||
dataGen.initialize(args);
|
||||
} else {
|
||||
// Default DataGenerator is MultiThreadedAction.DefaultDataGenerator
|
||||
|
@ -499,7 +508,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 +518,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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -174,7 +174,7 @@ public class MultiThreadedUpdater extends MultiThreadedWriterBase {
|
|||
Map<byte[], byte[]> 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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue