001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.chaos.factories;
019
020import org.apache.hadoop.hbase.chaos.actions.Action;
021import org.apache.hadoop.hbase.chaos.actions.CorruptDataFilesAction;
022import org.apache.hadoop.hbase.chaos.actions.DeleteDataFilesAction;
023import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction;
024import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
025import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
026import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
027
028/**
029 * A chaos monkey to delete and corrupt regionserver data, requires a user with passwordless ssh
030 * access to the cluster and sudo privileges. Highly destructive
031 */
032public class DataIssuesMonkeyFactory extends MonkeyFactory {
033
034  private long action1Period;
035  private long action2Period;
036
037  private float chanceToAct;
038
039  @Override
040  public ChaosMonkey build() {
041    loadProperties();
042
043    // Highly destructive actions to mess things around.
044    Action[] actions1 = new Action[] { new DeleteDataFilesAction(chanceToAct),
045      new CorruptDataFilesAction(chanceToAct) };
046
047    // Action to log more info for debugging
048    Action[] actions2 = new Action[] { new DumpClusterStatusAction() };
049
050    return new PolicyBasedChaosMonkey(properties, util,
051      new PeriodicRandomActionPolicy(action1Period, actions1),
052      new PeriodicRandomActionPolicy(action2Period, actions2));
053  }
054
055  private void loadProperties() {
056    action1Period =
057      Long.parseLong(this.properties.getProperty(MonkeyConstants.PERIODIC_ACTION1_PERIOD,
058        MonkeyConstants.DEFAULT_PERIODIC_ACTION1_PERIOD + ""));
059    action2Period =
060      Long.parseLong(this.properties.getProperty(MonkeyConstants.PERIODIC_ACTION2_PERIOD,
061        MonkeyConstants.DEFAULT_PERIODIC_ACTION2_PERIOD + ""));
062    chanceToAct = Float.parseFloat(this.properties.getProperty(MonkeyConstants.DATA_ISSUE_CHANCE,
063      MonkeyConstants.DEFAULT_DATA_ISSUE_CHANCE + ""));
064  }
065}