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.Set;
23  
24  import com.google.common.collect.ImmutableMap;
25  import org.apache.hadoop.hbase.IntegrationTestingUtility;
26  import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
27  
28  /**
29   * Base class of the factory that will create a ChaosMonkey.
30   */
31  public abstract class MonkeyFactory {
32  
33    protected String tableName;
34    protected Set<String> columnFamilies;
35    protected IntegrationTestingUtility util;
36  
37    public MonkeyFactory setTableName(String tableName) {
38      this.tableName = tableName;
39      return this;
40    }
41  
42    public MonkeyFactory setColumnFamilies(Set<String> columnFamilies) {
43      this.columnFamilies = columnFamilies;
44      return this;
45    }
46  
47    public MonkeyFactory setUtil(IntegrationTestingUtility util) {
48      this.util = util;
49      return this;
50    }
51  
52    public abstract ChaosMonkey build();
53  
54  
55    public static final String CALM = "calm";
56    // TODO: the name has become a misnomer since the default (not-slow) monkey has been removed
57    public static final String SLOW_DETERMINISTIC = "slowDeterministic";
58    public static final String UNBALANCE = "unbalance";
59  
60    public static Map<String, MonkeyFactory> FACTORIES = ImmutableMap.<String,MonkeyFactory>builder()
61      .put(CALM, new CalmMonkeyFactory())
62      .put(SLOW_DETERMINISTIC, new SlowDeterministicMonkeyFactory())
63      .put(UNBALANCE, new UnbalanceMonkeyFactory())
64      .build();
65  
66    public static MonkeyFactory getFactory(String factoryName) {
67      return FACTORIES.get(factoryName);
68    }
69  }