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.monkies.ChaosMonkey;
30  import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
31  import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
32  import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
33  import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
34  
35  /**
36   * Creates ChaosMonkeys for doing server restart actions, but not
37   * flush / compact / snapshot kind of actions.
38   */
39  public class ServerAndDependenciesKillingMonkeyFactory extends MonkeyFactory {
40  
41    @Override
42    public ChaosMonkey build() {
43  
44      // Destructive actions to mess things around. Cannot run batch restart.
45      Action[] actions1 = new Action[]{
46        new RestartRandomRsExceptMetaAction(60000),
47        new RestartActiveMasterAction(5000),
48        new RollingBatchRestartRsExceptMetaAction(5000, 1.0f, 2), // only allow 2 servers to be dead.
49        new ForceBalancerAction(),
50        new RestartRandomDataNodeAction(60000),
51        new RestartRandomZKNodeAction(60000)
52      };
53  
54      // Action to log more info for debugging
55      Action[] actions2 = new Action[]{
56        new DumpClusterStatusAction()
57      };
58  
59      return new PolicyBasedChaosMonkey(util,
60        new CompositeSequentialPolicy(
61          new DoActionsOncePolicy(60 * 1000, actions1),
62          new PeriodicRandomActionPolicy(60 * 1000, actions1)),
63        new PeriodicRandomActionPolicy(60 * 1000, actions2));
64    }
65  }