You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2013/08/15 07:44:57 UTC

svn commit: r1514163 [1/2] - in /hbase/trunk: hbase-it/src/test/java/org/apache/hadoop/hbase/ hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/ hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ hbase-it/src/test/java/org/apache/hadoop/h...

Author: eclark
Date: Thu Aug 15 05:44:56 2013
New Revision: 1514163

URL: http://svn.apache.org/r1514163
Log:
HBASE-9193 Make what Chaos monkey actions run configurable per test.

Added:
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/Action.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/AddColumnAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/BatchRestartRsAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeEncodingAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeVersionsAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactRandomRegionOfTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushRandomRegionOfTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ForceBalancerAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MergeRandomAdjacentRegionsOfTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRandomRegionOfTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRegionsOfTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RemoveColumnAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActionBaseAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveMasterAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRandomRsAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingMetaAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RollingBatchRestartRsAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SplitRandomRegionOfTableAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceRegionsAction.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/CalmMonkeyFactory.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/MonkeyFactory.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/SlowDeterministicMonkeyFactory.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/factories/UnbalanceMonkeyFactory.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/CalmChaosMonkey.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/ChaosMonkey.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/policies/
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/policies/CompositeSequentialPolicy.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/policies/DoActionsOncePolicy.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/policies/PeriodicPolicy.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/policies/PeriodicRandomActionPolicy.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/policies/Policy.java
Removed:
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IngestIntegrationTestBase.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestSlowDeterministic.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestWithChaosMonkey.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestRebalanceAndKillServersTargeted.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedListWithChaosMonkey.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/util/ChaosMonkey.java
Modified:
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestManyRegions.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestBulkLoad.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestImportTsv.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/mttr/IntegrationTestMTTR.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedList.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestLoadAndVerify.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/util/LoadTestTool.java

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java?rev=1514163&r1=1514162&r2=1514163&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java (original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java Thu Aug 15 05:44:56 2013
@@ -20,6 +20,7 @@ package org.apache.hadoop.hbase;
 import java.io.IOException;
 import java.util.HashMap;
 
+import com.google.common.collect.Sets;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.ClusterManager.ServiceType;
@@ -35,8 +36,6 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Threads;
 
-import com.google.common.collect.Sets;
-
 /**
  * Manages the interactions with an already deployed distributed cluster (as opposed to
  * a pseudo-distributed, or mini/local cluster). This is used by integration and system tests.

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBase.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,121 @@
+/**
+ * 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 java.util.Set;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.chaos.factories.MonkeyFactory;
+import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
+import org.apache.hadoop.hbase.util.AbstractHBaseTool;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * Base class for HBase integration tests that want to use the Chaos Monkey.
+ */
+public abstract class IntegrationTestBase extends AbstractHBaseTool {
+  public static final String LONG_OPT = "monkey";
+
+  protected IntegrationTestingUtility util;
+  protected ChaosMonkey monkey;
+  protected String monkeyToUse;
+
+  public IntegrationTestBase() {
+    this(MonkeyFactory.CALM);
+  }
+
+  public IntegrationTestBase(String monkeyToUse) {
+    this.monkeyToUse = monkeyToUse;
+  }
+
+  @Override
+  protected void addOptions() {
+    addOptWithArg("m", LONG_OPT, "Which chaos monkey to run");
+  }
+
+  @Override
+  protected void processOptions(CommandLine cmd) {
+    if (cmd.hasOption(LONG_OPT)) {
+      monkeyToUse = cmd.getOptionValue(LONG_OPT);
+    }
+  }
+
+  @Override
+  public Configuration getConf() {
+    Configuration c = super.getConf();
+    if (c == null && util != null) {
+      conf = util.getConfiguration();
+      c = conf;
+    }
+    return c;
+  }
+
+  @Override
+  protected int doWork() throws Exception {
+    setUpMonkey();
+    setUp();
+    int result = -1;
+    try {
+      runTestFromCommandLine();
+    } finally {
+      cleanUpMonkey();
+      cleanUp();
+    }
+
+    return result;
+  }
+
+  @Before
+  public void setUpMonkey() throws Exception {
+    util = getTestingUtil(getConf());
+    MonkeyFactory fact = MonkeyFactory.getFactory(monkeyToUse);
+    monkey = fact.setUtil(util)
+                 .setTableName(getTablename())
+                 .setColumnFamilies(getColumnFamilies()).build();
+  }
+
+  @After
+  public void cleanUpMonkey() throws Exception {
+    monkey.stop("Ending test");
+    monkey.waitForStop();
+  }
+
+  protected IntegrationTestingUtility getTestingUtil(Configuration conf) {
+    if (this.util == null) {
+      if (conf == null) {
+        this.util = new IntegrationTestingUtility();
+      } else {
+        this.util = new IntegrationTestingUtility(conf);
+      }
+    }
+    return util;
+  }
+
+  public abstract void setUp() throws Exception;
+
+  public abstract void cleanUp()  throws Exception;
+
+  public abstract int runTestFromCommandLine() throws Exception;
+
+  public abstract String getTablename();
+
+  protected abstract Set<String> getColumnFamilies();
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestIngest.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,179 @@
+/**
+ * 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 java.io.IOException;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.LoadTestTool;
+import org.apache.hadoop.util.ToolRunner;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * A base class for tests that do something with the cluster while running
+ * {@link LoadTestTool} to write and verify some data.
+ */
+@Category(IntegrationTests.class)
+public class IntegrationTestIngest extends IntegrationTestBase {
+  private static final int SERVER_COUNT = 4; // number of slaves for the smallest cluster
+  private static final long DEFAULT_RUN_TIME = 20 * 60 * 1000;
+
+  protected static String tableName = null;
+
+  /** A soft limit on how long we should run */
+  private static final String RUN_TIME_KEY = "hbase.%s.runtime";
+
+  protected static final Log LOG = LogFactory.getLog(IntegrationTestIngest.class);
+  protected IntegrationTestingUtility util;
+  protected HBaseCluster cluster;
+  private LoadTestTool loadTool;
+
+  protected void setUp(int numSlavesBase) throws Exception {
+    tableName = this.getClass().getSimpleName();
+    util = getTestingUtil(null);
+    LOG.debug("Initializing/checking cluster has " + numSlavesBase + " servers");
+    util.initializeCluster(numSlavesBase);
+    LOG.debug("Done initializing/checking cluster");
+    cluster = util.getHBaseClusterInterface();
+    deleteTableIfNecessary();
+    loadTool = new LoadTestTool();
+    loadTool.setConf(util.getConfiguration());
+    // Initialize load test tool before we start breaking things;
+    // LoadTestTool init, even when it is a no-op, is very fragile.
+    int ret = loadTool.run(new String[] { "-tn", tableName, "-init_only" });
+    Assert.assertEquals("Failed to initialize LoadTestTool", 0, ret);
+  }
+
+  @Override
+  public void setUp() throws Exception {
+    setUp(SERVER_COUNT);
+  }
+
+  @Override
+  public void cleanUp() throws Exception {
+    LOG.debug("Restoring the cluster");
+    util.restoreCluster();
+    LOG.debug("Done restoring the cluster");
+  }
+
+  @Override
+  public int runTestFromCommandLine() throws Exception {
+    internalRunIngestTest();
+    return 0;
+  }
+
+  @Test
+  public void internalRunIngestTest() throws Exception {
+    runIngestTest(DEFAULT_RUN_TIME, 2500, 10, 1024, 10);
+  }
+
+  @Override
+  public String getTablename() {
+    return tableName;
+  }
+
+  @Override
+  protected Set<String> getColumnFamilies() {
+    return Sets.newHashSet(Bytes.toString(LoadTestTool.COLUMN_FAMILY));
+  }
+
+  private void deleteTableIfNecessary() throws IOException {
+    if (util.getHBaseAdmin().tableExists(tableName)) {
+      util.deleteTable(Bytes.toBytes(tableName));
+    }
+  }
+
+  protected void runIngestTest(long defaultRunTime, int keysPerServerPerIter,
+      int colsPerKey, int recordSize, int writeThreads) throws Exception {
+    LOG.info("Running ingest");
+    LOG.info("Cluster size:" + util.getHBaseClusterInterface().getClusterStatus().getServersSize());
+
+    long start = System.currentTimeMillis();
+    String runtimeKey = String.format(RUN_TIME_KEY, this.getClass().getSimpleName());
+    long runtime = util.getConfiguration().getLong(runtimeKey, defaultRunTime);
+    long startKey = 0;
+
+    long numKeys = getNumKeys(keysPerServerPerIter);
+    while (System.currentTimeMillis() - start < 0.9 * runtime) {
+      LOG.info("Intended run time: " + (runtime/60000) + " min, left:" +
+          ((runtime - (System.currentTimeMillis() - start))/60000) + " min");
+
+      int ret = loadTool.run(new String[] {
+          "-tn", tableName,
+          "-write", String.format("%d:%d:%d", colsPerKey, recordSize, writeThreads),
+          "-start_key", String.valueOf(startKey),
+          "-num_keys", String.valueOf(numKeys),
+          "-skip_init"
+      });
+      if (0 != ret) {
+        String errorMsg = "Load failed with error code " + ret;
+        LOG.error(errorMsg);
+        Assert.fail(errorMsg);
+      }
+
+      ret = loadTool.run(new String[] {
+          "-tn", tableName,
+          "-update", String.format("60:%d", writeThreads),
+          "-start_key", String.valueOf(startKey),
+          "-num_keys", String.valueOf(numKeys),
+          "-skip_init"
+      });
+      if (0 != ret) {
+        String errorMsg = "Update failed with error code " + ret;
+        LOG.error(errorMsg);
+        Assert.fail(errorMsg);
+      }
+
+      ret = loadTool.run(new String[] {
+          "-tn", tableName,
+          "-read", "100:20",
+          "-start_key", String.valueOf(startKey),
+          "-num_keys", String.valueOf(numKeys),
+          "-skip_init"
+      });
+      if (0 != ret) {
+        String errorMsg = "Verification failed with error code " + ret;
+        LOG.error(errorMsg);
+        Assert.fail(errorMsg);
+      }
+      startKey += numKeys;
+    }
+  }
+
+  /** Estimates a data size based on the cluster size */
+  private long getNumKeys(int keysPerServer)
+      throws IOException {
+    int numRegionServers = cluster.getClusterStatus().getServersSize();
+    return keysPerServer * numRegionServers;
+  }
+
+  public static void main(String[] args) throws Exception {
+    Configuration conf = HBaseConfiguration.create();
+    IntegrationTestingUtility.setUseDistributedCluster(conf);
+    int ret = ToolRunner.run(conf, new IntegrationTestIngest(), args);
+    System.exit(ret);
+  }
+}

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestManyRegions.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestManyRegions.java?rev=1514163&r1=1514162&r2=1514163&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestManyRegions.java (original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestManyRegions.java Thu Aug 15 05:44:56 2013
@@ -18,9 +18,6 @@
 
 package org.apache.hadoop.hbase;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.io.IOException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -35,6 +32,9 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 /**
  * An integration test to detect regressions in HBASE-7220. Create
  * a table with many regions and verify it completes within a

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java?rev=1514163&r1=1514162&r2=1514163&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java (original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestsDriver.java Thu Aug 15 05:44:56 2013
@@ -23,15 +23,14 @@ import java.util.Set;
 import java.util.regex.Pattern;
 
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.util.AbstractHBaseTool;
 import org.apache.hadoop.util.ToolRunner;
 import org.junit.internal.TextListener;
 import org.junit.runner.JUnitCore;
 import org.junit.runner.Result;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 /**
  * This class drives the Integration test suite execution. Executes all
  * tests having @Category(IntegrationTests.class) annotation against an

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/Action.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/Action.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/Action.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/Action.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,150 @@
+/**
+ * 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.chaos.actions;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.ClusterStatus;
+import org.apache.hadoop.hbase.HBaseCluster;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.IntegrationTestingUtility;
+import org.apache.hadoop.hbase.ServerLoad;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * A (possibly mischievous) action that the ChaosMonkey can perform.
+ */
+public class Action {
+
+  protected static Log LOG = LogFactory.getLog(Action.class);
+
+  protected ActionContext context;
+  protected HBaseCluster cluster;
+  protected ClusterStatus initialStatus;
+  protected ServerName[] initialServers;
+
+  public void init(ActionContext context) throws IOException {
+    this.context = context;
+    cluster = context.getHBaseCluster();
+    initialStatus = cluster.getInitialClusterStatus();
+    Collection<ServerName> regionServers = initialStatus.getServers();
+    initialServers = regionServers.toArray(new ServerName[regionServers.size()]);
+  }
+
+  public void perform() throws Exception { };
+
+  /** Returns current region servers */
+  protected ServerName[] getCurrentServers() throws IOException {
+    Collection<ServerName> regionServers = cluster.getClusterStatus().getServers();
+    if (regionServers == null || regionServers.size() <= 0) return new ServerName [] {};
+    return regionServers.toArray(new ServerName[regionServers.size()]);
+  }
+
+  protected void killMaster(ServerName server) throws IOException {
+    LOG.info("Killing master:" + server);
+    cluster.killMaster(server);
+    cluster.waitForMasterToStop(server, PolicyBasedChaosMonkey.TIMEOUT);
+    LOG.info("Killed master server:" + server);
+  }
+
+  protected void startMaster(ServerName server) throws IOException {
+    LOG.info("Starting master:" + server.getHostname());
+    cluster.startMaster(server.getHostname());
+    cluster.waitForActiveAndReadyMaster(PolicyBasedChaosMonkey.TIMEOUT);
+    LOG.info("Started master: " + server);
+  }
+
+  protected void killRs(ServerName server) throws IOException {
+    LOG.info("Killing region server:" + server);
+    cluster.killRegionServer(server);
+    cluster.waitForRegionServerToStop(server, PolicyBasedChaosMonkey.TIMEOUT);
+    LOG.info("Killed region server:" + server + ". Reported num of rs:"
+        + cluster.getClusterStatus().getServersSize());
+  }
+
+  protected void startRs(ServerName server) throws IOException {
+    LOG.info("Starting region server:" + server.getHostname());
+    cluster.startRegionServer(server.getHostname());
+    cluster.waitForRegionServerToStart(server.getHostname(), PolicyBasedChaosMonkey.TIMEOUT);
+    LOG.info("Started region server:" + server + ". Reported num of rs:"
+        + cluster.getClusterStatus().getServersSize());
+  }
+
+  protected void unbalanceRegions(ClusterStatus clusterStatus,
+      List<ServerName> fromServers, List<ServerName> toServers,
+      double fractionOfRegions) throws Exception {
+    List<byte[]> victimRegions = new LinkedList<byte[]>();
+    for (ServerName server : fromServers) {
+      ServerLoad serverLoad = clusterStatus.getLoad(server);
+      // Ugh.
+      List<byte[]> regions = new LinkedList<byte[]>(serverLoad.getRegionsLoad().keySet());
+      int victimRegionCount = (int)Math.ceil(fractionOfRegions * regions.size());
+      LOG.debug("Removing " + victimRegionCount + " regions from " + server.getServerName());
+      for (int i = 0; i < victimRegionCount; ++i) {
+        int victimIx = RandomUtils.nextInt(regions.size());
+        String regionId = HRegionInfo.encodeRegionName(regions.remove(victimIx));
+        victimRegions.add(Bytes.toBytes(regionId));
+      }
+    }
+
+    LOG.info("Moving " + victimRegions.size() + " regions from " + fromServers.size()
+        + " servers to " + toServers.size() + " different servers");
+    HBaseAdmin admin = this.context.getHaseIntegrationTestingUtility().getHBaseAdmin();
+    for (byte[] victimRegion : victimRegions) {
+      int targetIx = RandomUtils.nextInt(toServers.size());
+      admin.move(victimRegion, Bytes.toBytes(toServers.get(targetIx).getServerName()));
+    }
+  }
+
+  protected void forceBalancer() throws Exception {
+    HBaseAdmin admin = this.context.getHaseIntegrationTestingUtility().getHBaseAdmin();
+    boolean result = admin.balancer();
+    if (!result) {
+      LOG.error("Balancer didn't succeed");
+    }
+  }
+
+  /**
+   * Context for Action's
+   */
+  public static class ActionContext {
+    private IntegrationTestingUtility util;
+
+    public ActionContext(IntegrationTestingUtility util) {
+      this.util = util;
+    }
+
+    public IntegrationTestingUtility getHaseIntegrationTestingUtility() {
+      return util;
+    }
+
+    public HBaseCluster getHBaseCluster() {
+      return util.getHBaseClusterInterface();
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/AddColumnAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/AddColumnAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/AddColumnAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/AddColumnAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,62 @@
+/**
+ * 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.chaos.actions;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * Action the adds a column family to a table.
+ */
+public class AddColumnAction extends Action {
+  private final Random random;
+  private final byte[] tableName;
+  private HBaseAdmin admin;
+
+  public AddColumnAction(String tableName) {
+    this.tableName = Bytes.toBytes(tableName);
+    this.random = new Random();
+  }
+
+  @Override
+  public void init(ActionContext context) throws IOException {
+    super.init(context);
+    this.admin = context.getHaseIntegrationTestingUtility().getHBaseAdmin();
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
+    HColumnDescriptor columnDescriptor = null;
+
+    while(columnDescriptor == null ||
+        tableDescriptor.getFamily(columnDescriptor.getName()) != null) {
+      columnDescriptor = new HColumnDescriptor(RandomStringUtils.randomAlphabetic(5));
+    }
+
+    tableDescriptor.addFamily(columnDescriptor);
+    admin.modifyTable(tableName, tableDescriptor);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/BatchRestartRsAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/BatchRestartRsAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/BatchRestartRsAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/BatchRestartRsAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,69 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.List;
+
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+
+/**
+ * Restarts a ratio of the running regionservers at the same time
+ */
+public class BatchRestartRsAction extends RestartActionBaseAction {
+  float ratio; //ratio of regionservers to restart
+
+  public BatchRestartRsAction(long sleepTime, float ratio) {
+    super(sleepTime);
+    this.ratio = ratio;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    LOG.info(String.format("Performing action: Batch restarting %d%% of region servers",
+        (int)(ratio * 100)));
+    List<ServerName> selectedServers = PolicyBasedChaosMonkey.selectRandomItems(getCurrentServers(),
+        ratio);
+
+    for (ServerName server : selectedServers) {
+      LOG.info("Killing region server:" + server);
+      cluster.killRegionServer(server);
+    }
+
+    for (ServerName server : selectedServers) {
+      cluster.waitForRegionServerToStop(server, PolicyBasedChaosMonkey.TIMEOUT);
+    }
+
+    LOG.info("Killed " + selectedServers.size() + " region servers. Reported num of rs:"
+        + cluster.getClusterStatus().getServersSize());
+
+    sleep(sleepTime);
+
+    for (ServerName server : selectedServers) {
+      LOG.info("Starting region server:" + server.getHostname());
+      cluster.startRegionServer(server.getHostname());
+
+    }
+    for (ServerName server : selectedServers) {
+      cluster.waitForRegionServerToStart(server.getHostname(), PolicyBasedChaosMonkey.TIMEOUT);
+    }
+    LOG.info("Started " + selectedServers.size() +" region servers. Reported num of rs:"
+        + cluster.getClusterStatus().getServersSize());
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeEncodingAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeEncodingAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeEncodingAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeEncodingAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,68 @@
+/**
+ * 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.chaos.actions;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * Action that changes the encoding on a column family from a list of tables.
+ */
+public class ChangeEncodingAction extends Action {
+  private final byte[] tableName;
+
+  private HBaseAdmin admin;
+  private Random random;
+
+  public ChangeEncodingAction(String tableName) {
+    this.tableName = Bytes.toBytes(tableName);
+    this.random = new Random();
+  }
+
+  @Override
+  public void init(ActionContext context) throws IOException {
+    super.init(context);
+    this.admin = context.getHaseIntegrationTestingUtility().getHBaseAdmin();
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
+    HColumnDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();
+
+    if (columnDescriptors == null || columnDescriptors.length == 0) {
+      return;
+    }
+
+    // possible DataBlockEncoding id's
+    int[] possibleIds = {0, 2, 3, 4, 6};
+    for (HColumnDescriptor descriptor : columnDescriptors) {
+      short id = (short) possibleIds[random.nextInt(possibleIds.length)];
+      descriptor.setDataBlockEncoding(DataBlockEncoding.getEncodingById(id));
+    }
+
+    admin.modifyTable(tableName, tableDescriptor);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeVersionsAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeVersionsAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeVersionsAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ChangeVersionsAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,68 @@
+/**
+ * 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.chaos.actions;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * Action that changes the number of versions on a column family from a list of tables.
+ *
+ * Always keeps at least 1 as the number of versions.
+ */
+public class ChangeVersionsAction extends Action {
+  private final byte[] tableName;
+
+  private HBaseAdmin admin;
+  private Random random;
+
+  public ChangeVersionsAction(String tableName) {
+    this.tableName = Bytes.toBytes(tableName);
+    this.random = new Random();
+  }
+
+  @Override
+  public void init(ActionContext context) throws IOException {
+    super.init(context);
+    this.admin = context.getHaseIntegrationTestingUtility().getHBaseAdmin();
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
+    HColumnDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();
+
+    if ( columnDescriptors == null || columnDescriptors.length == 0) {
+      return;
+    }
+
+    int versions =  random.nextInt(3) + 1;
+    for(HColumnDescriptor descriptor:columnDescriptors) {
+      descriptor.setMaxVersions(versions);
+      descriptor.setMinVersions(versions);
+    }
+
+    admin.modifyTable(tableName, tableDescriptor);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactRandomRegionOfTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactRandomRegionOfTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactRandomRegionOfTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactRandomRegionOfTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,75 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.List;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * Region that queues a compaction of a random region from the table.
+ */
+public class CompactRandomRegionOfTableAction extends Action {
+  private final byte[] tableNameBytes;
+  private final int majorRatio;
+  private final long sleepTime;
+  private final String tableName;
+
+  public CompactRandomRegionOfTableAction(
+      String tableName, float majorRatio) {
+    this(-1, tableName, majorRatio);
+  }
+
+  public CompactRandomRegionOfTableAction(
+      int sleepTime, String tableName, float majorRatio) {
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.majorRatio = (int) (100 * majorRatio);
+    this.sleepTime = sleepTime;
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    HBaseAdmin admin = util.getHBaseAdmin();
+    List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+    boolean major = RandomUtils.nextInt(100) < majorRatio;
+
+    LOG.info("Performing action: Compact random region of table "
+      + tableName + ", major=" + major);
+    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+
+    if (major) {
+      LOG.debug("Major compacting region " + region.getRegionNameAsString());
+      admin.majorCompact(region.getRegionName());
+    } else {
+      LOG.debug("Compacting region " + region.getRegionNameAsString());
+      admin.compact(region.getRegionName());
+    }
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,63 @@
+/**
+ * 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.chaos.actions;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+* Created by eclark on 8/12/13.
+*/
+public class CompactTableAction extends Action {
+  private final byte[] tableNameBytes;
+  private final int majorRatio;
+  private final long sleepTime;
+  private final String tableName;
+
+  public CompactTableAction(String tableName, float majorRatio) {
+    this(-1, tableName, majorRatio);
+  }
+
+  public CompactTableAction(
+      int sleepTime, String tableName, float majorRatio) {
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.majorRatio = (int) (100 * majorRatio);
+    this.sleepTime = sleepTime;
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    HBaseAdmin admin = util.getHBaseAdmin();
+    boolean major = RandomUtils.nextInt(100) < majorRatio;
+
+    LOG.info("Performing action: Compact table " + tableName + ", major=" + major);
+    if (major) {
+      admin.majorCompact(tableNameBytes);
+    } else {
+      admin.compact(tableNameBytes);
+    }
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushRandomRegionOfTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushRandomRegionOfTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushRandomRegionOfTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushRandomRegionOfTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,62 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.List;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+* Action that tries to flush a random region of a table.
+*/
+public class FlushRandomRegionOfTableAction extends Action {
+  private final byte[] tableNameBytes;
+  private final long sleepTime;
+  private final String tableName;
+
+  public FlushRandomRegionOfTableAction(String tableName) {
+   this (-1, tableName);
+  }
+
+  public FlushRandomRegionOfTableAction(int sleepTime, String tableName) {
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.sleepTime = sleepTime;
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    HBaseAdmin admin = util.getHBaseAdmin();
+
+    LOG.info("Performing action: Flush random region of table " + tableName);
+    List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+    LOG.debug("Flushing region " + region.getRegionNameAsString());
+    admin.flush(region.getRegionName());
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/FlushTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,54 @@
+/**
+ * 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.chaos.actions;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+* Action that tries to flush a table.
+*/
+public class FlushTableAction extends Action {
+  private final byte[] tableNameBytes;
+  private final long sleepTime;
+  private final String tableName;
+
+  public FlushTableAction(String tableName) {
+    this(-1, tableName);
+  }
+
+  public FlushTableAction(int sleepTime, String tableName) {
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.sleepTime = sleepTime;
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    HBaseAdmin admin = util.getHBaseAdmin();
+
+    LOG.info("Performing action: Flush table " + tableName);
+    admin.flush(tableNameBytes);
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ForceBalancerAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ForceBalancerAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ForceBalancerAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/ForceBalancerAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,30 @@
+/**
+ * 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.chaos.actions;
+
+/**
+* Action that tries to force a balancer run.
+*/
+public class ForceBalancerAction extends Action {
+  @Override
+  public void perform() throws Exception {
+    LOG.info("Balancing regions");
+    forceBalancer();
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MergeRandomAdjacentRegionsOfTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MergeRandomAdjacentRegionsOfTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MergeRandomAdjacentRegionsOfTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MergeRandomAdjacentRegionsOfTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,68 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.List;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * Action to merge regions of a table.
+ */
+public class MergeRandomAdjacentRegionsOfTableAction extends Action {
+  private final byte[] tableNameBytes;
+  private final String tableName;
+  private final long sleepTime;
+
+  public MergeRandomAdjacentRegionsOfTableAction(String tableName) {
+    this(-1, tableName);
+  }
+
+  public MergeRandomAdjacentRegionsOfTableAction(int sleepTime, String tableName) {
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.tableName = tableName;
+    this.sleepTime = sleepTime;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    HBaseAdmin admin = util.getHBaseAdmin();
+
+    LOG.info("Performing action: Merge random adjacent regions of table " + tableName);
+    List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+    if (regions.size() < 2) {
+      LOG.info("Table " + tableName + " doesn't have enough region to merge");
+      return;
+    }
+
+    int i = RandomUtils.nextInt(regions.size() - 1);
+    HRegionInfo a = regions.get(i++);
+    HRegionInfo b = regions.get(i);
+    LOG.debug("Merging " + a.getRegionNameAsString() + " and " + b.getRegionNameAsString());
+    admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRandomRegionOfTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRandomRegionOfTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRandomRegionOfTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRandomRegionOfTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,62 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.List;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+* Action that tries to move a random region of a table.
+*/
+public class MoveRandomRegionOfTableAction extends Action {
+  private final long sleepTime;
+  private final byte[] tableNameBytes;
+  private final String tableName;
+
+  public MoveRandomRegionOfTableAction(String tableName) {
+    this(-1, tableName);
+  }
+
+  public MoveRandomRegionOfTableAction(long sleepTime, String tableName) {
+    this.sleepTime = sleepTime;
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    HBaseAdmin admin = util.getHBaseAdmin();
+
+    LOG.info("Performing action: Move random region of table " + tableName);
+    List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+    LOG.debug("Unassigning region " + region.getRegionNameAsString());
+    admin.unassign(region.getRegionName(), false);
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRegionsOfTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRegionsOfTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRegionsOfTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/MoveRegionsOfTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,71 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+* Action that tries to move every region of a table.
+*/
+public class MoveRegionsOfTableAction extends Action {
+  private final long sleepTime;
+  private final byte[] tableNameBytes;
+  private final String tableName;
+
+  public MoveRegionsOfTableAction(String tableName) {
+    this(-1, tableName);
+  }
+
+  public MoveRegionsOfTableAction(long sleepTime, String tableName) {
+    this.sleepTime = sleepTime;
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseAdmin admin = this.context.getHaseIntegrationTestingUtility().getHBaseAdmin();
+
+    List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+    Collection<ServerName> serversList = admin.getClusterStatus().getServers();
+    ServerName[] servers = serversList.toArray(new ServerName[serversList.size()]);
+
+    LOG.info("Performing action: Move regions of table " + tableName);
+    for (HRegionInfo regionInfo:regions) {
+      try {
+        String destServerName =
+          servers[RandomUtils.nextInt(servers.length)].getServerName();
+        LOG.debug("Moving " + regionInfo.getRegionNameAsString() + " to " + destServerName);
+        admin.move(regionInfo.getRegionName(), Bytes.toBytes(destServerName));
+      } catch (Exception e) {
+        LOG.debug("Error moving region", e);
+      }
+    }
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RemoveColumnAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RemoveColumnAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RemoveColumnAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RemoveColumnAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,69 @@
+/**
+ * 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.chaos.actions;
+
+import java.io.IOException;
+import java.util.Random;
+import java.util.Set;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * Action that removes a column family.
+ */
+public class RemoveColumnAction extends Action {
+  private final byte[] tableName;
+  private final Set<String> protectedColumns;
+  private HBaseAdmin admin;
+  private Random random;
+
+  public RemoveColumnAction(String tableName, Set<String> protectedColumns) {
+    this.tableName = Bytes.toBytes(tableName);
+    this.protectedColumns = protectedColumns;
+    random = new Random();
+  }
+
+  @Override
+  public void init(ActionContext context) throws IOException {
+    super.init(context);
+    this.admin = context.getHaseIntegrationTestingUtility().getHBaseAdmin();
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
+    HColumnDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();
+
+    if (columnDescriptors.length <= 1) {
+      return;
+    }
+
+    int index = random.nextInt(columnDescriptors.length);
+    while(protectedColumns.contains(columnDescriptors[index].getNameAsString())) {
+      index = random.nextInt(columnDescriptors.length);
+    }
+
+    tableDescriptor.removeFamily(columnDescriptors[index].getName());
+
+    admin.modifyTable(tableName, tableDescriptor);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActionBaseAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActionBaseAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActionBaseAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActionBaseAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,54 @@
+/**
+ * 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.chaos.actions;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.util.Threads;
+
+/**
+* Base class for restarting HBaseServer's
+*/
+public class RestartActionBaseAction extends Action {
+  long sleepTime; // how long should we sleep
+
+  public RestartActionBaseAction(long sleepTime) {
+    this.sleepTime = sleepTime;
+  }
+
+  void sleep(long sleepTime) {
+    LOG.info("Sleeping for:" + sleepTime);
+    Threads.sleep(sleepTime);
+  }
+
+  void restartMaster(ServerName server, long sleepTime) throws IOException {
+    sleepTime = Math.max(sleepTime, 1000);
+    killMaster(server);
+    sleep(sleepTime);
+    startMaster(server);
+  }
+
+  void restartRs(ServerName server, long sleepTime) throws IOException {
+    sleepTime = Math.max(sleepTime, 1000);
+    killRs(server);
+    sleep(sleepTime);
+    startRs(server);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveMasterAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveMasterAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveMasterAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveMasterAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,37 @@
+/**
+ * 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.chaos.actions;
+
+import org.apache.hadoop.hbase.ServerName;
+
+/**
+* Action that tries to restart the active master.
+*/
+public class RestartActiveMasterAction extends RestartActionBaseAction {
+  public RestartActiveMasterAction(long sleepTime) {
+    super(sleepTime);
+  }
+  @Override
+  public void perform() throws Exception {
+    LOG.info("Performing action: Restart active master");
+
+    ServerName master = cluster.getClusterStatus().getMaster();
+    restartMaster(master, sleepTime);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRandomRsAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRandomRsAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRandomRsAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRandomRsAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,39 @@
+/**
+ * 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.chaos.actions;
+
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+
+/**
+* Created by eclark on 8/12/13.
+*/
+public class RestartRandomRsAction extends RestartActionBaseAction {
+  public RestartRandomRsAction(long sleepTime) {
+    super(sleepTime);
+  }
+
+  @Override
+  public void perform() throws Exception {
+    LOG.info("Performing action: Restart random region server");
+    ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
+
+    restartRs(server, sleepTime);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingMetaAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingMetaAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingMetaAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingMetaAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,40 @@
+/**
+ * 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.chaos.actions;
+
+import org.apache.hadoop.hbase.ServerName;
+
+/**
+* Action that tries to restart the HRegionServer holding Meta.
+*/
+public class RestartRsHoldingMetaAction extends RestartActionBaseAction {
+  public RestartRsHoldingMetaAction(long sleepTime) {
+    super(sleepTime);
+  }
+  @Override
+  public void perform() throws Exception {
+    LOG.info("Performing action: Restart region server holding META");
+    ServerName server = cluster.getServerHoldingMeta();
+    if (server == null) {
+      LOG.warn("No server is holding .META. right now.");
+      return;
+    }
+    restartRs(server, sleepTime);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartRsHoldingTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,57 @@
+/**
+ * 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.chaos.actions;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.client.HTable;
+
+/**
+* Action that restarts an HRegionServer holding one of the regions of the table.
+*/
+public class RestartRsHoldingTableAction extends RestartActionBaseAction {
+
+  private final String tableName;
+
+  public RestartRsHoldingTableAction(long sleepTime, String tableName) {
+    super(sleepTime);
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HTable table = null;
+    try {
+      Configuration conf = context.getHaseIntegrationTestingUtility().getConfiguration();
+      table = new HTable(conf, tableName);
+    } catch (IOException e) {
+      LOG.debug("Error creating HTable used to get list of region locations.", e);
+      return;
+    }
+
+    Collection<ServerName> serverNames = table.getRegionLocations().values();
+    ServerName[] nameArray = serverNames.toArray(new ServerName[serverNames.size()]);
+
+    restartRs(nameArray[RandomUtils.nextInt(nameArray.length)], sleepTime);
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RollingBatchRestartRsAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RollingBatchRestartRsAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RollingBatchRestartRsAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RollingBatchRestartRsAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,70 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+
+/**
+ * Restarts a ratio of the regionservers in a rolling fashion. At each step, either kills a
+ * server, or starts one, sleeping randomly (0-sleepTime) in between steps.
+ */
+public class RollingBatchRestartRsAction extends BatchRestartRsAction {
+  public RollingBatchRestartRsAction(long sleepTime, float ratio) {
+    super(sleepTime, ratio);
+  }
+
+  @Override
+  public void perform() throws Exception {
+    LOG.info(String.format("Performing action: Rolling batch restarting %d%% of region servers",
+        (int)(ratio * 100)));
+    List<ServerName> selectedServers = PolicyBasedChaosMonkey.selectRandomItems(getCurrentServers(),
+        ratio);
+
+    Queue<ServerName> serversToBeKilled = new LinkedList<ServerName>(selectedServers);
+    Queue<ServerName> deadServers = new LinkedList<ServerName>();
+
+    //
+    while (!serversToBeKilled.isEmpty() || !deadServers.isEmpty()) {
+      boolean action = true; //action true = kill server, false = start server
+
+      if (serversToBeKilled.isEmpty() || deadServers.isEmpty()) {
+        action = deadServers.isEmpty();
+      } else {
+        action = RandomUtils.nextBoolean();
+      }
+
+      if (action) {
+        ServerName server = serversToBeKilled.remove();
+        killRs(server);
+        deadServers.add(server);
+      } else {
+        ServerName server = deadServers.remove();
+        startRs(server);
+      }
+
+      sleep(RandomUtils.nextInt((int)sleepTime));
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SnapshotTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,52 @@
+/**
+ * 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.chaos.actions;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+
+/**
+* Action that tries to take a snapshot of a table.
+*/
+public class SnapshotTableAction extends Action {
+  private final String tableName;
+  private final long sleepTime;
+
+  public SnapshotTableAction(String tableName) {
+    this(-1, tableName);
+  }
+
+  public SnapshotTableAction(int sleepTime, String tableName) {
+    this.tableName = tableName;
+    this.sleepTime = sleepTime;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    String snapshotName = tableName + "-it-" + System.currentTimeMillis();
+    HBaseAdmin admin = util.getHBaseAdmin();
+
+    LOG.info("Performing action: Snapshot table " + tableName);
+    admin.snapshot(snapshotName, tableName);
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SplitRandomRegionOfTableAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SplitRandomRegionOfTableAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SplitRandomRegionOfTableAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/SplitRandomRegionOfTableAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,62 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.List;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+* Action that tries to split a random region of a table.
+*/
+public class SplitRandomRegionOfTableAction extends Action {
+  private final byte[] tableNameBytes;
+  private final long sleepTime;
+  private final String tableName;
+
+  public SplitRandomRegionOfTableAction(String tableName) {
+    this(-1, tableName);
+  }
+
+  public SplitRandomRegionOfTableAction(int sleepTime, String tableName) {
+    this.tableNameBytes = Bytes.toBytes(tableName);
+    this.sleepTime = sleepTime;
+    this.tableName = tableName;
+  }
+
+  @Override
+  public void perform() throws Exception {
+    HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+    HBaseAdmin admin = util.getHBaseAdmin();
+
+    LOG.info("Performing action: Split random region of table " + tableName);
+    List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+    HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+    LOG.debug("Splitting region " + region.getRegionNameAsString());
+    admin.split(region.getRegionName());
+    if (sleepTime > 0) {
+      Thread.sleep(sleepTime);
+    }
+  }
+}

Added: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java?rev=1514163&view=auto
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java (added)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/UnbalanceKillAndRebalanceAction.java Thu Aug 15 05:44:56 2013
@@ -0,0 +1,67 @@
+/**
+ * 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.chaos.actions;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.lang.math.RandomUtils;
+import org.apache.hadoop.hbase.ClusterStatus;
+import org.apache.hadoop.hbase.ServerName;
+import org.junit.Assert;
+
+/** This action is too specific to put in ChaosMonkey; put it here */
+public class UnbalanceKillAndRebalanceAction extends Action {
+  /** Fractions of servers to get regions and live and die respectively; from all other
+   * servers, HOARD_FRC_OF_REGIONS will be removed to the above randomly */
+  private static final double FRC_SERVERS_THAT_HOARD_AND_LIVE = 0.1;
+  private static final double FRC_SERVERS_THAT_HOARD_AND_DIE = 0.1;
+  private static final double HOARD_FRC_OF_REGIONS = 0.8;
+  /** Waits between calling unbalance and killing servers, kills and rebalance, and rebalance
+   * and restarting the servers; to make sure these events have time to impact the cluster. */
+  private static final long WAIT_FOR_UNBALANCE_MS = 2 * 1000;
+  private static final long WAIT_FOR_KILLS_MS = 2 * 1000;
+  private static final long WAIT_AFTER_BALANCE_MS = 5 * 1000;
+
+  @Override
+  public void perform() throws Exception {
+    ClusterStatus status = this.cluster.getClusterStatus();
+    List<ServerName> victimServers = new LinkedList<ServerName>(status.getServers());
+    int liveCount = (int)Math.ceil(FRC_SERVERS_THAT_HOARD_AND_LIVE * victimServers.size());
+    int deadCount = (int)Math.ceil(FRC_SERVERS_THAT_HOARD_AND_DIE * victimServers.size());
+    Assert.assertTrue((liveCount + deadCount) < victimServers.size());
+    List<ServerName> targetServers = new ArrayList<ServerName>(liveCount);
+    for (int i = 0; i < liveCount + deadCount; ++i) {
+      int victimIx = RandomUtils.nextInt(victimServers.size());
+      targetServers.add(victimServers.remove(victimIx));
+    }
+    unbalanceRegions(status, victimServers, targetServers, HOARD_FRC_OF_REGIONS);
+    Thread.sleep(WAIT_FOR_UNBALANCE_MS);
+    for (int i = 0; i < liveCount; ++i) {
+      killRs(targetServers.get(i));
+    }
+    Thread.sleep(WAIT_FOR_KILLS_MS);
+    forceBalancer();
+    Thread.sleep(WAIT_AFTER_BALANCE_MS);
+    for (int i = 0; i < liveCount; ++i) {
+      startRs(targetServers.get(i));
+    }
+  }
+}