viktorsomogyi commented on code in PR #15048:
URL: https://github.com/apache/kafka/pull/15048#discussion_r1440302423


##########
core/src/main/scala/kafka/docker/KafkaDockerWrapper.scala:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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 kafka.docker
+
+import kafka.tools.StorageTool
+import kafka.utils.Exit
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.{Files, Paths, StandardCopyOption, StandardOpenOption}
+
+object KafkaDockerWrapper {
+  def main(args: Array[String]): Unit = {
+    if (args.length == 0) {
+      throw new RuntimeException(s"Error: No operation input provided. " +
+        s"Please provide a valid operation: 'setup'.")
+    }
+    val operation = args.head
+    val arguments = args.tail
+
+    operation match {
+      case "setup" =>
+        if (arguments.length != 3) {
+          val errMsg = "not enough arguments passed. Usage: " +
+            "setup <default-configs-dir> <mounted-configs-dir>, 
<final-configs-dir>"
+          System.err.println(errMsg)
+          Exit.exit(1, Some(errMsg))
+        }
+        val defaultConfigsDir = arguments(0)
+        val mountedConfigsDir = arguments(1)
+        val finalConfigsDir = arguments(2)

Review Comment:
   Parsing these 3 arguments would also be a good opportunity to validate and 
convert these into `Path` objects. Using the API of `Path` also makes your code 
more robust down the line when you append the config file names in 
`prepareConfigs`.



##########
core/src/main/scala/kafka/docker/KafkaDockerWrapper.scala:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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 kafka.docker
+
+import kafka.tools.StorageTool
+import kafka.utils.Exit
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.{Files, Paths, StandardCopyOption, StandardOpenOption}
+
+object KafkaDockerWrapper {
+  def main(args: Array[String]): Unit = {
+    if (args.length == 0) {
+      throw new RuntimeException(s"Error: No operation input provided. " +
+        s"Please provide a valid operation: 'setup'.")
+    }
+    val operation = args.head
+    val arguments = args.tail
+
+    operation match {
+      case "setup" =>
+        if (arguments.length != 3) {
+          val errMsg = "not enough arguments passed. Usage: " +
+            "setup <default-configs-dir> <mounted-configs-dir>, 
<final-configs-dir>"
+          System.err.println(errMsg)
+          Exit.exit(1, Some(errMsg))
+        }
+        val defaultConfigsDir = arguments(0)
+        val mountedConfigsDir = arguments(1)
+        val finalConfigsDir = arguments(2)
+        try {
+          prepareConfigs(defaultConfigsDir, mountedConfigsDir, finalConfigsDir)
+        } catch {
+          case e: Throwable =>
+            val errMsg = s"error while preparing configs: ${e.getMessage}"
+            System.err.println(errMsg)
+            Exit.exit(1, Some(errMsg))
+        }
+
+        val formatCmd = formatStorageCmd(finalConfigsDir, envVars)
+        StorageTool.main(formatCmd)
+      case _ =>
+        throw new RuntimeException(s"Unknown operation $operation. " +
+          s"Please provide a valid operation: 'setup'.")
+    }
+  }
+
+  import Constants._
+
+  private def formatStorageCmd(configsDir: String, env: Map[String, String]): 
Array[String] = {

Review Comment:
   While I agree that it works, it's not a nice solution. Would it be a big 
refactor to use a specific method from `StorageTool` instead of `main`?



##########
core/src/main/scala/kafka/docker/KafkaDockerWrapper.scala:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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 kafka.docker
+
+import kafka.tools.StorageTool
+import kafka.utils.Exit
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.{Files, Paths, StandardCopyOption, StandardOpenOption}
+
+object KafkaDockerWrapper {
+  def main(args: Array[String]): Unit = {
+    if (args.length == 0) {
+      throw new RuntimeException(s"Error: No operation input provided. " +
+        s"Please provide a valid operation: 'setup'.")
+    }
+    val operation = args.head

Review Comment:
   While this is a simple command and it works, it would be more future proof 
to use argparse4j as do tools.



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

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to