2
2
3
3
import com .alibaba .fastjson .JSON ;
4
4
import com .alipay .oceanbase .hbase .execute .AbstractObTableMetaExecutor ;
5
+ import com .alipay .oceanbase .rpc .protocol .payload .ResultCodes ;
5
6
import com .alipay .oceanbase .rpc .ObTableClient ;
7
+ import com .alipay .oceanbase .rpc .exception .ObTableException ;
6
8
import com .alipay .oceanbase .rpc .meta .ObTableMetaRequest ;
7
9
import com .alipay .oceanbase .rpc .meta .ObTableMetaResponse ;
8
10
import com .alipay .oceanbase .rpc .meta .ObTableRpcMetaType ;
@@ -40,7 +42,21 @@ public Void enableTable(String tableName) throws IOException, TableNotFoundExcep
40
42
requestData .put ("table_name" , tableName );
41
43
String jsonData = JSON .toJSONString (requestData );
42
44
request .setData (jsonData );
43
- return execute (tableClient , request );
45
+ try {
46
+ return execute (tableClient , request );
47
+ } catch (IOException e ) {
48
+ Throwable cause = e .getCause ();
49
+ if (cause instanceof ObTableException ) {
50
+ ObTableException obEx = (ObTableException ) cause ;
51
+ int errCode = obEx .getErrorCode ();
52
+ if (ResultCodes .OB_KV_TABLE_NOT_ENABLED .errorCode == errCode ) {
53
+ throw new TableNotEnabledException ("Table is not enabled: " + tableName + obEx );
54
+ } else if (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode == errCode ) {
55
+ throw new TableNotFoundException ("Table not found: " + tableName + obEx );
56
+ }
57
+ }
58
+ throw e ;
59
+ }
44
60
}
45
61
46
62
public Void disableTable (String tableName ) throws IOException , TableNotFoundException , TableNotDisabledException {
@@ -50,6 +66,20 @@ public Void disableTable(String tableName) throws IOException, TableNotFoundExce
50
66
requestData .put ("table_name" , tableName );
51
67
String jsonData = JSON .toJSONString (requestData );
52
68
request .setData (jsonData );
53
- return execute (tableClient , request );
69
+ try {
70
+ return execute (tableClient , request );
71
+ } catch (IOException e ) {
72
+ Throwable cause = e .getCause ();
73
+ if (cause instanceof ObTableException ) {
74
+ ObTableException obEx = (ObTableException ) cause ;
75
+ int errCode = obEx .getErrorCode ();
76
+ if (ResultCodes .OB_KV_TABLE_NOT_DISABLED .errorCode == errCode ) {
77
+ throw new TableNotDisabledException ("Table is not disabled: " + tableName + obEx );
78
+ } else if (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode == errCode ) {
79
+ throw new TableNotFoundException ("Table not found: " + tableName + obEx );
80
+ }
81
+ }
82
+ throw e ;
83
+ }
54
84
}
55
85
}
0 commit comments