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 * <p>
010 * http://www.apache.org/licenses/LICENSE-2.0
011 * <p>
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.MergeRandomAdjacentRegionsOfTableAction;
031import org.apache.hadoop.hbase.chaos.actions.MoveRandomRegionOfTableAction;
032import org.apache.hadoop.hbase.chaos.actions.MoveRegionsOfTableAction;
033import org.apache.hadoop.hbase.chaos.actions.RemoveColumnAction;
034import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsAction;
035import org.apache.hadoop.hbase.chaos.actions.RestartRsHoldingMetaAction;
036import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction;
037import org.apache.hadoop.hbase.chaos.actions.SplitAllRegionOfTableAction;
038import org.apache.hadoop.hbase.chaos.actions.SplitRandomRegionOfTableAction;
039import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
040import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
041import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
042import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
043import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
044
045public class StressAssignmentManagerMonkeyFactory extends MonkeyFactory {
046  @Override
047  public ChaosMonkey build() {
048
049    // Actions that could slow down region movement.
050    // These could also get regions stuck if there are issues.
051    Action[] actions1 = new Action[]{
052        new CompactTableAction(tableName, 0.5f),
053        new CompactRandomRegionOfTableAction(tableName, 0.6f),
054        new FlushTableAction(tableName),
055        new FlushRandomRegionOfTableAction(tableName)
056    };
057
058    Action[] actions2 = new Action[]{
059        new SplitRandomRegionOfTableAction(tableName),
060        new MergeRandomAdjacentRegionsOfTableAction(tableName),
061        new AddColumnAction(tableName),
062        new RemoveColumnAction(tableName, columnFamilies),
063        new MoveRegionsOfTableAction(MonkeyConstants.DEFAULT_MOVE_REGIONS_SLEEP_TIME,
064            1600,
065            tableName),
066        new MoveRandomRegionOfTableAction(MonkeyConstants.DEFAULT_MOVE_RANDOM_REGION_SLEEP_TIME,
067            tableName),
068        new RestartRandomRsAction(MonkeyConstants.DEFAULT_RESTART_RANDOM_RS_SLEEP_TIME),
069        new BatchRestartRsAction(MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME, 0.5f),
070        new RollingBatchRestartRsAction(MonkeyConstants.DEFAULT_BATCH_RESTART_RS_SLEEP_TIME, 1.0f),
071        new RestartRsHoldingMetaAction(MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME),
072        new ChangeSplitPolicyAction(tableName),
073        new SplitAllRegionOfTableAction(tableName),
074        new DecreaseMaxHFileSizeAction(MonkeyConstants.DEFAULT_DECREASE_HFILE_SIZE_SLEEP_TIME,
075            tableName),
076    };
077
078    // Action to log more info for debugging
079    Action[] actions3 = new Action[]{
080        new DumpClusterStatusAction()
081    };
082
083    return new PolicyBasedChaosMonkey(util,
084        new PeriodicRandomActionPolicy(90 * 1000, actions1),
085        new CompositeSequentialPolicy(
086            new DoActionsOncePolicy(90 * 1000, actions2),
087            new PeriodicRandomActionPolicy(90 * 1000, actions2)),
088        new PeriodicRandomActionPolicy(90 * 1000, actions3)
089    );
090  }
091}