This is an automated email from the ASF dual-hosted git repository. shaofengshi pushed a commit to branch 3.0.x in repository https://gitbox.apache.org/repos/asf/kylin.git
commit 81995ca99394d64ff4bc304a47abf9dd60792d25 Author: shaofengshi <shaofeng...@apache.org> AuthorDate: Sat Aug 15 10:14:17 2020 +0800 minor, update restclient --- .../apache/kylin/common/restclient/RestClient.java | 13 +++++++++---- .../apache/kylin/restclient/ITRestClientTest.java | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java index 955b0ff..bf13059 100644 --- a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java +++ b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java @@ -201,24 +201,29 @@ public class RestClient { } public String getKylinProperties() throws IOException { - String url = baseUrl + "/admin/config"; - HttpGet request = new HttpGet(url); + return getConfiguration(baseUrl + "/admin/config", true); + } + + private String getConfiguration(String url, boolean ifAuth) throws IOException { + HttpGet request = ifAuth ? newGet(url) : new HttpGet(url); HttpResponse response = null; try { response = client.execute(request); String msg = EntityUtils.toString(response.getEntity()); - Map<String, String> map = JsonUtil.readValueAsMap(msg); - msg = map.get("config"); if (response.getStatusLine().getStatusCode() != 200) throw new IOException(INVALID_RESPONSE + response.getStatusLine().getStatusCode() + " with cache wipe url " + url + "\n" + msg); + + Map<String, String> map = JsonUtil.readValueAsMap(msg); + msg = map.get("config"); return msg; } finally { cleanup(request, response); } } + public boolean enableCache() throws IOException { return setCache(true); } diff --git a/kylin-it/src/test/java/org/apache/kylin/restclient/ITRestClientTest.java b/kylin-it/src/test/java/org/apache/kylin/restclient/ITRestClientTest.java index adf98fa..b73f7b4 100644 --- a/kylin-it/src/test/java/org/apache/kylin/restclient/ITRestClientTest.java +++ b/kylin-it/src/test/java/org/apache/kylin/restclient/ITRestClientTest.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.Random; @@ -104,6 +105,25 @@ public class ITRestClientTest extends HBaseMetadataTestCase { HttpResponse result = client.query(sql, PROJECT_NAME); } + @Test + public void testGetConfigByAdmin() throws Exception { + RestClient client = new RestClient(HOST, PORT, USERNAME, PASSWD); + String result = client.getKylinProperties(); + assertTrue(result != null && result.length() > 0); + } + + @Test(expected = IOException.class) + public void testGetConfigUnauthorized() throws Exception { + RestClient client = new RestClient(HOST, PORT, "", ""); + client.getKylinProperties(); + } + + @Test(expected = IOException.class) + public void testGetConfigNonAdmin() throws Exception { + RestClient client = new RestClient(HOST, PORT, "MODELER", "MODELER"); + client.getKylinProperties(); + } + protected static void stopJetty() throws Exception { if (server != null) server.stop();