You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2022/06/01 12:42:07 UTC
[incubator-kyuubi] branch master updated: [KYUUBI #2794] Change KyuubiRestException to extend RuntimeException
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 9ed652e9e [KYUUBI #2794] Change KyuubiRestException to extend RuntimeException
9ed652e9e is described below
commit 9ed652e9ee6d87db5da19de8f5d1e32bfd18b859
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Wed Jun 1 20:41:59 2022 +0800
[KYUUBI #2794] Change KyuubiRestException to extend RuntimeException
### _Why are the changes needed?_
Checked exceptions are evil, we should always avoid using that.
https://phauer.com/2015/checked-exceptions-are-evil/
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #2794 from pan3793/rest-ex.
Closes #2794
c87abdde [Cheng Pan] Clean up
40a5897f [Cheng Pan] Change KyuubiRestException to extend RuntimeException
Authored-by: Cheng Pan <ch...@apache.org>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../java/org/apache/kyuubi/client/BatchRestApi.java | 14 +++++---------
.../java/org/apache/kyuubi/client/RestClient.java | 21 ++++++++-------------
.../client/exception/KyuubiRestException.java | 2 +-
.../org/apache/kyuubi/client/util/JsonUtil.java | 4 ++--
.../apache/kyuubi/client/BatchRestClientTest.java | 16 ++++++++--------
5 files changed, 24 insertions(+), 33 deletions(-)
diff --git a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/BatchRestApi.java b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/BatchRestApi.java
index ce452a0bb..6bc91241b 100644
--- a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/BatchRestApi.java
+++ b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/BatchRestApi.java
@@ -23,7 +23,6 @@ import org.apache.kyuubi.client.api.v1.dto.Batch;
import org.apache.kyuubi.client.api.v1.dto.BatchRequest;
import org.apache.kyuubi.client.api.v1.dto.GetBatchesResponse;
import org.apache.kyuubi.client.api.v1.dto.OperationLog;
-import org.apache.kyuubi.client.exception.KyuubiRestException;
import org.apache.kyuubi.client.util.JsonUtil;
public class BatchRestApi {
@@ -38,18 +37,17 @@ public class BatchRestApi {
this.client = client;
}
- public Batch createBatch(BatchRequest request) throws KyuubiRestException {
+ public Batch createBatch(BatchRequest request) {
String requestBody = JsonUtil.toJson(request);
return this.getClient().post(API_BASE_PATH, requestBody, Batch.class, client.getAuthHeader());
}
- public Batch getBatchById(String batchId) throws KyuubiRestException {
+ public Batch getBatchById(String batchId) {
String path = String.format("%s/%s", API_BASE_PATH, batchId);
return this.getClient().get(path, null, Batch.class, client.getAuthHeader());
}
- public GetBatchesResponse listBatches(String batchType, int from, int size)
- throws KyuubiRestException {
+ public GetBatchesResponse listBatches(String batchType, int from, int size) {
Map<String, Object> params = new HashMap<>();
params.put("batchType", batchType);
params.put("from", from);
@@ -58,8 +56,7 @@ public class BatchRestApi {
.get(API_BASE_PATH, params, GetBatchesResponse.class, client.getAuthHeader());
}
- public OperationLog getBatchLocalLog(String batchId, int from, int size)
- throws KyuubiRestException {
+ public OperationLog getBatchLocalLog(String batchId, int from, int size) {
Map<String, Object> params = new HashMap<>();
params.put("batchId", batchId);
params.put("from", from);
@@ -69,8 +66,7 @@ public class BatchRestApi {
return this.getClient().get(path, params, OperationLog.class, client.getAuthHeader());
}
- public void deleteBatch(String batchId, boolean killApp, String hs2ProxyUser)
- throws KyuubiRestException {
+ public void deleteBatch(String batchId, boolean killApp, String hs2ProxyUser) {
Map<String, Object> params = new HashMap<>();
params.put("killApp", killApp);
params.put("hive.server2.proxy.user", hs2ProxyUser);
diff --git a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/RestClient.java b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/RestClient.java
index 4793e3905..f6a6fda0f 100644
--- a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/RestClient.java
+++ b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/RestClient.java
@@ -60,36 +60,31 @@ public class RestClient implements AutoCloseable {
}
}
- public <T> T get(String path, Map<String, Object> params, Class<T> type, String authHeader)
- throws KyuubiRestException {
+ public <T> T get(String path, Map<String, Object> params, Class<T> type, String authHeader) {
String responseJson = get(path, params, authHeader);
return JsonUtil.toObject(responseJson, type);
}
- public String get(String path, Map<String, Object> params, String authHeader)
- throws KyuubiRestException {
+ public String get(String path, Map<String, Object> params, String authHeader) {
return doRequest(buildURI(path, params), authHeader, RequestBuilder.get());
}
- public <T> T post(String path, String body, Class<T> type, String authHeader)
- throws KyuubiRestException {
+ public <T> T post(String path, String body, Class<T> type, String authHeader) {
String responseJson = post(path, body, authHeader);
return JsonUtil.toObject(responseJson, type);
}
- public String post(String path, String body, String authHeader) throws KyuubiRestException {
+ public String post(String path, String body, String authHeader) {
RequestBuilder postRequestBuilder =
RequestBuilder.post().setEntity(new StringEntity(body, StandardCharsets.UTF_8));
return doRequest(buildURI(path), authHeader, postRequestBuilder);
}
- public String delete(String path, Map<String, Object> params, String authHeader)
- throws KyuubiRestException {
+ public String delete(String path, Map<String, Object> params, String authHeader) {
return doRequest(buildURI(path, params), authHeader, RequestBuilder.delete());
}
- private String doRequest(URI uri, String authHeader, RequestBuilder requestBuilder)
- throws KyuubiRestException {
+ private String doRequest(URI uri, String authHeader, RequestBuilder requestBuilder) {
String response = "";
CloseableHttpResponse httpResponse = null;
try {
@@ -134,11 +129,11 @@ public class RestClient implements AutoCloseable {
return response;
}
- private URI buildURI(String path) throws KyuubiRestException {
+ private URI buildURI(String path) {
return buildURI(path, null);
}
- private URI buildURI(String path, Map<String, Object> params) throws KyuubiRestException {
+ private URI buildURI(String path, Map<String, Object> params) {
URI uri = null;
try {
String url = StringUtils.isNotBlank(path) ? this.baseUrl + "/" + path : this.baseUrl;
diff --git a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/exception/KyuubiRestException.java b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/exception/KyuubiRestException.java
index d09843bf3..7f7d828dd 100644
--- a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/exception/KyuubiRestException.java
+++ b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/exception/KyuubiRestException.java
@@ -17,7 +17,7 @@
package org.apache.kyuubi.client.exception;
-public class KyuubiRestException extends Exception {
+public class KyuubiRestException extends RuntimeException {
public KyuubiRestException(String message, Throwable cause) {
super(message, cause);
diff --git a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtil.java b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtil.java
index 20a10fe56..dcedcbbf8 100644
--- a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtil.java
+++ b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/util/JsonUtil.java
@@ -24,7 +24,7 @@ public final class JsonUtil {
private static ObjectMapper MAPPER = new ObjectMapper();
- public static String toJson(Object object) throws KyuubiRestException {
+ public static String toJson(Object object) {
try {
return MAPPER.writeValueAsString(object);
} catch (Exception e) {
@@ -32,7 +32,7 @@ public final class JsonUtil {
}
}
- public static <T> T toObject(String json, Class<T> clazz) throws KyuubiRestException {
+ public static <T> T toObject(String json, Class<T> clazz) {
try {
return MAPPER.readValue(json, clazz);
} catch (Exception e) {
diff --git a/kyuubi-rest-client/src/test/java/org/apache/kyuubi/client/BatchRestClientTest.java b/kyuubi-rest-client/src/test/java/org/apache/kyuubi/client/BatchRestClientTest.java
index 53da5bb7c..a10d17e92 100644
--- a/kyuubi-rest-client/src/test/java/org/apache/kyuubi/client/BatchRestClientTest.java
+++ b/kyuubi-rest-client/src/test/java/org/apache/kyuubi/client/BatchRestClientTest.java
@@ -81,7 +81,7 @@ public class BatchRestClientTest {
}
@Test(expected = KyuubiRestException.class)
- public void testInvalidUrl() throws KyuubiRestException {
+ public void testInvalidUrl() {
KyuubiRestClient basicClient =
KyuubiRestClient.builder("https://localhost:8443")
.authSchema(KyuubiRestClient.AuthSchema.BASIC)
@@ -94,7 +94,7 @@ public class BatchRestClientTest {
}
@Test
- public void testNoPasswordBasicClient() throws KyuubiRestException {
+ public void testNoPasswordBasicClient() {
BatchTestServlet.setAuthSchema(BASIC_AUTH);
BatchTestServlet.allowAnonymous(true);
@@ -115,7 +115,7 @@ public class BatchRestClientTest {
}
@Test
- public void testAnonymousBasicClient() throws KyuubiRestException {
+ public void testAnonymousBasicClient() {
BatchTestServlet.setAuthSchema(BASIC_AUTH);
BatchTestServlet.allowAnonymous(true);
@@ -135,7 +135,7 @@ public class BatchRestClientTest {
}
@Test
- public void createBatchTest() throws KyuubiRestException {
+ public void createBatchTest() {
// test spnego auth
BatchTestServlet.setAuthSchema(NEGOTIATE_AUTH);
@@ -158,7 +158,7 @@ public class BatchRestClientTest {
}
@Test
- public void getBatchByIdTest() throws KyuubiRestException {
+ public void getBatchByIdTest() {
// test spnego auth
BatchTestServlet.setAuthSchema(NEGOTIATE_AUTH);
@@ -181,7 +181,7 @@ public class BatchRestClientTest {
}
@Test
- public void getBatchInfoListTest() throws KyuubiRestException {
+ public void getBatchInfoListTest() {
// test spnego auth
BatchTestServlet.setAuthSchema(NEGOTIATE_AUTH);
@@ -204,7 +204,7 @@ public class BatchRestClientTest {
}
@Test
- public void getOperationLogTest() throws KyuubiRestException {
+ public void getOperationLogTest() {
// test spnego auth
BatchTestServlet.setAuthSchema(NEGOTIATE_AUTH);
@@ -223,7 +223,7 @@ public class BatchRestClientTest {
}
@Test
- public void deleteBatchTest() throws KyuubiRestException {
+ public void deleteBatchTest() {
// test spnego auth
BatchTestServlet.setAuthSchema(NEGOTIATE_AUTH);
spnegoBatchRestApi.deleteBatch("71535", true, "b_test");