You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/12/19 14:31:55 UTC

[GitHub] mhenke1 commented on a change in pull request #4187: Handle kafka exception thrown when creating the admin client

mhenke1 commented on a change in pull request #4187: Handle kafka exception thrown when creating the admin client
URL: https://github.com/apache/incubator-openwhisk/pull/4187#discussion_r242936571
 
 

 ##########
 File path: common/scala/src/main/scala/org/apache/openwhisk/connector/kafka/KafkaMessagingProvider.scala
 ##########
 @@ -60,30 +60,35 @@ object KafkaMessagingProvider extends MessagingProvider {
       } getOrElse Map.empty)
 
     val commonConfig = configMapToKafkaConfig(loadConfigOrThrow[Map[String, String]](ConfigKeys.kafkaCommon))
-    val client = AdminClient.create(commonConfig + (AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG -> config.kafkaHosts))
-    val partitions = 1
-    val nt = new NewTopic(topic, partitions, kafkaConfig.replicationFactor).configs(topicConfig.asJava)
-
-    def createTopic(retries: Int = 5): Try[Unit] = {
-      Try(client.createTopics(List(nt).asJava).values().get(topic).get())
-        .map(_ => logging.info(this, s"created topic $topic"))
-        .recoverWith {
-          case CausedBy(_: TopicExistsException) =>
-            Success(logging.info(this, s"topic $topic already existed"))
-          case CausedBy(t: RetriableException) if retries > 0 =>
-            logging.warn(this, s"topic $topic could not be created because of $t, retries left: $retries")
-            Thread.sleep(1.second.toMillis)
-            createTopic(retries - 1)
-          case t =>
-            logging.error(this, s"ensureTopic for $topic failed due to $t")
-            Failure(t)
+    Try(AdminClient.create(commonConfig + (AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG -> config.kafkaHosts)))
+      .map(client => {
+        val partitions = 1
+        val nt = new NewTopic(topic, partitions, kafkaConfig.replicationFactor).configs(topicConfig.asJava)
+
+        def createTopic(retries: Int = 5): Try[Unit] = {
+          Try(client.createTopics(List(nt).asJava).values().get(topic).get())
+            .map(_ => logging.info(this, s"created topic $topic"))
+            .recoverWith {
+              case CausedBy(_: TopicExistsException) =>
+                Success(logging.info(this, s"topic $topic already existed"))
+              case CausedBy(t: RetriableException) if retries > 0 =>
+                logging.warn(this, s"topic $topic could not be created because of $t, retries left: $retries")
+                Thread.sleep(1.second.toMillis)
+                createTopic(retries - 1)
+              case t =>
+                logging.error(this, s"ensureTopic for $topic failed due to $t")
+                Failure(t)
+            }
         }
-    }
-
-    val result = createTopic()
 
-    client.close()
-    result
+        val result = createTopic()
+        client.close()
+      })
+      .recoverWith {
+        case e =>
+          logging.error(this, s"ensureTopic for $topic failed due to $e")
+          Failure(e)
+      }
 
 Review comment:
   ´createTopic´ does use the admin client. Does it really make sense to continue when we have failed to get the client ?

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


With regards,
Apache Git Services