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.policies;
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24
25 import org.apache.hadoop.hbase.chaos.actions.Action;
26 import org.apache.hadoop.util.StringUtils;
27
28
29 public class DoActionsOncePolicy extends PeriodicPolicy {
30 private List<Action> actions;
31
32 public DoActionsOncePolicy(long periodMs, List<Action> actions) {
33 super(periodMs);
34 this.actions = new ArrayList<Action>(actions);
35 }
36
37 public DoActionsOncePolicy(long periodMs, Action... actions) {
38 this(periodMs, Arrays.asList(actions));
39 }
40
41 @Override
42 protected void runOneIteration() {
43 if (actions.isEmpty()) {
44 this.stop("done");
45 return;
46 }
47 Action action = actions.remove(0);
48
49 try {
50 action.perform();
51 } catch (Exception ex) {
52 LOG.warn("Exception occured during performing action: "
53 + StringUtils.stringifyException(ex));
54 }
55 }
56
57 @Override
58 public void init(PolicyContext context) throws Exception {
59 super.init(context);
60 for (Action action : actions) {
61 action.init(this.context);
62 }
63 }
64 }