diff --git a/kyuubi-server/src/main/java/org/apache/kyuubi/server/api/v1/dto/SessionOpenRequest.java b/kyuubi-server/src/main/java/org/apache/kyuubi/server/api/v1/dto/SessionOpenRequest.java deleted file mode 100644 index 68f2c3a84..000000000 --- a/kyuubi-server/src/main/java/org/apache/kyuubi/server/api/v1/dto/SessionOpenRequest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.api.v1.dto; - -import java.util.Map; - -public class SessionOpenRequest { - - private int protocolVersion; - private String user; - private String password; - private String ipAddr; - private Map configs; - - public SessionOpenRequest() { - } - - public int getProtocolVersion() { - return protocolVersion; - } - - public void setProtocolVersion(int protocolVersion) { - this.protocolVersion = protocolVersion; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getIpAddr() { - return ipAddr; - } - - public void setIpAddr(String ipAddr) { - this.ipAddr = ipAddr; - } - - public Map getConfigs() { - return configs; - } - - public void setConfigs(Map configs) { - this.configs = configs; - } -} diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala index 201b2fc9d..3c5ca9dcf 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala @@ -22,10 +22,8 @@ import com.fasterxml.jackson.module.scala.DefaultScalaModule import javax.ws.rs.{Consumes, GET, Path, POST, Produces} import javax.ws.rs.core.MediaType import org.apache.hive.service.rpc.thrift.TProtocolVersion -import scala.collection.JavaConverters.mapAsScalaMapConverter import org.apache.kyuubi.server.api.ApiRequestContext -import org.apache.kyuubi.server.api.v1.dto.{SessionOpenedCount, SessionOpenRequest} @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class SessionsResource extends ApiRequestContext { @@ -34,23 +32,20 @@ private[v1] class SessionsResource extends ApiRequestContext { @GET @Path("count") - def sessionCount(): SessionOpenedCount = { - val sessionOpenedCount = new SessionOpenedCount() - sessionOpenedCount.setOpenSessionCount( - backendService.sessionManager.getOpenSessionCount - ) - sessionOpenedCount + def sessionCount(): String = { + mapper.writeValueAsString(SessionOpenCount(backendService.sessionManager.getOpenSessionCount)) } @POST @Consumes(Array(MediaType.APPLICATION_JSON)) - def openSession(request : SessionOpenRequest): String = { + def openSession(req : String): String = { + val request = mapper.readValue(req, classOf[SessionOpenRequest]) val sessionHandle = backendService.openSession( - TProtocolVersion.findByValue(request.getProtocolVersion), - request.getUser, - request.getPassword, - request.getIpAddr, - request.getConfigs.asScala.toMap) + TProtocolVersion.findByValue(request.protocolVersion), + request.user, + request.password, + request.ipAddr, + request.configs) mapper.writeValueAsString(sessionHandle) } } diff --git a/kyuubi-server/src/main/java/org/apache/kyuubi/server/api/v1/dto/SessionOpenedCount.java b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala similarity index 50% rename from kyuubi-server/src/main/java/org/apache/kyuubi/server/api/v1/dto/SessionOpenedCount.java rename to kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala index 84964b442..995e7e1b1 100644 --- a/kyuubi-server/src/main/java/org/apache/kyuubi/server/api/v1/dto/SessionOpenedCount.java +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala @@ -15,40 +15,14 @@ * limitations under the License. */ -package org.apache.kyuubi.server.api.v1.dto; +package org.apache.kyuubi.server.api.v1 -import java.io.Serializable; -import java.util.Objects; +case class SessionOpenCount(openSessionCount: Int) -public class SessionOpenedCount implements Serializable { - - private int openSessionCount; - - public SessionOpenedCount() { - } - - public int getOpenSessionCount() { - return openSessionCount; - } - - public void setOpenSessionCount(int openSessionCount) { - this.openSessionCount = openSessionCount; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof SessionOpenedCount)) { - return false; - } - SessionOpenedCount that = (SessionOpenedCount) o; - return openSessionCount == that.getOpenSessionCount(); - } - - @Override - public int hashCode() { - return Objects.hash(openSessionCount); - } -} +case class SessionOpenRequest( + protocolVersion: Int, + user: String, + password: String, + ipAddr: String, + configs: Map[String, String] +) diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala index 41ca0131b..924a0c719 100644 --- a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala +++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala @@ -28,7 +28,6 @@ import org.junit.Test import org.apache.kyuubi.server.RestFrontendServiceSuite import org.apache.kyuubi.server.RestFrontendServiceSuite.{OBJECT_MAPPER, TEST_SERVER_PORT} -import org.apache.kyuubi.server.api.v1.dto.{SessionOpenedCount, SessionOpenRequest} import org.apache.kyuubi.session.SessionHandle class SessionsResourceSuite extends JerseyTest { @@ -42,20 +41,16 @@ class SessionsResourceSuite extends JerseyTest { @Test def testOpenAndCountSession: Unit = { - val requestObj = new SessionOpenRequest - requestObj.setProtocolVersion(1) - requestObj.setUser("admin") - requestObj.setPassword("123456") - requestObj.setIpAddr("localhost") - val configs = new java.util.HashMap[String, String] - configs.put("testConfig", "testValue") - requestObj.setConfigs(configs) + val requestObj = SessionOpenRequest( + 1, "admin", "123456", "localhost", Map("testConfig" -> "testValue")) + + val requestObjStr = OBJECT_MAPPER.writeValueAsString(requestObj) RestFrontendServiceSuite.withKyuubiRestServer { (_, _, _) => var response = target(s"api/v1/sessions") .request(MediaType.APPLICATION_JSON_TYPE) - .post(Entity.entity(requestObj, MediaType.APPLICATION_JSON_TYPE)) + .post(Entity.entity(requestObjStr, MediaType.APPLICATION_JSON_TYPE)) assert(200 == response.getStatus) @@ -66,12 +61,10 @@ class SessionsResourceSuite extends JerseyTest { assert(sessionHandle.identifier != null) // verify the open session count - val expectedCount = new SessionOpenedCount() - expectedCount.setOpenSessionCount(1) - response = target("api/v1/sessions/count").request().get() - val responseObj = response.readEntity(classOf[SessionOpenedCount]) - assert(responseObj.equals(expectedCount)) + val openedSessionCount = OBJECT_MAPPER.readValue( + response.readEntity(classOf[String]), classOf[SessionOpenCount]) + assert(openedSessionCount.openSessionCount == 1) } }