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  private long gracefulRollingRestartTSSLeepTime;
050  private long rollingBatchSuspendRSSleepTime;
051  private float rollingBatchSuspendtRSRatio;
052
053  @Override
054  public ChaosMonkey build() {
055    loadProperties();
056
057    // Actions that could slow down region movement.
058    // These could also get regions stuck if there are issues.
059    Action[] actions1 = new Action[]{
060        new CompactTableAction(tableName, 0.5f),
061        new CompactRandomRegionOfTableAction(tableName, 0.6f),
062        new FlushTableAction(tableName),
063        new FlushRandomRegionOfTableAction(tableName)
064    };
065
066    Action[] actions2 = new Action[]{
067        new SplitRandomRegionOfTableAction(tableName),
068        new MergeRandomAdjacentRegionsOfTableAction(tableName),
069        new AddColumnAction(tableName),
070        new RemoveColumnAction(tableName, columnFamilies),
071        new MoveRegionsOfTableAction(MonkeyConstants.DEFAULT_MOVE_REGIONS_SLEEP_TIME,
072            1600,
073            tableName),
074        new MoveRandomRegionOfTableAction(MonkeyConstants.DEFAULT_MOVE_RANDOM_REGION_SLEEP_TIME,
075            tableName),
076        new RestartRandomRsAction(MonkeyConstants.DEFAULT_RESTART_RANDOM_RS_SLEEP_TIME),
077        new BatchRestartRsAction(MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME, 0.5f),
078        new RollingBatchRestartRsAction(MonkeyConstants.DEFAULT_BATCH_RESTART_RS_SLEEP_TIME, 1.0f),
079        new RestartRsHoldingMetaAction(MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME),
080        new ChangeSplitPolicyAction(tableName),
081        new SplitAllRegionOfTableAction(tableName),
082        new DecreaseMaxHFileSizeAction(MonkeyConstants.DEFAULT_DECREASE_HFILE_SIZE_SLEEP_TIME,
083            tableName),
084      new GracefulRollingRestartRsAction(gracefulRollingRestartTSSLeepTime),
085      new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime,
086          rollingBatchSuspendtRSRatio)
087    };
088
089    // Action to log more info for debugging
090    Action[] actions3 = new Action[]{
091        new DumpClusterStatusAction()
092    };
093
094    return new PolicyBasedChaosMonkey(properties, util,
095        new PeriodicRandomActionPolicy(90 * 1000, actions1),
096        new CompositeSequentialPolicy(
097            new DoActionsOncePolicy(90 * 1000, actions2),
098            new PeriodicRandomActionPolicy(90 * 1000, actions2)),
099        new PeriodicRandomActionPolicy(90 * 1000, actions3)
100    );
101  }
102
103  private void loadProperties() {
104    gracefulRollingRestartTSSLeepTime = Long.parseLong(this.properties.getProperty(
105        MonkeyConstants.GRACEFUL_RESTART_RS_SLEEP_TIME,
106        MonkeyConstants.DEFAULT_GRACEFUL_RESTART_RS_SLEEP_TIME + ""));
107    rollingBatchSuspendRSSleepTime = Long.parseLong(this.properties.getProperty(
108        MonkeyConstants.ROLLING_BATCH_SUSPEND_RS_SLEEP_TIME,
109        MonkeyConstants.DEFAULT_ROLLING_BATCH_SUSPEND_RS_SLEEP_TIME+ ""));
110    rollingBatchSuspendtRSRatio = Float.parseFloat(this.properties.getProperty(
111        MonkeyConstants.ROLLING_BATCH_SUSPEND_RS_RATIO,
112        MonkeyConstants.DEFAULT_ROLLING_BATCH_SUSPEND_RS_RATIO + ""));
113  }
114}