devmadhuu commented on code in PR #9584:
URL: https://github.com/apache/ozone/pull/9584#discussion_r2711819564


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/PendingDeletionEndpoint.java:
##########
@@ -75,8 +87,57 @@ public Response 
getPendingDeletionByComponent(@QueryParam("component") String co
     }
   }
 
-  private Response handleDataNodeMetrics() {
-    DataNodeMetricsServiceResponse response = 
dataNodeMetricsService.getCollectedMetrics();
+  @GET
+  @Path("/download")
+  public Response downloadPendingDeleteData() {
+    DataNodeMetricsServiceResponse dnMetricsResponse = 
dataNodeMetricsService.getCollectedMetrics(-1);
+
+    if (dnMetricsResponse.getStatus() != 
DataNodeMetricsService.MetricCollectionStatus.FINISHED) {
+      return Response.status(Response.Status.ACCEPTED)
+          .entity(dnMetricsResponse)
+          .type("application/json")
+          .build();
+    }
+
+    if (null == dnMetricsResponse.getPendingDeletionPerDataNode()) {
+      return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+          .entity("Metrics data is missing despite FINISHED status.")
+          .type("text/plain")
+          .build();
+    }
+
+    StreamingOutput stream = output -> {
+      CSVFormat format = CSVFormat.DEFAULT.builder()
+          .setHeader("HostName", "Datanode UUID", "Pending Block Size 
(bytes)").build();
+      try (CSVPrinter csvPrinter = new CSVPrinter(
+          new BufferedWriter(new OutputStreamWriter(output)), format)) {
+        for (DatanodePendingDeletionMetrics metric : 
dnMetricsResponse.getPendingDeletionPerDataNode()) {
+          csvPrinter.printRecord(
+              metric.getHostName(),
+              metric.getDatanodeUuid(),
+              metric.getPendingBlockSize()
+          );
+        }
+        csvPrinter.flush();
+      } catch (Exception e) {
+        LOG.error("Failed to stream CSV", e);
+        throw new WebApplicationException("Failed to generate CSV", e);
+      }
+    };
+
+    return Response.status(Response.Status.ACCEPTED)
+        .entity(stream)
+        .type("text/csv")
+        .header("Content-Disposition", "attachment; 
filename=\"pending_deletion_stats.csv\"")

Review Comment:
   if pending deletion data is for all datanodes, then we can rename the csv as 
"pending_deletion_alldatanode_stats.csv"



-- 
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]

Reply via email to