Skip to content

Commit

Permalink
[KYUUBI apache#4657] Building rest client to kyuubi instance includin…
Browse files Browse the repository at this point in the history
…g 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 apache#4657 from turboFei/direct_connect.

Closes apache#4657

084fdfb [fwang12] host urls
689ff8f [fwang12] rest client

Authored-by: fwang12 <fwang12@ebay.com>
Signed-off-by: fwang12 <fwang12@ebay.com>
  • Loading branch information
turboFei committed Apr 4, 2023
1 parent 7a83901 commit 82c5392
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class KyuubiRestClient implements AutoCloseable, Cloneable {

private RestClientConf conf;

private List<String> hostUrls;

private List<String> baseUrls;

private ApiVersion version;
Expand Down Expand Up @@ -77,14 +79,20 @@ public void setHostUrls(List<String> hostUrls) {
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();
Expand Down

0 comments on commit 82c5392

Please sign in to comment.