[KYUUBI #1088] Refactor java version dto to scala version
<!-- 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. --> ### _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 #1089 from yanghua/KYUUBI-1088. Closes #1088 c905bde3 [yanghua] [KYUUBI #1088] Refactor java version dto to scala version Authored-by: yanghua <yanghua1127@gmail.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
This commit is contained in:
parent
c080283671
commit
61752d90de
@ -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<String, String> getConfigs() {
|
||||
return configs;
|
||||
}
|
||||
|
||||
public void setConfigs(Map<String, String> configs) {
|
||||
this.configs = configs;
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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]
|
||||
)
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user