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

    https://github.com/apache/spark/pull/10953#discussion_r52360764
  
    --- 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 --
    
    Mario, see my comment below about new. As far as marking the previous ones 
as deprecated, I don't quite feel the same way. The new consumer API is brand 
new, and may take a bit to bake in (given issues like 
[KAFKA-3029](issues.apache.org/jira/browse/KAFKA-3029) and 
[KAFKA-3159](https://issues.apache.org/jira/browse/KAFKA-3159) are being 
found). It's also currently marked as beta. So, my recommendation would not be 
to deprecate the old API. It's only for those who are eager and curious to use 
the new API, and especially the associated encryption and authentication 
capabilities it offers, for now, in my opinion. Let me know if you differ 
though.


---
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