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.RestartRandomDataNodeAction;
26  import org.apache.hadoop.hbase.chaos.actions.RestartRandomRsExceptMetaAction;
27  import org.apache.hadoop.hbase.chaos.actions.RestartRandomZKNodeAction;
28  import org.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsExceptMetaAction;
29  import org.apache.hadoop.hbase.chaos.actions.RollingBatchSuspendResumeRsAction;
30  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
31  import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
32  import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
33  import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
34  import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
35  
36  /**
37   * Creates ChaosMonkeys for doing server restart actions, but not
38   * flush / compact / snapshot kind of actions.
39   */
40  public class ServerAndDependenciesKillingMonkeyFactory extends MonkeyFactory {
41  
42    private long rollingBatchSuspendRSSleepTime;
43    private float rollingBatchSuspendtRSRatio;
44  
45    @Override
46    public ChaosMonkey build() {
47      loadProperties();
48  
49      // Destructive actions to mess things around. Cannot run batch restart.
50      Action[] actions1 = new Action[]{
51        new RestartRandomRsExceptMetaAction(60000),
52        new RestartActiveMasterAction(5000),
53        new RollingBatchRestartRsExceptMetaAction(5000, 1.0f, 2), // only allow 2 servers to be dead.
54        new ForceBalancerAction(),
55        new RestartRandomDataNodeAction(60000),
56        new RestartRandomZKNodeAction(60000),
57        new RollingBatchSuspendResumeRsAction(rollingBatchSuspendRSSleepTime,
58            rollingBatchSuspendtRSRatio)
59      };
60  
61      // Action to log more info for debugging
62      Action[] actions2 = new Action[]{
63        new DumpClusterStatusAction()
64      };
65  
66      return new PolicyBasedChaosMonkey(util,
67        new CompositeSequentialPolicy(
68          new DoActionsOncePolicy(60 * 1000, actions1),
69          new PeriodicRandomActionPolicy(60 * 1000, actions1)),
70        new PeriodicRandomActionPolicy(60 * 1000, actions2));
71    }
72  
73    private void loadProperties() {
74      rollingBatchSuspendRSSleepTime = Long.parseLong(this.properties.getProperty(
75          MonkeyConstants.ROLLING_BATCH_RESTART_RS_SLEEP_TIME,
76          MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME + ""));
77      rollingBatchSuspendtRSRatio = Float.parseFloat(this.properties.getProperty(
78          MonkeyConstants.ROLLING_BATCH_RESTART_RS_RATIO,
79          MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_RATIO + ""));
80    }
81  }