shounakmk219 commented on code in PR #13544:
URL: https://github.com/apache/pinot/pull/13544#discussion_r1677949730


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotDatabaseRestletResource.java:
##########
@@ -107,6 +120,61 @@ public DeleteDatabaseResponse deleteTablesInDatabase(
     }
     return new DeleteDatabaseResponse(deletedTables, failedTables, dryRun);
   }
+
+  /**
+   * API to update the quota configs for database
+   * If database config is not present it will be created implicitly
+   */
+  @POST
+  @Produces(MediaType.APPLICATION_JSON)
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Path("/databases/{databaseName}/quotas")
+  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.UPDATE_DATABASE_QUOTA)
+  @ApiOperation(value = "Update database quotas", notes = "Update database 
quotas")
+  public SuccessResponse addTable(
+      @PathParam("databaseName") String databaseName, 
@QueryParam("maxQueriesPerSecond") String queryQuota,
+      @Context HttpHeaders httpHeaders) {
+    if 
(!databaseName.equals(DatabaseUtils.extractDatabaseFromHttpHeaders(httpHeaders)))
 {
+      throw new ControllerApplicationException(LOGGER, "Database config name 
and request context does not match",
+          Response.Status.BAD_REQUEST);
+    }
+    try {
+      DatabaseConfig databaseConfig = 
_pinotHelixResourceManager.getDatabaseConfig(databaseName);
+      QuotaConfig quotaConfig = new QuotaConfig(null, queryQuota);
+      if (databaseConfig == null) {
+         databaseConfig = new DatabaseConfig(databaseName, quotaConfig);
+        _pinotHelixResourceManager.addDatabaseConfig(databaseConfig);
+      } else {
+        databaseConfig.setQuotaConfig(quotaConfig);
+        _pinotHelixResourceManager.updateDatabaseConfig(databaseConfig);
+      }
+      return new SuccessResponse("Database quotas for database config " + 
databaseName + " successfully updated");
+    } catch (Exception e) {
+      throw new ControllerApplicationException(LOGGER, e.getMessage(), 
Response.Status.INTERNAL_SERVER_ERROR, e);
+    }
+  }
+
+  /**
+   * API to get database quota configs.
+   * Will return null if database config is not defined or database quotas are 
not defined
+   */
+  @GET
+  @Produces(MediaType.APPLICATION_JSON)
+  @Path("/databases/{databaseName}/quotas")
+  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.GET_DATABASE_QUOTA)
+  @ApiOperation(value = "Get database quota configs", notes = "Get database 
quota configs")
+  public QuotaConfig getDatabaseQuota(
+      @PathParam("databaseName") String databaseName, @Context HttpHeaders 
httpHeaders) {
+    if 
(!databaseName.equals(DatabaseUtils.extractDatabaseFromHttpHeaders(httpHeaders)))
 {
+      throw new ControllerApplicationException(LOGGER, "Database config name 
and request context does not match",
+          Response.Status.BAD_REQUEST);
+    }
+    DatabaseConfig databaseConfig = 
_pinotHelixResourceManager.getDatabaseConfig(databaseName);
+    if (databaseConfig != null) {
+      return databaseConfig.getQuotaConfig();
+    }
+    return new QuotaConfig(null, null);

Review Comment:
   That's a good idea



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to