Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KYUUBI #5380][UT] Create PySpark batch jobs tests for RESTful API #5498

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.rest.client

import java.nio.file.Paths

import org.apache.kyuubi.{BatchTestHelper, RestClientTestHelper}
import org.apache.kyuubi.client.{BatchRestApi, KyuubiRestClient}
import org.apache.kyuubi.client.api.v1.dto.Batch
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.engine.spark.SparkProcessBuilder

class BatchRestApiPySparkSuite extends RestClientTestHelper with BatchTestHelper {
weixi62961 marked this conversation as resolved.
Show resolved Hide resolved
object PySparkJobPI {
weixi62961 marked this conversation as resolved.
Show resolved Hide resolved
val batchType = "PYSPARK"
val className: String = null // For PySpark, mainClass isn't needed.
weixi62961 marked this conversation as resolved.
Show resolved Hide resolved
val name = "PythonPi" // the app name is hard coded in spark example code
lazy val resource: Option[String] = {
val sparkProcessBuilder = new SparkProcessBuilder("kyuubi", KyuubiConf())
Paths.get(
sparkProcessBuilder.sparkHome,
"examples",
"src",
"main",
"python").toFile.listFiles().find(
_.getName.equalsIgnoreCase("pi.py")) map (_.getCanonicalPath)
}
}

test("pyspark submit - basic batch rest client with existing resource file") {
val basicKyuubiRestClient: KyuubiRestClient =
KyuubiRestClient.builder(baseUri.toString)
.authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.BASIC)
.username(ldapUser)
.password(ldapUserPasswd)
.socketTimeout(30000)
.build()
val batchRestApi: BatchRestApi = new BatchRestApi(basicKyuubiRestClient)

val requestObj = newBatchRequest(
batchType = PySparkJobPI.batchType,
resource = PySparkJobPI.resource.get,
className = null,
name = PySparkJobPI.name,
conf = Map("spark.master" -> "local"),
args = Seq("10"))
val batch: Batch = batchRestApi.createBatch(requestObj)

assert(batch.getKyuubiInstance === fe.connectionUrl)
assert(batch.getBatchType === "PYSPARK")
basicKyuubiRestClient.close()
}

test("pyspark submit - basic batch rest client with uploading resource file") {
val basicKyuubiRestClient: KyuubiRestClient =
KyuubiRestClient.builder(baseUri.toString)
.authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.BASIC)
.username(ldapUser)
.password(ldapUserPasswd)
.socketTimeout(30000)
.build()
val batchRestApi: BatchRestApi = new BatchRestApi(basicKyuubiRestClient)

val requestObj = newBatchRequest(
batchType = PySparkJobPI.batchType,
resource = null,
className = null,
name = PySparkJobPI.name,
conf = Map("spark.master" -> "local"),
args = Seq("10"))
val resourceFile = Paths.get(PySparkJobPI.resource.get).toFile
val batch: Batch = batchRestApi.createBatch(requestObj, resourceFile)

assert(batch.getKyuubiInstance === fe.connectionUrl)
assert(batch.getBatchType === "PYSPARK")
basicKyuubiRestClient.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,5 @@ class BatchRestApiSuite extends RestClientTestHelper with BatchTestHelper {
assert(
batchSession.conf.get(KyuubiReservedKeys.KYUUBI_CLIENT_VERSION_KEY) == Some(KYUUBI_VERSION))
}

weixi62961 marked this conversation as resolved.
Show resolved Hide resolved
}