Skip to content

Commit

Permalink
HDDS-10272. Container Report admin command displays incorrect value i…
Browse files Browse the repository at this point in the history
…mmediately after SCM restart (apache#6148)
  • Loading branch information
sodonnel authored Feb 4, 2024
1 parent 822c0de commit cb313f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public class ReportSubcommand extends ScmSubcommand {
@Override
public void execute(ScmClient scmClient) throws IOException {
ReplicationManagerReport report = scmClient.getReplicationManagerReport();
if (report.getReportTimeStamp() == 0) {
System.err.println("The Container Report is not available until Replication Manager completes" +
" its first run after startup or fail over. All values will be zero until that time.\n");
}

if (json) {
output(JsonUtils.toJsonStringWithDefaultPrettyPrinter(report));
Expand All @@ -68,9 +72,11 @@ public void execute(ScmClient scmClient) throws IOException {
}

private void outputHeader(long epochMs) {
if (epochMs == 0) {
epochMs = Instant.now().toEpochMilli();
}
Instant reportTime = Instant.ofEpochSecond(epochMs / 1000);
outputHeading("Container Summary Report generated at " + reportTime);

}

private void outputContainerStats(ReplicationManagerReport report) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ public void testCorrectValuesAppearInEmptyReport() throws IOException {

cmd.execute(scmClient);

Pattern p = Pattern.compile("^The Container Report is not available until Replication Manager completes.*");
Matcher m = p.matcher(errContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());

for (HddsProtos.LifeCycleState state : HddsProtos.LifeCycleState.values()) {
Pattern p = Pattern.compile(
"^" + state.toString() + ": 0$", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
p = Pattern.compile("^" + state.toString() + ": 0$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}

for (ReplicationManagerReport.HealthState state :
ReplicationManagerReport.HealthState.values()) {
Pattern p = Pattern.compile(
"^" + state.toString() + ": 0$", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
p = Pattern.compile("^" + state.toString() + ": 0$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}
}
Expand All @@ -101,6 +103,10 @@ public void testValidJsonOutput() throws IOException {
c.parseArgs("--json");
cmd.execute(scmClient);

Pattern p = Pattern.compile("^The Container Report is not available until Replication Manager completes.*");
Matcher m = p.matcher(errContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());

ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(outContent.toString("UTF-8"));

Expand Down

0 comments on commit cb313f6

Please sign in to comment.