This is an automated email from the ASF dual-hosted git repository.

feiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 82c53924d [KYUUBI #4657] Building rest client to kyuubi instance 
including original host urls
82c53924d is described below

commit 82c53924d5d2ad3628fd19be38fd4d6617ce9724
Author: fwang12 <[email protected]>
AuthorDate: Tue Apr 4 16:19:45 2023 +0800

    [KYUUBI #4657] Building rest client to kyuubi instance including original 
host urls
    
    ### _Why are the changes needed?_
    
    Usually, the host url to create a batch is the load balancer uri.
    
    To reduce the internal rest redirection when fetching log, we support to 
call the kyuubi instance that created the batch directly.
    
    It is better to add original host urls when building the rest client to 
kyuubi instance, in case that there is firewall to the kyuubi instance directly.
    
    ### _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.readthedocs.io/en/master/develop_tools/testing.html#running-tests)
 locally before make a pull request
    
    Closes #4657 from turboFei/direct_connect.
    
    Closes #4657
    
    084fdfb49 [fwang12] host urls
    689ff8f8c [fwang12] rest client
    
    Authored-by: fwang12 <[email protected]>
    Signed-off-by: fwang12 <[email protected]>
---
 .../src/main/scala/org/apache/kyuubi/ctl/RestClientFactory.scala  | 5 ++++-
 .../src/main/java/org/apache/kyuubi/client/KyuubiRestClient.java  | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/RestClientFactory.scala 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/RestClientFactory.scala
index bbaa5f668..75b490a4a 100644
--- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/RestClientFactory.scala
+++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/RestClientFactory.scala
@@ -18,6 +18,8 @@ package org.apache.kyuubi.ctl
 
 import java.util.{Map => JMap}
 
+import scala.collection.JavaConverters._
+
 import org.apache.commons.lang3.StringUtils
 
 import org.apache.kyuubi.KyuubiException
@@ -45,7 +47,8 @@ object RestClientFactory {
       kyuubiRestClient: KyuubiRestClient,
       kyuubiInstance: String)(f: KyuubiRestClient => Unit): Unit = {
     val kyuubiInstanceRestClient = kyuubiRestClient.clone()
-    kyuubiInstanceRestClient.setHostUrls(s"http://${kyuubiInstance}";)
+    val hostUrls = Seq(s"http://$kyuubiInstance";) ++ 
kyuubiRestClient.getHostUrls.asScala
+    kyuubiInstanceRestClient.setHostUrls(hostUrls.asJava)
     try {
       f(kyuubiInstanceRestClient)
     } finally {
diff --git 
a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/KyuubiRestClient.java
 
b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/KyuubiRestClient.java
index dbcc89b16..c83eff7e0 100644
--- 
a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/KyuubiRestClient.java
+++ 
b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/KyuubiRestClient.java
@@ -30,6 +30,8 @@ public class KyuubiRestClient implements AutoCloseable, 
Cloneable {
 
   private RestClientConf conf;
 
+  private List<String> hostUrls;
+
   private List<String> baseUrls;
 
   private ApiVersion version;
@@ -77,14 +79,20 @@ public class KyuubiRestClient implements AutoCloseable, 
Cloneable {
     if (hostUrls.isEmpty()) {
       throw new IllegalArgumentException("hostUrls cannot be blank.");
     }
+    this.hostUrls = hostUrls;
     List<String> baseUrls = initBaseUrls(hostUrls, version);
     this.httpClient = RetryableRestClient.getRestClient(baseUrls, this.conf);
   }
 
+  public List<String> getHostUrls() {
+    return hostUrls;
+  }
+
   private KyuubiRestClient() {}
 
   private KyuubiRestClient(Builder builder) {
     this.version = builder.version;
+    this.hostUrls = builder.hostUrls;
     this.baseUrls = initBaseUrls(builder.hostUrls, builder.version);
 
     RestClientConf conf = new RestClientConf();

Reply via email to