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.actions;
20
21 import org.apache.hadoop.hbase.HBaseTestingUtility;
22 import org.apache.hadoop.hbase.client.HBaseAdmin;
23
24
25
26
27 public class SnapshotTableAction extends Action {
28 private final String tableName;
29 private final long sleepTime;
30
31 public SnapshotTableAction(String tableName) {
32 this(-1, tableName);
33 }
34
35 public SnapshotTableAction(int sleepTime, String tableName) {
36 this.tableName = tableName;
37 this.sleepTime = sleepTime;
38 }
39
40 @Override
41 public void perform() throws Exception {
42 HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
43 String snapshotName = tableName + "-it-" + System.currentTimeMillis();
44 HBaseAdmin admin = util.getHBaseAdmin();
45
46 LOG.info("Performing action: Snapshot table " + tableName);
47 admin.snapshot(snapshotName, tableName);
48 if (sleepTime > 0) {
49 Thread.sleep(sleepTime);
50 }
51 }
52 }