[KYUUBI #3977] [KYUUBI #3905] Add basic TrinoResource

close #3905

### _Why are the changes needed?_

### _How was this patch tested?_
- [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #3977 from iodone/kyuubi-3905.

Closes #3977

Closes #3905

4e4a22b1 [odone] trino server init and run

Authored-by: odone <odone.zhang@gmail.com>
Signed-off-by: ulysses-you <ulyssesyou@apache.org>
This commit is contained in:
odone 2022-12-15 09:27:06 +08:00 committed by ulysses-you
parent 0295c0fceb
commit b5590b829d
No known key found for this signature in database
GPG Key ID: 4C500BC62D576766
14 changed files with 610 additions and 2 deletions

View File

@ -65,6 +65,7 @@ jackson-annotations/2.14.1//jackson-annotations-2.14.1.jar
jackson-core/2.14.1//jackson-core-2.14.1.jar
jackson-databind/2.14.1//jackson-databind-2.14.1.jar
jackson-dataformat-yaml/2.14.1//jackson-dataformat-yaml-2.14.1.jar
jackson-datatype-jdk8/2.12.3//jackson-datatype-jdk8-2.12.3.jar
jackson-datatype-jsr310/2.14.1//jackson-datatype-jsr310-2.14.1.jar
jackson-jaxrs-base/2.14.1//jackson-jaxrs-base-2.14.1.jar
jackson-jaxrs-json-provider/2.14.1//jackson-jaxrs-json-provider-2.14.1.jar
@ -148,6 +149,7 @@ netty-transport-native-epoll/4.1.84.Final/linux-aarch_64/netty-transport-native-
netty-transport-native-epoll/4.1.84.Final/linux-x86_64/netty-transport-native-epoll-4.1.84.Final-linux-x86_64.jar
netty-transport-native-unix-common/4.1.84.Final//netty-transport-native-unix-common-4.1.84.Final.jar
netty-transport/4.1.84.Final//netty-transport-4.1.84.Final.jar
okhttp-urlconnection/3.14.9//okhttp-urlconnection-3.14.9.jar
okhttp/3.12.12//okhttp-3.12.12.jar
okio/1.15.0//okio-1.15.0.jar
osgi-resource-locator/1.0.3//osgi-resource-locator-1.0.3.jar
@ -174,6 +176,8 @@ swagger-integration/2.2.1//swagger-integration-2.2.1.jar
swagger-jaxrs2/2.2.1//swagger-jaxrs2-2.2.1.jar
swagger-models/2.2.1//swagger-models-2.2.1.jar
swagger-ui/4.9.1//swagger-ui-4.9.1.jar
trino-client/363//trino-client-363.jar
units/1.6//units-1.6.jar
vertx-core/4.3.2//vertx-core-4.3.2.jar
vertx-grpc/4.3.2//vertx-grpc-4.3.2.jar
zjsonpatch/0.3.0//zjsonpatch-0.3.0.jar

View File

@ -299,7 +299,7 @@ kyuubi.frontend.mysql.max.worker.threads|999|Maximum number of threads in the co
kyuubi.frontend.mysql.min.worker.threads|9|Minimum number of threads in the command execution thread pool for the MySQL frontend service|int|1.4.0
kyuubi.frontend.mysql.netty.worker.threads|&lt;undefined&gt;|Number of thread in the netty worker event loop of MySQL frontend service. Use min(cpu_cores, 8) in default.|int|1.4.0
kyuubi.frontend.mysql.worker.keepalive.time|PT1M|Time(ms) that an idle async thread of the command execution thread pool will wait for a new task to arrive before terminating in MySQL frontend service|duration|1.4.0
kyuubi.frontend.protocols|THRIFT_BINARY|A comma separated list for all frontend protocols <ul> <li>THRIFT_BINARY - HiveServer2 compatible thrift binary protocol.</li> <li>THRIFT_HTTP - HiveServer2 compatible thrift http protocol.</li> <li>REST - Kyuubi defined REST API(experimental).</li> <li>MYSQL - MySQL compatible text protocol(experimental).</li> </ul>|seq|1.4.0
kyuubi.frontend.protocols|THRIFT_BINARY|A comma separated list for all frontend protocols <ul> <li>THRIFT_BINARY - HiveServer2 compatible thrift binary protocol.</li> <li>THRIFT_HTTP - HiveServer2 compatible thrift http protocol.</li> <li>REST - Kyuubi defined REST API(experimental).</li> <li>MYSQL - MySQL compatible text protocol(experimental).</li> <li>TRINO - Trino compatible http protocol(experimental).</li> </ul>|seq|1.4.0
kyuubi.frontend.proxy.http.client.ip.header|X-Real-IP|The http header to record the real client ip address. If your server is behind a load balancer or other proxy, the server will see this load balancer or proxy IP address as the client IP address, to get around this common issue, most load balancers or proxies offer the ability to record the real remote IP address in an HTTP header that will be added to the request for other devices to use. Note that, because the header value can be specified to any ip address, so it will not be used for authentication.|string|1.6.0
kyuubi.frontend.rest.bind.host|&lt;undefined&gt;|Hostname or IP of the machine on which to run the REST frontend service.|string|1.4.0
kyuubi.frontend.rest.bind.port|10099|Port of the machine on which to run the REST frontend service.|int|1.4.0
@ -338,6 +338,9 @@ kyuubi.frontend.thrift.max.message.size|104857600|Maximum message size in bytes
kyuubi.frontend.thrift.max.worker.threads|999|Maximum number of threads in the of frontend worker thread pool for the thrift frontend service|int|1.4.0
kyuubi.frontend.thrift.min.worker.threads|9|Minimum number of threads in the of frontend worker thread pool for the thrift frontend service|int|1.4.0
kyuubi.frontend.thrift.worker.keepalive.time|PT1M|Keep-alive time (in milliseconds) for an idle worker thread|duration|1.4.0
kyuubi.frontend.trino.bind.host|&lt;undefined&gt;|Hostname or IP of the machine on which to run the TRINO frontend service.|string|1.7.0
kyuubi.frontend.trino.bind.port|10999|Port of the machine on which to run the TRINO frontend service.|int|1.7.0
kyuubi.frontend.trino.max.worker.threads|999|Maximum number of threads in the of frontend worker thread pool for the trino frontend service|int|1.7.0
kyuubi.frontend.worker.keepalive.time|PT1M|(deprecated) Keep-alive time (in milliseconds) for an idle worker thread|duration|1.0.0

View File

@ -362,7 +362,7 @@ object KyuubiConf {
object FrontendProtocols extends Enumeration {
type FrontendProtocol = Value
val THRIFT_BINARY, THRIFT_HTTP, REST, MYSQL = Value
val THRIFT_BINARY, THRIFT_HTTP, REST, MYSQL, TRINO = Value
}
val FRONTEND_PROTOCOLS: ConfigEntry[Seq[String]] =
@ -373,6 +373,7 @@ object KyuubiConf {
" <li>THRIFT_HTTP - HiveServer2 compatible thrift http protocol.</li>" +
" <li>REST - Kyuubi defined REST API(experimental).</li> " +
" <li>MYSQL - MySQL compatible text protocol(experimental).</li> " +
" <li>TRINO - Trino compatible http protocol(experimental).</li> " +
"</ul>")
.version("1.4.0")
.stringConf
@ -928,6 +929,28 @@ object KyuubiConf {
.version("1.4.0")
.fallbackConf(FRONTEND_WORKER_KEEPALIVE_TIME)
val FRONTEND_TRINO_BIND_HOST: ConfigEntry[Option[String]] =
buildConf("kyuubi.frontend.trino.bind.host")
.doc("Hostname or IP of the machine on which to run the TRINO frontend service.")
.version("1.7.0")
.serverOnly
.fallbackConf(FRONTEND_BIND_HOST)
val FRONTEND_TRINO_BIND_PORT: ConfigEntry[Int] = buildConf("kyuubi.frontend.trino.bind.port")
.doc("Port of the machine on which to run the TRINO frontend service.")
.version("1.7.0")
.serverOnly
.intConf
.checkValue(p => p == 0 || (p > 1024 && p < 65535), "Invalid Port number")
.createWithDefault(10999)
val FRONTEND_TRINO_MAX_WORKER_THREADS: ConfigEntry[Int] =
buildConf("kyuubi.frontend.trino.max.worker.threads")
.doc("Maximum number of threads in the of frontend worker thread pool for the trino " +
"frontend service")
.version("1.7.0")
.fallbackConf(FRONTEND_MAX_WORKER_THREADS)
val KUBERNETES_CONTEXT: OptionalConfigEntry[String] =
buildConf("kyuubi.kubernetes.context")
.doc("The desired context from your kubernetes config file used to configure the K8S " +

View File

@ -221,6 +221,11 @@
<artifactId>derby</artifactId>
</dependency>
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-client</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>

View File

@ -124,6 +124,9 @@ class KyuubiServer(name: String) extends Serverable(name) {
case MYSQL =>
warn("MYSQL frontend protocol is experimental.")
new KyuubiMySQLFrontendService(this)
case TRINO =>
warn("Trio frontend protocol is experimental.")
new KyuubiTrinoFrontendService(this)
case other =>
throw new UnsupportedOperationException(s"Frontend protocol $other is not supported yet.")
}

View File

@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server
import java.util.concurrent.atomic.AtomicBoolean
import org.apache.kyuubi.{KyuubiException, Utils}
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.{FRONTEND_TRINO_BIND_HOST, FRONTEND_TRINO_BIND_PORT, FRONTEND_TRINO_MAX_WORKER_THREADS}
import org.apache.kyuubi.server.trino.api.v1.ApiRootResource
import org.apache.kyuubi.server.ui.JettyServer
import org.apache.kyuubi.service.{AbstractFrontendService, Serverable, Service}
/**
* A frontend service based on RESTful api via HTTP protocol.
* Note: Currently, it only be used in the Kyuubi Server side.
*/
class KyuubiTrinoFrontendService(override val serverable: Serverable)
extends AbstractFrontendService("KyuubiTrinoFrontendService") {
private var server: JettyServer = _
private val isStarted = new AtomicBoolean(false)
lazy val host: String = conf.get(FRONTEND_TRINO_BIND_HOST)
.getOrElse {
if (conf.get(KyuubiConf.FRONTEND_CONNECTION_URL_USE_HOSTNAME)) {
Utils.findLocalInetAddress.getCanonicalHostName
} else {
Utils.findLocalInetAddress.getHostAddress
}
}
override def initialize(conf: KyuubiConf): Unit = synchronized {
this.conf = conf
server = JettyServer(
getName,
host,
conf.get(FRONTEND_TRINO_BIND_PORT),
conf.get(FRONTEND_TRINO_MAX_WORKER_THREADS))
super.initialize(conf)
}
override def connectionUrl: String = {
checkInitialized()
server.getServerUri
}
private def startInternal(): Unit = {
val contextHandler = ApiRootResource.getServletHandler(this)
server.addHandler(contextHandler)
server.addStaticHandler("org/apache/kyuubi/ui/static", "/static/")
server.addRedirectHandler("/", "/static/")
server.addRedirectHandler("/static", "/static/")
server.addStaticHandler("META-INF/resources/webjars/swagger-ui/4.9.1/", "/swagger-static/")
server.addStaticHandler("org/apache/kyuubi/ui/swagger", "/swagger/")
server.addRedirectHandler("/docs", "/swagger/")
server.addRedirectHandler("/docs/", "/swagger/")
server.addRedirectHandler("/swagger", "/swagger/")
}
override def start(): Unit = synchronized {
if (!isStarted.get) {
try {
server.start()
isStarted.set(true)
info(s"$getName has started at ${server.getServerUri}")
startInternal()
} catch {
case e: Exception => throw new KyuubiException(s"Cannot start $getName", e)
}
}
super.start()
}
override def stop(): Unit = synchronized {
if (isStarted.getAndSet(false)) {
server.stop()
}
super.stop()
}
override val discoveryService: Option[Service] = None
}

View File

@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server.trino.api
import javax.ws.rs.ext.ContextResolver
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
class KyuubiScalaObjectMapper extends ContextResolver[ObjectMapper] {
private val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
override def getContext(aClass: Class[_]): ObjectMapper = mapper
}

View File

@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server.trino.api
import org.glassfish.jersey.server.ResourceConfig
class TrinoServerConfig extends ResourceConfig {
packages("org.apache.kyuubi.server.trino.api.v1")
register(classOf[KyuubiScalaObjectMapper])
register(classOf[RestExceptionMapper])
}

View File

@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server.trino.api
import javax.servlet.ServletContext
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.WebApplicationException
import javax.ws.rs.core.{Context, MediaType, Response}
import javax.ws.rs.ext.{ExceptionMapper, Provider}
import org.eclipse.jetty.server.handler.ContextHandler
import org.apache.kyuubi.server.KyuubiTrinoFrontendService
private[api] trait ApiRequestContext {
@Context
protected var servletContext: ServletContext = _
@Context
protected var httpRequest: HttpServletRequest = _
final protected def fe: KyuubiTrinoFrontendService = FrontendServiceContext.get(servletContext)
}
@Provider
class RestExceptionMapper extends ExceptionMapper[Exception] {
override def toResponse(exception: Exception): Response = {
exception match {
case e: WebApplicationException =>
Response.status(e.getResponse.getStatus)
.`type`(e.getResponse.getMediaType)
.entity(e.getMessage)
.build()
case e =>
Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.`type`(MediaType.APPLICATION_JSON)
.entity(e.getMessage)
.build()
}
}
}
private[api] object FrontendServiceContext {
private val attribute = getClass.getCanonicalName
def set(contextHandler: ContextHandler, fe: KyuubiTrinoFrontendService): Unit = {
contextHandler.setAttribute(attribute, fe)
}
def get(context: ServletContext): KyuubiTrinoFrontendService = {
context.getAttribute(attribute).asInstanceOf[KyuubiTrinoFrontendService]
}
}

View File

@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server.trino.api.v1
import javax.ws.rs.{GET, Path, Produces}
import javax.ws.rs.core.{MediaType, Response}
import com.google.common.annotations.VisibleForTesting
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.responses.ApiResponse
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
import org.glassfish.jersey.server.ResourceConfig
import org.glassfish.jersey.servlet.ServletContainer
import org.apache.kyuubi.KYUUBI_VERSION
import org.apache.kyuubi.client.api.v1.dto._
import org.apache.kyuubi.server.KyuubiTrinoFrontendService
import org.apache.kyuubi.server.trino.api.{ApiRequestContext, FrontendServiceContext, TrinoServerConfig}
@Path("/v1")
private[v1] class ApiRootResource extends ApiRequestContext {
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_JSON)),
description = "Get the version of Kyuubi server.")
@GET
@Path("version")
@Produces(Array(MediaType.APPLICATION_JSON))
def version(): VersionInfo = new VersionInfo(KYUUBI_VERSION)
@GET
@Path("ping")
@Produces(Array(MediaType.TEXT_PLAIN))
def ping(): String = "pong"
@Path("statement")
def admin: Class[StatementResource] = classOf[StatementResource]
@GET
@Path("exception")
@Produces(Array(MediaType.TEXT_PLAIN))
@VisibleForTesting
def test(): Response = {
1 / 0
Response.ok().build()
}
}
private[server] object ApiRootResource {
def getServletHandler(fe: KyuubiTrinoFrontendService): ServletContextHandler = {
val openapiConf: ResourceConfig = new TrinoServerConfig
val holder = new ServletHolder(new ServletContainer(openapiConf))
val handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS)
FrontendServiceContext.set(handler, fe)
handler.addServlet(holder, "/*")
handler
}
}

View File

@ -0,0 +1,119 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server.trino.api.v1
import javax.ws.rs._
import javax.ws.rs.core.{Context, HttpHeaders, MediaType}
import io.swagger.v3.oas.annotations.media.{Content, Schema}
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag
import io.trino.client.QueryResults
import org.apache.kyuubi.Logging
import org.apache.kyuubi.server.trino.api.ApiRequestContext
import org.apache.kyuubi.server.trino.api.v1.dto.Ok
@Tag(name = "Statement")
@Produces(Array(MediaType.APPLICATION_JSON))
private[v1] class StatementResource extends ApiRequestContext with Logging {
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_JSON)),
description = "test")
@GET
@Path("test")
def test(): Ok = new Ok("trino server is running")
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_JSON,
schema = new Schema(implementation = classOf[QueryResults]))),
description =
"Create a query")
@GET
@Path("/")
@Consumes(Array(MediaType.TEXT_PLAIN))
def query(statement: String, @Context headers: HttpHeaders): QueryResults = {
throw new UnsupportedOperationException
}
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_JSON)),
description =
"Get queued statement status")
@GET
@Path("/queued/{queryId}/{slug}/{token}")
def getQueuedStatementStatus(
@PathParam("queryId") queryId: String,
@PathParam("slug") slug: String,
@PathParam("token") token: Long): QueryResults = {
throw new UnsupportedOperationException
}
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_JSON)),
description =
"Get executing statement status")
@GET
@Path("/executing/{queryId}/{slug}/{token}")
def getExecutingStatementStatus(
@PathParam("queryId") queryId: String,
@PathParam("slug") slug: String,
@PathParam("token") token: Long): QueryResults = {
throw new UnsupportedOperationException
}
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_JSON)),
description =
"Cancel queued statement")
@DELETE
@Path("/queued/{queryId}/{slug}/{token}")
def cancelQueuedStatement(
@PathParam("queryId") queryId: String,
@PathParam("slug") slug: String,
@PathParam("token") token: Long): QueryResults = {
throw new UnsupportedOperationException
}
@ApiResponse(
responseCode = "200",
content = Array(new Content(
mediaType = MediaType.APPLICATION_JSON)),
description =
"Cancel executing statement")
@DELETE
@Path("/executing/{queryId}/{slug}/{token}")
def cancelExecutingStatementStatus(
@PathParam("queryId") queryId: String,
@PathParam("slug") slug: String,
@PathParam("token") token: Long): QueryResults = {
throw new UnsupportedOperationException
}
}

