1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.hadoop.hbase.quotas.policies;
18
19 import java.io.IOException;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.hbase.TableNotDisabledException;
24 import org.apache.hadoop.hbase.TableNotEnabledException;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.client.Mutation;
27 import org.apache.hadoop.hbase.quotas.SpaceLimitingException;
28 import org.apache.hadoop.hbase.quotas.SpaceViolationPolicy;
29 import org.apache.hadoop.hbase.quotas.SpaceViolationPolicyEnforcement;
30
31
32
33
34
35 @InterfaceAudience.Private
36 public class DisableTableViolationPolicyEnforcement extends DefaultViolationPolicyEnforcement {
37 private static final Log LOG = LogFactory.getLog(DisableTableViolationPolicyEnforcement.class);
38
39 @Override
40 public void enable() throws IOException {
41 try {
42 if (LOG.isTraceEnabled()) {
43 LOG.trace("Starting disable of " + getTableName());
44 }
45 getRegionServerServices().getConnection().getAdmin().disableTable(getTableName());
46 if (LOG.isTraceEnabled()) {
47 LOG.trace("Disable is complete for " + getTableName());
48 }
49 } catch (TableNotEnabledException tnee) {
50
51 }
52 }
53
54 @Override
55 public void disable() throws IOException {
56 try {
57 if (LOG.isTraceEnabled()) {
58 LOG.trace("Starting enable of " + getTableName());
59 }
60 getRegionServerServices().getConnection().getAdmin().enableTable(getTableName());
61 if (LOG.isTraceEnabled()) {
62 LOG.trace("Enable is complete for " + getTableName());
63 }
64 } catch (TableNotDisabledException tnde) {
65
66 }
67 }
68
69 @Override
70 public void check(Mutation m) throws SpaceLimitingException {
71
72 throw new SpaceLimitingException(
73 getPolicyName(), "This table is disabled due to violating a space quota.");
74 }
75
76 @Override
77 public String getPolicyName() {
78 return SpaceViolationPolicy.DISABLE.name();
79 }
80 }