hddong commented on a change in pull request #25412: [SPARK-28691][EXAMPLES] 
Add Java/Scala DirectKerberizedKafkaWordCount examples
URL: https://github.com/apache/spark/pull/25412#discussion_r316465282
 
 

 ##########
 File path: 
examples/src/main/java/org/apache/spark/examples/streaming/JavaDirectKerberizedKafkaWordCount.java
 ##########
 @@ -0,0 +1,138 @@
+/*
+ * 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.examples.streaming;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import scala.Tuple2;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.common.security.auth.SecurityProtocol;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.serialization.StringDeserializer;
+
+import org.apache.spark.SparkConf;
+import org.apache.spark.streaming.api.java.*;
+import org.apache.spark.streaming.kafka010.ConsumerStrategies;
+import org.apache.spark.streaming.kafka010.KafkaUtils;
+import org.apache.spark.streaming.kafka010.LocationStrategies;
+import org.apache.spark.streaming.Durations;
+
+/**
+ * Consumes messages from one or more topics in Kafka and does wordcount.
+ * Usage: JavaDirectKerberizedKafkaWordCount <brokers> <groupId> <topics>
+ *   <brokers> is a list of one or more Kafka brokers
+ *   <groupId> is a consumer group name to consume from topics
+ *   <topics> is a list of one or more kafka topics to consume from
+ *
+ * Example:
+ *   Yarn client:
+ *    $ bin/run-example --files 
${jaas_path}/kafka_jaas.conf,${keytab_path}/kafka.service.keytab \
+ *      --driver-java-options 
"-Djava.security.auth.login.config=${path}/kafka_driver_jaas.conf" \
+ *      --conf \
+ *      
"spark.executor.extraJavaOptions=-Djava.security.auth.login.config=./kafka_jaas.conf"
 \
+ *      --master yarn
+ *      streaming.JavaDirectKerberizedKafkaWordCount 
broker1-host:port,broker2-host:port \
+ *      consumer-group topic1,topic2
+ *   Yarn cluster:
+ *    $ bin/run-example --files \
+ *      
${jaas_path}/kafka_jaas.conf,${keytab_path}/kafka.service.keytab,${krb5_path}/krb5.conf
 \
+ *      --driver-java-options \
+ *      "-Djava.security.auth.login.config=./kafka_jaas.conf \
+ *      -Djava.security.krb5.conf=./krb5.conf" \
 
 Review comment:
   @gaborgsomogyi , Client mode, driver run on client which usually has 
environment of kerberos, so it's not need. Cluster mode, driver run in a random 
executor which not contain
   krb5.conf and it will throw exception:
   ···
   Caused by: javax.security.auth.login.LoginException: Cannot locate KDC
           at 
com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:804)
           at 
com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:617)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
           at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:498)
           at 
javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
           at 
javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
           at 
javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
           at 
javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
           at java.security.AccessController.doPrivileged(Native Method)
           at 
javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
           at 
javax.security.auth.login.LoginContext.login(LoginContext.java:587)
           at 
org.apache.kafka.common.security.authenticator.AbstractLogin.login(AbstractLogin.java:60)
           at 
org.apache.kafka.common.security.kerberos.KerberosLogin.login(KerberosLogin.java:103)
           at 
org.apache.kafka.common.security.authenticator.LoginManager.<init>(LoginManager.java:64)
           at 
org.apache.kafka.common.security.authenticator.LoginManager.acquireLoginManager(LoginManager.java:114)
           at 
org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:142)
           ... 26 more
   ···
   so , `krb5.conf` needed for cluster mode.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to