[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326209107
 
 

 ##
 File path: 
tests/src/test/scala/org/apache/openwhisk/standalone/StandaloneServerFixture.scala
 ##
 @@ -93,6 +95,7 @@ trait StandaloneServerFixture extends TestSuite with 
BeforeAndAfterAll with Stre
   manifestFile.foreach(FileUtils.deleteQuietly)
   serverProcess.destroy()
 }
+FileUtils.forceDelete(new File(dataDirPath))
 
 Review comment:
   At least for tests...


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326203622
 
 

 ##
 File path: 
tests/src/test/scala/org/apache/openwhisk/standalone/StandaloneServerFixture.scala
 ##
 @@ -93,6 +95,7 @@ trait StandaloneServerFixture extends TestSuite with 
BeforeAndAfterAll with Stre
   manifestFile.foreach(FileUtils.deleteQuietly)
   serverProcess.destroy()
 }
+FileUtils.forceDelete(new File(dataDirPath))
 
 Review comment:
   I guess this answers my question from above regarding data deletion when the 
process exits...


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326191971
 
 

 ##
 File path: 
core/standalone/src/main/scala/org/apache/openwhisk/standalone/StandaloneOpenWhisk.scala
 ##
 @@ -63,6 +64,25 @@ class Conf(arguments: Seq[String]) extends 
