/** * Generates a {@link Configuration} instance by applying property overrides prefixed by * a cluster profile key to the base Configuration. Override properties are extracted by * the {@link #subset(Configuration, String)} method, then the merged on top of the base * Configuration and returned. * * @param baseConf the base configuration to use, containing prefixed override properties * @param clusterKey the ZooKeeper quorum cluster key to apply, or {@code null} if none * @param overridePrefix the property key prefix to match for override properties, * or {@code null} if none * @return the merged configuration with override properties and cluster key applied */ public static Configuration createClusterConf(Configuration baseConf, String clusterKey, String overridePrefix) throws IOException { Configuration clusterConf = HBaseConfiguration.create(baseConf); if (clusterKey != null && !clusterKey.isEmpty()) { applyClusterKeyToConf(clusterConf, clusterKey); } if (overridePrefix != null && !overridePrefix.isEmpty()) { Configuration clusterSubset = HBaseConfiguration.subset(clusterConf, overridePrefix); HBaseConfiguration.merge(clusterConf, clusterSubset); } return clusterConf; }
@Test public void testSubset() throws Exception { Configuration conf = HBaseConfiguration.create(); // subset is used in TableMapReduceUtil#initCredentials to support different security // configurations between source and destination clusters, so we'll use that as an example String prefix = "hbase.mapred.output."; conf.set("hbase.security.authentication", "kerberos"); conf.set("hbase.regionserver.kerberos.principal", "hbasesource"); HBaseConfiguration.setWithPrefix(conf, prefix, ImmutableMap.of( "hbase.regionserver.kerberos.principal", "hbasedest", "", "shouldbemissing") .entrySet()); Configuration subsetConf = HBaseConfiguration.subset(conf, prefix); assertNull(subsetConf.get(prefix + "hbase.regionserver.kerberos.principal")); assertEquals("hbasedest", subsetConf.get("hbase.regionserver.kerberos.principal")); assertNull(subsetConf.get("hbase.security.authentication")); assertNull(subsetConf.get("")); Configuration mergedConf = HBaseConfiguration.create(conf); HBaseConfiguration.merge(mergedConf, subsetConf); assertEquals("hbasedest", mergedConf.get("hbase.regionserver.kerberos.principal")); assertEquals("kerberos", mergedConf.get("hbase.security.authentication")); assertEquals("shouldbemissing", mergedConf.get(prefix)); }
/** * Generates a {@link Configuration} instance by applying property overrides prefixed by * a cluster profile key to the base Configuration. Override properties are extracted by * the {@link #subset(Configuration, String)} method, then the merged on top of the base * Configuration and returned. * * @param baseConf the base configuration to use, containing prefixed override properties * @param clusterKey the ZooKeeper quorum cluster key to apply, or {@code null} if none * @param overridePrefix the property key prefix to match for override properties, * or {@code null} if none * @return the merged configuration with override properties and cluster key applied */ public static Configuration createClusterConf(Configuration baseConf, String clusterKey, String overridePrefix) throws IOException { Configuration clusterConf = HBaseConfiguration.create(baseConf); if (clusterKey != null && !clusterKey.isEmpty()) { applyClusterKeyToConf(clusterConf, clusterKey); } if (overridePrefix != null && !overridePrefix.isEmpty()) { Configuration clusterSubset = HBaseConfiguration.subset(clusterConf, overridePrefix); HBaseConfiguration.merge(clusterConf, clusterSubset); } return clusterConf; }
/** * Generates a {@link Configuration} instance by applying property overrides prefixed by * a cluster profile key to the base Configuration. Override properties are extracted by * the {@link #subset(Configuration, String)} method, then the merged on top of the base * Configuration and returned. * * @param baseConf the base configuration to use, containing prefixed override properties * @param clusterKey the ZooKeeper quorum cluster key to apply, or {@code null} if none * @param overridePrefix the property key prefix to match for override properties, * or {@code null} if none * @return the merged configuration with override properties and cluster key applied */ public static Configuration createClusterConf(Configuration baseConf, String clusterKey, String overridePrefix) throws IOException { Configuration clusterConf = HBaseConfiguration.create(baseConf); if (clusterKey != null && !clusterKey.isEmpty()) { applyClusterKeyToConf(clusterConf, clusterKey); } if (overridePrefix != null && !overridePrefix.isEmpty()) { Configuration clusterSubset = HBaseConfiguration.subset(clusterConf, overridePrefix); HBaseConfiguration.merge(clusterConf, clusterSubset); } return clusterConf; }
/** * Generates a {@link Configuration} instance by applying property overrides prefixed by * a cluster profile key to the base Configuration. Override properties are extracted by * the {@link #subset(Configuration, String)} method, then the merged on top of the base * Configuration and returned. * * @param baseConf the base configuration to use, containing prefixed override properties * @param clusterKey the ZooKeeper quorum cluster key to apply, or {@code null} if none * @param overridePrefix the property key prefix to match for override properties, * or {@code null} if none * @return the merged configuration with override properties and cluster key applied */ public static Configuration createClusterConf(Configuration baseConf, String clusterKey, String overridePrefix) throws IOException { Configuration clusterConf = HBaseConfiguration.create(baseConf); if (clusterKey != null && !clusterKey.isEmpty()) { applyClusterKeyToConf(clusterConf, clusterKey); } if (overridePrefix != null && !overridePrefix.isEmpty()) { Configuration clusterSubset = HBaseConfiguration.subset(clusterConf, overridePrefix); HBaseConfiguration.merge(clusterConf, clusterSubset); } return clusterConf; }
@Test public void testSubset() throws Exception { Configuration conf = HBaseConfiguration.create(); // subset is used in TableMapReduceUtil#initCredentials to support different security // configurations between source and destination clusters, so we'll use that as an example String prefix = "hbase.mapred.output."; conf.set("hbase.security.authentication", "kerberos"); conf.set("hbase.regionserver.kerberos.principal", "hbasesource"); HBaseConfiguration.setWithPrefix(conf, prefix, ImmutableMap.of( "hbase.regionserver.kerberos.principal", "hbasedest", "", "shouldbemissing") .entrySet()); Configuration subsetConf = HBaseConfiguration.subset(conf, prefix); assertNull(subsetConf.get(prefix + "hbase.regionserver.kerberos.principal")); assertEquals("hbasedest", subsetConf.get("hbase.regionserver.kerberos.principal")); assertNull(subsetConf.get("hbase.security.authentication")); assertNull(subsetConf.get("")); Configuration mergedConf = HBaseConfiguration.create(conf); HBaseConfiguration.merge(mergedConf, subsetConf); assertEquals("hbasedest", mergedConf.get("hbase.regionserver.kerberos.principal")); assertEquals("kerberos", mergedConf.get("hbase.security.authentication")); assertEquals("shouldbemissing", mergedConf.get(prefix)); }
@Test public void testSubset() throws Exception { Configuration conf = HBaseConfiguration.create(); // subset is used in TableMapReduceUtil#initCredentials to support different security // configurations between source and destination clusters, so we'll use that as an example String prefix = "hbase.mapred.output."; conf.set("hbase.security.authentication", "kerberos"); conf.set("hbase.regionserver.kerberos.principal", "hbasesource"); HBaseConfiguration.setWithPrefix(conf, prefix, ImmutableMap.of( "hbase.regionserver.kerberos.principal", "hbasedest", "", "shouldbemissing") .entrySet()); Configuration subsetConf = HBaseConfiguration.subset(conf, prefix); assertNull(subsetConf.get(prefix + "hbase.regionserver.kerberos.principal")); assertEquals("hbasedest", subsetConf.get("hbase.regionserver.kerberos.principal")); assertNull(subsetConf.get("hbase.security.authentication")); assertNull(subsetConf.get("")); Configuration mergedConf = HBaseConfiguration.create(conf); HBaseConfiguration.merge(mergedConf, subsetConf); assertEquals("hbasedest", mergedConf.get("hbase.regionserver.kerberos.principal")); assertEquals("kerberos", mergedConf.get("hbase.security.authentication")); assertEquals("shouldbemissing", mergedConf.get(prefix)); }