fluo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject [1/5] incubator-fluo git commit: Fixes #683 - Move class config to impl props
Date Fri, 01 Jul 2016 03:14:03 GMT
Repository: incubator-fluo
Updated Branches:
  refs/heads/master fee0ca74d -> 734061bd4


Fixes #683 - Move class config to impl props


Project: http://git-wip-us.apache.org/repos/asf/incubator-fluo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fluo/commit/28b9f2f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fluo/tree/28b9f2f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fluo/diff/28b9f2f9

Branch: refs/heads/master
Commit: 28b9f2f933f3c6ce3db8e618acd826288645300a
Parents: 6fd8629
Author: Mike Walch <mwalch@gmail.com>
Authored: Tue Jun 28 13:33:12 2016 -0400
Committer: Mike Walch <mwalch@gmail.com>
Committed: Tue Jun 28 16:54:07 2016 -0400

----------------------------------------------------------------------
 .../org/apache/fluo/api/client/FluoFactory.java | 50 +++++++++++++----
 .../fluo/api/config/FluoConfiguration.java      | 57 --------------------
 .../fluo/api/config/FluoConfigurationTest.java  | 13 +----
 3 files changed, 41 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/28b9f2f9/modules/api/src/main/java/org/apache/fluo/api/client/FluoFactory.java
----------------------------------------------------------------------
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/FluoFactory.java b/modules/api/src/main/java/org/apache/fluo/api/client/FluoFactory.java
index 1b684e8..91cc966 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/client/FluoFactory.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/FluoFactory.java
@@ -16,7 +16,9 @@
 package org.apache.fluo.api.client;
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.Objects;
 
+import com.google.common.base.Preconditions;
 import org.apache.commons.configuration.Configuration;
 import org.apache.fluo.api.config.FluoConfiguration;
 import org.apache.fluo.api.exceptions.FluoException;
@@ -26,6 +28,8 @@ import org.apache.fluo.api.service.FluoWorker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.fluo.api.config.FluoConfiguration.FLUO_PREFIX;
+
 /**
  * Factory for creating {@link FluoClient}, {@link FluoAdmin}, and {@link MiniFluo}. All
factory
  * methods take a configuration object which can be built using {@link FluoConfiguration}.
@@ -34,6 +38,18 @@ public class FluoFactory {
 
   private static final Logger log = LoggerFactory.getLogger(FluoFactory.class);
 
+  private static final String FLUO_IMPL_PREFIX = FLUO_PREFIX + ".impl";
+  private static final String CLIENT_CLASS_PROP = FLUO_IMPL_PREFIX + ".client.class";
+  private static final String CLIENT_CLASS_DEFAULT = FLUO_PREFIX + ".core.client.FluoClientImpl";
+  private static final String ADMIN_CLASS_PROP = FLUO_IMPL_PREFIX + ".admin.class";
+  private static final String ADMIN_CLASS_DEFAULT = FLUO_PREFIX + ".core.client.FluoAdminImpl";
+  private static final String WORKER_CLASS_PROP = FLUO_IMPL_PREFIX + ".worker.class";
+  private static final String WORKER_CLASS_DEFAULT = FLUO_PREFIX + ".core.worker.FluoWorkerImpl";
+  private static final String ORACLE_CLASS_PROP = FLUO_IMPL_PREFIX + ".oracle.class";
+  private static final String ORACLE_CLASS_DEFAULT = FLUO_PREFIX + ".core.oracle.FluoOracleImpl";
+  private static final String MINI_CLASS_PROP = FLUO_IMPL_PREFIX + ".mini.class";
+  private static final String MINI_CLASS_DEFAULT = FLUO_PREFIX + ".mini.MiniFluoImpl";
+
   /**
    * Creates a {@link FluoClient} for reading and writing data to Fluo. {@link FluoClient#close()}
    * should be called when you are finished using it. Configuration (see {@link FluoConfiguration})
@@ -43,8 +59,7 @@ public class FluoFactory {
    * org.apache.fluo.client.accumulo.instance
    */
   public static FluoClient newClient(Configuration configuration) {
-    FluoConfiguration config = new FluoConfiguration(configuration);
-    return buildClassWithConfig(config.getClientClass(), config);
+    return getAndBuildClassWithConfig(configuration, CLIENT_CLASS_PROP, CLIENT_CLASS_DEFAULT);
   }
 
   /**
@@ -56,8 +71,7 @@ public class FluoFactory {
    * org.apache.fluo.admin.accumulo.table, org.apache.fluo.admin.accumulo.classpath
    */
   public static FluoAdmin newAdmin(Configuration configuration) {
-    FluoConfiguration config = new FluoConfiguration(configuration);
-    return buildClassWithConfig(config.getAdminClass(), config);
+    return getAndBuildClassWithConfig(configuration, ADMIN_CLASS_PROP, ADMIN_CLASS_DEFAULT);
   }
 
   /**
@@ -70,24 +84,40 @@ public class FluoFactory {
    * org.apache.fluo.admin.accumulo.table
    */
   public static MiniFluo newMiniFluo(Configuration configuration) {
-    FluoConfiguration config = new FluoConfiguration(configuration);
-    return buildClassWithConfig(config.getMiniClass(), config);
+    return getAndBuildClassWithConfig(configuration, MINI_CLASS_PROP, MINI_CLASS_DEFAULT);
   }
 
   /**
    * Creates a {@link FluoOracle} using the provided configuration.
    */
   public static FluoOracle newOracle(Configuration configuration) {
-    FluoConfiguration config = new FluoConfiguration(configuration);
-    return buildClassWithConfig(config.getOracleClass(), config);
+    return getAndBuildClassWithConfig(configuration, ORACLE_CLASS_PROP, ORACLE_CLASS_DEFAULT);
   }
 
   /**
    * Creates a {@link FluoWorker} using the provided configuration.
    */
   public static FluoWorker newWorker(Configuration configuration) {
+    return getAndBuildClassWithConfig(configuration, WORKER_CLASS_PROP, WORKER_CLASS_DEFAULT);
+  }
+
+  @SuppressWarnings("unchecked")
+  private static <T> T getAndBuildClassWithConfig(Configuration configuration, String
classProp,
+      String classDefault) {
     FluoConfiguration config = new FluoConfiguration(configuration);
-    return buildClassWithConfig(config.getWorkerClass(), config);
+    String clazz = config.getString(classProp, classDefault);
+    Objects.requireNonNull(clazz, classProp + " cannot be null");
+    Preconditions.checkArgument(!clazz.isEmpty(), classProp + " cannot be empty");
+    return buildClassWithConfig(clazz, config);
+  }
+
+  @SuppressWarnings({"unchecked", "unused"})
+  private static <T> T getAndBuildClass(Configuration configuration, String classProp,
+      String classDefault) {
+    String clazz = configuration.getString(classProp, classDefault);
+    Objects.requireNonNull(clazz, classProp + " cannot be null");
+    Preconditions.checkArgument(!clazz.isEmpty(), classProp + " cannot be empty");
+    return buildClass(clazz);
   }
 
   @SuppressWarnings("unchecked")
