Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -74,6 +74,7 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with

private var provider: FsHistoryProvider = null
private var server: HistoryServer = null
private val localhost: String = Utils.localCanonicalHostName()
private var port: Int = -1

protected def diskBackend: HybridStoreDiskBackend.Value
Expand Down Expand Up @@ -428,12 +429,12 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with

// build a URL for an app or app/attempt plus a page underneath
def buildURL(appId: String, suffix: String): URL = {
new URL(s"http://localhost:$port/history/$appId$suffix")
new URL(s"http://$localhost:$port/history/$appId$suffix")
}

// build a rest URL for the application and suffix.
def applications(appId: String, suffix: String): URL = {
new URL(s"http://localhost:$port/api/v1/applications/$appId$suffix")
new URL(s"http://$localhost:$port/api/v1/applications/$appId$suffix")
}

// start initial job
Expand Down Expand Up @@ -586,11 +587,11 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with

val port = server.boundPort
val testUrls = Seq(
s"http://localhost:$port/api/v1/applications/$appId/1/jobs",
s"http://localhost:$port/history/$appId/1/jobs/",
s"http://localhost:$port/api/v1/applications/$appId/logs",
s"http://localhost:$port/api/v1/applications/$appId/1/logs",
s"http://localhost:$port/api/v1/applications/$appId/2/logs")
s"http://$localhost:$port/api/v1/applications/$appId/1/jobs",
s"http://$localhost:$port/history/$appId/1/jobs/",
s"http://$localhost:$port/api/v1/applications/$appId/logs",
s"http://$localhost:$port/api/v1/applications/$appId/1/logs",
s"http://$localhost:$port/api/v1/applications/$appId/2/logs")

