Github user andrewor14 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4216#discussion_r23876918
  
    --- Diff: 
core/src/main/scala/org/apache/spark/deploy/rest/SubmitRestProtocolMessage.scala
 ---
    @@ -0,0 +1,209 @@
    +/*
    + * 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.rest
    +
    +import com.fasterxml.jackson.annotation._
    +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
    +import com.fasterxml.jackson.annotation.JsonInclude.Include
    +import com.fasterxml.jackson.databind.ObjectMapper
    +import org.json4s.JsonAST._
    +import org.json4s.jackson.JsonMethods._
    +
    +import org.apache.spark.util.Utils
    +
    +/**
    + * An abstract message exchanged in the REST application submission 
protocol.
    + *
    + * This message is intended to be serialized to and deserialized from JSON 
in the exchange.
    + * Each message can either be a request or a response and consists of 
three common fields:
    + *   (1) the action, which fully specifies the type of the message
    + *   (2) the Spark version of the client / server
    + *   (3) an optional message
    + */
    +@JsonInclude(Include.NON_NULL)
    +@JsonAutoDetect(getterVisibility = Visibility.ANY, setterVisibility = 
Visibility.ANY)
    +@JsonPropertyOrder(alphabetic = true)
    +abstract class SubmitRestProtocolMessage {
    +  private val messageType = Utils.getFormattedClassName(this)
    +  protected val action: String = messageType
    +  protected val sparkVersion: SubmitRestProtocolField[String]
    +  protected val message = new SubmitRestProtocolField[String]("message")
    +
    +  // Required for JSON de/serialization and not explicitly used
    +  private def getAction: String = action
    +  private def setAction(s: String): this.type = this
    +
    +  // Intended for the user and not for JSON de/serialization, which 
expects more specific keys
    +  @JsonIgnore
    +  def getSparkVersion: String
    +  @JsonIgnore
    +  def setSparkVersion(s: String): this.type
    +
    +  def getMessage: String = message.toString
    +  def setMessage(s: String): this.type = setField(message, s)
    +
    +  /**
    +   * Serialize the message to JSON.
    +   * This also ensures that the message is valid and its fields are in the 
expected format.
    +   */
    +  def toJson: String = {
    +    validate()
    +    val mapper = new ObjectMapper
    +    pretty(parse(mapper.writeValueAsString(this)))
    --- End diff --
    
    great


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to