From fbfe3f29e5911146361e04f4514689e05257a491 Mon Sep 17 00:00:00 2001 From: Jonathan Hsieh Date: Thu, 29 Mar 2012 20:04:49 +0000 Subject: [PATCH] HBASE-5638 Readability improvements on HBASE-5633: NPE reading ZK config in HBase (Matteo Bertozzi) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1307085 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/hadoop/hbase/HConstants.java | 6 +++--- .../java/org/apache/hadoop/hbase/LocalHBaseCluster.java | 4 ++-- .../java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/HConstants.java b/src/main/java/org/apache/hadoop/hbase/HConstants.java index 07041b5dccb..21ac4bad171 100644 --- a/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -77,13 +77,13 @@ public final class HConstants { public static final String HBASE_MASTER_LOADBALANCER_CLASS = "hbase.master.loadbalancer.class"; /** Cluster is standalone or pseudo-distributed */ - public static final String CLUSTER_IS_LOCAL = "false"; + public static final boolean CLUSTER_IS_LOCAL = false; /** Cluster is fully-distributed */ - public static final String CLUSTER_IS_DISTRIBUTED = "true"; + public static final boolean CLUSTER_IS_DISTRIBUTED = true; /** Default value for cluster distributed mode */ - public static final String DEFAULT_CLUSTER_DISTRIBUTED = CLUSTER_IS_LOCAL; + public static final boolean DEFAULT_CLUSTER_DISTRIBUTED = CLUSTER_IS_LOCAL; /** default host address */ public static final String DEFAULT_HOST = "0.0.0.0"; diff --git a/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java b/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java index cc8a6897647..9c9c7cc4415 100644 --- a/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java +++ b/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java @@ -436,8 +436,8 @@ public class LocalHBaseCluster { * @return True if a 'local' address in hbase.master value. */ public static boolean isLocal(final Configuration c) { - final String mode = c.get(HConstants.CLUSTER_DISTRIBUTED); - return mode == null || mode.equals(HConstants.CLUSTER_IS_LOCAL); + boolean mode = c.getBoolean(HConstants.CLUSTER_DISTRIBUTED, HConstants.DEFAULT_CLUSTER_DISTRIBUTED); + return(mode == HConstants.CLUSTER_IS_LOCAL); } /** diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java index b6fef32ed5e..99c04bdc757 100644 --- a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java +++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java @@ -163,9 +163,8 @@ public class ZKConfig { } // Special case for 'hbase.cluster.distributed' property being 'true' if (key.startsWith("server.")) { - if (conf.get(HConstants.CLUSTER_DISTRIBUTED, HConstants.DEFAULT_CLUSTER_DISTRIBUTED). - equals(HConstants.CLUSTER_IS_DISTRIBUTED) - && value.startsWith(HConstants.LOCALHOST)) { + boolean mode = conf.getBoolean(HConstants.CLUSTER_DISTRIBUTED, HConstants.DEFAULT_CLUSTER_DISTRIBUTED); + if (mode == HConstants.CLUSTER_IS_DISTRIBUTED && value.startsWith(HConstants.LOCALHOST)) { String msg = "The server in zoo.cfg cannot be set to localhost " + "in a fully-distributed setup because it won't be reachable. " + "See \"Getting Started\" for more information.";