[GitHub] [helix] dasahcc commented on a change in pull request #761: Add REST read endpoints to helix-rest for metadata store directory

2020-02-13 Thread GitBox
dasahcc commented on a change in pull request #761: Add REST read endpoints to 
helix-rest for metadata store directory
URL: https://github.com/apache/helix/pull/761#discussion_r379208017
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/metadatastore/MetadataStoreDirectoryAccessor.java
 ##
 @@ -66,24 +67,44 @@ private void postConstruct() {
   }
 
   /**
-   * Gets all metadata store realms in a namespace with the endpoint.
+   * Gets all existing namespaces in the routing metadata store at endpoint:
+   * "GET /metadata-store-namespaces"
+   *
+   * @return Json response of all namespaces.
+   */
+  @GET
+  @Path("/metadata-store-namespaces")
+  public Response getAllNamespaces() {
+Collection namespaces = _metadataStoreDirectory.getAllNamespaces();
+Map> responseMap =
+
ImmutableMap.of(MetadataStoreRoutingConstants.METADATA_STORE_NAMESPACES, 
namespaces);
+
+return JSONRepresentation(responseMap);
+  }
+
+  /**
+   * Gets all metadata store realms in a namespace at path: "GET 
/metadata-store-realms",
+   * or gets a metadata store realm with the sharding key at path:
+   * "GET /metadata-store-realms?sharding-key={sharding-key}"
*
* @return Json representation of all realms.
*/
   @GET
   @Path("/metadata-store-realms")