@@ -111,7 +141,7 @@ public class FluoFactory {
     }
   }
 
-  @SuppressWarnings({"unchecked", "unused"})
+  @SuppressWarnings({"unchecked"})
   private static <T> T buildClass(String clazz) {
     try {
       return (T) Class.forName(clazz).newInstance();

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/28b9f2f9/modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java b/modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java
index 6a3b74a..c3f459a 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java
@@ -55,25 +55,19 @@ public class FluoConfiguration extends CompositeConfiguration {
   public static final String CLIENT_ZOOKEEPER_TIMEOUT_PROP = CLIENT_PREFIX + ".zookeeper.timeout";
   public static final String CLIENT_ZOOKEEPER_CONNECT_PROP = CLIENT_PREFIX + ".zookeeper.connect";
   public static final String CLIENT_RETRY_TIMEOUT_MS_PROP = CLIENT_PREFIX + ".retry.timeout.ms";
-  public static final String CLIENT_CLASS_PROP = CLIENT_PREFIX + ".class";
   public static final int CLIENT_ZOOKEEPER_TIMEOUT_DEFAULT = 30000;
   public static final String CLIENT_ACCUMULO_ZOOKEEPERS_DEFAULT = "localhost";
   public static final String CLIENT_ZOOKEEPER_CONNECT_DEFAULT = "localhost/fluo";
   public static final int CLIENT_RETRY_TIMEOUT_MS_DEFAULT = -1;
-  public static final String CLIENT_CLASS_DEFAULT = FLUO_PREFIX + ".core.client.FluoClientImpl";
 
   // Administration
   private static final String ADMIN_PREFIX = FLUO_PREFIX + ".admin";
   public static final String ADMIN_ACCUMULO_TABLE_PROP = ADMIN_PREFIX + ".accumulo.table";
   public static final String ADMIN_ACCUMULO_CLASSPATH_PROP = ADMIN_PREFIX + ".accumulo.classpath";
   public static final String ADMIN_ACCUMULO_CLASSPATH_DEFAULT = "";
-  public static final String ADMIN_CLASS_PROP = ADMIN_PREFIX + ".class";
-  public static final String ADMIN_CLASS_DEFAULT = FLUO_PREFIX + ".core.client.FluoAdminImpl";
 
   // Worker
   private static final String WORKER_PREFIX = FLUO_PREFIX + ".worker";
-  public static final String WORKER_CLASS_PROP = WORKER_PREFIX + ".class";
-  public static final String WORKER_CLASS_DEFAULT = FLUO_PREFIX + ".core.worker.FluoWorkerImpl";
   public static final String WORKER_NUM_THREADS_PROP = WORKER_PREFIX + ".num.threads";
   public static final String WORKER_INSTANCES_PROP = WORKER_PREFIX + ".instances";
   public static final String WORKER_MAX_MEMORY_MB_PROP = WORKER_PREFIX + ".max.memory.mb";
@@ -92,8 +86,6 @@ public class FluoConfiguration extends CompositeConfiguration {
 
   // Oracle
   private static final String ORACLE_PREFIX = FLUO_PREFIX + ".oracle";
-  public static final String ORACLE_CLASS_PROP = ORACLE_PREFIX + ".class";
-  public static final String ORACLE_CLASS_DEFAULT = FLUO_PREFIX + ".core.oracle.FluoOracleImpl";
   public static final String ORACLE_INSTANCES_PROP = ORACLE_PREFIX + ".instances";
   public static final String ORACLE_MAX_MEMORY_MB_PROP = ORACLE_PREFIX + ".max.memory.mb";
   public static final String ORACLE_NUM_CORES_PROP = ORACLE_PREFIX + ".num.cores";
@@ -103,10 +95,8 @@ public class FluoConfiguration extends CompositeConfiguration {
 
   // MiniFluo
   private static final String MINI_PREFIX = FLUO_PREFIX + ".mini";
-  public static final String MINI_CLASS_PROP = MINI_PREFIX + ".class";
   public static final String MINI_START_ACCUMULO_PROP = MINI_PREFIX + ".start.accumulo";
   public static final String MINI_DATA_DIR_PROP = MINI_PREFIX + ".data.dir";
-  public static final String MINI_CLASS_DEFAULT = FLUO_PREFIX + ".mini.MiniFluoImpl";
   public static final boolean MINI_START_ACCUMULO_DEFAULT = true;
   public static final String MINI_DATA_DIR_DEFAULT = "${env:FLUO_HOME}/mini";
 
@@ -171,20 +161,16 @@ public class FluoConfiguration extends CompositeConfiguration {
     getAccumuloTable();
     getAccumuloUser();
     getAccumuloZookeepers();
-    getAdminClass();
     getApplicationName();
     getAppZookeepers();
-    getClientClass();
     getClientRetryTimeout();
     getLoaderQueueSize();
     getLoaderThreads();
     getObserverConfig();
-    getOracleClass();
     getOracleInstances();
     getOracleMaxMemory();
     getOracleNumCores();
     getTransactionRollbackTime();
-    getWorkerClass();
     getWorkerInstances();
     getWorkerMaxMemory();
     getWorkerNumCores();
@@ -306,14 +292,6 @@ public class FluoConfiguration extends CompositeConfiguration {
     return getNonEmptyString(CLIENT_ACCUMULO_ZOOKEEPERS_PROP, CLIENT_ACCUMULO_ZOOKEEPERS_DEFAULT);
   }
 
-  public FluoConfiguration setClientClass(String clientClass) {
-    return setNonEmptyString(CLIENT_CLASS_PROP, clientClass);
-  }
-
-  public String getClientClass() {
-    return getNonEmptyString(CLIENT_CLASS_PROP, CLIENT_CLASS_DEFAULT);
-  }
-
   /**
    * Sets Accumulo table. This property only needs to be set for FluoAdmin as it will be
stored in
    * retrieved from Zookeeper for clients.
@@ -335,22 +313,6 @@ public class FluoConfiguration extends CompositeConfiguration {
     return getString(ADMIN_ACCUMULO_CLASSPATH_PROP, ADMIN_ACCUMULO_CLASSPATH_DEFAULT);
   }
 
-  public FluoConfiguration setAdminClass(String adminClass) {
-    return setNonEmptyString(ADMIN_CLASS_PROP, adminClass);
-  }
-
-  public String getAdminClass() {
-    return getNonEmptyString(ADMIN_CLASS_PROP, ADMIN_CLASS_DEFAULT);
-  }
-
-  public FluoConfiguration setWorkerClass(String workerClass) {
-    return setNonEmptyString(WORKER_CLASS_PROP, workerClass);
-  }
-
-  public String getWorkerClass() {
-    return getNonEmptyString(WORKER_CLASS_PROP, WORKER_CLASS_DEFAULT);
-  }
-
   public FluoConfiguration setWorkerThreads(int numThreads) {
     return setPositiveInt(WORKER_NUM_THREADS_PROP, numThreads);
   }
@@ -516,14 +478,6 @@ public class FluoConfiguration extends CompositeConfiguration {
     return getNonNegativeInt(LOADER_QUEUE_SIZE_PROP, LOADER_QUEUE_SIZE_DEFAULT);
   }
 
-  public FluoConfiguration setOracleClass(String oracleClass) {
-    return setNonEmptyString(ORACLE_CLASS_PROP, oracleClass);
-  }
-
-  public String getOracleClass() {
-    return getNonEmptyString(ORACLE_CLASS_PROP, ORACLE_CLASS_DEFAULT);
-  }
-
   public FluoConfiguration setOracleMaxMemory(int oracleMaxMemory) {
     return setPositiveInt(ORACLE_MAX_MEMORY_MB_PROP, oracleMaxMemory);
   }
@@ -548,14 +502,6 @@ public class FluoConfiguration extends CompositeConfiguration {
     return getPositiveInt(ORACLE_NUM_CORES_PROP, ORACLE_NUM_CORES_DEFAULT);
   }
 
-  public FluoConfiguration setMiniClass(String miniClass) {
-    return setNonEmptyString(MINI_CLASS_PROP, miniClass);
-  }
-
-  public String getMiniClass() {
-    return getNonEmptyString(MINI_CLASS_PROP, MINI_CLASS_DEFAULT);
-  }
-
   /**
    * @param reporter The name of the reporter to get configuration for, i.e. console, jmx,
graphite.
    * @return A {@link SubsetConfiguration} using the prefix {@value #REPORTER_PREFIX} with
the
@@ -723,8 +669,6 @@ public class FluoConfiguration extends CompositeConfiguration {
     config.setProperty(CLIENT_ZOOKEEPER_CONNECT_PROP, CLIENT_ZOOKEEPER_CONNECT_DEFAULT);
     config.setProperty(CLIENT_ZOOKEEPER_TIMEOUT_PROP, CLIENT_ZOOKEEPER_TIMEOUT_DEFAULT);
     config.setProperty(CLIENT_ACCUMULO_ZOOKEEPERS_PROP, CLIENT_ACCUMULO_ZOOKEEPERS_DEFAULT);
-    config.setProperty(CLIENT_CLASS_PROP, CLIENT_CLASS_DEFAULT);
-    config.setProperty(ADMIN_CLASS_PROP, ADMIN_CLASS_DEFAULT);
     config.setProperty(WORKER_NUM_THREADS_PROP, WORKER_NUM_THREADS_DEFAULT);
     config.setProperty(WORKER_INSTANCES_PROP, WORKER_INSTANCES_DEFAULT);
     config.setProperty(WORKER_MAX_MEMORY_MB_PROP, WORKER_MAX_MEMORY_MB_DEFAULT);
@@ -734,7 +678,6 @@ public class FluoConfiguration extends CompositeConfiguration {
     config.setProperty(LOADER_QUEUE_SIZE_PROP, LOADER_QUEUE_SIZE_DEFAULT);
     config.setProperty(ORACLE_MAX_MEMORY_MB_PROP, ORACLE_MAX_MEMORY_MB_DEFAULT);
     config.setProperty(ORACLE_NUM_CORES_PROP, ORACLE_NUM_CORES_DEFAULT);
-    config.setProperty(MINI_CLASS_PROP, MINI_CLASS_DEFAULT);
     config.setProperty(MINI_START_ACCUMULO_PROP, MINI_START_ACCUMULO_DEFAULT);
     config.setProperty(MINI_DATA_DIR_PROP, MINI_DATA_DIR_DEFAULT);
   }

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/28b9f2f9/modules/api/src/test/java/org/apache/fluo/api/config/FluoConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/api/src/test/java/org/apache/fluo/api/config/FluoConfigurationTest.java
b/modules/api/src/test/java/org/apache/fluo/api/config/FluoConfigurationTest.java
index f475311..01b14e8 100644
--- a/modules/api/src/test/java/org/apache/fluo/api/config/FluoConfigurationTest.java
+++ b/modules/api/src/test/java/org/apache/fluo/api/config/FluoConfigurationTest.java
@@ -46,11 +46,8 @@ public class FluoConfigurationTest {
         base.getClientRetryTimeout());
     Assert.assertEquals(FluoConfiguration.CLIENT_ACCUMULO_ZOOKEEPERS_DEFAULT,
         base.getAccumuloZookeepers());
-    Assert.assertEquals(FluoConfiguration.CLIENT_CLASS_DEFAULT, base.getClientClass());
-    Assert.assertEquals(FluoConfiguration.ADMIN_CLASS_DEFAULT, base.getAdminClass());
     Assert.assertEquals(FluoConfiguration.ADMIN_ACCUMULO_CLASSPATH_DEFAULT,
         base.getAccumuloClasspath());
-    Assert.assertEquals(FluoConfiguration.WORKER_CLASS_DEFAULT, base.getWorkerClass());
     Assert.assertEquals(FluoConfiguration.WORKER_NUM_THREADS_DEFAULT, base.getWorkerThreads());
     Assert.assertEquals(FluoConfiguration.WORKER_INSTANCES_DEFAULT, base.getWorkerInstances());
     Assert.assertEquals(FluoConfiguration.WORKER_MAX_MEMORY_MB_DEFAULT, base.getWorkerMaxMemory());
@@ -59,11 +56,9 @@ public class FluoConfigurationTest {
         base.getTransactionRollbackTime());
     Assert.assertEquals(FluoConfiguration.LOADER_NUM_THREADS_DEFAULT, base.getLoaderThreads());
     Assert.assertEquals(FluoConfiguration.LOADER_QUEUE_SIZE_DEFAULT, base.getLoaderQueueSize());
-    Assert.assertEquals(FluoConfiguration.ORACLE_CLASS_DEFAULT, base.getOracleClass());
     Assert.assertEquals(FluoConfiguration.ORACLE_INSTANCES_DEFAULT, base.getOracleInstances());
     Assert.assertEquals(FluoConfiguration.ORACLE_MAX_MEMORY_MB_DEFAULT, base.getOracleMaxMemory());
     Assert.assertEquals(FluoConfiguration.ORACLE_NUM_CORES_DEFAULT, base.getOracleNumCores());
-    Assert.assertEquals(FluoConfiguration.MINI_CLASS_DEFAULT, base.getMiniClass());
     Assert.assertEquals(FluoConfiguration.MINI_START_ACCUMULO_DEFAULT, base.getMiniStartAccumulo());
     Assert.assertTrue(base.getMiniDataDir().endsWith("/mini"));
   }
@@ -97,17 +92,12 @@ public class FluoConfigurationTest {
     Assert.assertEquals("pass", config.setAccumuloPassword("pass").getAccumuloPassword());
     Assert.assertEquals("table", config.setAccumuloTable("table").getAccumuloTable());
     Assert.assertEquals("user", config.setAccumuloUser("user").getAccumuloUser());
-    Assert.assertEquals("admin", config.setAdminClass("admin").getAdminClass());
-    Assert.assertEquals("client", config.setClientClass("client").getClientClass());
     Assert.assertEquals(4, config.setLoaderQueueSize(4).getLoaderQueueSize());
     Assert.assertEquals(0, config.setLoaderQueueSize(0).getLoaderQueueSize());
     Assert.assertEquals(7, config.setLoaderThreads(7).getLoaderThreads());
     Assert.assertEquals(0, config.setLoaderThreads(0).getLoaderThreads());
-    Assert.assertEquals("mini", config.setMiniClass("mini").getMiniClass());
-    Assert.assertEquals("oracle", config.setOracleClass("oracle").getOracleClass());
     Assert.assertEquals(8, config.setOracleMaxMemory(8).getOracleMaxMemory());
     Assert.assertEquals(10, config.setOracleInstances(10).getOracleInstances());
-    Assert.assertEquals("worker", config.setWorkerClass("worker").getWorkerClass());
     Assert.assertEquals(11, config.setWorkerInstances(11).getWorkerInstances());
     Assert.assertEquals(12, config.setWorkerMaxMemory(12).getWorkerMaxMemory());
     Assert.assertEquals(13, config.setWorkerThreads(13).getWorkerThreads());
@@ -379,8 +369,7 @@ public class FluoConfigurationTest {
     }
     String[] nonEmptyMethods =
         {"setAccumuloInstance", "setAccumuloTable", "setAccumuloUser", "setAccumuloZookeepers",
-            "setAdminClass", "setClientClass", "setMiniClass", "setMiniDataDir",
-            "setInstanceZookeepers", "setWorkerClass", "setOracleClass"};
+            "setMiniDataDir", "setInstanceZookeepers"};
     for (String methodName : nonEmptyMethods) {
       try {
         config.getClass().getMethod(methodName, String.class).invoke(config, "");


Mime
View raw message