hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1434541 - in /hbase/trunk: hbase-common/src/main/java/org/apache/hadoop/hbase/ hbase-common/src/test/java/org/apache/hadoop/hbase/ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ hbase-server/src/test/java/org/apache/hadoo...
Date Thu, 17 Jan 2013 02:29:03 GMT
Author: enis
Date: Thu Jan 17 02:29:03 2013
New Revision: 1434541

URL: http://svn.apache.org/viewvc?rev=1434541&view=rev
Log:
HBASE-7563. Move CompoundConfiguration to common and add string map support (Sergey Shelukhin).
Addendum commit for the moved files.

Added:
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java
      - copied, changed from r1434538, hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompoundConfiguration.java
    hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java
      - copied, changed from r1434538, hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundConfiguration.java
Removed:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompoundConfiguration.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundConfiguration.java

Copied: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java
(from r1434538, hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompoundConfiguration.java)
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java?p2=hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java&p1=hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompoundConfiguration.java&r1=1434538&r2=1434541&rev=1434541&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompoundConfiguration.java
(original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java
Thu Jan 17 02:29:03 2013
@@ -17,7 +17,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.hadoop.hbase.regionserver;
+package org.apache.hadoop.hbase;
 
 import java.io.DataInput;
 import java.io.DataOutput;
@@ -46,13 +46,9 @@ import org.apache.hadoop.util.StringUtil
  * configuration objects and have changes reflected everywhere. In contrast to a
  * deep merge, that requires you to explicitly know all applicable copies to
  * propagate changes.
- * <p>
- * This class is package private because we expect significant refactoring here
- * on the HBase side when certain HDFS changes are added & ubiquitous. Will
- * revisit expanding access at that point.
  */
 @InterfaceAudience.Private
-class CompoundConfiguration extends Configuration {
+public class CompoundConfiguration extends Configuration {
   /**
    * Default Constructor. Initializes empty configuration
    */
@@ -71,12 +67,9 @@ class CompoundConfiguration extends Conf
   protected List<ImmutableConfigMap> configs
     = new ArrayList<ImmutableConfigMap>();
 
-  /****************************************************************************
-   * These initial APIs actually required original thought
-   ***************************************************************************/
-
   /**
-   * Add Hadoop Configuration object to config list
+   * Add Hadoop Configuration object to config list.
+   * The added configuration overrides the previous ones if there are name collisions.
    * @param conf configuration object
    * @return this, for builder pattern
    */
@@ -121,13 +114,14 @@ class CompoundConfiguration extends Conf
   /**
    * Add ImmutableBytesWritable map to config list. This map is generally
    * created by HTableDescriptor or HColumnDescriptor, but can be abstractly
-   * used.
+   * used. The added configuration overrides the previous ones if there are
+   * name collisions.
    *
    * @param map
    *          ImmutableBytesWritable map
    * @return this, for builder pattern
    */
-  public CompoundConfiguration add(
+  public CompoundConfiguration addWritableMap(
       final Map<ImmutableBytesWritable, ImmutableBytesWritable> map) {
     // put new map at the front of the list (top priority)
     this.configs.add(0, new ImmutableConfigMap() {
@@ -158,7 +152,47 @@ class CompoundConfiguration extends Conf
 
       @Override
       public int size() {
-        // TODO Auto-generated method stub
+        return m.size();
+      }
+
+      @Override
+      public String toString() {
+        return m.toString();
+      }
+    });
+    return this;
+  }
+
+  /**
+   * Add String map to config list. This map is generally created by HTableDescriptor
+   * or HColumnDescriptor, but can be abstractly used. The added configuration
+   * overrides the previous ones if there are name collisions.
+   *
+   * @return this, for builder pattern
+   */
+  public CompoundConfiguration addStringMap(final Map<String, String> map) {
+    // put new map at the front of the list (top priority)
+    this.configs.add(0, new ImmutableConfigMap() {
+      Map<String, String> m = map;
+
+      @Override
+      public String get(String key) {
+        return m.get(key);
+      }
+
+      @Override
+      public String getRaw(String key) {
+        return get(key);
+      }
+
+      @Override
+      public Class<?> getClassByName(String name)
+      throws ClassNotFoundException {
+        return null;
+      }
+
+      @Override
+      public int size() {
         return m.size();
       }
 
@@ -205,14 +239,9 @@ class CompoundConfiguration extends Conf
   @Override
   public Class<?> getClassByName(String name) throws ClassNotFoundException {
     for (ImmutableConfigMap m : this.configs) {
-      try {
-        Class<?> value = m.getClassByName(name);
-        if (value != null) {
-          return value;
-        }
-      } catch (ClassNotFoundException e) {
-        // don't propagate an exception until all configs fail
-        continue;
+      Class<?> value = m.getClassByName(name);
+      if (value != null) {
+        return value;
       }
     }
     throw new ClassNotFoundException();

Copied: hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java
(from r1434538, hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundConfiguration.java)
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java?p2=hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java&p1=hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundConfiguration.java&r1=1434538&r2=1434541&rev=1434541&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundConfiguration.java
(original)
+++ hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java
Thu Jan 17 02:29:03 2013
@@ -17,14 +17,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.hadoop.hbase.regionserver;
+package org.apache.hadoop.hbase;
 
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.regionserver.CompoundConfiguration;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.SmallTests;
 
@@ -99,7 +98,7 @@ public class TestCompoundConfiguration e
 
     CompoundConfiguration compoundConf = new CompoundConfiguration()
       .add(baseConf)
-      .add(map);
+      .addWritableMap(map);
     assertEquals("1", compoundConf.get("A"));
     assertEquals("2b", compoundConf.get("B"));
     assertEquals(33, compoundConf.getInt("C", 0));
@@ -110,4 +109,41 @@ public class TestCompoundConfiguration e
     assertNull(compoundConf.get("G"));
   }
 
+  @Test
+  public void testWithStringMap() {
+    Map<String, String> map = new HashMap<String, String>();
+    map.put("B", "2b");
+    map.put("C", "33");
+    map.put("D", "4");
+    // unlike config, note that IBW Maps can accept null values
+    map.put("G", null);
+
+    CompoundConfiguration compoundConf = new CompoundConfiguration().addStringMap(map);
+    assertEquals("2b", compoundConf.get("B"));
+    assertEquals(33, compoundConf.getInt("C", 0));
+    assertEquals("4", compoundConf.get("D"));
+    assertEquals(4, compoundConf.getInt("D", 0));
+    assertNull(compoundConf.get("E"));
+    assertEquals(6, compoundConf.getInt("F", 6));
+    assertNull(compoundConf.get("G"));
+  }
+
+  @Test
+  public void testLaterConfigsOverrideEarlier() {
+    Map<String, String> map1 = new HashMap<String, String>();
+    map1.put("A", "2");
+    map1.put("D", "5");
+    Map<String, String> map2 = new HashMap<String, String>();
+    map2.put("A", "3");
+    map2.put("B", "4");
+
+    CompoundConfiguration compoundConf = new CompoundConfiguration()
+      .addStringMap(map1).add(baseConf);
+    assertEquals("1", compoundConf.get("A"));
+    assertEquals("5", compoundConf.get("D"));
+    compoundConf.addStringMap(map2);
+    assertEquals("3", compoundConf.get("A"));
+    assertEquals("4", compoundConf.get("B"));
+    assertEquals("5", compoundConf.get("D"));
+  }
 }



Mime
View raw message