HBASE-18631 Allow ChaosMonkey properties to be specified in hbase-site
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/13028d71 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/13028d71 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/13028d71 Branch: refs/heads/HBASE-18467 Commit: 13028d71576eebda3f5a831903e2a2e6d5f97ff4 Parents: b932d38 Author: Josh Elser <els...@apache.org> Authored: Fri Aug 18 22:25:14 2017 -0400 Committer: Josh Elser <els...@apache.org> Committed: Sun Aug 20 14:51:32 2017 -0400 ---------------------------------------------------------------------- .../hadoop/hbase/IntegrationTestBase.java | 21 +++++++++ .../hadoop/hbase/TestIntegrationTestBase.java | 48 ++++++++++++++++++++ .../hbase/chaos/factories/MonkeyConstants.java | 11 +++++ 3 files changed, 80 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/13028d71/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java ---------------------------------------------------------------------- diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java index d3433c7..46f0490 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase; import java.io.IOException; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; @@ -27,6 +28,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.chaos.factories.MonkeyConstants; import org.apache.hadoop.hbase.chaos.factories.MonkeyFactory; import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey; import org.apache.hadoop.hbase.util.AbstractHBaseTool; @@ -86,6 +88,10 @@ public abstract class IntegrationTestBase extends AbstractHBaseTool { noClusterCleanUp = true; } monkeyProps = new Properties(); + // Add entries for the CM from hbase-site.xml as a convenience. + // Do this prior to loading from the properties file to make sure those in the properties + // file are given precedence to those in hbase-site.xml (backwards compatibility). + loadMonkeyProperties(monkeyProps, HBaseConfiguration.create()); if (cmd.hasOption(CHAOS_MONKEY_PROPS)) { String chaosMonkeyPropsFile = cmd.getOptionValue(CHAOS_MONKEY_PROPS); if (StringUtils.isNotEmpty(chaosMonkeyPropsFile)) { @@ -100,6 +106,21 @@ public abstract class IntegrationTestBase extends AbstractHBaseTool { } } + /** + * Loads entries from the provided {@code conf} into {@code props} when the configuration key + * is one that may be configuring ChaosMonkey actions. + */ + void loadMonkeyProperties(Properties props, Configuration conf) { + for (Entry<String,String> entry : conf) { + for (String prefix : MonkeyConstants.MONKEY_CONFIGURATION_KEY_PREFIXES) { + if (entry.getKey().startsWith(prefix)) { + props.put(entry.getKey(), entry.getValue()); + break; + } + } + } + } + @Override protected void processOptions(CommandLine cmd) { processBaseOptions(cmd); http://git-wip-us.apache.org/repos/asf/hbase/blob/13028d71/hbase-it/src/test/java/org/apache/hadoop/hbase/TestIntegrationTestBase.java ---------------------------------------------------------------------- diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/TestIntegrationTestBase.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/TestIntegrationTestBase.java new file mode 100644 index 0000000..7330909 --- /dev/null +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/TestIntegrationTestBase.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase; + +import static org.junit.Assert.assertEquals; + +import java.util.Properties; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.chaos.factories.MonkeyConstants; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(SmallTests.class) +public class TestIntegrationTestBase { + + @Test + public void testMonkeyPropertiesParsing() { + final Configuration conf = new Configuration(false); + conf.set(MonkeyConstants.BATCH_RESTART_RS_RATIO, "0.85"); + conf.set(MonkeyConstants.MOVE_REGIONS_MAX_TIME, "60000"); + conf.set("hbase.rootdir", "/foo/bar/baz"); + + final Properties props = new Properties(); + IntegrationTestBase testBase = new IntegrationTestDDLMasterFailover(); + assertEquals(0, props.size()); + testBase.loadMonkeyProperties(props, conf); + assertEquals(2, props.size()); + assertEquals("0.85", props.getProperty(MonkeyConstants.BATCH_RESTART_RS_RATIO)); + assertEquals("60000", props.getProperty(MonkeyConstants.MOVE_REGIONS_MAX_TIME)); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/13028d71/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java ---------------------------------------------------------------------- diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java index 452d903..5657d39 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyConstants.java @@ -17,6 +17,10 @@ */ package org.apache.hadoop.hbase.chaos.factories; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + public interface MonkeyConstants { String PERIODIC_ACTION1_PERIOD = "sdm.action1.period"; @@ -42,6 +46,13 @@ public interface MonkeyConstants { String UNBALANCE_KILL_META_RS = "unbalance.action.kill.meta.rs"; String DECREASE_HFILE_SIZE_SLEEP_TIME = "decrease.hfile.size.sleep.time"; + /** + * A Set of prefixes which encompasses all of the configuration properties for the ChaosMonky. + */ + Set<String> MONKEY_CONFIGURATION_KEY_PREFIXES = new HashSet<>( + Arrays.asList("sdm.", "move.", "restart.", "batch.", "rolling.", "compact.", + "unbalance.", "decrease.")); + long DEFAULT_PERIODIC_ACTION1_PERIOD = 60 * 1000; long DEFAULT_PERIODIC_ACTION2_PERIOD = 90 * 1000; long DEFAULT_PERIODIC_ACTION4_PERIOD = 90 * 1000;