|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.kyuubi.kubernetes.test |
| 19 | + |
| 20 | +import io.fabric8.kubernetes.client.DefaultKubernetesClient |
| 21 | + |
| 22 | +import org.apache.kyuubi.WithKyuubiServer |
| 23 | +import org.apache.kyuubi.config.KyuubiConf |
| 24 | + |
| 25 | +trait WithKyuubiServerOnKubernetes extends WithKyuubiServer { |
| 26 | + protected val kyuubiServerConf: KyuubiConf = KyuubiConf() |
| 27 | + protected val connectionConf: Map[String, String] |
| 28 | + private var miniKubernetesClient: DefaultKubernetesClient = _ |
| 29 | + |
| 30 | + final override protected lazy val conf: KyuubiConf = { |
| 31 | + connectionConf.foreach { case (k, v) => kyuubiServerConf.set(k, v) } |
| 32 | + kyuubiServerConf |
| 33 | + } |
| 34 | + |
| 35 | + override def beforeAll(): Unit = { |
| 36 | + miniKubernetesClient = MiniKube.getKubernetesClient |
| 37 | + super.beforeAll() |
| 38 | + } |
| 39 | + |
| 40 | + override def afterAll(): Unit = super.afterAll() |
| 41 | + |
| 42 | + override protected def getJdbcUrl: String = { |
| 43 | + val kyuubiServers = |
| 44 | + miniKubernetesClient.pods().list().getItems |
| 45 | + assert(kyuubiServers.size() == 1) |
| 46 | + val kyuubiServer = kyuubiServers.get(0) |
| 47 | + // Kyuubi server state should be running since mvn compile is quite slowly.. |
| 48 | + if (!"running".equalsIgnoreCase(kyuubiServer.getStatus.getPhase)) { |
| 49 | + val log = |
| 50 | + miniKubernetesClient |
| 51 | + .pods() |
| 52 | + .withName(kyuubiServer.getMetadata.getName) |
| 53 | + .getLog |
| 54 | + throw new IllegalStateException( |
| 55 | + s"Kyuubi server pod state error: ${kyuubiServer.getStatus.getPhase}, log:\n$log") |
| 56 | + } |
| 57 | + val kyuubiServerIp = MiniKube.getIp |
| 58 | + val kyuubiServerPort = |
| 59 | + kyuubiServer.getSpec.getContainers.get(0).getPorts.get(0).getHostPort |
| 60 | + s"jdbc:hive2://$kyuubiServerIp:$kyuubiServerPort/;" |
| 61 | + } |
| 62 | +} |
0 commit comments