[KYUUBI #2359] [Test] Build WithKyuubiServerOnKuberntes

### _Why are the changes needed?_

Refactor KyuubiOnKubernetesTestsSuite
Build WithKyuubiServerOnKuberntes like WithKyuubiServerOnYarn

### _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

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

Closes #2359 from zwangsheng/test/kyuubi_on_kubernetes.

Closes #2359

c1048c6a [zwangsheng] fix
81c98cd2 [zwangsheng] unused import
976f9091 [zwangsheng] fix
bad6720b [zwangsheng] fix
98d8995c [zwangsheng] refactor
628de557 [zwangsheng] style check
9dc6675a [zwangsheng] Build WithKyuubiServerOnKubernetes

Authored-by: zwangsheng <2213335496@qq.com>
Signed-off-by: ulysses-you <ulyssesyou@apache.org>
This commit is contained in:
zwangsheng 2022-04-15 14:16:54 +08:00 committed by ulysses-you
parent 6d147894a0
commit 65a272f6e4
No known key found for this signature in database
GPG Key ID: 4C500BC62D576766
2 changed files with 69 additions and 31 deletions

View File

@ -0,0 +1,62 @@
/*
* 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.kubernetes.test
import io.fabric8.kubernetes.client.DefaultKubernetesClient
import org.apache.kyuubi.WithKyuubiServer
import org.apache.kyuubi.config.KyuubiConf
trait WithKyuubiServerOnKubernetes extends WithKyuubiServer {
protected val kyuubiServerConf: KyuubiConf = KyuubiConf()
protected val connectionConf: Map[String, String]
private var miniKubernetesClient: DefaultKubernetesClient = _
final override protected lazy val conf: KyuubiConf = {
connectionConf.foreach { case (k, v) => kyuubiServerConf.set(k, v) }
kyuubiServerConf
}
override def beforeAll(): Unit = {
miniKubernetesClient = MiniKube.getKubernetesClient
super.beforeAll()
}
override def afterAll(): Unit = super.afterAll()
override protected def getJdbcUrl: String = {
val kyuubiServers =
miniKubernetesClient.pods().list().getItems
assert(kyuubiServers.size() == 1)
val kyuubiServer = kyuubiServers.get(0)
// Kyuubi server state should be running since mvn compile is quite slowly..
if (!"running".equalsIgnoreCase(kyuubiServer.getStatus.getPhase)) {
val log =
miniKubernetesClient
.pods()
.withName(kyuubiServer.getMetadata.getName)
.getLog
throw new IllegalStateException(
s"Kyuubi server pod state error: ${kyuubiServer.getStatus.getPhase}, log:\n$log")
}
val kyuubiServerIp = MiniKube.getIp
val kyuubiServerPort =
kyuubiServer.getSpec.getContainers.get(0).getPorts.get(0).getHostPort
s"jdbc:hive2://$kyuubiServerIp:$kyuubiServerPort/;"
}
}

View File

@ -17,8 +17,7 @@
package org.apache.kyuubi.kubernetes.test.deployment
import org.apache.kyuubi.Logging
import org.apache.kyuubi.kubernetes.test.MiniKube
import org.apache.kyuubi.kubernetes.test.WithKyuubiServerOnKubernetes
import org.apache.kyuubi.operation.SparkQueryTests
/**
@ -31,34 +30,11 @@ import org.apache.kyuubi.operation.SparkQueryTests
* | | | |
* ------------ -----------------------------------------------------
*/
class KyuubiOnKubernetesTestsSuite extends SparkQueryTests with Logging {
private lazy val _jdbcUrl: String = {
val kubernetesclient = MiniKube.getKubernetesClient
val kyuubiServers =
kubernetesclient
.pods()
.list()
.getItems
assert(kyuubiServers.size() == 1)
val kyuubiServer = kyuubiServers.get(0)
// Kyuubi server state should be running since mvn compile is quite slowly..
if (!"running".equalsIgnoreCase(kyuubiServer.getStatus.getPhase)) {
val log =
kubernetesclient
.pods()
.withName(kyuubiServer.getMetadata.getName)
.getLog
throw new IllegalStateException(
s"Kyuubi server pod state error: ${kyuubiServer.getStatus.getPhase}, log:\n$log")
}
val kyuubiServerIp = MiniKube.getIp
val kyuubiServerPort =
kyuubiServer.getSpec.getContainers.get(0).getPorts.get(0).getHostPort
s"jdbc:hive2://$kyuubiServerIp:$kyuubiServerPort/;"
}
class KyuubiOnKubernetesWithLocalSparkTestsSuite extends WithKyuubiServerOnKubernetes
with SparkQueryTests {
override protected val connectionConf: Map[String, String] = Map(
"spark.master" -> "local",
"spark.executor.instances" -> "1")
override protected def jdbcUrl: String = {
assert(_jdbcUrl != null, "Failed to get Kyuubi server")
_jdbcUrl
}
override protected def jdbcUrl: String = getJdbcUrl
}