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