View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.chaos.factories;
20  
21  import org.apache.hadoop.hbase.chaos.actions.Action;
22  import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction;
23  import org.apache.hadoop.hbase.chaos.actions.ForceBalancerAction;
24  import org.apache.hadoop.hbase.chaos.actions.RestartActiveMasterAction;
25  import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsExceptMetaAction;
26  import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsExceptMetaAction;
27  import org.apache.hadoop.hbase.chaos.actions.RollingBatchSuspendResumeRsAction;
28  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
29  import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
30  import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
31  import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
32  import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
33  
34  /**
35   * Creates ChaosMonkeys for doing server restart actions, but not
36   * flush / compact / snapshot kind of actions.
37   */
38  public class ServerKillingMonkeyFactory extends MonkeyFactory {
39  
40    private long rollingBatchSuspendRSSleepTime;
41    private float rollingBatchSuspendtRSRatio;
42  
43    @Override
44    public ChaosMonkey build() {
45      loadProperties();
46  
47      // Destructive actions to mess things around. Cannot run batch restart
48      Action[] actions1 = new Action[] {
49          new RestartRandomRsExceptMetaAction(60000),
50          new RestartActiveMasterAction(5000),
51          new RollingBatchRestartRsExceptMetaAction(5000, 1.0f, 2), //only allow 2 servers to be dead
52        new ForceBalancerAction(),
53        new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime,
54            rollingBatchSuspendtRSRatio)
55      };
56  
57      // Action to log more info for debugging
58      Action[] actions2 = new Action[] {
59          new DumpClusterStatusAction()
60      };
61  
62      return new PolicyBasedChaosMonkey(util,
63        new CompositeSequentialPolicy(
64            new DoActionsOncePolicy(60 * 1000, actions1),
65            new PeriodicRandomActionPolicy(60 * 1000, actions1)),
66        new PeriodicRandomActionPolicy(60 * 1000, actions2));
67    }
68  
69    private void loadProperties() {
70      rollingBatchSuspendRSSleepTime = Long.parseLong(this.properties.getProperty(
71          MonkeyConstants.ROLLING_BATCH_RESTART_RS_SLEEP_TIME,
72          MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME + ""));
73      rollingBatchSuspendtRSRatio = Float.parseFloat(this.properties.getProperty(
74          MonkeyConstants.ROLLING_BATCH_RESTART_RS_RATIO,
75          MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_RATIO + ""));
76    }
77  }