ashishkumar50 commented on code in PR #8282:
URL: https://github.com/apache/ozone/pull/8282#discussion_r2059873213


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/containerlog/parser/ContainerDatanodeDatabase.java:
##########
@@ -84,37 +66,41 @@ private static Connection getConnection() throws Exception {
     config.setSynchronous(SQLiteConfig.SynchronousMode.OFF);
     config.setTempStore(SQLiteConfig.TempStore.MEMORY);
 
-    return DriverManager.getConnection(DBConsts.CONNECTION_PREFIX + 
DBConsts.DATABASE_NAME, config.toProperties());
+    return DriverManager.getConnection(DBConsts.CONNECTION_PREFIX + 
databasePath, config.toProperties());
   }
 
   public void createDatanodeContainerLogTable() throws SQLException {
-    String createTableSQL = queries.get("CREATE_DATANODE_CONTAINER_LOG_TABLE");
+    String createTableSQL = DBConsts.CREATE_DATANODE_CONTAINER_LOG_TABLE;
     try (Connection connection = getConnection();
          Statement dropStmt = connection.createStatement();
          Statement createStmt = connection.createStatement()) {
       dropTable(DBConsts.DATANODE_CONTAINER_LOG_TABLE_NAME, dropStmt);
       createStmt.execute(createTableSQL);
       createDatanodeContainerIndex(createStmt);
     } catch (SQLException e) {
+      System.err.println("Error while creating the table: " + e.getMessage());
       LOG.error("Error while creating the table: {}", e.getMessage());

Review Comment:
   No need for `LOG.error` already printing in `System.err`



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/logs/container/ListContainers.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.hadoop.ozone.debug.logs.container;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.Callable;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.ozone.containerlog.parser.ContainerDatanodeDatabase;
+import org.apache.hadoop.ozone.shell.ListOptions;
+import picocli.CommandLine;
+
+
+/**
+ * List containers based on the parameter given.
+ */
+
[email protected](
+    name = "list",
+    description = "Finds containers from the database based on the option 
provided."
+)
+public class ListContainers implements Callable<Void> {
+  
+  @CommandLine.Option(names = {"--state"},
+      description = "Life cycle state of the container.",
+      required = true)
+  private HddsProtos.LifeCycleState state;
+
+  @CommandLine.Mixin
+  private ListOptions listOptions;
+
+  @CommandLine.ParentCommand
+  private ContainerLogController parent;
+
+  @Override
+  public Void call() throws Exception {
+    if (parent.getDbPath() == null) {
+      System.err.println("No database path provided.Please provide a valid 
database path.");

Review Comment:
   When path is not provided, can you check if the current path has db, if not 
throw the error to provide path.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/logs/container/ContainerLogParser.java:
##########
@@ -57,36 +58,39 @@ public Void call() throws Exception {
       threadCount = DEFAULT_THREAD_COUNT;
     }
     
-    if (path != null) {
-      Path logPath = Paths.get(path);
-      if (!Files.exists(logPath) || !Files.isDirectory(logPath)) {
-        System.err.println("Invalid path provided: " + path);
-        return null;
-      }
-
-      ContainerDatanodeDatabase cdd = new ContainerDatanodeDatabase();
-      ContainerLogFileParser parser = new ContainerLogFileParser();
-
-      try {
+    Path logPath = Paths.get(path);
+    if (!Files.exists(logPath) || !Files.isDirectory(logPath)) {
+      System.err.println("Invalid path provided: " + path);
+      return null;
+    }
 
-        cdd.createDatanodeContainerLogTable();
+    if (parent.getDbPath() == null) {
+      System.err.println("No database path provided.Please provide a valid 
database path.");

Review Comment:
   If path is not provided, generate db in the current path where CLI command 
is executed.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/containerlog/parser/ContainerDatanodeDatabase.java:
##########
@@ -84,37 +66,41 @@ private static Connection getConnection() throws Exception {
     config.setSynchronous(SQLiteConfig.SynchronousMode.OFF);
     config.setTempStore(SQLiteConfig.TempStore.MEMORY);
 
-    return DriverManager.getConnection(DBConsts.CONNECTION_PREFIX + 
DBConsts.DATABASE_NAME, config.toProperties());
+    return DriverManager.getConnection(DBConsts.CONNECTION_PREFIX + 
databasePath, config.toProperties());
   }
 
   public void createDatanodeContainerLogTable() throws SQLException {
-    String createTableSQL = queries.get("CREATE_DATANODE_CONTAINER_LOG_TABLE");
+    String createTableSQL = DBConsts.CREATE_DATANODE_CONTAINER_LOG_TABLE;
     try (Connection connection = getConnection();
          Statement dropStmt = connection.createStatement();
          Statement createStmt = connection.createStatement()) {
       dropTable(DBConsts.DATANODE_CONTAINER_LOG_TABLE_NAME, dropStmt);
       createStmt.execute(createTableSQL);
       createDatanodeContainerIndex(createStmt);
     } catch (SQLException e) {
+      System.err.println("Error while creating the table: " + e.getMessage());
       LOG.error("Error while creating the table: {}", e.getMessage());
       throw e;
     } catch (Exception e) {
+      System.err.println("Unexpected error: " + e.getMessage());
       LOG.error(e.getMessage());

Review Comment:
   Same here no need of extra `LOG.error`, check in other places as well.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to