1717
1818package org .apache .spark .deploy .rest
1919
20- import java .io .{FileNotFoundException , DataOutputStream }
21- import java .net .{HttpURLConnection , URL }
20+ import java .io .{DataOutputStream , FileNotFoundException }
21+ import java .net .{HttpURLConnection , SocketException , URL }
2222
2323import scala .io .Source
2424
2525import com .google .common .base .Charsets
2626
27- import org .apache .spark .{Logging , SparkException , SPARK_VERSION => sparkVersion }
27+ import org .apache .spark .{Logging , SPARK_VERSION => sparkVersion }
2828import org .apache .spark .deploy .SparkSubmitArguments
2929
3030/**
@@ -43,8 +43,8 @@ import org.apache.spark.deploy.SparkSubmitArguments
4343 * Additionally, the base URL includes the version of the protocol. For instance:
4444 * http://1.2.3.4:6066/v1/submissions/create. Since the protocol is expected to be stable
4545 * across Spark versions, existing fields cannot be added or removed. In the rare event that
46- * backward compatibility is broken, Spark must introduce a new protocol version (e.g. v2).
47- * The client and the server must communicate on the same version of the protocol.
46+ * forward or backward compatibility is broken, Spark must introduce a new protocol version
47+ * (e.g. v2). The client and the server must communicate on the same version of the protocol.
4848 */
4949private [spark] class StandaloneRestClient extends Logging {
5050 import StandaloneRestClient ._
@@ -123,7 +123,7 @@ private[spark] class StandaloneRestClient extends Logging {
123123 private def readResponse (connection : HttpURLConnection ): SubmitRestProtocolResponse = {
124124 try {
125125 val responseJson = Source .fromInputStream(connection.getInputStream).mkString
126- logDebug(s " Response from the REST server: \n $responseJson" )
126+ logDebug(s " Response from the server: \n $responseJson" )
127127 val response = SubmitRestProtocolMessage .fromJson(responseJson)
128128 // The response should have already been validated on the server.
129129 // In case this is not true, validate it ourselves to avoid potential NPEs.
@@ -139,39 +139,40 @@ private[spark] class StandaloneRestClient extends Logging {
139139 case error : ErrorResponse =>
140140 logError(s " Server responded with error: \n ${error.message}" )
141141 error
142- case response : SubmitRestProtocolResponse =>
143- response
142+ case response : SubmitRestProtocolResponse => response
144143 case unexpected =>
145144 throw new SubmitRestProtocolException (
146- s " Unexpected message received from server:\n $unexpected" )
145+ s " Message received from server was not a response :\n ${ unexpected.toJson} " )
147146 }
148147 } catch {
149- case e : FileNotFoundException =>
150- throw new SparkException (s " Unable to connect to server ${connection.getURL}" , e)
148+ case e @ (_ : FileNotFoundException | _ : SocketException ) =>
149+ throw new SubmitRestConnectionException (
150+ s " Unable to connect to server ${connection.getURL}" , e)
151151 }
152152 }
153153
154154 /** Return the REST URL for creating a new submission. */
155155 private def getSubmitUrl (master : String ): URL = {
156156 val baseUrl = getBaseUrl(master)
157- new URL (s " $baseUrl/submissions/ create " )
157+ new URL (s " $baseUrl/create " )
158158 }
159159
160160 /** Return the REST URL for killing an existing submission. */
161161 private def getKillUrl (master : String , submissionId : String ): URL = {
162162 val baseUrl = getBaseUrl(master)
163- new URL (s " $baseUrl/submissions/ kill/ $submissionId" )
163+ new URL (s " $baseUrl/kill/ $submissionId" )
164164 }
165165
166166 /** Return the REST URL for requesting the status of an existing submission. */
167167 private def getStatusUrl (master : String , submissionId : String ): URL = {
168168 val baseUrl = getBaseUrl(master)
169- new URL (s " $baseUrl/submissions/ status/ $submissionId" )
169+ new URL (s " $baseUrl/status/ $submissionId" )
170170 }
171171
172172 /** Return the base URL for communicating with the server, including the protocol version. */
173173 private def getBaseUrl (master : String ): String = {
174- " http://" + master.stripPrefix(" spark://" ).stripSuffix(" /" ) + " /" + PROTOCOL_VERSION
174+ val masterUrl = master.stripPrefix(" spark://" ).stripSuffix(" /" )
175+ s " http:// $masterUrl/ $PROTOCOL_VERSION/submissions "
175176 }
176177
177178 /** Throw an exception if this is not standalone mode. */
@@ -223,10 +224,11 @@ private[spark] class StandaloneRestClient extends Logging {
223224 if (submitSuccess) {
224225 val submissionId = submitResponse.submissionId
225226 if (submissionId != null ) {
226- logInfo(s " Driver successfully submitted as $submissionId. Polling driver state... " )
227+ logInfo(s " Submission successfully created as $submissionId. Polling submission state... " )
227228 pollSubmissionStatus(master, submissionId)
228229 } else {
229- logError(" Application successfully submitted, but driver ID was not provided!" )
230+ // should never happen
231+ logError(" Application successfully submitted, but submission ID was not provided!" )
230232 }
231233 } else {
232234 val failMessage = Option (submitResponse.message).map { " : " + _ }.getOrElse(" " )
@@ -267,7 +269,7 @@ private[spark] class StandaloneRestClient extends Logging {
267269 }
268270 Thread .sleep(REPORT_DRIVER_STATUS_INTERVAL )
269271 }
270- logError(s " Error: Master did not recognize submission $submissionId. " )
272+ logError(s " Error: Master did not recognize driver $submissionId. " )
271273 }
272274}
273275
0 commit comments