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 java.util.Map;
22  import java.util.Properties;
23  import java.util.Set;
24  
25  import org.apache.hadoop.hbase.IntegrationTestingUtility;
26  import org.apache.hadoop.hbase.TableName;
27  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
28  
29  import com.google.common.collect.ImmutableMap;
30  
31  /**
32   * Base class of the factory that will create a ChaosMonkey.
33   */
34  public abstract class MonkeyFactory {
35  
36    protected TableName tableName;
37    protected Set<String> columnFamilies;
38    protected IntegrationTestingUtility util;
39    protected Properties properties = new Properties();
40  
41    public MonkeyFactory setTableName(TableName tableName) {
42      this.tableName = tableName;
43      return this;
44    }
45  
46    public MonkeyFactory setColumnFamilies(Set<String> columnFamilies) {
47      this.columnFamilies = columnFamilies;
48      return this;
49    }
50  
51    public MonkeyFactory setUtil(IntegrationTestingUtility util) {
52      this.util = util;
53      return this;
54    }
55  
56    public MonkeyFactory setProperties(Properties props) {
57      if (props != null) {
58        this.properties = props;
59      }
60      return this;
61    }
62  
63    public abstract ChaosMonkey build();
64  
65    public static final String CALM = "calm";
66    // TODO: the name has become a misnomer since the default (not-slow) monkey has been removed
67    public static final String SLOW_DETERMINISTIC = "slowDeterministic";
68    public static final String UNBALANCE = "unbalance";
69    public static final String SERVER_KILLING = "serverKilling";
70    public static final String STRESS_AM = "stressAM";
71    public static final String NO_KILL = "noKill";
72    public static final String MASTER_KILLING = "masterKilling";
73    public static final String MOB_NO_KILL = "mobNoKill";
74    public static final String MOB_SLOW_DETERMINISTIC = "mobSlowDeterministic";
75  
76    public static Map<String, MonkeyFactory> FACTORIES = ImmutableMap.<String,MonkeyFactory>builder()
77      .put(CALM, new CalmMonkeyFactory())
78      .put(SLOW_DETERMINISTIC, new SlowDeterministicMonkeyFactory())
79      .put(UNBALANCE, new UnbalanceMonkeyFactory())
80      .put(SERVER_KILLING, new ServerKillingMonkeyFactory())
81      .put(STRESS_AM, new StressAssignmentManagerMonkeyFactory())
82      .put(NO_KILL, new NoKillMonkeyFactory())
83      .put(MASTER_KILLING, new MasterKillingMonkeyFactory())
84      .put(MOB_NO_KILL, new MobNoKillMonkeyFactory())
85      .put(MOB_SLOW_DETERMINISTIC, new MobNoKillMonkeyFactory())
86      .build();
87  
88    public static MonkeyFactory getFactory(String factoryName) {
89      return FACTORIES.get(factoryName);
90    }
91  }