You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2020/02/14 01:12:57 UTC

[GitHub] [helix] pkuwm opened a new pull request #761: Add REST read endpoints to helix-rest for metadata store directory

pkuwm opened a new pull request #761: Add REST read endpoints to helix-rest for metadata store directory
URL: https://github.com/apache/helix/pull/761
 
 
   ### Issues
   
   - [x] My PR addresses the following Helix issues and references them in the PR description:
   
   Implements #752 
   
   ### Description
   
   - [x] Here are some details about my PR, including screenshots of any UI changes:
   
   We have metadata store directory service to help scale out zookeeper. Metadata store directory service provides REST APIs to access.
   This PR adds remaining MSDS read endpoints to Helix REST.
   
   ### Tests
   
   - [x] The following tests are written for this issue:
    - 5 unit tests in TestMetadataStoreDirectoryAccessor
   
   - [x] The following is the result of the "mvn test" command on the appropriate module:
   ```
   [INFO] Tests run: 145, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 26.54 s - in TestSuite
   [INFO]
   [INFO] Results:
   [INFO]
   [INFO] Tests run: 145, Failures: 0, Errors: 0, Skipped: 0
   [INFO]
   [INFO] ------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] ------------------------------------------------------------------------
   [INFO] Total time:  01:01 min
   [INFO] Finished at: 2020-02-13T17:10:02-08:00
   [INFO] ------------------------------------------------------------------------
   ```
   ### Commits
   
   - [x] My commits all reference appropriate Apache Helix GitHub issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation in the following wiki page:
   
   (Link the GitHub wiki you added)
   
   ### Code Quality
   
   - [x] My diff has been formatted using helix-style.xml

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@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

