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