ScallopConf(arguments) {
   val apiGwPort = opt[Int](descr = "Api Gateway Port", default = Some(3234), 
noshort = true)
   val dataDir = opt[File](descr = "Directory used for storage", default = 
Some(StandaloneOpenWhisk.defaultWorkDir))
 
+  val kafka = opt[Boolean](descr = "Enable embedded Kafka support", noshort = 
true)
+  val kafkaUi = opt[Boolean](descr = "Enable Kafka UI", noshort = true)
+
+  val kafkaPort = opt[Int](
+descr = "Kafka port. If not specified then 9092 or some random free port 
(if 9092 is busy) would be used",
+noshort = true,
+required = false)
 
 Review comment:
   I understand. Background of my proposal was that there is some duplication 
of the default ports. We have the port number 9092 for Kafka here AND in 
`startKafka()`. Wouldn't it make sense to define a `val defaultKafkaPort = 
9092` and use it to build the description string and in `startKafka()`?


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326189887
 
 

 ##
 File path: 
core/standalone/src/main/scala/org/apache/openwhisk/standalone/StandaloneOpenWhisk.scala
 ##
 @@ -393,6 +417,42 @@ object StandaloneOpenWhisk extends SLF4JLogging {
 Await.result(g, 5.minutes)
   }
 
+  private def startKafka(workDir: File, dockerClient: StandaloneDockerClient, 
conf: Conf, kafkaUi: Boolean)(
+implicit logging: Logging,
+as: ActorSystem,
+ec: ExecutionContext,
+materializer: ActorMaterializer): (Int, Seq[ServiceContainer]) = {
+val kafkaPort = getPort(conf.kafkaPort.toOption, 9092)
 
 Review comment:
   If we add a default value to the `kafkaPort` option, can probably solve this 
differently and not repeat the port number literal here?


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326155928
 
 

 ##
 File path: 
core/standalone/src/main/scala/org/apache/openwhisk/standalone/KafkaLauncher.scala
 ##
 @@ -0,0 +1,120 @@
+/*
+ * 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.openwhisk.standalone
+
+import java.io.File
+
+import akka.actor.ActorSystem
+import akka.stream.ActorMaterializer
+import kafka.server.KafkaConfig
+import net.manub.embeddedkafka.{EmbeddedKafka, EmbeddedKafkaConfig}
+import org.apache.commons.io.FileUtils
+import org.apache.openwhisk.common.{Logging, TransactionId}
+import org.apache.openwhisk.core.WhiskConfig
+import org.apache.openwhisk.core.WhiskConfig.kafkaHosts
+import org.apache.openwhisk.core.entity.ControllerInstanceId
+import org.apache.openwhisk.core.loadBalancer.{LeanBalancer, LoadBalancer, 
LoadBalancerProvider}
+import 
org.apache.openwhisk.standalone.StandaloneDockerSupport.{checkOrAllocatePort, 
containerName, createRunCmd}
+
+import scala.concurrent.{ExecutionContext, Future}
+import scala.reflect.io.Directory
+import scala.util.Try
+
+class KafkaLauncher(docker: StandaloneDockerClient,
+kafkaPort: Int,
+kafkaDockerPort: Int,
+zkPort: Int,
+workDir: File,
+kafkaUi: Boolean)(implicit logging: Logging,
+  ec: ExecutionContext,
+  actorSystem: ActorSystem,
+  materializer: ActorMaterializer,
+  tid: TransactionId) {
+
+  def run(): Future[Seq[ServiceContainer]] = {
+for {
+  kafkaSvcs <- runKafka()
+  uiSvcs <- if (kafkaUi) runKafkaUI() else 
Future.successful(Seq.empty[ServiceContainer])
+} yield kafkaSvcs ++ uiSvcs
+  }
+
+  def runKafka(): Future[Seq[ServiceContainer]] = {
+
+//Below setting based on 
https://rmoff.net/2018/08/02/kafka-listeners-explained/
+// We configure two listeners where one is used for host based application 
and other is used for docker based application
+// to connect to Kafka server running on host
+val brokerProps = Map(
+  KafkaConfig.ListenersProp -> 
s"LISTENER_LOCAL://localhost:$kafkaPort,LISTENER_DOCKER://localhost:$kafkaDockerPort",
+  KafkaConfig.AdvertisedListenersProp -> 
s"LISTENER_LOCAL://localhost:$kafkaPort,LISTENER_DOCKER://${StandaloneDockerSupport
+.getLocalHostIp()}:$kafkaDockerPort",
+  KafkaConfig.ListenerSecurityProtocolMapProp -> 
"LISTENER_LOCAL:PLAINTEXT,LISTENER_DOCKER:PLAINTEXT",
+  KafkaConfig.InterBrokerListenerNameProp -> "LISTENER_LOCAL")
+implicit val config: EmbeddedKafkaConfig =
+  EmbeddedKafkaConfig(kafkaPort = kafkaPort, zooKeeperPort = zkPort, 
customBrokerProperties = brokerProps)
+
+val t = Try {
+  EmbeddedKafka.startZooKeeper(createDir("zookeeper"))
+  EmbeddedKafka.startKafka(createDir("kafka"))
+}
+
+Future
+  .fromTry(t)
+  .map(
+_ =>
+  Seq(
+ServiceContainer(kafkaPort, s"localhost:$kafkaPort", "kafka"),
+ServiceContainer(
+  kafkaDockerPort,
+  s"${StandaloneDockerSupport.getLocalHostIp()}:$kafkaDockerPort",
+  "kafka-docker"),
+ServiceContainer(zkPort, "Zookeeper", "zookeeper")))
+  }
+
+  def runKafkaUI(): Future[Seq[ServiceContainer]] = {
+val hostIp = StandaloneDockerSupport.getLocalHostIp()
+val port = checkOrAllocatePort(9000)
+val env = Map(
+  "ZOOKEEPER_CONNECT" -> s"$hostIp:$zkPort",
+  "KAFKA_BROKERCONNECT" -> s"$hostIp:$kafkaDockerPort",
+  "JVM_OPTS" -> "-Xms32M -Xmx64M",
+  "SERVER_SERVLET_CONTEXTPATH" -> "/")
+
+logging.info(this, s"Starting Kafka Drop UI port: $port")
+val name = containerName("kafka-drop-ui")
+val params = Map("-p" -> Set(s"$port:9000"))
+val args = createRunCmd(name, env, params)
+
+val f = docker.runDetached("obsidiandynamics/kafdrop", args, true)
+f.map(_ => Seq(ServiceContainer(port, s"http://localhost:$port;, 

[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326150517
 
 

 ##
 File path: 
core/standalone/src/main/scala/org/apache/openwhisk/standalone/StandaloneOpenWhisk.scala
 ##
 @@ -63,6 +64,25 @@ class Conf(arguments: Seq[String]) extends 
ScallopConf(arguments) {
   val apiGwPort = opt[Int](descr = "Api Gateway Port", default = Some(3234), 
noshort = true)
   val dataDir = opt[File](descr = "Directory used for storage", default = 
Some(StandaloneOpenWhisk.defaultWorkDir))
 
+  val kafka = opt[Boolean](descr = "Enable embedded Kafka support", noshort = 
true)
+  val kafkaUi = opt[Boolean](descr = "Enable Kafka UI", noshort = true)
+
+  val kafkaPort = opt[Int](
+descr = "Kafka port. If not specified then 9092 or some random free port 
(if 9092 is busy) would be used",
+noshort = true,
+required = false)
+
+  val kafkaDockerPort = opt[Int](
+descr = "Kafka port for use by docker based services. If not specified 
then 9091 or some random free port " +
+  "(if 9091 is busy) would be used",
+noshort = true,
+required = false)
+
+  val zkPort = opt[Int](
+descr = "Zookeeper port. If not specified then 2181 or some random free 
port (if 2181 is busy) would be used",
+noshort = true,
+required = false)
 
 Review comment:
   Would it make sense to add a `default = Some(2181)` here?


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326150351
 
 

 ##
 File path: 
core/standalone/src/main/scala/org/apache/openwhisk/standalone/StandaloneOpenWhisk.scala
 ##
 @@ -63,6 +64,25 @@ class Conf(arguments: Seq[String]) extends 
ScallopConf(arguments) {
   val apiGwPort = opt[Int](descr = "Api Gateway Port", default = Some(3234), 
noshort = true)
   val dataDir = opt[File](descr = "Directory used for storage", default = 
Some(StandaloneOpenWhisk.defaultWorkDir))
 
+  val kafka = opt[Boolean](descr = "Enable embedded Kafka support", noshort = 
true)
+  val kafkaUi = opt[Boolean](descr = "Enable Kafka UI", noshort = true)
+
+  val kafkaPort = opt[Int](
+descr = "Kafka port. If not specified then 9092 or some random free port 
(if 9092 is busy) would be used",
+noshort = true,
+required = false)
 
 Review comment:
   Would it make sense to add a `default = Some(9092)` here?


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326150432
 
 

 ##
 File path: 
core/standalone/src/main/scala/org/apache/openwhisk/standalone/StandaloneOpenWhisk.scala
 ##
 @@ -63,6 +64,25 @@ class Conf(arguments: Seq[String]) extends 
ScallopConf(arguments) {
   val apiGwPort = opt[Int](descr = "Api Gateway Port", default = Some(3234), 
noshort = true)
   val dataDir = opt[File](descr = "Directory used for storage", default = 
Some(StandaloneOpenWhisk.defaultWorkDir))
 
+  val kafka = opt[Boolean](descr = "Enable embedded Kafka support", noshort = 
true)
+  val kafkaUi = opt[Boolean](descr = "Enable Kafka UI", noshort = true)
+
+  val kafkaPort = opt[Int](
+descr = "Kafka port. If not specified then 9092 or some random free port 
(if 9092 is busy) would be used",
+noshort = true,
+required = false)
+
+  val kafkaDockerPort = opt[Int](
+descr = "Kafka port for use by docker based services. If not specified 
then 9091 or some random free port " +
+  "(if 9091 is busy) would be used",
+noshort = true,
+required = false)
 
 Review comment:
   Would it make sense to add a `default = Some(9091)` here?


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-19 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r326149173
 
 

 ##
 File path: 
core/standalone/src/main/scala/org/apache/openwhisk/standalone/KafkaLauncher.scala
 ##
 @@ -0,0 +1,120 @@
+/*
+ * 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.openwhisk.standalone
+
+import java.io.File
+
+import akka.actor.ActorSystem
+import akka.stream.ActorMaterializer
+import kafka.server.KafkaConfig
+import net.manub.embeddedkafka.{EmbeddedKafka, EmbeddedKafkaConfig}
+import org.apache.commons.io.FileUtils
+import org.apache.openwhisk.common.{Logging, TransactionId}
+import org.apache.openwhisk.core.WhiskConfig
+import org.apache.openwhisk.core.WhiskConfig.kafkaHosts
+import org.apache.openwhisk.core.entity.ControllerInstanceId
+import org.apache.openwhisk.core.loadBalancer.{LeanBalancer, LoadBalancer, 
LoadBalancerProvider}
+import 
org.apache.openwhisk.standalone.StandaloneDockerSupport.{checkOrAllocatePort, 
containerName, createRunCmd}
+
+import scala.concurrent.{ExecutionContext, Future}
+import scala.reflect.io.Directory
+import scala.util.Try
+
+class KafkaLauncher(docker: StandaloneDockerClient,
+kafkaPort: Int,
+kafkaDockerPort: Int,
+zkPort: Int,
+workDir: File,
+kafkaUi: Boolean)(implicit logging: Logging,
+  ec: ExecutionContext,
+  actorSystem: ActorSystem,
+  materializer: ActorMaterializer,
+  tid: TransactionId) {
+
+  def run(): Future[Seq[ServiceContainer]] = {
+for {
+  kafkaSvcs <- runKafka()
+  uiSvcs <- if (kafkaUi) runKafkaUI() else 
Future.successful(Seq.empty[ServiceContainer])
+} yield kafkaSvcs ++ uiSvcs
+  }
+
+  def runKafka(): Future[Seq[ServiceContainer]] = {
+
+//Below setting based on 
https://rmoff.net/2018/08/02/kafka-listeners-explained/
+// We configure two listeners where one is used for host based application 
and other is used for docker based application
+// to connect to Kafka server running on host
 
 Review comment:
   It would be helpful to add some more detail - for example, controller / 
invoker will use `LISTENER_LOCAL` since they run in the same JVM as the 
embedded Kafka and Kafka UI will run in a Docker container and use 
`LISTENER_DOCKER`.


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


[GitHub] [openwhisk] sven-lange-last commented on a change in pull request #4628: Embedded Kafka support in OpenWhisk Standalone mode

2019-09-18 Thread GitBox
sven-lange-last commented on a change in pull request #4628: Embedded Kafka 
support in OpenWhisk Standalone mode
URL: https://github.com/apache/openwhisk/pull/4628#discussion_r325710115
 
 

 ##
 File path: core/standalone/src/main/resources/logback-standalone.xml
 ##
 @@ -29,6 +29,8 @@
 
 
 
 
 Review comment:
   I guess the existing definition for `org.apache.kafka` is for Kafka clients 
(consumer, producer)?


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