dombizita commented on code in PR #10579:
URL: https://github.com/apache/ozone/pull/10579#discussion_r3467318646
##########
hadoop-ozone/cli-admin/src/test/java/org/apache/hadoop/ozone/admin/upgrade/TestStatusSubCommand.java:
##########
@@ -42,40 +49,87 @@ public class TestStatusSubCommand {
private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
+ private final PrintStream originalErr = System.err;
+ private OzoneManagerProtocol omClient;
private StatusSubCommand cmd;
@BeforeEach
- public void setup() throws UnsupportedEncodingException {
- cmd = new StatusSubCommand();
+ public void setup() throws IOException {
+ omClient = mock(OzoneManagerProtocol.class);
+
when(omClient.getServiceInfo()).thenReturn(serviceInfoWithVersion(OzoneManagerVersion.ZDU));
+
+ cmd = new StatusSubCommand() {
+ @Override
+ protected OzoneManagerProtocol getClient() throws Exception {
+ return omClient;
+ }
+ };
System.setOut(new PrintStream(outContent, false, DEFAULT_ENCODING));
+ System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
}
@AfterEach
public void tearDown() {
System.setOut(originalOut);
+ System.setErr(originalErr);
}
@Test
- public void testStatusCommandPrintsUpgradeStatus() throws IOException {
- ScmClient scmClient = mock(ScmClient.class);
- HddsProtos.UpgradeStatus status = HddsProtos.UpgradeStatus.newBuilder()
+ public void testStatusCommandPrintsUpgradeStatus() throws Exception {
+ HddsProtos.UpgradeStatus hddsStatus = HddsProtos.UpgradeStatus.newBuilder()
.setScmFinalized(false)
.setNumDatanodesFinalized(1)
.setNumDatanodesTotal(3)
.setShouldFinalize(true)
.build();
- when(scmClient.queryUpgradeStatus()).thenReturn(status);
+ OzoneManagerProtocolProtos.QueryUpgradeStatusResponse response =
+ OzoneManagerProtocolProtos.QueryUpgradeStatusResponse.newBuilder()
+ .setOmFinalized(false)
+ .setHddsStatus(hddsStatus)
+ .build();
+
+ when(omClient.queryUpgradeStatus()).thenReturn(response);
new CommandLine(cmd).parseArgs();
- cmd.execute(scmClient);
+ cmd.call();
String output = outContent.toString(DEFAULT_ENCODING);
assertTrue(output.contains("Upgrade status:"));
+ assertTrue(output.contains("OM Finalized: false"));
assertTrue(output.contains("SCM Finalized: false"));
assertTrue(output.contains("Datanodes finalized: 1"));
assertTrue(output.contains("Total Datanodes: 3"));
assertTrue(output.contains("Should Finalize: true"));
- verify(scmClient).queryUpgradeStatus();
+ verify(omClient).queryUpgradeStatus();
+ }
+
+ @Test
+ public void testStatusCommandPropagatesException() throws Exception {
+ when(omClient.queryUpgradeStatus()).thenThrow(new IOException("OM
unavailable"));
+ new CommandLine(cmd).parseArgs();
+ assertThrows(IOException.class, () -> cmd.call());
+ }
+
+ @Test
+ public void testNonZduServerPrintsErrorAndReturnsNonZero() throws Exception {
+
when(omClient.getServiceInfo()).thenReturn(serviceInfoWithVersion(OzoneManagerVersion.DEFAULT_VERSION));
+
+ new CommandLine(cmd).parseArgs();
+ assertEquals(1, cmd.call());
+
+ String errOutput = errContent.toString(DEFAULT_ENCODING);
+ assertTrue(errOutput.contains("OM does not support ZDU"));
+ verify(omClient, never()).finalizeUpgrade();
Review Comment:
Shouldn't this check `queryUpgradeStatus()`?
```suggestion
verify(omClient, never()).queryUpgradeStatus();
```
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/upgrade/StatusSubCommand.java:
##########
@@ -17,32 +17,54 @@
package org.apache.hadoop.ozone.admin.upgrade;
-import java.io.IOException;
+import java.util.concurrent.Callable;
+import org.apache.hadoop.hdds.cli.AbstractSubcommand;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
-import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
-import org.apache.hadoop.hdds.scm.cli.ScmSubcommand;
-import org.apache.hadoop.hdds.scm.client.ScmClient;
+import org.apache.hadoop.ozone.OzoneManagerVersion;
+import org.apache.hadoop.ozone.admin.om.OmAddressOptions;
+import org.apache.hadoop.ozone.client.rpc.RpcClient;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import picocli.CommandLine;
/**
* Sub command to query the overall upgrade status of the cluster, returning
information about the finalization
- * status of SCM, the datanodes and OM.
+ * status of SCM, the datanodes and OM. The command makes a single call to OM
which returns the status of the other
+ * components as well as itself.
*/
@CommandLine.Command(
name = "status",
description = "Show status of the cluster upgrade",
mixinStandardHelpOptions = true,
versionProvider = HddsVersionProvider.class)
-public class StatusSubCommand extends ScmSubcommand {
+public class StatusSubCommand extends AbstractSubcommand implements
Callable<Integer> {
+
+ @CommandLine.Mixin
+ private OmAddressOptions.OptionalServiceIdOrHostMixin omAddressOptions;
@Override
- public void execute(ScmClient client) throws IOException {
- HddsProtos.UpgradeStatus status = client.queryUpgradeStatus();
-
- out().println("Upgrade status:");
- out().println(" SCM Finalized: " + status.getScmFinalized());
- out().println(" Datanodes finalized: " +
status.getNumDatanodesFinalized());
- out().println(" Total Datanodes: " + status.getNumDatanodesTotal());
- out().println(" Should Finalize: " + status.getShouldFinalize());
+ public Integer call() throws Exception {
+ try (OzoneManagerProtocol client = getClient()) {
+ OzoneManagerVersion omVersion =
RpcClient.getOmVersion(client.getServiceInfo());
+ if (!OzoneManagerVersion.ZDU.isSupportedBy(omVersion)) {
+ err().println("OM does not support ZDU. The cluster upgrade status
should be queried with the pre ZDU " +
+ "commands, eg `ozone admin scm finalizationstatus` and `ozone
admin om finalizationstatus`");
+ return 1;
+ }
+ OzoneManagerProtocolProtos.QueryUpgradeStatusResponse status =
client.queryUpgradeStatus();
+
+ out().println("Upgrade status:");
+ out().println(" OM Finalized: " + status.getOmFinalized());
+ out().println(" SCM Finalized: " +
status.getHddsStatus().getScmFinalized());
+ out().println(" Datanodes finalized: " +
status.getHddsStatus().getNumDatanodesFinalized());
Review Comment:
Maybe it's worth to phrase it differently, as the first two line are
true/false and this is the number of finalized datanodes, right?
--
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]