tests.foreach { case (user, expectedCode) =>
testUrls.foreach { url =>
Expand All @@ -609,9 +610,9 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with

val port = server.boundPort
val testUrls = Seq(
s"http://localhost:$port/api/v1/applications/$appId/logs",
s"http://localhost:$port/api/v1/applications/$appId/1/logs",
s"http://localhost:$port/api/v1/applications/$appId/2/logs")
s"http://$localhost:$port/api/v1/applications/$appId/logs",
s"http://$localhost:$port/api/v1/applications/$appId/1/logs",
s"http://$localhost:$port/api/v1/applications/$appId/2/logs")

testUrls.foreach { url =>
TestUtils.httpResponseCode(new URL(url))
Expand All @@ -636,9 +637,9 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with
def buildPageAttemptUrl(appId: String, attemptId: Option[Int]): URL = {
attemptId match {
case Some(id) =>
new URL(s"http://localhost:$port/history/$appId/$id")
new URL(s"http://$localhost:$port/history/$appId/$id")
case None =>
new URL(s"http://localhost:$port/history/$appId")
new URL(s"http://$localhost:$port/history/$appId")
}
}

Expand All @@ -663,15 +664,15 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with
}

def getContentAndCode(path: String, port: Int = port): (Int, Option[String], Option[String]) = {
HistoryServerSuite.getContentAndCode(new URL(s"http://localhost:$port/api/v1/$path"))
HistoryServerSuite.getContentAndCode(new URL(s"http://$localhost:$port/api/v1/$path"))
}

def getUrl(path: String): String = {
HistoryServerSuite.getUrl(generateURL(path))
}

def generateURL(path: String): URL = {
new URL(s"http://localhost:$port/api/v1/$path")
new URL(s"http://$localhost:$port/api/v1/$path")
}

def generateExpectation(name: String, path: String): Unit = {
Expand All @@ -686,7 +687,7 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with
test("SPARK-31697: HistoryServer should set Content-Type") {
val port = server.boundPort
val nonExistenceAppId = "local-non-existence"
val url = new URL(s"http://localhost:$port/history/$nonExistenceAppId")
val url = new URL(s"http://$localhost:$port/history/$nonExistenceAppId")
val conn = url.openConnection().asInstanceOf[HttpURLConnection]
conn.setRequestMethod("GET")
conn.connect()
Expand All @@ -697,15 +698,15 @@ abstract class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with

test("Redirect to the root page when accessed to /history/") {
val port = server.boundPort
val url = new URL(s"http://localhost:$port/history/")
val url = new URL(s"http://$localhost:$port/history/")
val conn = url.openConnection().asInstanceOf[HttpURLConnection]
conn.setRequestMethod("GET")
conn.setUseCaches(false)
conn.setDefaultUseCaches(false)
conn.setInstanceFollowRedirects(false)
conn.connect()
assert(conn.getResponseCode === 302)
assert(conn.getHeaderField("Location") === s"http://localhost:$port/")
assert(conn.getHeaderField("Location") === s"http://$localhost:$port/")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ class MasterSuite extends SparkFunSuite
val conf = new SparkConf()
val localCluster = LocalSparkCluster(2, 2, 512, conf)
localCluster.start()
val masterUrl = s"http://localhost:${localCluster.masterWebUIPort}"
val masterUrl = s"http://${Utils.localCanonicalHostName()}:${localCluster.masterWebUIPort}"
try {
eventually(timeout(5.seconds), interval(100.milliseconds)) {
eventually(timeout(50.seconds), interval(100.milliseconds)) {
val json = Utils
.tryWithResource(Source.fromURL(s"$masterUrl/json"))(_.getLines().mkString("\n"))
val JArray(workers) = (parse(json) \ "workers")
Expand Down Expand Up @@ -362,9 +362,9 @@ class MasterSuite extends SparkFunSuite
conf.set(UI_REVERSE_PROXY, true)
val localCluster = LocalSparkCluster(2, 2, 512, conf)
localCluster.start()
val masterUrl = s"http://localhost:${localCluster.masterWebUIPort}"
val masterUrl = s"http://${Utils.localCanonicalHostName()}:${localCluster.masterWebUIPort}"
try {
eventually(timeout(5.seconds), interval(100.milliseconds)) {
eventually(timeout(50.seconds), interval(100.milliseconds)) {
val json = Utils
.tryWithResource(Source.fromURL(s"$masterUrl/json"))(_.getLines().mkString("\n"))
val JArray(workers) = (parse(json) \ "workers")
Expand Down Expand Up @@ -400,9 +400,9 @@ class MasterSuite extends SparkFunSuite
conf.set(UI_REVERSE_PROXY_URL, reverseProxyUrl)
val localCluster = LocalSparkCluster(2, 2, 512, conf)
localCluster.start()
val masterUrl = s"http://localhost:${localCluster.masterWebUIPort}"
val masterUrl = s"http://${Utils.localCanonicalHostName()}:${localCluster.masterWebUIPort}"
try {
eventually(timeout(5.seconds), interval(100.milliseconds)) {
eventually(timeout(50.seconds), interval(100.milliseconds)) {
val json = Utils
.tryWithResource(Source.fromURL(s"$masterUrl/json"))(_.getLines().mkString("\n"))
val JArray(workers) = (parse(json) \ "workers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.apache.spark.deploy.DeployMessages.{DecommissionWorkersOnHosts, KillD
import org.apache.spark.deploy.DeployTestUtils._
import org.apache.spark.deploy.master._
import org.apache.spark.rpc.{RpcEndpointRef, RpcEnv}
import org.apache.spark.util.Utils


class MasterWebUISuite extends SparkFunSuite with BeforeAndAfterAll {
Expand Down Expand Up @@ -68,7 +69,7 @@ class MasterWebUISuite extends SparkFunSuite with BeforeAndAfterAll {

when(master.idToApp).thenReturn(HashMap[String, ApplicationInfo]((activeApp.id, activeApp)))

val url = s"http://localhost:${masterWebUI.boundPort}/app/kill/"
val url = s"http://${Utils.localCanonicalHostName()}:${masterWebUI.boundPort}/app/kill/"
val body = convPostDataToString(Map(("id", activeApp.id), ("terminate", "true")))
val conn = sendHttpRequest(url, "POST", body)
conn.getResponseCode
Expand All @@ -79,7 +80,7 @@ class MasterWebUISuite extends SparkFunSuite with BeforeAndAfterAll {

test("kill driver") {
val activeDriverId = "driver-0"
val url = s"http://localhost:${masterWebUI.boundPort}/driver/kill/"
val url = s"http://${Utils.localCanonicalHostName()}:${masterWebUI.boundPort}/driver/kill/"
val body = convPostDataToString(Map(("id", activeDriverId), ("terminate", "true")))
val conn = sendHttpRequest(url, "POST", body)
conn.getResponseCode
Expand All @@ -89,7 +90,7 @@ class MasterWebUISuite extends SparkFunSuite with BeforeAndAfterAll {
}

private def testKillWorkers(hostnames: Seq[String]): Unit = {
val url = s"http://localhost:${masterWebUI.boundPort}/workers/kill/"
val url = s"http://${Utils.localCanonicalHostName()}:${masterWebUI.boundPort}/workers/kill/"
val body = convPostDataToString(hostnames.map(("host", _)))
val conn = sendHttpRequest(url, "POST", body)
// The master is mocked here, so cannot assert on the response code
Expand All @@ -99,7 +100,7 @@ class MasterWebUISuite extends SparkFunSuite with BeforeAndAfterAll {
}

test("Kill one host") {
testKillWorkers(Seq("localhost"))
testKillWorkers(Seq("${Utils.localCanonicalHostName()}"))
}

test("Kill multiple hosts") {
Expand Down