You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ul...@apache.org on 2021/12/23 08:58:56 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #1611] Fix swagger-ui redirect wrong to other service address

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

ulyssesyou 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 54a1b88  [KYUUBI #1611] Fix swagger-ui redirect wrong to other service address
54a1b88 is described below

commit 54a1b88245d91d3d8dd3c2c056e440c499492fe6
Author: Fu Chen <cf...@gmail.com>
AuthorDate: Thu Dec 23 16:58:43 2021 +0800

    [KYUUBI #1611] Fix swagger-ui redirect wrong to other service address
    
    <!--
    Thanks for sending a pull request!
    
    Here are some tips for you:
      1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html
      2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
      3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
    -->
    
    ### _Why are the changes needed?_
    <!--
    Please clarify why the changes are needed. For instance,
      1. If you add a feature, you can talk about the use case of it.
      2. If you fix a bug, you can clarify why it is a bug.
    -->
    
    close #1611
    
    ### _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/latest/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #1615 from cfmcgrady/kyuubi-1611.
    
    Closes #1611
    
    f44bf3b1 [Fu Chen] fix swagger-ui
    
    Authored-by: Fu Chen <cf...@gmail.com>
    Signed-off-by: ulysses-you <ul...@apache.org>
---
 .../scala/org/apache/kyuubi/server/api/v1/ApiRootResource.scala   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/ApiRootResource.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/ApiRootResource.scala
index 5ecf1cf..c9052b8 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/ApiRootResource.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/ApiRootResource.scala
@@ -23,7 +23,7 @@ import javax.ws.rs.core.{MediaType, Response}
 
 import com.google.common.annotations.VisibleForTesting
 
-import org.apache.kyuubi.server.KyuubiServer
+import org.apache.kyuubi.server.{KyuubiRestFrontendService, KyuubiServer}
 import org.apache.kyuubi.server.api.ApiRequestContext
 
 @Path("/api/v1")
@@ -53,7 +53,11 @@ private[v1] class ApiRootResource extends ApiRequestContext {
   @Path("swagger-ui")
   @Produces(Array(MediaType.TEXT_HTML))
   def swaggerUi(): Response = {
-    val serverIP = KyuubiServer.kyuubiServer.frontendServices.head.connectionUrl
+    val restServiceOpt = KyuubiServer.kyuubiServer
+      .frontendServices
+      .collectFirst { case rest: KyuubiRestFrontendService => rest }
+    assert(restServiceOpt.isDefined)
+    val serverIP = restServiceOpt.map(_.connectionUrl).get
     val swaggerUi =
       s"http://$serverIP/swagger-ui-redirected/index.html?url=http://$serverIP/openapi.json"
     Response.temporaryRedirect(new URI(swaggerUi)).build()