001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.chaos.factories;
019
020import org.apache.hadoop.hbase.chaos.actions.Action;
021import org.apache.hadoop.hbase.chaos.actions.AddColumnAction;
022import org.apache.hadoop.hbase.chaos.actions.BatchRestartRsAction;
023import org.apache.hadoop.hbase.chaos.actions.ChangeSplitPolicyAction;
024import org.apache.hadoop.hbase.chaos.actions.CompactRandomRegionOfTableAction;
025import org.apache.hadoop.hbase.chaos.actions.CompactTableAction;
026import org.apache.hadoop.hbase.chaos.actions.DecreaseMaxHFileSizeAction;
027import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction;
028import org.apache.hadoop.hbase.chaos.actions.FlushRandomRegionOfTableAction;
029import org.apache.hadoop.hbase.chaos.actions.FlushTableAction;
030import org.apache.hadoop.hbase.chaos.actions.GracefulRollingRestartRsAction;
031import org.apache.hadoop.hbase.chaos.actions.MergeRandomAdjacentRegionsOfTableAction;
032import org.apache.hadoop.hbase.chaos.actions.MoveRandomRegionOfTableAction;
033import org.apache.hadoop.hbase.chaos.actions.MoveRegionsOfTableAction;
034import org.apache.hadoop.hbase.chaos.actions.RemoveColumnAction;
035import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsAction;
036import org.apache.hadoop.hbase.chaos.actions.RestartRsHoldingMetaAction;
037import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction;
038import org.apache.hadoop.hbase.chaos.actions.RollingBatchSuspendResumeRsAction;
039import org.apache.hadoop.hbase.chaos.actions.SplitAllRegionOfTableAction;
040import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction;
041import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
042import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
043import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
044import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
045import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
046
047public class StressAssignmentManagerMonkeyFactory extends MonkeyFactory {
048
049  @Override
050  public ChaosMonkey build() {
051    loadProperties();
052
053    // Actions that could slow down region movement.
054    // These could also get regions stuck if there are issues.
055    Action[] actions1 = new Action[] { new CompactTableAction(tableName, 0.5f),
056      new CompactRandomRegionOfTableAction(tableName, 0.6f), new FlushTableAction(tableName),
057      new FlushRandomRegionOfTableAction(tableName) };
058
059    Action[] actions2 = new Action[] { new SplitRandomRegionOfTableAction(tableName),
060      new MergeRandomAdjacentRegionsOfTableAction(tableName), new AddColumnAction(tableName),
061      new RemoveColumnAction(tableName, columnFamilies),
062      new MoveRegionsOfTableAction(moveRegionsSleepTime, 1600, tableName),
063      new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName),
064      new RestartRandomRsAction(restartRandomRSSleepTime),
065      new BatchRestartRsAction(batchRestartRSSleepTime, rollingBatchSuspendRSRatio),
066      new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime, rollingBatchRestartRSRatio),
067      new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime),
068      new ChangeSplitPolicyAction(tableName), new SplitAllRegionOfTableAction(tableName),
069      new DecreaseMaxHFileSizeAction(decreaseHFileSizeSleepTime, decreaseHFileSizeMinHFileSize,
070        decreaseHFileSizeHFileSizeJitter, tableName),
071      new GracefulRollingRestartRsAction(gracefulRollingRestartTSSLeepTime),
072      new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime,
073        rollingBatchSuspendRSRatio) };
074
075    // Action to log more info for debugging
076    Action[] actions3 = new Action[] { new DumpClusterStatusAction() };
077
078    return new PolicyBasedChaosMonkey(properties, util,
079      new PeriodicRandomActionPolicy(action1Period, actions1),
080      new CompositeSequentialPolicy(new DoActionsOncePolicy(action2Period, actions2),
081        new PeriodicRandomActionPolicy(action2Period, actions2)),
082      new PeriodicRandomActionPolicy(action3Period, actions3));
083  }
084}