HBASE-14658 Allow loading a MonkeyFactory by class name

This commit is contained in:
Elliott Clark 2015-10-20 18:28:48 -07:00
parent 9a5423fc42
commit 2e2cbd0201
1 changed files with 15 additions and 1 deletions

View File

@ -22,16 +22,20 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.IntegrationTestingUtility; import org.apache.hadoop.hbase.IntegrationTestingUtility;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey; import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.hadoop.hbase.util.ReflectionUtils;
/** /**
* Base class of the factory that will create a ChaosMonkey. * Base class of the factory that will create a ChaosMonkey.
*/ */
public abstract class MonkeyFactory { public abstract class MonkeyFactory {
private static final Log LOG = LogFactory.getLog(MonkeyFactory.class);
protected TableName tableName; protected TableName tableName;
protected Set<String> columnFamilies; protected Set<String> columnFamilies;
@ -88,6 +92,16 @@ public abstract class MonkeyFactory {
.build(); .build();
public static MonkeyFactory getFactory(String factoryName) { public static MonkeyFactory getFactory(String factoryName) {
return FACTORIES.get(factoryName); MonkeyFactory fact = FACTORIES.get(factoryName);
if (fact == null) {
Class klass = null;
try {
klass = Class.forName(factoryName);
fact = (MonkeyFactory) ReflectionUtils.newInstance(klass);
} catch (ClassNotFoundException e) {
LOG.error("Error trying to create " + factoryName + " could not load it by class name");
}
}
return fact;
} }
} }