1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.chaos.factories;
20
21 import org.apache.hadoop.hbase.chaos.actions.*;
22 import org.apache.hadoop.hbase.chaos.monkies.ChaosMonkey;
23 import org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey;
24 import org.apache.hadoop.hbase.chaos.policies.CompositeSequentialPolicy;
25 import org.apache.hadoop.hbase.chaos.policies.DoActionsOncePolicy;
26 import org.apache.hadoop.hbase.chaos.policies.PeriodicRandomActionPolicy;
27
28 public class SlowDeterministicMonkeyFactory extends MonkeyFactory {
29
30 private long action1Period;
31 private long action2Period;
32 private long action3Period;
33 private long action4Period;
34 private long moveRegionsMaxTime;
35 private long moveRegionsSleepTime;
36 private long moveRandomRegionSleepTime;
37 private long restartRandomRSSleepTime;
38 private long batchRestartRSSleepTime;
39 private float batchRestartRSRatio;
40 private long restartActiveMasterSleepTime;
41 private long rollingBatchRestartRSSleepTime;
42 private float rollingBatchRestartRSRatio;
43 private long restartRsHoldingMetaSleepTime;
44 private float compactTableRatio;
45 private float compactRandomRegionRatio;
46 private long decreaseHFileSizeSleepTime;
47
48 @Override
49 public ChaosMonkey build() {
50
51 loadProperties();
52
53
54
55 Action[] actions1 = new Action[] {
56 new CompactTableAction(tableName, compactTableRatio),
57 new CompactRandomRegionOfTableAction(tableName, compactRandomRegionRatio),
58 new FlushTableAction(tableName),
59 new FlushRandomRegionOfTableAction(tableName),
60 new MoveRandomRegionOfTableAction(tableName)
61 };
62
63
64
65
66 Action[] actions2 = new Action[] {
67 new SplitRandomRegionOfTableAction(tableName),
68 new MergeRandomAdjacentRegionsOfTableAction(tableName),
69 new SnapshotTableAction(tableName),
70 new AddColumnAction(tableName),
71 new RemoveColumnAction(tableName, columnFamilies),
72 new ChangeEncodingAction(tableName),
73 new ChangeCompressionAction(tableName),
74 new ChangeBloomFilterAction(tableName),
75 new ChangeVersionsAction(tableName),
76 new ChangeSplitPolicyAction(tableName),
77 };
78
79
80 Action[] actions3 = new Action[] {
81 new MoveRegionsOfTableAction(moveRegionsSleepTime, moveRegionsMaxTime,
82 tableName),
83 new MoveRandomRegionOfTableAction(moveRandomRegionSleepTime, tableName),
84 new RestartRandomRsAction(restartRandomRSSleepTime),
85 new BatchRestartRsAction(batchRestartRSSleepTime, batchRestartRSRatio),
86 new RestartActiveMasterAction(restartActiveMasterSleepTime),
87 new RollingBatchRestartRsAction(rollingBatchRestartRSSleepTime,
88 rollingBatchRestartRSRatio),
89 new RestartRsHoldingMetaAction(restartRsHoldingMetaSleepTime),
90 new DecreaseMaxHFileSizeAction(decreaseHFileSizeSleepTime, tableName),
91 new SplitAllRegionOfTableAction(tableName),
92 };
93
94
95 Action[] actions4 = new Action[] {
96 new DumpClusterStatusAction()
97 };
98
99 return new PolicyBasedChaosMonkey(util,
100 new PeriodicRandomActionPolicy(action1Period, actions1),
101 new PeriodicRandomActionPolicy(action2Period, actions2),
102 new CompositeSequentialPolicy(
103 new DoActionsOncePolicy(action3Period, actions3),
104 new PeriodicRandomActionPolicy(action3Period, actions3)),
105 new PeriodicRandomActionPolicy(action4Period, actions4));
106 }
107
108 private void loadProperties() {
109
110 action1Period = Long.parseLong(this.properties.getProperty(
111 MonkeyConstants.PERIODIC_ACTION1_PERIOD,
112 MonkeyConstants.DEFAULT_PERIODIC_ACTION1_PERIOD + ""));
113 action2Period = Long.parseLong(this.properties.getProperty(
114 MonkeyConstants.PERIODIC_ACTION2_PERIOD,
115 MonkeyConstants.DEFAULT_PERIODIC_ACTION2_PERIOD + ""));
116 action3Period = Long.parseLong(this.properties.getProperty(
117 MonkeyConstants.COMPOSITE_ACTION3_PERIOD,
118 MonkeyConstants.DEFAULT_COMPOSITE_ACTION3_PERIOD + ""));
119 action4Period = Long.parseLong(this.properties.getProperty(
120 MonkeyConstants.PERIODIC_ACTION4_PERIOD,
121 MonkeyConstants.DEFAULT_PERIODIC_ACTION4_PERIOD + ""));
122 moveRegionsMaxTime = Long.parseLong(this.properties.getProperty(
123 MonkeyConstants.MOVE_REGIONS_MAX_TIME,
124 MonkeyConstants.DEFAULT_MOVE_REGIONS_MAX_TIME + ""));
125 moveRegionsSleepTime = Long.parseLong(this.properties.getProperty(
126 MonkeyConstants.MOVE_REGIONS_SLEEP_TIME,
127 MonkeyConstants.DEFAULT_MOVE_REGIONS_SLEEP_TIME + ""));
128 moveRandomRegionSleepTime = Long.parseLong(this.properties.getProperty(
129 MonkeyConstants.MOVE_RANDOM_REGION_SLEEP_TIME,
130 MonkeyConstants.DEFAULT_MOVE_RANDOM_REGION_SLEEP_TIME + ""));
131 restartRandomRSSleepTime = Long.parseLong(this.properties.getProperty(
132 MonkeyConstants.RESTART_RANDOM_RS_SLEEP_TIME,
133 MonkeyConstants.DEFAULT_RESTART_RANDOM_RS_SLEEP_TIME + ""));
134 batchRestartRSSleepTime = Long.parseLong(this.properties.getProperty(
135 MonkeyConstants.BATCH_RESTART_RS_SLEEP_TIME,
136 MonkeyConstants.DEFAULT_BATCH_RESTART_RS_SLEEP_TIME + ""));
137 batchRestartRSRatio = Float.parseFloat(this.properties.getProperty(
138 MonkeyConstants.BATCH_RESTART_RS_RATIO,
139 MonkeyConstants.DEFAULT_BATCH_RESTART_RS_RATIO + ""));
140 restartActiveMasterSleepTime = Long.parseLong(this.properties.getProperty(
141 MonkeyConstants.RESTART_ACTIVE_MASTER_SLEEP_TIME,
142 MonkeyConstants.DEFAULT_RESTART_ACTIVE_MASTER_SLEEP_TIME + ""));
143 rollingBatchRestartRSSleepTime = Long.parseLong(this.properties.getProperty(
144 MonkeyConstants.ROLLING_BATCH_RESTART_RS_SLEEP_TIME,
145 MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_SLEEP_TIME + ""));
146 rollingBatchRestartRSRatio = Float.parseFloat(this.properties.getProperty(
147 MonkeyConstants.ROLLING_BATCH_RESTART_RS_RATIO,
148 MonkeyConstants.DEFAULT_ROLLING_BATCH_RESTART_RS_RATIO + ""));
149 restartRsHoldingMetaSleepTime = Long.parseLong(this.properties.getProperty(
150 MonkeyConstants.RESTART_RS_HOLDING_META_SLEEP_TIME,
151 MonkeyConstants.DEFAULT_RESTART_RS_HOLDING_META_SLEEP_TIME + ""));
152 compactTableRatio = Float.parseFloat(this.properties.getProperty(
153 MonkeyConstants.COMPACT_TABLE_ACTION_RATIO,
154 MonkeyConstants.DEFAULT_COMPACT_TABLE_ACTION_RATIO + ""));
155 compactRandomRegionRatio = Float.parseFloat(this.properties.getProperty(
156 MonkeyConstants.COMPACT_RANDOM_REGION_RATIO,
157 MonkeyConstants.DEFAULT_COMPACT_RANDOM_REGION_RATIO + ""));
158 decreaseHFileSizeSleepTime = Long.parseLong(this.properties.getProperty(
159 MonkeyConstants.DECREASE_HFILE_SIZE_SLEEP_TIME,
160 MonkeyConstants.DEFAULT_DECREASE_HFILE_SIZE_SLEEP_TIME + ""));
161 }
162 }