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 */ 018 019package org.apache.hadoop.hbase.chaos.factories; 020 021import org.apache.hadoop.hbase.chaos.actions.Action; 022import org.apache.hadoop.hbase.chaos.actions.CorruptDataFilesAction; 023import org.apache.hadoop.hbase.chaos.actions.DeleteDataFilesAction; 024import org.apache.hadoop.hbase.chaos.actions.DumpClusterStatusAction; 025import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey; 026import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey; 027import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy; 028 029/** 030 * A chaos monkey to delete and corrupt regionserver data, requires a user with 031 * passwordless ssh access to the cluster and sudo privileges. 032 * Highly destructive 033 */ 034public class DataIssuesMonkeyFactory extends MonkeyFactory { 035 036 private long action1Period; 037 private long action2Period; 038 039 private float chanceToAct; 040 041 @Override 042 public ChaosMonkey build() { 043 loadProperties(); 044 045 // Highly destructive actions to mess things around. 046 Action[] actions1 = new Action[] { 047 new DeleteDataFilesAction(chanceToAct), 048 new CorruptDataFilesAction(chanceToAct) 049 }; 050 051 // Action to log more info for debugging 052 Action[] actions2 = new Action[] { 053 new DumpClusterStatusAction() 054 }; 055 056 return new PolicyBasedChaosMonkey(properties, util, 057 new PeriodicRandomActionPolicy(action1Period, actions1), 058 new PeriodicRandomActionPolicy(action2Period, actions2)); 059 } 060 061 private void loadProperties() { 062 action1Period = Long.parseLong(this.properties.getProperty( 063 MonkeyConstants.PERIODIC_ACTION1_PERIOD, 064 MonkeyConstants.DEFAULT_PERIODIC_ACTION1_PERIOD + "")); 065 action2Period = Long.parseLong(this.properties.getProperty( 066 MonkeyConstants.PERIODIC_ACTION2_PERIOD, 067 MonkeyConstants.DEFAULT_PERIODIC_ACTION2_PERIOD + "")); 068 chanceToAct = Float.parseFloat(this.properties.getProperty( 069 MonkeyConstants.DATA_ISSUE_CHANCE, 070 MonkeyConstants.DEFAULT_DATA_ISSUE_CHANCE+ "")); 071 } 072}