Posted by GitBox <gi...@apache.org>.
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={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<String, Object> responseMap;
-    Collection<String> 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={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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on issue #761: Add REST read endpoints to helix-rest for metadata store directory

Posted by GitBox <gi...@apache.org>.
pkuwm commented on issue #761: Add REST read endpoints to helix-rest for metadata store directory
URL: https://github.com/apache/helix/pull/761#issuecomment-590018614
 
 
   This PR is ready to be merged, approved by @narendly 
   
   ```
   We need restful metadata store directory service to help scale out zookeeper.
   
   This commit adds REST read endpoints to helix-rest to get sharding keys, realms and namespaces.
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
NealSun96 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_r380997605
 
 

 ##########
 File path: helix-rest/src/test/java/org/apache/helix/rest/server/resources/zookeeper/TestMetadataStoreDirectoryAccessor.java
 ##########
 @@ -110,7 +110,33 @@ public void beforeClass() throws Exception {
     _metadataStoreDirectory = new ZkMetadataStoreDirectory(routingZkAddrMap);
   }
 
+  /*
+   * Tests REST endpoint: "GET /namespaces/{namespace}/metadata-store-namespaces"
+   */
   @Test
+  public void testGetAllNamespaces() throws IOException {
+    String responseBody = get(TEST_NAMESPACE_URI_PREFIX + "/metadata-store-namespaces", null,
+        Response.Status.OK.getStatusCode(), true);
+
+    // It is safe to cast the object and suppress warnings.
+    @SuppressWarnings("unchecked")
+    Map<String, Collection<String>> queriedNamespacesMap =
+        OBJECT_MAPPER.readValue(responseBody, Map.class);
+
+    Assert.assertTrue(
+        queriedNamespacesMap.containsKey(MetadataStoreRoutingConstants.METADATA_STORE_NAMESPACES));
 
 Review comment:
   When verifying a map, I'd make sure that "it contains the right elements and **only** the right elements". Therefore I usually perform a check on map length - without it if the map returns something extra and unexpected, the test cases would still incorrectly pass. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r379218684
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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}"
 
 Review comment:
   could we also document the difference in behavior depending on whether the query param is given?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r382427413
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
 
 Review comment:
   Fair.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r381053697
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   > There is a good way to simplify the logic here utilizing the default values as @dasahcc has mentioned. If the prefix is not provided, consider assigning "/" to the prefix variable and use the same logic as the situation where prefix exists.
   
   @NealSun96 I don't think adding "/" to the prefix var is a better idea because:
   - The Json responses are different for each case here. If you assign "/" to a method, the response could have `{ "prefix": "/" }`
   - I've tried to find a good default value for this prefix. If I assign "/" as a default value, I've no idea how to differentiate if prefix is not provide or it is "/".
   - The code logic to generate response map is different.
   
   If I don't understand your idea, feel free to clarify it. Thanks for the tip.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@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

Posted by GitBox <gi...@apache.org>.
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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> 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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] narendly merged pull request #761: Add REST read endpoints to helix-rest for metadata store directory

Posted by GitBox <gi...@apache.org>.
narendly merged pull request #761: Add REST read endpoints to helix-rest for metadata store directory
URL: https://github.com/apache/helix/pull/761
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
NealSun96 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_r380992746
 
 

 ##########
 File path: helix-rest/src/main/java/org/apache/helix/rest/server/resources/metadatastore/MetadataStoreDirectoryAccessor.java
 ##########
 @@ -111,41 +135,74 @@ 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"
+   *  }]
+   * }
    *
-   * @param realm Query param in endpoint path
-   * @return Json representation of a map: shardingKeys -> collection of sharding keys.
+   * - "HTTP GET /sharding-keys?realm={realm}&prefix={prefix}" which returns sharding keys in the
+   * realm and that have the prefix.
+   *
+   * @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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
       }
     } catch (NoSuchElementException ex) {
       return notFound(ex.getMessage());
     }
+  }
 
-    responseMap.put(MetadataStoreRoutingConstants.SHARDING_KEYS, shardingKeys);
-
-    return JSONRepresentation(responseMap);
+  /**
+   * Gets all path-based sharding keys for a queried realm at endpoint:
+   * "GET /metadata-store-realms/{realm}/sharding-keys". This endpoint is equivalent to
+   * the endpoint: "GET /sharding-keys?realm={realm}".
+   *
+   * @param realm Queried metadata store realm to get sharding keys.
+   * @return All path-based sharding keys in the queried realm.
+   */
+  @GET
+  @Path("/metadata-store-realms/{realm}/sharding-keys")
+  public Response getRealmShardingKeys(@PathParam("realm") String realm) {
+    try {
+      return getAllShardingKeysInRealm(realm);
+    } catch (NoSuchElementException ex) {
+      return notFound(ex.getMessage());
 
 Review comment:
   Given my understanding to the status code, `badRequest` is more suitable than `notFound` in this situation. What `notFound` entails is that this url is not matched to anything, however in this situation, the url is correctly connecting to the endpoint. Returning `notFound` might cause confusion. 
   I understand that `badRequest` is not perfect in this case either, but it should be more suitable than `notFound`. If you have a better idea, I'm happy to discuss. (Ref: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r382427503
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
 
 Review comment:
   Okay. I'm fine with the current implementation.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r379281125
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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}"
 
 Review comment:
   I think the endpoint already tells the behavior. That's why we need to follow the REST API design principal.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r379228170
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> shardingKeys;
+  public Response getShardingKeys(@QueryParam("realm") String realm,
 
 Review comment:
   I have a feeling that this path resource is again doing too many things. Do you think we should consider breaking this up into different path resources?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r379219384
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
 
 Review comment:
   I've thought about this carefully. As it is necessary, I've defined a POJO class `MetadataStoreShardingKey` to represent the object mapping. The response will look like:
   ```
   {
   	"metadataStoreRealms": ["realm-0", "realm-1"]
   }
   ```
   or  single ream with sharding key:
   ```
   {
   	"shardingKey": "/a/b/c",
   	"realm": "realm-0"
   }
   ```
   I definitely agree that if the response of object is complex (has more fields), we would need POJO classes to represent the responses.
   For the time being, since the most of the responses are quite simple: a list, I don't think we want to make it complex .  I've tried to make all json responses to have key-value mappings.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r379218365
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
     try {
-      Collection<String> realms = _metadataStoreDirectory.getAllMetadataStoreRealms(_namespace);
-
-      responseMap = new HashMap<>(1);
-      responseMap.put(MetadataStoreRoutingConstants.METADATA_STORE_REALMS, realms);
+      if (shardingKey == null) {
+        Collection<String> realms = _metadataStoreDirectory.getAllMetadataStoreRealms(_namespace);
+        Map<String, Collection<String>> responseMap =
+            ImmutableMap.of(MetadataStoreRoutingConstants.METADATA_STORE_REALMS, realms);
+        return JSONRepresentation(responseMap);
+      } else {
 
 Review comment:
   Is this else needed?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r379218026
 
 

 ##########
 File path: helix-rest/src/main/java/org/apache/helix/rest/metadatastore/constant/MetadataStoreRoutingConstants.java
 ##########
 @@ -28,14 +28,21 @@
   // Leader election ZNode for ZkRoutingDataWriter
   public static final String LEADER_ELECTION_ZNODE = "/_ZK_ROUTING_DATA_WRITER_LEADER";
 
+  // Field name in JSON REST response of getting all metadata store namespaces.
+  public static final String METADATA_STORE_NAMESPACES = "namespaces";
+
   // Field name in JSON REST response of getting metadata store realms in one namespace.
   public static final String METADATA_STORE_REALMS = "metadataStoreRealms";
 
   // Field name in JSON REST response of getting sharding keys in one realm.
-  public static final String SINGLE_METADATA_STORE_REALM = "metadataStoreRealm";
+  public static final String SINGLE_METADATA_STORE_REALM = "realm";
 
   // Field name in JSON REST response of getting sharding keys.
   public static final String SHARDING_KEYS = "shardingKeys";
 
+  // Field name in JSON REST response related to one single sharding key.
+  public static final String SINGLE_SHARDING_KEY = "shardingKey";
 
+  // Field name in JSON REST response of getting sharding keys with prefix.
+  public static final String SHARDING_KEY_PREFIX = "prefix";
 
 Review comment:
   `SHARDING_KEY_PREFIX`'s naming got me thinking for a little bit and I couldn't figure it out. Could we rename this?
   
   I think something like `SHARDING_KEY_PATH_PREFIX` would be more descriptive. To also help with understanding, could we please add where it's going to be used? (like getAllMappingUnderPath() for example).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
NealSun96 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_r381456004
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   When the prefix parameter is not provided, it's treated as the caller doesn't care about the prefix - this method is doing "return all keys regardless of any prefix". This behavior is functionally the same as if the caller provides "/" as the prefix. I think it's reasonable to use "/" as a default value. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r381000691
 
 

 ##########
 File path: helix-rest/src/main/java/org/apache/helix/rest/server/resources/metadatastore/MetadataStoreDirectoryAccessor.java
 ##########
 @@ -111,41 +135,74 @@ 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"
+   *  }]
+   * }
    *
-   * @param realm Query param in endpoint path
-   * @return Json representation of a map: shardingKeys -> collection of sharding keys.
+   * - "HTTP GET /sharding-keys?realm={realm}&prefix={prefix}" which returns sharding keys in the
+   * realm and that have the prefix.
+   *
+   * @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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
       }
     } catch (NoSuchElementException ex) {
       return notFound(ex.getMessage());
     }
+  }
 
-    responseMap.put(MetadataStoreRoutingConstants.SHARDING_KEYS, shardingKeys);
-
-    return JSONRepresentation(responseMap);
+  /**
+   * Gets all path-based sharding keys for a queried realm at endpoint:
+   * "GET /metadata-store-realms/{realm}/sharding-keys". This endpoint is equivalent to
+   * the endpoint: "GET /sharding-keys?realm={realm}".
+   *
+   * @param realm Queried metadata store realm to get sharding keys.
+   * @return All path-based sharding keys in the queried realm.
+   */
+  @GET
+  @Path("/metadata-store-realms/{realm}/sharding-keys")
+  public Response getRealmShardingKeys(@PathParam("realm") String realm) {
+    try {
+      return getAllShardingKeysInRealm(realm);
+    } catch (NoSuchElementException ex) {
+      return notFound(ex.getMessage());
 
 Review comment:
   @NealSun96 Thanks for reviewing.
   As you referred in the link, `400 Bad Request`: The request could not be understood by the server due to **malformed syntax**. If you request a POST/PUT with json payload which has syntax error, I believe `Bad Request` is more suitable.
   `404 Not Found` means the endpoint is correct but resource is not found in server, which matches exactly our case here `NoSuchElementException`.  (refs as an examples: 
   - https://stackoverflow.com/questions/26968479/404-not-found-or-bad-request;
   - https://stackoverflow.com/questions/19671317/400-bad-request-http-error-code-meaning)
   
   What do you think?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
NealSun96 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_r381625533
 
 

 ##########
 File path: helix-rest/src/main/java/org/apache/helix/rest/server/resources/metadatastore/MetadataStoreDirectoryAccessor.java
 ##########
 @@ -111,41 +135,74 @@ 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"
+   *  }]
+   * }
    *
-   * @param realm Query param in endpoint path
-   * @return Json representation of a map: shardingKeys -> collection of sharding keys.
+   * - "HTTP GET /sharding-keys?realm={realm}&prefix={prefix}" which returns sharding keys in the
+   * realm and that have the prefix.
+   *
+   * @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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
       }
     } catch (NoSuchElementException ex) {
       return notFound(ex.getMessage());
     }
+  }
 
-    responseMap.put(MetadataStoreRoutingConstants.SHARDING_KEYS, shardingKeys);
-
-    return JSONRepresentation(responseMap);
+  /**
+   * Gets all path-based sharding keys for a queried realm at endpoint:
+   * "GET /metadata-store-realms/{realm}/sharding-keys". This endpoint is equivalent to
+   * the endpoint: "GET /sharding-keys?realm={realm}".
+   *
+   * @param realm Queried metadata store realm to get sharding keys.
+   * @return All path-based sharding keys in the queried realm.
+   */
+  @GET
+  @Path("/metadata-store-realms/{realm}/sharding-keys")
+  public Response getRealmShardingKeys(@PathParam("realm") String realm) {
+    try {
+      return getAllShardingKeysInRealm(realm);
+    } catch (NoSuchElementException ex) {
+      return notFound(ex.getMessage());
 
 Review comment:
   `404` does not mean the endpoint is correct. If I enter an end point "/metadata-store-realms/test-realm/sharding-keys" and I receive a `404` in return, my first reaction would be to change "sharding-keys" to "sharding-key", then "shardingkeys". 
   On a second thought, `404` with appropriate message does work better than `400`. `400` is not very fitting. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
NealSun96 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_r380994410
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   There is a good way to simplify the logic here utilizing the default values as @dasahcc has mentioned. If the prefix is not provided, consider assigning "/" to the prefix variable and use the same logic as the situation where prefix exists. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r381044344
 
 

 ##########
 File path: helix-rest/src/test/java/org/apache/helix/rest/server/resources/zookeeper/TestMetadataStoreDirectoryAccessor.java
 ##########
 @@ -110,7 +110,33 @@ public void beforeClass() throws Exception {
     _metadataStoreDirectory = new ZkMetadataStoreDirectory(routingZkAddrMap);
   }
 
+  /*
+   * Tests REST endpoint: "GET /namespaces/{namespace}/metadata-store-namespaces"
+   */
   @Test
+  public void testGetAllNamespaces() throws IOException {
+    String responseBody = get(TEST_NAMESPACE_URI_PREFIX + "/metadata-store-namespaces", null,
+        Response.Status.OK.getStatusCode(), true);
+
+    // It is safe to cast the object and suppress warnings.
+    @SuppressWarnings("unchecked")
+    Map<String, Collection<String>> queriedNamespacesMap =
+        OBJECT_MAPPER.readValue(responseBody, Map.class);
+
+    Assert.assertTrue(
+        queriedNamespacesMap.containsKey(MetadataStoreRoutingConstants.METADATA_STORE_NAMESPACES));
 
 Review comment:
   Sure. I was checking the response has this field. It is definitely more accurate to check that the response has only expected fields.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r382859467
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   public static final String ROUTING_DATA_PATH = "/METADATA_STORE_ROUTING_DATA";
   
   This should be the default value.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r379216863
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   I've tried to make it as simple as possible. We have 3 different JAVA methods in MetadataDirectory which accept different params. https://github.com/apache/helix/blob/551ed63f98cf75b9953615386a0a9e1a9a566e33/helix-rest/src/main/java/org/apache/helix/rest/metadatastore/MetadataStoreDirectory.java#L52-L70
   
   So even we set default values to the query params, we still have to check the values and call the according method.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r382763795
 
 

 ##########
 File path: helix-rest/src/main/java/org/apache/helix/rest/server/resources/metadatastore/MetadataStoreDirectoryAccessor.java
 ##########
 @@ -111,41 +135,74 @@ 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"
+   *  }]
+   * }
    *
-   * @param realm Query param in endpoint path
-   * @return Json representation of a map: shardingKeys -> collection of sharding keys.
+   * - "HTTP GET /sharding-keys?realm={realm}&prefix={prefix}" which returns sharding keys in the
+   * realm and that have the prefix.
+   *
+   * @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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
       }
     } catch (NoSuchElementException ex) {
       return notFound(ex.getMessage());
     }
+  }
 
-    responseMap.put(MetadataStoreRoutingConstants.SHARDING_KEYS, shardingKeys);
-
-    return JSONRepresentation(responseMap);
+  /**
+   * Gets all path-based sharding keys for a queried realm at endpoint:
+   * "GET /metadata-store-realms/{realm}/sharding-keys". This endpoint is equivalent to
+   * the endpoint: "GET /sharding-keys?realm={realm}".
+   *
+   * @param realm Queried metadata store realm to get sharding keys.
+   * @return All path-based sharding keys in the queried realm.
+   */
+  @GET
+  @Path("/metadata-store-realms/{realm}/sharding-keys")
+  public Response getRealmShardingKeys(@PathParam("realm") String realm) {
+    try {
+      return getAllShardingKeysInRealm(realm);
+    } catch (NoSuchElementException ex) {
+      return notFound(ex.getMessage());
 
 Review comment:
   In your example, the **endpoint** is `/metadata-store-realms/{realm}/sharding-keys` is already correct. But the resource `test-realm` does not exist, and 404 is a **correct** response code. If endpoint is incorrect, you would not get 404 but 400 (bad URI) instead.
   So if you get 404, the first reaction is definitely checking the requested resource, not changing the endpoint.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r379283232
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
 
 Review comment:
   My explanation above. It is OK to have if-else because we accept query params. A better way to process query param is like we construct a query for DB:
   ```
   query += param1,
   query += param2
   ```
   But we don't have a query layer here so if-else acts as this query layer.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r379223922
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
 
 Review comment:
   Since this path resource seems to be doing two things, should we rename this to `getMetadataStoreRealm()`?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r379284824
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> shardingKeys;
+  public Response getShardingKeys(@QueryParam("realm") String realm,
 
 Review comment:
   A new endpoint which is equivalent to GET /sharding-keys?realm={realm} is added: GET /metadata-store-realms/{realm}/sharding-keys
   
   In my opinion, these 2 filters are valid for this resource. If remove one query param, this method would only have 1 query param `prefix` and 1 if-else: all sharding keys or sharding keys with prefix. 
   But again, I would like to offer this query param option as they are valid, and it is also implemented now.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r379283598
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   A new endpoint which is equivalent to `GET /sharding-keys?realm={realm}`  is added: `GET /metadata-store-realms/{realm}/sharding-keys`

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@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

Posted by GitBox <gi...@apache.org>.
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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
     try {
-      Collection<String> realms = _metadataStoreDirectory.getAllMetadataStoreRealms(_namespace);
-
-      responseMap = new HashMap<>(1);
-      responseMap.put(MetadataStoreRoutingConstants.METADATA_STORE_REALMS, realms);
+      if (shardingKey == null) {
+        Collection<String> realms = _metadataStoreDirectory.getAllMetadataStoreRealms(_namespace);
+        Map<String, Collection<String>> 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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
narendly 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_r379227909
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
 
 Review comment:
   Or better yet, should we consider breaking this up into two different path resources to eliminate if-elses?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r379282521
 
 

 ##########
 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<String> namespaces = _metadataStoreDirectory.getAllNamespaces();
+    Map<String, Collection<String>> 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<String, Collection<String>> responseMap;
+  public Response getAllMetadataStoreRealms(@QueryParam("sharding-key") String shardingKey) {
 
 Review comment:
   `?sharding-key=` is a query param to filter the result. In this case, a single object being returned is acceptable.
   It is like
   `/employees` returns all employees
   `/employees?name=david` could returns a single employee (assume name is unique).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


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

Posted by GitBox <gi...@apache.org>.
pkuwm 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_r381862514
 
 

 ##########
 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={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<String, Object> responseMap;
-    Collection<String> 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={prefix}"
+        return getRealmShardingKeysUnderPath(realm, prefix);
 
 Review comment:
   I understand the specific case “/“ in  getAllShardingKeysUnderPath could return the same result of getAllShardingKeys. But what if getAllShardingKeysUnderPath changes and returns different result?
   
   - The Json responses are different for each case here. If you assign "/" to a method, the response could have { "prefix": "/" }
   - I would like to decouple two cases that having prefix (getAllShardingKeysUnderPath ) and no prefix.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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