sumitagrawl commented on code in PR #4129:
URL: https://github.com/apache/ozone/pull/4129#discussion_r1059944398


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/NSSummaryEndpoint.java:
##########
@@ -62,6 +70,129 @@ public NSSummaryEndpoint(ReconNamespaceSummaryManager 
namespaceSummaryManager,
     this.reconSCM = reconSCM;
   }
 
+  @GET
+  @Path("/entitymetrics")
+  public Response getEntityMetrics(@QueryParam("path") String path,
+                                   @DefaultValue("size")

Review Comment:
   orderby should include "age" also a filter and as default



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/NSSummaryEndpoint.java:
##########
@@ -62,6 +70,129 @@ public NSSummaryEndpoint(ReconNamespaceSummaryManager 
namespaceSummaryManager,
     this.reconSCM = reconSCM;
   }
 
+  @GET
+  @Path("/entitymetrics")

Review Comment:
   uri name can be entityInfo or other better name, not a metrics as its not a 
metric data.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/NamespaceSummaryResponse.java:
##########
@@ -43,6 +43,16 @@ public class NamespaceSummaryResponse {
   @JsonProperty("numKey")
   private long numTotalKey;
 
+  /** Age of entity in
+   * human-readable format. */
+  @JsonProperty("age")
+  private long age;

Review Comment:
   can have same name as createTime, UI can calculate age and display name 
accordingly



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/NSSummaryEndpoint.java:
##########
@@ -62,6 +70,129 @@ public NSSummaryEndpoint(ReconNamespaceSummaryManager 
namespaceSummaryManager,
     this.reconSCM = reconSCM;
   }
 
+  @GET
+  @Path("/entitymetrics")
+  public Response getEntityMetrics(@QueryParam("path") String path,
+                                   @DefaultValue("size")
+                                   @QueryParam("orderBy") String orderBy,
+                                   @DefaultValue("10")
+                                   @QueryParam("count") int count)
+      throws IOException {
+    if (path == null || path.length() == 0) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    EntityMetricsResponse entityMetricsResponse;
+    if (!isInitializationComplete()) {
+      entityMetricsResponse =
+          new EntityMetricsResponse(EntityType.UNKNOWN);
+      entityMetricsResponse.setStatus(ResponseStatus.INITIALIZING);
+    } else {
+      Map<String, List<DUResponse.DiskUsage>> childMetricsListMap =
+          new HashMap<>();
+      NamespaceSummaryResponse nsSummaryData =
+          getNamespaceSummaryResponse(path);
+      DUResponse duResponse = getDuResponse(path, true, true);
+
+      EntityType entityType = nsSummaryData.getEntityType();
+      entityMetricsResponse = new EntityMetricsResponse(entityType);
+
+      if (COUNT.equalsIgnoreCase(orderBy)) {
+        switch (entityType) {
+        case ROOT:
+          childMetricsListMap.put(EntityType.VOLUME.name(),
+              duResponse.getDuData()
+              .stream().sorted(Comparator.comparingLong(
+                  DUResponse.DiskUsage::getVolumeCount).reversed())
+              .limit(count).collect(Collectors.toList()));
+          break;
+        case VOLUME:
+          childMetricsListMap.put(EntityType.BUCKET.name(),
+              duResponse.getDuData()
+              .stream().sorted(Comparator.comparingLong(
+                  DUResponse.DiskUsage::getBucketCount).reversed())
+              .limit(count).collect(Collectors.toList()));
+          break;
+        case BUCKET:
+        case DIRECTORY:
+          List<DUResponse.DiskUsage> keys = getKeys(duResponse.getDuData());
+          List<DUResponse.DiskUsage> dirs = getDirs(duResponse.getDuData());
+          childMetricsListMap.put(EntityType.KEY.name(),
+              keys.stream().sorted(Comparator.comparingLong(
+                      DUResponse.DiskUsage::getKeyCount).reversed())
+                  .limit(count).collect(Collectors.toList()));
+          childMetricsListMap.put(EntityType.DIRECTORY.name(),
+              dirs.stream().sorted(Comparator.comparingLong(
+                      DUResponse.DiskUsage::getKeyCount).reversed())
+                  .limit(count).collect(Collectors.toList()));
+          break;
+        default:
+          childMetricsListMap.put(EntityType.UNKNOWN.name(),
+              duResponse.getDuData()
+              .stream().sorted(Comparator.comparingLong(
+                  DUResponse.DiskUsage::getKeyCount).reversed())
+              .limit(count).collect(Collectors.toList()));
+          break;
+        }
+      } else {
+        switch (entityType) {
+        case ROOT:
+          childMetricsListMap.put(EntityType.VOLUME.name(),
+              duResponse.getDuData()
+                  .stream().sorted(Comparator.comparingLong(
+                      DUResponse.DiskUsage::getSizeWithReplica).reversed())
+                  .limit(count).collect(Collectors.toList()));
+          break;
+        case VOLUME:
+          childMetricsListMap.put(EntityType.BUCKET.name(),
+              duResponse.getDuData()
+                  .stream().sorted(Comparator.comparingLong(
+                      DUResponse.DiskUsage::getSizeWithReplica).reversed())
+                  .limit(count).collect(Collectors.toList()));
+          break;
+        case BUCKET:
+        case DIRECTORY:
+          List<DUResponse.DiskUsage> keys = getKeys(duResponse.getDuData());
+          List<DUResponse.DiskUsage> dirs = getDirs(duResponse.getDuData());
+          childMetricsListMap.put(EntityType.KEY.name(),
+              keys.stream().sorted(Comparator.comparingLong(
+                      DUResponse.DiskUsage::getSizeWithReplica).reversed())
+                  .limit(count).collect(Collectors.toList()));
+          childMetricsListMap.put(EntityType.DIRECTORY.name(),
+              dirs.stream().sorted(Comparator.comparingLong(
+                      DUResponse.DiskUsage::getSizeWithReplica).reversed())
+                  .limit(count).collect(Collectors.toList()));
+          break;
+        default:
+          childMetricsListMap.put(EntityType.UNKNOWN.name(),
+              duResponse.getDuData()
+              .stream().sorted(Comparator.comparingLong(
+                  DUResponse.DiskUsage::getSizeWithReplica).reversed())
+              .limit(count).collect(Collectors.toList()));
+          break;
+        }
+      }
+      entityMetricsResponse.setNsSummaryResponse(nsSummaryData);
+      entityMetricsResponse.setChildMetricsListMap(childMetricsListMap);

Review Comment:
   childMetricsList should be part of NsSummary as it belongs to it.



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