View File

@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.kyuubi.server.trino.api.v1.dto;
import java.util.Objects;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class Ok {
private String content;
public Ok() {}
public Ok(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setContent(String version) {
this.content = version;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Ok that = (Ok) o;
return Objects.equals(getContent(), that.getContent());
}
@Override
public int hashCode() {
return Objects.hash(getContent());
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
}
}

View File

@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server
import org.apache.kyuubi.{KYUUBI_VERSION, RestFrontendTestHelper}
import org.apache.kyuubi.client.api.v1.dto.VersionInfo
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.FrontendProtocol
class KyuubiTrinoFrontendServiceSuite extends RestFrontendTestHelper {
override protected val frontendProtocols: Seq[FrontendProtocol] =
FrontendProtocols.TRINO :: Nil
test("version") {
val resp = webTarget.path("v1/version").request().get()
assert(resp.readEntity(classOf[VersionInfo]).getVersion === KYUUBI_VERSION)
}
test("kyuubi REST frontend service http basic") {
val resp = webTarget.path("v1/ping").request().get()
assert(resp.readEntity(classOf[String]) === "pong")
}
test("error and exception response") {
var response = webTarget.path("v1/pong").request().get()
assert(404 == response.getStatus)
assert(response.getStatusInfo.getReasonPhrase.equalsIgnoreCase("not found"))
response = webTarget.path("v1/ping").request().post(null)
assert(405 == response.getStatus)
assert(response.getStatusInfo.getReasonPhrase.equalsIgnoreCase("method not allowed"))
response = webTarget.path("v1/exception").request().get()
assert(500 == response.getStatus)
assert(response.getStatusInfo.getReasonPhrase.equalsIgnoreCase("Internal Server Error"))
}
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.server.trino.api.v1
import org.apache.kyuubi.{KyuubiFunSuite, RestFrontendTestHelper}
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.FrontendProtocol
import org.apache.kyuubi.server.trino.api.v1.dto.Ok
class StatementResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
override protected val frontendProtocols: Seq[FrontendProtocol] =
FrontendProtocols.TRINO :: Nil
test("statement test") {
val response = webTarget.path("v1/statement/test").request().get()
val result = response.readEntity(classOf[Ok])
assert(result == new Ok("trino server is running"))
}
}