-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-2778] [yarn] Add yarn integration tests. #2257
Changes from 4 commits
add8416
d07ef9a
68fbbbf
f01517c
67f5b02
ec73f17
5c2b56f
8b0933d
6d5b84e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
# Set everything to be logged to the file core/target/unit-tests.log | ||
log4j.rootCategory=INFO, file | ||
log4j.appender.file=org.apache.log4j.FileAppender | ||
log4j.appender.file.append=false | ||
log4j.appender.file.file=target/unit-tests.log | ||
log4j.appender.file.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.file.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss.SSS} %p %c{1}: %m%n | ||
|
||
# Ignore messages below warning level from Jetty, because it's a bit verbose | ||
log4j.logger.org.eclipse.jetty=WARN | ||
org.eclipse.jetty.LEVEL=WARN |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* 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.spark.deploy.yarn | ||
|
||
import java.io.File | ||
|
||
import scala.collection.JavaConversions._ | ||
|
||
import com.google.common.base.Charsets | ||
import com.google.common.io.Files | ||
import org.scalatest.{BeforeAndAfterAll, FunSuite, Matchers} | ||
|
||
import org.apache.hadoop.yarn.conf.YarnConfiguration | ||
import org.apache.hadoop.yarn.server.MiniYARNCluster | ||
|
||
import org.apache.spark.{Logging, SparkConf, SparkContext} | ||
import org.apache.spark.deploy.SparkHadoopUtil | ||
import org.apache.spark.util.Utils | ||
|
||
class YarnClusterSuite extends FunSuite with BeforeAndAfterAll with Matchers { | ||
|
||
private var oldConf: Map[String, String] = _ | ||
private var yarnCluster: MiniYARNCluster = _ | ||
private var tempDir: File = _ | ||
private var fakeSparkJar: File = _ | ||
|
||
override def beforeAll() { | ||
tempDir = Utils.createTempDir() | ||
|
||
yarnCluster = new MiniYARNCluster(getClass().getName(), 1, 1, 1) | ||
yarnCluster.init(new YarnConfiguration()) | ||
yarnCluster.start() | ||
|
||
oldConf = sys.props.toMap | ||
yarnCluster.getConfig().foreach { e => | ||
sys.props += ("spark.hadoop." + e.getKey() -> e.getValue()) | ||
} | ||
|
||
fakeSparkJar = File.createTempFile("sparkJar", null, tempDir) | ||
sys.props += ("spark.yarn.jar" -> ("local:" + fakeSparkJar.getAbsolutePath())) | ||
sys.props += ("spark.executor.instances" -> "1") | ||
sys.props += ("spark.driver.extraClassPath" -> sys.props("java.class.path")) | ||
sys.props += ("spark.executor.extraClassPath" -> sys.props("java.class.path")) | ||
|
||
super.beforeAll() | ||
} | ||
|
||
override def afterAll() { | ||
yarnCluster.stop() | ||
|
||
val sysProps = sys.props.map { case (k, v) => (k, v) } | ||
sysProps.foreach { case (k, v) => | ||
if (k.startsWith("spark.")) { | ||
sys.props -= k | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole chunk can be rewritten as:
|
||
|
||
sys.props ++= oldConf | ||
|
||
super.afterAll() | ||
} | ||
|
||
test("run Spark in yarn-client mode") { | ||
var result = File.createTempFile("result", null, tempDir) | ||
YarnClusterDriver.main(Array("yarn-client", result.getAbsolutePath())) | ||
checkResult(result) | ||
} | ||
|
||
test("run Spark in yarn-cluster mode") { | ||
val main = YarnClusterDriver.getClass.getName().stripSuffix("$") | ||
var result = File.createTempFile("result", null, tempDir) | ||
|
||
// The Client object will call System.exit() after the job is done, and we don't want | ||
// that because it messes up the scalatest monitoring. So replicate some of what main() | ||
// does here. | ||
val args = Array("--class", main, | ||
"--jar", "file:" + fakeSparkJar.getAbsolutePath(), | ||
"--arg", "yarn-cluster", | ||
"--arg", result.getAbsolutePath(), | ||
"--num-executors", "1") | ||
val sparkConf = new SparkConf() | ||
val yarnConf = SparkHadoopUtil.get.newConfiguration(sparkConf) | ||
val clientArgs = new ClientArguments(args, sparkConf) | ||
new Client(clientArgs, yarnConf, sparkConf).run() | ||
checkResult(result) | ||
} | ||
|
||
/** | ||
* This is a workaround for an issue with yarn-cluster mode: the Client class will not provide | ||
* any sort of error when the job process finishes successfully, but the job itself fails. So | ||
* the tests enforce that something is written to a file after everything is ok to indicate | ||
* that the job succeeded. | ||
*/ | ||
private def checkResult(result: File) = { | ||
var resultString = Files.toString(result, Charsets.UTF_8) | ||
resultString should be ("success") | ||
} | ||
|
||
} | ||
|
||
private object YarnClusterDriver extends Logging with Matchers { | ||
|
||
def main(args: Array[String]) = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an arg check here that prints usage and exits if not enough args are provided? |
||
val sc = new SparkContext(new SparkConf().setMaster(args(0)) | ||
.setAppName("yarn \"test app\" 'with quotes' and \\back\\slashes and $dollarSigns")) | ||
val status = new File(args(1)) | ||
var result = "failure" | ||
try { | ||
val data = sc.parallelize(1 to 4).map(i => i).collect().toSet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the map to identity here do anything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was just a way to trigger an actual job. I guess I could do |
||
data should be (Set(1, 2, 3, 4)) | ||
result = "success" | ||
} finally { | ||
sc.stop() | ||
Files.write(result, status, Charsets.UTF_8) | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this? Is it not used or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to this test it was not used. SPARK_CLASSPATH is also deprecated.
The new test uses
spark.{driver|executor}.extraClassPath
instead, to make sure they work correctly, and those two settings also conflict with SPARK_CLASSPATH.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and one more: I can't see
spark.classpath
being set anywhere.