yandrey321 commented on code in PR #9258:
URL: https://github.com/apache/ozone/pull/9258#discussion_r2833774684
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -392,33 +391,41 @@ public Response getUnhealthyContainers(
@QueryParam(RECON_QUERY_MAX_CONTAINER_ID) long maxContainerId,
@DefaultValue(PREV_CONTAINER_ID_DEFAULT_VALUE)
@QueryParam(RECON_QUERY_MIN_CONTAINER_ID) long minContainerId) {
- Optional<Long> maxContainerIdOpt = maxContainerId > 0 ?
Optional.of(maxContainerId) : Optional.empty();
+ return getUnhealthyContainersV2(state, limit, maxContainerId,
minContainerId);
+ }
+
+ /**
+ * V2 implementation - reads from UNHEALTHY_CONTAINERS_V2 table.
+ */
+ private Response getUnhealthyContainersV2(
+ String state,
+ int limit,
+ long maxContainerId,
+ long minContainerId) {
List<UnhealthyContainerMetadata> unhealthyMeta = new ArrayList<>();
- List<UnhealthyContainersSummary> summary;
+ List<UnhealthyContainersSummary> summary = new ArrayList<>();
+
try {
- UnHealthyContainerStates internalState = null;
+ ContainerSchemaDefinitionV2.UnHealthyContainerStates v2State = null;
if (state != null) {
- // If an invalid state is passed in, this will throw
- // illegalArgumentException and fail the request
- internalState = UnHealthyContainerStates.valueOf(state);
+ // Convert V1 state string to V2 enum
+ v2State =
ContainerSchemaDefinitionV2.UnHealthyContainerStates.valueOf(state);
}
- summary = containerHealthSchemaManager.getUnhealthyContainersSummary();
- List<UnhealthyContainers> containers = containerHealthSchemaManager
- .getUnhealthyContainers(internalState, minContainerId,
maxContainerIdOpt, limit);
-
- // Filtering out EMPTY_MISSING and NEGATIVE_SIZE containers from the
response.
- // These container states are not being inserted into the database as
they represent
- // edge cases that are not critical to track as unhealthy containers.
- List<UnhealthyContainers> filteredContainers = containers.stream()
- .filter(container -> !container.getContainerState()
- .equals(UnHealthyContainerStates.EMPTY_MISSING.toString())
- && !container.getContainerState()
- .equals(UnHealthyContainerStates.NEGATIVE_SIZE.toString()))
- .collect(Collectors.toList());
+ // Get summary from V2 table and convert to V1 format
+ List<ContainerHealthSchemaManagerV2.UnhealthyContainersSummaryV2>
v2Summary =
+ containerHealthSchemaManagerV2.getUnhealthyContainersSummary();
+ for (ContainerHealthSchemaManagerV2.UnhealthyContainersSummaryV2 s :
v2Summary) {
+ summary.add(new UnhealthyContainersSummary(s.getContainerState(),
s.getCount()));
+ }
- for (UnhealthyContainers c : filteredContainers) {
+ // Get containers from V2 table
+ List<ContainerHealthSchemaManagerV2.UnhealthyContainerRecordV2>
v2Containers =
+ containerHealthSchemaManagerV2.getUnhealthyContainers(v2State,
minContainerId, maxContainerId, limit);
+
+ // Convert V2 records to response format
+ for (ContainerHealthSchemaManagerV2.UnhealthyContainerRecordV2 c :
v2Containers) {
Review Comment:
its better to move the transformation logic into helper function and then do
map().collect()
--
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]