From 13028d71576eebda3f5a831903e2a2e6d5f97ff4 Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Fri, 18 Aug 2017 22:25:14 -0400 Subject: [PATCH] HBASE-18631 Allow ChaosMonkey properties to be specified in hbase-site --- .../hadoop/hbase/IntegrationTestBase.java | 21 ++++++++ .../hadoop/hbase/TestIntegrationTestBase.java | 48 +++++++++++++++++++ .../chaos/factories/MonkeyConstants.java | 11 +++++ 3 files changed, 80 insertions(+) create mode 100644 hbase-it/src/test/java/org/apache/hadoop/hbase/TestIntegrationTestBase.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 d3433c75184..46f049045be 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 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); 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 00000000000..7330909c89c --- /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)); + } +} 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 452d903f101..5657d3962e8 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 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;