You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2015/10/23 21:25:54 UTC

[2/2] hbase git commit: HBASE-14658 Allow loading a MonkeyFactory by class name

HBASE-14658 Allow loading a MonkeyFactory by class name


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b5a5548f
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b5a5548f
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b5a5548f

Branch: refs/heads/0.98
Commit: b5a5548f2330ff22925bfbf90b6b946494807d37
Parents: ba02635
Author: Elliott Clark <ec...@apache.org>
Authored: Tue Oct 20 18:28:48 2015 -0700
Committer: Andrew Purtell <ap...@apache.org>
Committed: Fri Oct 23 12:23:45 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/chaos/factories/MonkeyFactory.java | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/b5a5548f/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyFactory.java
----------------------------------------------------------------------
diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyFactory.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyFactory.java
index d8e921d..9ea34fd 100644
--- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyFactory.java
+++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyFactory.java
@@ -22,15 +22,19 @@ import java.util.Map;
 import java.util.Properties;
 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.chaos.monkies.ChaosMonkey;
 
 import com.google.common.collect.ImmutableMap;
+import org.apache.hadoop.hbase.util.ReflectionUtils;
 
 /**
  * Base class of the factory that will create a ChaosMonkey.
  */
 public abstract class MonkeyFactory {
+  private static final Log LOG = LogFactory.getLog(MonkeyFactory.class);
 
   protected String tableName;
   protected Set<String> columnFamilies;
@@ -83,6 +87,16 @@ public abstract class MonkeyFactory {
     .build();
 
   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;
   }
 }