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

    https://github.com/apache/spark/pull/10953#discussion_r52201905
  
    --- Diff: 
external/kafka/src/main/scala/org/apache/spark/streaming/kafka/KafkaUtils.scala 
---
    @@ -610,6 +619,417 @@ object KafkaUtils {
           Set(topics.asScala.toSeq: _*)
         )
       }
    +
    +  // Start - Kafka functions using the new Consumer API
    +
    +  def addSSLOptions(
    +    kafkaParams: Map[String, String],
    +    sc: SparkContext): Map[String, String] = {
    +    val sparkConf = sc.getConf
    +    val defaultSSLOptions = SSLOptions.parse(sparkConf, "spark.ssl", None)
    +    val kafkaSSLOptions = SSLOptions.parse(sparkConf, "spark.ssl.kafka", 
Some(defaultSSLOptions))
    +
    +    if (kafkaSSLOptions.enabled) {
    +      val sslParams = Map[String, Option[_]](
    +        CommonClientConfigs.SECURITY_PROTOCOL_CONFIG -> Some("SSL"),
    +        SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG -> 
kafkaSSLOptions.trustStore,
    +        SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG -> 
kafkaSSLOptions.trustStorePassword,
    +        SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG -> 
kafkaSSLOptions.keyStore,
    +        SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG -> 
kafkaSSLOptions.keyStorePassword,
    +        SslConfigs.SSL_KEY_PASSWORD_CONFIG -> kafkaSSLOptions.keyPassword)
    +      kafkaParams ++ 
sslParams.filter(_._2.isDefined).mapValues(_.get.toString)
    +    } else {
    +      kafkaParams
    +    }
    +
    +  }
    +
    +  /** Make sure offsets are available in kafka, or throw an exception */
    +  private def newCheckOffsets(
    +    kafkaParams: Map[String, String],
    +    offsetRanges: Array[OffsetRange]): Array[OffsetRange] = {
    +    val kc = new NewKafkaCluster(kafkaParams)
    +    try {
    +      val topics = offsetRanges.map(_.topicPartition).toSet
    +      val low = kc.getEarliestOffsets(topics)
    +      val high = kc.getLatestOffsetsWithLeaders(topics)
    +
    +      val result = offsetRanges.filterNot { o =>
    +        low(o.topicPartition()) <= o.fromOffset &&
    +          o.untilOffset <= high(o.topicPartition()).offset
    +      }
    +
    +      if (!result.isEmpty) {
    +        throw new SparkException("Offsets not available in Kafka: " + 
result.mkString(","))
    +      }
    +
    +      offsetRanges.map { o =>
    +        OffsetRange(o.topic, o.partition, o.fromOffset, o.untilOffset,
    +          high(o.topicPartition()).host)
    +      }
    +    } finally {
    +      kc.close()
    +    }
    +  }
    +
    +  /**
    +    * Create a RDD from Kafka using offset ranges for each topic and 
partition.
    +    *
    +    * @param sc SparkContext object
    +    * @param kafkaParams Kafka <a 
href="http://kafka.apache.org/documentation.html#configuration";>
    +    *                    configuration parameters</a>. Requires 
"bootstrap.servers"
    +    *                    to be set with Kafka broker(s) (NOT zookeeper 
servers) specified in
    +    *                    host1:port1,host2:port2 form.
    +    * @param offsetRanges Each OffsetRange in the batch corresponds to a
    +    *                     range of offsets for a given Kafka 
topic/partition
    +    * @tparam K type of Kafka message key
    +    * @tparam V type of Kafka message value
    +    * @return RDD of (Kafka message key, Kafka message value)
    +    */
    +  def createNewRDD[K: ClassTag, V: ClassTag](
    --- End diff --
    
    I think we should avoid method names like createNewRDD and 
createNewDirectStream in the public API. Hari commented about the word 'new' 
and i think this takes it 1 step further in the -ve direction.
    
    Can we just drop the 'new' here. Anyhow the signatures dont conflict and i 
assume we will mark the prev ones as deprecated, which is good enough to bring 
to the user notice as to which ones is expected to be used.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to