Github user rekhajoshm commented on a diff in the pull request:
https://github.com/apache/spark/pull/21684#discussion_r200735457
--- Diff:
core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionClient.scala ---
@@ -233,30 +233,41 @@ private[spark] class RestSubmissionClient(master:
String) extends Logging {
private[rest] def readResponse(connection: HttpURLConnection):
SubmitRestProtocolResponse = {
import scala.concurrent.ExecutionContext.Implicits.global
val responseFuture = Future {
- val dataStream =
- if (connection.getResponseCode == HttpServletResponse.SC_OK) {
- connection.getInputStream
- } else {
- connection.getErrorStream
+ val responseCode = connection.getResponseCode
+
+ if (responseCode != HttpServletResponse.SC_OK) {
+ val errString =
Some(Source.fromInputStream(connection.getErrorStream())
+ .getLines().mkString("\n"))
+ logError(s"Server responded with error:\n${errString}")
+ val error = new ErrorResponse
+ if (responseCode ==
RestSubmissionServer.SC_UNKNOWN_PROTOCOL_VERSION) {
+ error.highestProtocolVersion =
RestSubmissionServer.PROTOCOL_VERSION
}
- // If the server threw an exception while writing a response, it
will not have a body
- if (dataStream == null) {
- throw new SubmitRestProtocolException("Server returned empty body")
+ error.message = errString.get
+ error
}
- val responseJson = Source.fromInputStream(dataStream).mkString
- logDebug(s"Response from the server:\n$responseJson")
- val response = SubmitRestProtocolMessage.fromJson(responseJson)
- response.validate()
- response match {
- // If the response is an error, log the message
- case error: ErrorResponse =>
- logError(s"Server responded with error:\n${error.message}")
- error
- // Otherwise, simply return the response
- case response: SubmitRestProtocolResponse => response
- case unexpected =>
- throw new SubmitRestProtocolException(
- s"Message received from server was not a
response:\n${unexpected.toJson}")
+ else {
--- End diff --
thanks, done.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]