-  public Response getAllMetadataStoreRealms() {
-Map> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String 
shardingKey) {
 try {
-  Collection realms = 
_metadataStoreDirectory.getAllMetadataStoreRealms(_namespace);
-
-  responseMap = new HashMap<>(1);
-  responseMap.put(MetadataStoreRoutingConstants.METADATA_STORE_REALMS, 
realms);
+  if (shardingKey == null) {
+Collection realms = 
_metadataStoreDirectory.getAllMetadataStoreRealms(_namespace);
+Map> responseMap =
+
ImmutableMap.of(MetadataStoreRoutingConstants.METADATA_STORE_REALMS, realms);
+return JSONRepresentation(responseMap);
+  } else {
 
 Review comment:
   Remove else clause.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [helix] dasahcc commented on a change in pull request #761: Add REST read endpoints to helix-rest for metadata store directory

2020-02-13 Thread GitBox
dasahcc commented on a change in pull request #761: Add REST read endpoints to 
helix-rest for metadata store directory
URL: https://github.com/apache/helix/pull/761#discussion_r379208234
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/metadatastore/MetadataStoreDirectoryAccessor.java
 ##
 @@ -66,24 +67,44 @@ private void postConstruct() {
   }
 
   /**
-   * Gets all metadata store realms in a namespace with the endpoint.
+   * Gets all existing namespaces in the routing metadata store at endpoint:
+   * "GET /metadata-store-namespaces"
+   *
+   * @return Json response of all namespaces.
+   */
+  @GET
+  @Path("/metadata-store-namespaces")
+  public Response getAllNamespaces() {
+Collection namespaces = _metadataStoreDirectory.getAllNamespaces();
+Map> responseMap =
+
ImmutableMap.of(MetadataStoreRoutingConstants.METADATA_STORE_NAMESPACES, 
namespaces);
+
+return JSONRepresentation(responseMap);
+  }
+
+  /**
+   * Gets all metadata store realms in a namespace at path: "GET 
/metadata-store-realms",
+   * or gets a metadata store realm with the sharding key at path:
+   * "GET /metadata-store-realms?sharding-key={sharding-key}"
*
* @return Json representation of all realms.
*/
   @GET
   @Path("/metadata-store-realms")
-  public Response getAllMetadataStoreRealms() {
-Map> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String 
shardingKey) {
 
 Review comment:
   Shall we define different response object instead of using plain Response.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] [helix] dasahcc commented on a change in pull request #761: Add REST read endpoints to helix-rest for metadata store directory

2020-02-13 Thread GitBox
dasahcc commented on a change in pull request #761: Add REST read endpoints to 
helix-rest for metadata store directory
URL: https://github.com/apache/helix/pull/761#discussion_r379208465
 
 

 ##
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/metadatastore/MetadataStoreDirectoryAccessor.java
 ##
 @@ -111,41 +132,56 @@ public Response 
deleteMetadataStoreRealm(@PathParam("realm") String realm) {
   }
 
   /**
-   * Gets sharding keys mapped at path "HTTP GET /sharding-keys" which returns 
all sharding keys in
-   * a namespace, or path "HTTP GET /sharding-keys?realm={realmName}" which 
returns sharding keys in
-   * a realm.
+   * Gets all sharding keys mapped at paths:
+   * - "HTTP GET /sharding-keys" which returns all sharding keys in a 
namespace.
+   * - "HTTP GET /sharding-keys?realm={realm}" which returns sharding keys in 
the realm.
+   * - "HTTP GET /sharding-keys?prefix={prefix}" which returns sharding keys 
that have the prefix.
+   * -- JSON response example for this path:
+   * {
+   *   "prefix": "/sharding/key",
+   *   "shardingKeys": [{
+   *   "realm": "testRealm2",
+   *   "shardingKey": "/sharding/key/1/f"
+   *}, {
+   *   "realm": "testRealm2",
+   *   "shardingKey": "/sharding/key/1/e"
+   *  }, {
+   *   "realm": "testRealm1",
+   *   "shardingKey": "/sharding/key/1/b"
+   *  }, {
+   *   "realm": "testRealm1",
+   *   "shardingKey": "/sharding/key/1/a"
+   *  }]
+   * }
+   *
+   * - "HTTP GET /sharding-keys?realm={realm}={prefix}" which returns 
sharding keys in the
+   * realm and that have the prefix.
*
-   * @param realm Query param in endpoint path
-   * @return Json representation of a map: shardingKeys -> collection of 
sharding keys.
+   * @param realm Query param in endpoint path: metadata store realm.
+   * @param prefix Query param in endpoint path: prefix substring of sharding 
key.
+   * @return Json representation for the sharding keys.
*/
   @GET
   @Path("/sharding-keys")
-  public Response getShardingKeys(@QueryParam("realm") String realm) {
-Map responseMap;
-Collection shardingKeys;
+  public Response getShardingKeys(@QueryParam("realm") String realm,
+  @QueryParam("prefix") String prefix) {
 try {
-  // If realm is not set in query param, the endpoint is: "/sharding-keys"
-  // to get all sharding keys in a namespace.
-  if (realm == null) {
-shardingKeys = _metadataStoreDirectory.getAllShardingKeys(_namespace);
-// To avoid allocating unnecessary resource, limit the map's capacity 
only for
-// SHARDING_KEYS.
-responseMap = new HashMap<>(1);
+  if (realm == null && prefix == null) {
+// For endpoint: "/sharding-keys" to get all sharding keys in a 
namespace.
+return getAllShardingKeys();
+  } else if (prefix == null) {
+// For endpoint: "/sharding-keys?realm={realm}"
+return getAllShardingKeysInRealm(realm);
+  } else if (realm == null) {
+// For endpoint: "/sharding-keys?prefix={prefix}"
+return getAllShardingKeysUnderPath(prefix);
   } else {
-// For endpoint: "/sharding-keys?realm={realmName}"
-shardingKeys = 
_metadataStoreDirectory.getAllShardingKeysInRealm(_namespace, realm);
-// To avoid allocating unnecessary resource, limit the map's capacity 
only for
-// SHARDING_KEYS and SINGLE_METADATA_STORE_REALM.
-responseMap = new HashMap<>(2);
-
responseMap.put(MetadataStoreRoutingConstants.SINGLE_METADATA_STORE_REALM, 
realm);
+// For endpoint: "/sharding-keys?realm={realm}={prefix}"
+return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   This logic is very complex. Can we leverage the default value to simplify 
the logic?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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