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.RestartActiveMasterAction;
24  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
25  import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
26  import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
27  
28  /**
29   * A chaos monkey to kill the active master periodically. Can be run in single master
30   * or multi master setup.
31   */
32  public class MasterKillingMonkeyFactory extends MonkeyFactory {
33  
34    private long action1Period;
35    private long action2Period;
36  
37    private long restartActiveMasterSleepTime;
38  
39    @Override
40    public ChaosMonkey build() {
41      loadProperties();
42  
43      // Destructive actions to mess things around.
44      Action[] actions1 = new Action[] {
45          new RestartActiveMasterAction(restartActiveMasterSleepTime),
46      };
47  
48      // Action to log more info for debugging
49      Action[] actions2 = new Action[] {
50          new DumpClusterStatusAction()
51      };
52  
53      return new PolicyBasedChaosMonkey(util,
54          new PeriodicRandomActionPolicy(action1Period, actions1),
55          new PeriodicRandomActionPolicy(action2Period, actions2));
56    }
57  
58    private void loadProperties() {
59  
60        action1Period = Long.parseLong(this.properties.getProperty(
61          MonkeyConstants.PERIODIC_ACTION1_PERIOD,
62          MonkeyConstants.DEFAULT_PERIODIC_ACTION1_PERIOD + ""));
63        action2Period = Long.parseLong(this.properties.getProperty(
64          MonkeyConstants.PERIODIC_ACTION2_PERIOD,
65          MonkeyConstants.DEFAULT_PERIODIC_ACTION2_PERIOD + ""));
66        restartActiveMasterSleepTime = Long.parseLong(this.properties.getProperty(
67          MonkeyConstants.RESTART_ACTIVE_MASTER_SLEEP_TIME,
68          MonkeyConstants.DEFAULT_RESTART_ACTIVE_MASTER_SLEEP_TIME + ""));
69    }
70  
71  }