diff --git a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/InfoSubcommand.java b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/InfoSubcommand.java index f045ec63bc9..9524ce94716 100644 --- a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/InfoSubcommand.java +++ b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/InfoSubcommand.java @@ -39,8 +39,10 @@ .ContainerWithPipeline; import com.google.common.base.Preconditions; +import org.apache.hadoop.hdds.scm.ha.SCMHAUtils; import org.apache.hadoop.hdds.scm.pipeline.Pipeline; import org.apache.hadoop.hdds.scm.pipeline.PipelineID; +import org.apache.hadoop.hdds.scm.pipeline.PipelineNotFoundException; import org.apache.hadoop.hdds.server.JsonUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,12 +92,14 @@ public void execute(ScmClient scmClient) throws IOException { if (container.getPipeline().size() != 0) { ContainerWithPipelineAndReplicas wrapper = new ContainerWithPipelineAndReplicas(container.getContainerInfo(), - container.getPipeline(), replicas); + container.getPipeline(), replicas, + container.getContainerInfo().getPipelineID()); LOG.info(JsonUtils.toJsonStringWithDefaultPrettyPrinter(wrapper)); } else { ContainerWithoutDatanodes wrapper = new ContainerWithoutDatanodes(container.getContainerInfo(), - container.getPipeline(), replicas); + container.getPipeline(), replicas, + container.getContainerInfo().getPipelineID()); LOG.info(JsonUtils.toJsonStringWithDefaultPrettyPrinter(wrapper)); } } else { @@ -109,6 +113,21 @@ public void execute(ScmClient scmClient) throws IOException { } else { LOG.info("Pipeline id: {}", container.getPipeline().getId().getId()); } + LOG.info("Write PipelineId: {}", + container.getContainerInfo().getPipelineID().getId()); + try { + String pipelineState = scmClient.getPipeline( + container.getContainerInfo().getPipelineID().getProtobuf()) + .getPipelineState().toString(); + LOG.info("Write Pipeline State: {}", pipelineState); + } catch (IOException ioe) { + if (SCMHAUtils.unwrapException( + ioe) instanceof PipelineNotFoundException) { + LOG.info("Write Pipeline State: CLOSED"); + } else { + LOG.error("Failed to retrieve pipeline info"); + } + } LOG.info("Container State: {}", container.getContainerInfo().getState()); // Print pipeline of an existing container. @@ -149,12 +168,14 @@ private static class ContainerWithPipelineAndReplicas { private ContainerInfo containerInfo; private Pipeline pipeline; private List replicas; + private PipelineID writePipelineID; ContainerWithPipelineAndReplicas(ContainerInfo container, Pipeline pipeline, - List replicas) { + List replicas, PipelineID pipelineID) { this.containerInfo = container; this.pipeline = pipeline; this.replicas = replicas; + this.writePipelineID = pipelineID; } public ContainerInfo getContainerInfo() { @@ -168,6 +189,11 @@ public Pipeline getPipeline() { public List getReplicas() { return replicas; } + + public PipelineID getWritePipelineID() { + return writePipelineID; + } + } private static class ContainerWithoutDatanodes { @@ -175,12 +201,14 @@ private static class ContainerWithoutDatanodes { private ContainerInfo containerInfo; private PipelineWithoutDatanodes pipeline; private List replicas; + private PipelineID writePipelineId; ContainerWithoutDatanodes(ContainerInfo container, Pipeline pipeline, - List replicas) { + List replicas, PipelineID pipelineID) { this.containerInfo = container; this.pipeline = new PipelineWithoutDatanodes(pipeline); this.replicas = replicas; + this.writePipelineId = pipelineID; } public ContainerInfo getContainerInfo() { @@ -194,6 +222,10 @@ public PipelineWithoutDatanodes getPipeline() { public List getReplicas() { return replicas; } + + public PipelineID getWritePipelineId() { + return writePipelineId; + } } // All Pipeline information except the ones dependent on datanodes diff --git a/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/container/TestInfoSubCommand.java b/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/container/TestInfoSubCommand.java index 128708c44ae..6058546c97d 100644 --- a/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/container/TestInfoSubCommand.java +++ b/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/container/TestInfoSubCommand.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline; import org.apache.hadoop.hdds.scm.pipeline.Pipeline; import org.apache.hadoop.hdds.scm.pipeline.PipelineID; +import org.apache.hadoop.hdds.scm.pipeline.PipelineNotFoundException; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -49,6 +50,7 @@ import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSED; import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.THREE; import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; /** @@ -95,6 +97,8 @@ private void testReplicaIncludedInOutput(boolean includeIndex) throws IOException { Mockito.when(scmClient.getContainerReplicas(anyLong())) .thenReturn(getReplicas(includeIndex)); + Mockito.when(scmClient.getPipeline(any())) + .thenThrow(new PipelineNotFoundException("Pipeline not found.")); cmd = new InfoSubcommand(); CommandLine c = new CommandLine(cmd); c.parseArgs("1"); @@ -135,6 +139,8 @@ private void testReplicaIncludedInOutput(boolean includeIndex) public void testReplicasNotOutputIfError() throws IOException { Mockito.when(scmClient.getContainerReplicas(anyLong())) .thenThrow(new IOException("Error getting Replicas")); + Mockito.when(scmClient.getPipeline(any())) + .thenThrow(new PipelineNotFoundException("Pipeline not found.")); cmd = new InfoSubcommand(); CommandLine c = new CommandLine(cmd); c.parseArgs("1");