Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
subcommands = {
ContainerLogController.class
},
description = "This serves as a common entry point for all commands that parse and analyze logs," +
"regardless of their source or type and require logs to be extracted first."
description = "Command to parse and analyze logs, " +
"regardless of their source or type. It require logs to be extracted first."
)
@MetaInfServices(DebugSubcommand.class)
public class LogParser implements DebugSubcommand {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.cli.AbstractSubcommand;
import org.apache.hadoop.ozone.debug.logs.container.utils.ContainerDatanodeDatabase;
import org.apache.hadoop.ozone.debug.logs.container.utils.SQLDBConstants;
import picocli.CommandLine;

/**
* Command to display detailed information of a single container by ID.
*/

@CommandLine.Command(
name = "info",
description = "Provides complete state transition history of each replica for a single container along with " +
"analysis over the container"
)
public class ContainerInfoCommand extends AbstractSubcommand implements Callable<Void> {

@CommandLine.Parameters(index = "0", description = "Container ID")
private Long containerId;

@CommandLine.ParentCommand
private ContainerLogController parent;

@Override
public Void call() throws Exception {

if (containerId < 0) {
err().println("Invalid container ID: " + containerId);
return null;
}

Path providedDbPath;
if (parent.getDbPath() == null) {
providedDbPath = Paths.get(System.getProperty("user.dir"), SQLDBConstants.DEFAULT_DB_FILENAME);

if (Files.exists(providedDbPath) && Files.isRegularFile(providedDbPath)) {
out().println("Using default database file found in current directory: " + providedDbPath);
} else {
err().println("No database path provided and default file '" + SQLDBConstants.DEFAULT_DB_FILENAME + "' not " +
"found in current directory. Please provide a valid database path");
return null;
}
} else {
providedDbPath = Paths.get(parent.getDbPath());
Path parentDir = providedDbPath.getParent();

if (parentDir != null && !Files.exists(parentDir)) {
err().println("The parent directory of the provided database path does not exist: " + parentDir);
return null;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--db is inherited from the parent command, but validation is duplicated among subcommands. It should be done in ContainerLogController.


ContainerDatanodeDatabase.setDatabasePath(providedDbPath.toString());

ContainerDatanodeDatabase cdd = new ContainerDatanodeDatabase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DB path should be passed to the ContainerDatanodeDatabase instance, where databasePath should not be static.


cdd.showContainerDetails(containerId);

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@CommandLine.Command(
name = "container",
subcommands = {
ContainerInfoCommand.class,
ContainerLogParser.class,
ListContainers.class
},
Expand Down
Loading