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


##########
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:
   The way storage tool is written, we will need the logic that's present in 
the main function. We can create a new function that contains entirety of the 
main function logic and call that from both storage tool main and our code. But 
that will be kind of same as the present solution, but with just one extra 
method. 
   Proper solution will require thorough refactoring of the storage tool, which 
I think is out of scope for this change. Please let us know your thoughts on 
this.



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