diff --git a/docs/REST_Endpoints/Quotas.md b/docs/REST_Endpoints/Quotas.md index 32ef9de7..ef3c713d 100644 --- a/docs/REST_Endpoints/Quotas.md +++ b/docs/REST_Endpoints/Quotas.md @@ -5,6 +5,34 @@ It takes an optional parameter `?user=` to specify looking at cached direc It also takes a required parameter `&sum=` to specify which quota you wish to look at; either namespace or diskspace. Directories can be added to NNA for quota scanning via `/addDirectory` and `/removeDirectory` ADMIN endpoints. +If you make the call with `?all` as the parameter then the JSON dump will contain information of all directory quotas. + +Example response: +```json +{ + nsQuota: { + user1: { + /dir1/dir1: 10, + /dir1/dir2: 20 + }, + user2: { + /dir2/dir2: 30, + /dir3/dir3: 40 + } + }, + dsQuota: { + user1: { + /dir1/dir1: 50, + /dir1/dir2: 60 + }, + user2: { + /dir2/dir2: 70, + /dir3/dir3: 80 + } + } +} +``` + Response code is 200 and a JSON dump of directories and a mapping to a percentage (0-100) of their quota used. Response code of 403 means you are not authorized to view this endpoint. \ No newline at end of file diff --git a/src/main/java/com/paypal/namenode/WebServerMain.java b/src/main/java/com/paypal/namenode/WebServerMain.java index 6f5f9fa8..1af7ead1 100644 --- a/src/main/java/com/paypal/namenode/WebServerMain.java +++ b/src/main/java/com/paypal/namenode/WebServerMain.java @@ -1627,9 +1627,14 @@ public void init( (req, res) -> { res.header("Access-Control-Allow-Origin", "*"); res.header("Content-Type", "application/json"); - String user = req.queryMap("user").value(); - String sum = req.queryMap("sum").value(); - return nameNodeLoader.getSuggestionsEngine().getQuotaAsJson(user, sum); + boolean allJson = req.queryMap().toMap().containsKey("all"); + if (allJson) { + return nameNodeLoader.getSuggestionsEngine().getAllQuotasAsJson(); + } else { + String user = req.queryMap("user").value(); + String sum = req.queryMap("sum").value(); + return nameNodeLoader.getSuggestionsEngine().getQuotaAsJson(user, sum); + } }); /* USERS endpoint is an admin-level endpoint meant to dump the cached set of detected users by NNA. */ diff --git a/src/main/java/org/apache/hadoop/hdfs/server/namenode/cache/SuggestionsEngine.java b/src/main/java/org/apache/hadoop/hdfs/server/namenode/cache/SuggestionsEngine.java index e304b531..8e406f99 100644 --- a/src/main/java/org/apache/hadoop/hdfs/server/namenode/cache/SuggestionsEngine.java +++ b/src/main/java/org/apache/hadoop/hdfs/server/namenode/cache/SuggestionsEngine.java @@ -538,6 +538,20 @@ public Set getDirectoriesForAnalysis() { return cachedDirs; } + /** + * Get all quota information from cache as a JSON String. + * + * @return quota info returned as JSON string + */ + public String getAllQuotasAsJson() { + Map>> allQuotaRatios = new HashMap<>(); + Map> nsQuotas = cachedUserNsQuotas; + Map> dsQuotas = cachedUserDsQuotas; + allQuotaRatios.put("nsQuotas", nsQuotas); + allQuotaRatios.put("dsQuotas", dsQuotas); + return Histograms.toJson(allQuotaRatios); + } + /** * Get quota information from cache as a JSON String. * diff --git a/src/main/resources/public/qoutas.html b/src/main/resources/public/qoutas.html deleted file mode 100644 index 80628bef..00000000 --- a/src/main/resources/public/qoutas.html +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - - - - - -
- - - - -
-

Welcome to NNAnalytics

-
-

- View directories that have qoutas set on them.
-

- -
-
-
-
- -
- - - - - - - - - - - - - - - - - diff --git a/src/main/resources/public/quotas.html b/src/main/resources/public/quotas.html new file mode 100644 index 00000000..7931e855 --- /dev/null +++ b/src/main/resources/public/quotas.html @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+

Welcome to NNAnalytics

+
+

+ View directories that have quotas set on them and how filled those quotas are.
+

+
+
+
+
+ + + + + + + + + +
PathOwnerNamespace Quota % UsedDiskspace Quota % Used
+
+ +
+ + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/com/paypal/nnanalytics/TestNNAnalyticsBase.java b/src/test/java/com/paypal/nnanalytics/TestNNAnalyticsBase.java index a2510619..2a8fbca3 100644 --- a/src/test/java/com/paypal/nnanalytics/TestNNAnalyticsBase.java +++ b/src/test/java/com/paypal/nnanalytics/TestNNAnalyticsBase.java @@ -210,6 +210,13 @@ public void testUsersSuggestions() throws IOException { assertThat(res.getStatusLine().getStatusCode(), is(200)); } + @Test + public void testAllQuotas() throws IOException { + HttpGet get = new HttpGet("http://localhost:4567/quotas?all"); + HttpResponse res = client.execute(hostPort, get); + assertThat(res.getStatusLine().getStatusCode(), is(200)); + } + @Test public void testDsQuotas() throws IOException { HttpGet get = new HttpGet("http://localhost:4567/quotas?sum=dsQuotaRatioUsed"); @@ -304,7 +311,7 @@ public void testModDateFilterGt() throws IOException { } @Test - public void testHasQouta() throws IOException { + public void testHasQuota() throws IOException { HttpGet get = new HttpGet("http://localhost:4567/filter?set=dirs&filters=hasQuota:eq:true&sum=count"); HttpResponse res = client.execute(hostPort, get); @@ -315,7 +322,7 @@ public void testHasQouta() throws IOException { } @Test - public void testHasQoutaList() throws IOException { + public void testHasQuotaList() throws IOException { HttpGet get = new HttpGet("http://localhost:4567/filter?set=dirs&filters=hasQuota:eq:true"); HttpResponse res = client.execute(hostPort, get); List result = IOUtils.readLines(res.getEntity().getContent());