diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/UtilizationEndpoint.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/UtilizationEndpoint.java index 5a19890d3dcf..5800f0032054 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/UtilizationEndpoint.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/UtilizationEndpoint.java @@ -116,7 +116,10 @@ public Response getFileCounts( if (bucket != null && !bucket.equals(key.getBucket())) { matches = false; } - + if (fileSize > 0 && fileSize != key.getFileSizeUpperBound()) { + matches = false; + } + if (matches && count != null && count > 0) { FileCountBySize record = new FileCountBySize(); record.setVolume(key.getVolume()); diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java index db9301e4795e..0d869a3b64ce 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java @@ -915,6 +915,15 @@ public void testGetFileCounts() throws Exception { assertEquals(2L, rocksCount3.longValue(), "Expected RocksDB bin 1024 to have count 2 for vol2/bucket1"); // --- Now test the query endpoints of the utilization service --- + verifyFileCountQueries(); + } + + /** + * Verify the filtering behaviour of the fileCount endpoint against the + * bins written by {@link #testGetFileCounts()}: vol1/bucket1:1024, + * vol1/bucket1:131072 and vol2/bucket1:1024, each with count 2. + */ + private void verifyFileCountQueries() { Response response = utilizationEndpoint.getFileCounts(null, null, 0); List resultSet = (List) response.getEntity(); @@ -952,6 +961,32 @@ public void testGetFileCounts() throws Exception { resultSet = (List) response.getEntity(); assertEquals(0, resultSet.size()); + // Test for "fileSize" query param on its own. + response = utilizationEndpoint.getFileCounts(null, null, 131072); + resultSet = (List) response.getEntity(); + assertEquals(1, resultSet.size()); + assertTrue(resultSet.stream().allMatch(o -> o.getVolume().equals("vol1") && + o.getBucket().equals("bucket1") && o.getFileSize() == 131072L)); + + // Test for "volume" + "fileSize" query params, without bucket. + response = utilizationEndpoint.getFileCounts("vol1", null, 131072); + resultSet = (List) response.getEntity(); + assertEquals(1, resultSet.size()); + assertTrue(resultSet.stream().allMatch(o -> o.getVolume().equals("vol1") && + o.getFileSize() == 131072L)); + + // Test for "bucket" + "fileSize" query params, without volume. + response = utilizationEndpoint.getFileCounts(null, "bucket1", 1024); + resultSet = (List) response.getEntity(); + assertEquals(2, resultSet.size()); + assertTrue(resultSet.stream().allMatch(o -> o.getBucket().equals("bucket1") && + o.getFileSize() == 1024L)); + + // Test for a fileSize that is not a bin upper bound, without volume and bucket. + response = utilizationEndpoint.getFileCounts(null, null, 1310725); + resultSet = (List) response.getEntity(); + assertEquals(0, resultSet.size()); + // Test for "volume" + "bucket" + "fileSize" query params. response = utilizationEndpoint.getFileCounts("vol1", "bucket1", 131072); resultSet = (List) response.getEntity();