adoroszlai commented on code in PR #8282: URL: https://github.com/apache/ozone/pull/8282#discussion_r2046835424
########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/container/ListContainers.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.container; + +import java.sql.SQLException; +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 = "state of the container") + private HddsProtos.LifeCycleState state; + + @CommandLine.Mixin + private ListOptions listOptions; + + @CommandLine.ParentCommand + private ContainerLogController parent; + + @Override + public Void call() throws Exception { + if (state != null) { + + ContainerDatanodeDatabase cdd = new ContainerDatanodeDatabase(); + try { + cdd.listContainersByState(state.name(), listOptions.getLimit()); + } catch (SQLException e) { + System.err.println("Error while retrieving containers with state: " + state + " " + e.getMessage()); + } catch (Exception e) { + System.err.println("Error while retrieving containers with state: " + state + " " + e.getMessage()); + } + } else { + System.out.println("state not provided"); Review Comment: Clarification: this is also an error message. Also, if state is required, I think we should add `required = true` to make picocli handle error if option is omitted. https://picocli.info/#_required_options ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/container/ListContainers.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.container; + +import java.sql.SQLException; +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 = "state of the container") + private HddsProtos.LifeCycleState state; + + @CommandLine.Mixin + private ListOptions listOptions; + + @CommandLine.ParentCommand + private ContainerLogController parent; + + @Override + public Void call() throws Exception { + if (state != null) { + + ContainerDatanodeDatabase cdd = new ContainerDatanodeDatabase(); + try { + cdd.listContainersByState(state.name(), listOptions.getLimit()); + } catch (SQLException e) { + System.err.println("Error while retrieving containers with state: " + state + " " + e.getMessage()); Review Comment: > * Do we really need different messages for `SQLException` and `Exception`? Clarification: if message is the same, separate `catch` is not needed either. ```suggestion ``` -- 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]
