You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "kerneltime (via GitHub)" <gi...@apache.org> on 2025/03/11 16:29:17 UTC
[PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
kerneltime opened a new pull request, #8050:
URL: https://github.com/apache/ozone/pull/8050
## What changes were proposed in this pull request?
Support listing containers in json array format.
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-12553
## How was this patch tested?
Additional robot tests.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r1989820692
##########
hadoop-ozone/dist/src/main/smoketest/admincli/container.robot:
##########
@@ -96,6 +96,33 @@ List all containers from a particular container ID
${output} = Execute ozone admin container list --all --start 1
Should contain ${output} OPEN
+List containers in JSON array format
+ ${output} = Execute ozone admin container list --json | jq -r '.'
+ Should Start With ${output} [
Review Comment:
The goal is to see if the parsing matches, other tests delve deeper into the returned payload. I can add some additional checks here as well.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2716217836
@errose28 for now I am not breaking the old CLI output, if developers feel strongly we can do it as a separate PR with updates to existing tests that fail.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2721992976
@adoroszlai why prefer `IOUtils.closeQuietly` ?
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2722022419
> why prefer `IOUtils.closeQuietly` ?
Convenience. I don't expect `SequenceWriter.close` to have any problem, but implementing `AutoCloseable` requires declaring `throws Exception`.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r2007126389
##########
hadoop-ozone/dist/src/main/smoketest/admincli/container.robot:
##########
@@ -87,17 +97,54 @@ Report containers as JSON
List all containers
${output} = Execute ozone admin container list --all
Should contain ${output} OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
List all containers according to count (batchSize)
${output} = Execute ozone admin container list --all --count 10
Should contain ${output} OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
List all containers from a particular container ID
- ${output} = Execute ozone admin container list --all --start 1
+ ${output} = Execute ozone admin container list --all --start 2
Should contain ${output} OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
+
+Check JSON array parsing
+ ${output} = Execute ozone admin container list
+ Should Start With ${output} [
+ Should Contain ${output} containerID
+ Should End With ${output} ]
+ ${containerIDs} = Execute echo '${output}' | jq -r '.[].containerID'
+ Should Not Be Empty ${containerIDs}
+
+Check state filtering with JSON array format
+ ${output} = Execute ozone admin container list --state=OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
+ ${states} = Execute echo '${output}' | jq -r '.[].state'
+ Should Contain ${states} OPEN
+ Should Not Contain ${states} CLOSED
+
+Check count limit with JSON array format
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
Review Comment:
I would like to eliminate this duplication, as well as the duplicated start/end checks, in a follow-up.
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java:
##########
@@ -114,44 +116,104 @@ public void execute(ScmClient scmClient) throws IOException {
.getInt(ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT,
ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT_DEFAULT);
- ContainerListResult containerListAndTotalCount;
+ // Use SequenceWriter to output JSON array format for all cases
+ SequenceWriter sequenceWriter = WRITER.writeValues(new NonClosingOutputStream(System.out));
+ sequenceWriter.init(true); // Initialize as a JSON array
if (!all) {
+ // Regular listing with count limit
if (count > maxCountAllowed) {
System.err.printf("Attempting to list the first %d records of containers." +
" However it exceeds the cluster's current limit of %d. The results will be capped at the" +
- " maximum allowed count.%n", count, ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT_DEFAULT);
+ " maximum allowed count.%n", count, maxCountAllowed);
count = maxCountAllowed;
}
- containerListAndTotalCount = scmClient.listContainer(startId, count, state, type, repConfig);
- for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
- outputContainerInfo(container);
- }
- if (containerListAndTotalCount.getTotalCount() > count) {
+ ContainerListResult containerListResult =
+ scmClient.listContainer(startId, count, state, type, repConfig);
+
+ writeContainers(sequenceWriter, containerListResult.getContainerInfoList());
+
+ closeStream(sequenceWriter);
+ if (containerListResult.getTotalCount() > count) {
System.err.printf("Displaying %d out of %d containers. " +
- "Container list has more containers.%n",
- count, containerListAndTotalCount.getTotalCount());
+ "Container list has more containers.%n",
+ count, containerListResult.getTotalCount());
}
} else {
- // Batch size is either count passed through cli or maxCountAllowed
+ // List all containers by fetching in batches
int batchSize = (count > 0) ? count : maxCountAllowed;
- long currentStartId = startId;
- int fetchedCount;
-
- do {
- // Fetch containers in batches of 'batchSize'
- containerListAndTotalCount = scmClient.listContainer(currentStartId, batchSize, state, type, repConfig);
- fetchedCount = containerListAndTotalCount.getContainerInfoList().size();
-
- for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
- outputContainerInfo(container);
- }
-
- if (fetchedCount > 0) {
- currentStartId = containerListAndTotalCount.getContainerInfoList().get(fetchedCount - 1).getContainerID() + 1;
- }
- } while (fetchedCount > 0);
+ listAllContainers(scmClient, sequenceWriter, batchSize, repConfig);
+ closeStream(sequenceWriter);
+ }
+ }
+
+ private void writeContainers(SequenceWriter writer, List<ContainerInfo> containers)
+ throws IOException {
+ for (ContainerInfo container : containers) {
+ writer.write(container);
+ }
+ }
+
+ private void closeStream(SequenceWriter writer) throws IOException {
+ writer.flush();
+ writer.close();
+ // Add the final newline
+ System.out.println();
+ }
+
+ private void listAllContainers(ScmClient scmClient, SequenceWriter writer,
+ int batchSize, ReplicationConfig repConfig)
Review Comment:
nit: Please do not format method signature like this. Whenever visibility / return type / method name / other modifiers are changed, we would have to reindent parameters.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. ozone admin container list should output real JSON array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r2008014275
##########
hadoop-ozone/dist/src/main/smoketest/admincli/container.robot:
##########
@@ -87,17 +97,54 @@ Report containers as JSON
List all containers
${output} = Execute ozone admin container list --all
Should contain ${output} OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
List all containers according to count (batchSize)
${output} = Execute ozone admin container list --all --count 10
Should contain ${output} OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
List all containers from a particular container ID
- ${output} = Execute ozone admin container list --all --start 1
+ ${output} = Execute ozone admin container list --all --start 2
Should contain ${output} OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
+
+Check JSON array parsing
+ ${output} = Execute ozone admin container list
+ Should Start With ${output} [
+ Should Contain ${output} containerID
+ Should End With ${output} ]
+ ${containerIDs} = Execute echo '${output}' | jq -r '.[].containerID'
+ Should Not Be Empty ${containerIDs}
+
+Check state filtering with JSON array format
+ ${output} = Execute ozone admin container list --state=OPEN
+ Should Start With ${output} [
+ Should End With ${output} ]
+ ${states} = Execute echo '${output}' | jq -r '.[].state'
+ Should Contain ${states} OPEN
+ Should Not Contain ${states} CLOSED
+
+Check count limit with JSON array format
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
+ ${output} = Execute ozone admin container create
+ Should contain ${output} is created
Review Comment:
Yes the robot tests need an over haul
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2718260668
I'm ok with doing a follow up Jira to make json list the default so this PR does not get bloated with test updates. I don't think having two different "json" outputs should be the final state of the command though.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2723409339
> > why prefer `IOUtils.closeQuietly` ?
>
> Convenience. I don't expect `SequenceWriter.close` to have any problem, but implementing `AutoCloseable` requires declaring `throws Exception`.
>
> Using `try-with` is also fine, probably could also rewrite my suggestion that way.
Yeah.. I think I will
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2721977448
Hmm let me just get rid of the backward compatibility, as it was a bug to begin with.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. ozone admin container list should output real JSON array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r2008014980
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java:
##########
@@ -114,44 +116,104 @@ public void execute(ScmClient scmClient) throws IOException {
.getInt(ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT,
ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT_DEFAULT);
- ContainerListResult containerListAndTotalCount;
+ // Use SequenceWriter to output JSON array format for all cases
+ SequenceWriter sequenceWriter = WRITER.writeValues(new NonClosingOutputStream(System.out));
+ sequenceWriter.init(true); // Initialize as a JSON array
if (!all) {
+ // Regular listing with count limit
if (count > maxCountAllowed) {
System.err.printf("Attempting to list the first %d records of containers." +
" However it exceeds the cluster's current limit of %d. The results will be capped at the" +
- " maximum allowed count.%n", count, ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT_DEFAULT);
+ " maximum allowed count.%n", count, maxCountAllowed);
count = maxCountAllowed;
}
- containerListAndTotalCount = scmClient.listContainer(startId, count, state, type, repConfig);
- for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
- outputContainerInfo(container);
- }
- if (containerListAndTotalCount.getTotalCount() > count) {
+ ContainerListResult containerListResult =
+ scmClient.listContainer(startId, count, state, type, repConfig);
+
+ writeContainers(sequenceWriter, containerListResult.getContainerInfoList());
+
+ closeStream(sequenceWriter);
+ if (containerListResult.getTotalCount() > count) {
System.err.printf("Displaying %d out of %d containers. " +
- "Container list has more containers.%n",
- count, containerListAndTotalCount.getTotalCount());
+ "Container list has more containers.%n",
+ count, containerListResult.getTotalCount());
}
} else {
- // Batch size is either count passed through cli or maxCountAllowed
+ // List all containers by fetching in batches
int batchSize = (count > 0) ? count : maxCountAllowed;
- long currentStartId = startId;
- int fetchedCount;
-
- do {
- // Fetch containers in batches of 'batchSize'
- containerListAndTotalCount = scmClient.listContainer(currentStartId, batchSize, state, type, repConfig);
- fetchedCount = containerListAndTotalCount.getContainerInfoList().size();
-
- for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
- outputContainerInfo(container);
- }
-
- if (fetchedCount > 0) {
- currentStartId = containerListAndTotalCount.getContainerInfoList().get(fetchedCount - 1).getContainerID() + 1;
- }
- } while (fetchedCount > 0);
+ listAllContainers(scmClient, sequenceWriter, batchSize, repConfig);
+ closeStream(sequenceWriter);
+ }
+ }
+
+ private void writeContainers(SequenceWriter writer, List<ContainerInfo> containers)
+ throws IOException {
+ for (ContainerInfo container : containers) {
+ writer.write(container);
+ }
+ }
+
+ private void closeStream(SequenceWriter writer) throws IOException {
+ writer.flush();
+ writer.close();
+ // Add the final newline
+ System.out.println();
+ }
+
+ private void listAllContainers(ScmClient scmClient, SequenceWriter writer,
+ int batchSize, ReplicationConfig repConfig)
Review Comment:
I can change this in a followup.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r1989826869
##########
hadoop-ozone/dist/src/main/smoketest/admincli/container.robot:
##########
@@ -96,6 +96,33 @@ List all containers from a particular container ID
${output} = Execute ozone admin container list --all --start 1
Should contain ${output} OPEN
+List containers in JSON array format
+ ${output} = Execute ozone admin container list --json | jq -r '.'
+ Should Start With ${output} [
Review Comment:
> `ozone admin container list --json | jq '.[] | .containerID'`
I suggest splitting it into two commands:
```
${output} = Execute <command returns JSON>
${excerpt} = Execute echo '${output}' | jq '....'
```
This has the benefit of showing raw output, which helps in case `jq` fails to find expected structure. Plus you can reuse `output` for multiple extractions.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. ozone admin container list should output real JSON array [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2753981221
Thanks @kerneltime for the patch, @errose28 for the review.
Please make sure to file follow-up tasks.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2739161243
I am facing an issue with the integration test; for some reason, `out` does not reflect up the output of the second command in the integration tests, and this happens after I switch to sequenceWriter... still debugging.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r1989816086
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java:
##########
@@ -90,11 +95,35 @@ public class ListSubcommand extends ScmSubcommand {
}
- private void outputContainerInfo(ContainerInfo containerInfo)
- throws IOException {
- // Print container report info.
+ private void outputContainerInfo(ContainerInfo containerInfo) throws IOException {
+ // Original behavior - just print the container JSON
System.out.println(WRITER.writeValueAsString(containerInfo));
}
+
+ private void outputContainerInfoAsJsonMember(ContainerInfo containerInfo, boolean isFirst,
+ boolean isLast) throws IOException {
+ // JSON array format with proper brackets and commas
+ if (isFirst) {
+ // Start of array
+ System.out.print("[");
Review Comment:
Will look into SequenceWriter
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r1989770192
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java:
##########
@@ -90,11 +95,35 @@ public class ListSubcommand extends ScmSubcommand {
}
- private void outputContainerInfo(ContainerInfo containerInfo)
- throws IOException {
- // Print container report info.
+ private void outputContainerInfo(ContainerInfo containerInfo) throws IOException {
+ // Original behavior - just print the container JSON
System.out.println(WRITER.writeValueAsString(containerInfo));
}
+
+ private void outputContainerInfoAsJsonMember(ContainerInfo containerInfo, boolean isFirst,
+ boolean isLast) throws IOException {
+ // JSON array format with proper brackets and commas
+ if (isFirst) {
+ // Start of array
+ System.out.print("[");
Review Comment:
Let's use Jackson's `SequenceWriter` for this similar to what is done in #7944. We may need to duplicate some minor changes to `JsonUtils` here but that should be ok and we can resolve it on the next reverse merge into reconciler branch.
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java:
##########
@@ -76,6 +76,11 @@ public class ListSubcommand extends ScmSubcommand {
description = "Container replication (ONE, THREE for Ratis, " +
"rs-6-3-1024k for EC)")
private String replication;
+
+ @Option(names = {"--json"},
+ description = "Output the entire list in JSON array format",
Review Comment:
The original is still json (and can still be streamed into jq), it just doesn't represent a valid json file if it is saved that way. In that sense I think the flag here is confusing. I would just make json list the default and only behavior. We did something similar in HDDS-5824 and did not consider it a breaking change, since the original was a "bug". With 2.0 coming up such a change makes sense as well.
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java:
##########
@@ -76,6 +76,11 @@ public class ListSubcommand extends ScmSubcommand {
description = "Container replication (ONE, THREE for Ratis, " +
"rs-6-3-1024k for EC)")
private String replication;
+
+ @Option(names = {"--json"},
+ description = "Output the entire list in JSON array format",
Review Comment:
Existing acceptance tests would need to be updated to account for this.
##########
hadoop-ozone/dist/src/main/smoketest/admincli/container.robot:
##########
@@ -96,6 +96,33 @@ List all containers from a particular container ID
${output} = Execute ozone admin container list --all --start 1
Should contain ${output} OPEN
+List containers in JSON array format
+ ${output} = Execute ozone admin container list --json | jq -r '.'
+ Should Start With ${output} [
Review Comment:
This way of testing works, but a jq query to do the same test might be more robust (although failure messages may be more confusing):
`ozone admin container list --json | jq '.[] | .containerID'` then ensure that we actually get content in the output.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. ozone admin container list should output real JSON array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2765178194
> Thanks @kerneltime for the patch, @errose28 for the review.
>
> Please make sure to file follow-up tasks.
Done https://issues.apache.org/jira/browse/HDDS-12743
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2739369437
Found the issue the absence of new line was throwing off the integration tests. Fixed that and also added additional tests to check that a new line should be printed post the json array.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #8050:
URL: https://github.com/apache/ozone/pull/8050#discussion_r1989819489
##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java:
##########
@@ -76,6 +76,11 @@ public class ListSubcommand extends ScmSubcommand {
description = "Container replication (ONE, THREE for Ratis, " +
"rs-6-3-1024k for EC)")
private String replication;
+
+ @Option(names = {"--json"},
+ description = "Output the entire list in JSON array format",
Review Comment:
Yeah, I was trying to avoid changing the existing behavior of the CLI, as it would be good to tread CLI output as a contract. I ran into JSON parsing errors when analyzing a bunch of returned containers. `jq` works fine with streaming in the container JSONs, but it would be good to have JSON array as per speck as well.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2716087082
@errose28 @adoroszlai thank you for the review, I have addressed the review comments.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. Support ozone admin container list to print list in Json array [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #8050:
URL: https://github.com/apache/ozone/pull/8050#issuecomment-2721582730
I know duplication is temporary, but it still bothers me.
```diff
diff --git hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java
index 888a01f211..c651750ce3 100644
--- hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java
+++ hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/ListSubcommand.java
@@ -26,6 +26,7 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.base.Strings;
import java.io.IOException;
+import java.util.List;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationType;
@@ -36,6 +37,8 @@
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ContainerListResult;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.ratis.util.function.CheckedConsumer;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Visibility;
import picocli.CommandLine.Option;
@@ -96,7 +99,7 @@ public class ListSubcommand extends ScmSubcommand {
}
- private void outputContainerInfo(ContainerInfo containerInfo) throws IOException {
+ private static void outputContainerInfo(ContainerInfo containerInfo) throws IOException {
// Original behavior - just print the container JSON
System.out.println(WRITER.writeValueAsString(containerInfo));
}
@@ -120,6 +123,7 @@ public void execute(ScmClient scmClient) throws IOException {
ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT_DEFAULT);
ContainerListResult containerListAndTotalCount;
+ ContainerListProcesor processor = jsonFormat ? new JsonListWriter() : new JsonItemsWriter();
if (!all) {
if (count > maxCountAllowed) {
@@ -129,19 +133,11 @@ public void execute(ScmClient scmClient) throws IOException {
count = maxCountAllowed;
}
containerListAndTotalCount = scmClient.listContainer(startId, count, state, type, repConfig);
-
- if (jsonFormat) {
- // JSON array format using SequenceWriter directly
- try (SequenceWriter sequenceWriter = WRITER.writeValues(System.out)) {
- sequenceWriter.init(true); // Initialize as a JSON array
- sequenceWriter.writeAll(containerListAndTotalCount.getContainerInfoList());
- }
- System.out.println(); // Add final newline
- } else {
- // Original format - one JSON object per line
- for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
- outputContainerInfo(container);
- }
+
+ try {
+ processor.accept(containerListAndTotalCount.getContainerInfoList());
+ } finally {
+ IOUtils.closeQuietly(processor);
}
if (containerListAndTotalCount.getTotalCount() > count) {
@@ -154,46 +150,61 @@ public void execute(ScmClient scmClient) throws IOException {
int batchSize = (count > 0) ? count : maxCountAllowed;
long currentStartId = startId;
int fetchedCount;
-
- if (jsonFormat) {
- // For JSON array format, use SequenceWriter to stream containers as we fetch them
- try (SequenceWriter sequenceWriter = WRITER.writeValues(System.out)) {
- sequenceWriter.init(true); // Initialize as a JSON array
-
- do {
- // Fetch containers in batches of 'batchSize'
- containerListAndTotalCount = scmClient.listContainer(currentStartId, batchSize, state, type, repConfig);
- fetchedCount = containerListAndTotalCount.getContainerInfoList().size();
-
- // Write containers directly to the SequenceWriter
- for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
- sequenceWriter.write(container);
- }
-
- if (fetchedCount > 0) {
- currentStartId =
- containerListAndTotalCount.getContainerInfoList().get(fetchedCount - 1).getContainerID() + 1;
- }
- } while (fetchedCount > 0);
- }
- System.out.println(); // Add final newline
- } else {
- // Original format - one JSON object per line
+
+ try {
do {
// Fetch containers in batches of 'batchSize'
containerListAndTotalCount = scmClient.listContainer(currentStartId, batchSize, state, type, repConfig);
fetchedCount = containerListAndTotalCount.getContainerInfoList().size();
- for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
- outputContainerInfo(container);
- }
+ // Write containers directly to the SequenceWriter
+ processor.accept(containerListAndTotalCount.getContainerInfoList());
if (fetchedCount > 0) {
currentStartId =
containerListAndTotalCount.getContainerInfoList().get(fetchedCount - 1).getContainerID() + 1;
}
} while (fetchedCount > 0);
+ } finally {
+ IOUtils.closeQuietly(processor);
}
}
}
+
+ private interface ContainerListProcesor extends CheckedConsumer<List<ContainerInfo>, IOException>, AutoCloseable {
+ //
+ }
+
+ private static final class JsonListWriter implements ContainerListProcesor {
+ private final SequenceWriter sequenceWriter;
+
+ private JsonListWriter() throws IOException {
+ // For JSON array format, use SequenceWriter to stream containers as we fetch them
+ sequenceWriter = WRITER.writeValues(System.out).init(true);
+ }
+
+ @Override
+ public void accept(List<ContainerInfo> list) throws IOException {
+ sequenceWriter.writeAll(list);
+ }
+
+ @Override
+ public void close() throws Exception {
+ sequenceWriter.close();
+ }
+ }
+
+ private static final class JsonItemsWriter implements ContainerListProcesor {
+ @Override
+ public void accept(List<ContainerInfo> list) throws IOException {
+ for (ContainerInfo container : list) {
+ outputContainerInfo(container);
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ System.out.println(); // Add final newline
+ }
+ }
}
```
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-12553. ozone admin container list should output real JSON array [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #8050:
URL: https://github.com/apache/ozone/pull/8050
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org