This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new bf85e79  [helix-rest] Delete unused default namespace (api 
"/namespaces/default") (#449)
bf85e79 is described below

commit bf85e797acd749d4310d75b00c4bafe677acdbea
Author: pkuwm <[email protected]>
AuthorDate: Tue Sep 17 14:33:37 2019 -0700

    [helix-rest] Delete unused default namespace (api "/namespaces/default") 
(#449)
    
    We have a namespace api: /admin/v2/namespaces/{namespace}/. However, the 
/namespaces/default path is not in use. We need to delete it. On the code level,
    if there is not a default namespace, we won't create a DEFAULT_SERVLET.
    On the app level, we can configure app not to add name "default" namespace.
    With this change, endpoint /admin/v2/namespaces/ will be disable if no 
namespace
    sets IS_DEFAULT to true.
---
 .../apache/helix/rest/server/HelixRestServer.java  |  9 ++--
 .../helix/rest/server/TestHelixRestServer.java     |  2 +-
 .../helix/rest/server/TestNamespacedAPIAccess.java | 50 ++++++++--------------
 3 files changed, 25 insertions(+), 36 deletions(-)

diff --git 
a/helix-rest/src/main/java/org/apache/helix/rest/server/HelixRestServer.java 
b/helix-rest/src/main/java/org/apache/helix/rest/server/HelixRestServer.java
index af49395..c25fbc5 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/HelixRestServer.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/HelixRestServer.java
@@ -94,14 +94,17 @@ public class HelixRestServer {
     _servletContextHandler = new ServletContextHandler(_server, _urlPrefix);
     _helixNamespaces = namespaces;
 
-    // Initialize all namespaces
+    // Initialize all namespaces.
+    // If there is not a default namespace (namespace.isDefault() is false),
+    // endpoint "/namespaces" will be disabled.
     try {
       for (HelixRestNamespace namespace : _helixNamespaces) {
-        LOG.info("Initializing namespace " + namespace.getName());
-        prepareServlet(namespace, ServletType.COMMON_SERVLET);
         if (namespace.isDefault()) {
           LOG.info("Creating default servlet for default namespace");
           prepareServlet(namespace, ServletType.DEFAULT_SERVLET);
+        } else {
+          LOG.info("Creating common servlet for namespace {}", 
namespace.getName());
+          prepareServlet(namespace, ServletType.COMMON_SERVLET);
         }
       }
     } catch (Exception e) {
diff --git 
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestHelixRestServer.java
 
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestHelixRestServer.java
index 4d2239d..ce7c1a6 100644
--- 
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestHelixRestServer.java
+++ 
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestHelixRestServer.java
@@ -59,7 +59,7 @@ public class TestHelixRestServer extends AbstractTestClass {
     try {
       List<HelixRestNamespace> invalidManifest3 = new ArrayList<>();
       invalidManifest3.add(
-          new HelixRestNamespace("DuplicatedName", 
HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR, true));
+          new HelixRestNamespace("DuplicatedName", 
HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR, false));
       invalidManifest3.add(
           new HelixRestNamespace("DuplicatedName", 
HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR,
               false));
diff --git 
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestNamespacedAPIAccess.java
 
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestNamespacedAPIAccess.java
index ccc0d4f..e38279f 100644
--- 
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestNamespacedAPIAccess.java
+++ 
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestNamespacedAPIAccess.java
@@ -42,28 +42,23 @@ public class TestNamespacedAPIAccess extends 
AbstractTestClass {
   ObjectMapper _mapper = new ObjectMapper();
 
   @Test
-  public void testDefaultNamespaceCompatibility() {
-    String testClusterName1 = "testClusterForDefaultNamespaceCompatibility1";
-    String testClusterName2 = "testClusterForDefaultNamespaceCompatibility2";
+  public void testDefaultNamespaceDisabled() {
+    String testClusterName = "testDefaultNamespaceDisabled";
 
-    // Create from namespaced API and ensure we can access it from old apis, 
and vice-versa
-    // Assume other api end points will behave the same way
-    put(String.format("/namespaces/%s/clusters/%s", 
HelixRestNamespace.DEFAULT_NAMESPACE_NAME, testClusterName1), null,
-        Entity.entity("", MediaType.APPLICATION_JSON_TYPE), 
Response.Status.CREATED.getStatusCode());
-    get(String.format("/clusters/%s", testClusterName1), null, 
Response.Status.OK.getStatusCode(), false);
+    // "/namespaces/default" is disabled.
+    get(String.format("/namespaces/%s", 
HelixRestNamespace.DEFAULT_NAMESPACE_NAME), null, 
Response.Status.NOT_FOUND.getStatusCode(), false);
 
-    put(String.format("/clusters/%s", testClusterName2), null, 
Entity.entity("", MediaType.APPLICATION_JSON_TYPE),
+    // Create a cluster.
+    put(String.format("/clusters/%s", testClusterName), null, 
Entity.entity("", MediaType.APPLICATION_JSON_TYPE),
         Response.Status.CREATED.getStatusCode());
-    get(String.format("/namespaces/%s/clusters/%s", 
HelixRestNamespace.DEFAULT_NAMESPACE_NAME, testClusterName2), null,
-        Response.Status.OK.getStatusCode(), false);
-    // Remove empty test clusters. Otherwise, it could fail ClusterAccessor 
tests
-    delete(String.format("/clusters/%s", testClusterName1), 
Response.Status.OK.getStatusCode());
-    delete(String.format("/clusters/%s", testClusterName2), 
Response.Status.OK.getStatusCode());
-    System.out.println("End test :" + TestHelper.getTestMethodName());
-  }
 
+    get(String.format("/clusters/%s", testClusterName), null, 
Response.Status.OK.getStatusCode(), false);
+
+    // Remove empty test cluster. Otherwise, it could fail ClusterAccessor 
tests
+    delete(String.format("/clusters/%s", testClusterName), 
Response.Status.OK.getStatusCode());
+  }
 
-  @Test(dependsOnMethods = "testDefaultNamespaceCompatibility")
+  @Test(dependsOnMethods = "testDefaultNamespaceDisabled")
   public void testNamespacedCRUD() throws IOException {
     String testClusterName = "testClusterForNamespacedCRUD";
 
@@ -74,9 +69,9 @@ public class TestNamespacedAPIAccess extends 
AbstractTestClass {
         Response.Status.OK.getStatusCode(), false);
     get(String.format("/clusters/%s", testClusterName), null, 
Response.Status.NOT_FOUND.getStatusCode(), false);
 
-    // Create cluster with same name in different namespacces
-    put(String.format("/clusters/%s", testClusterName), null, 
Entity.entity("", MediaType.APPLICATION_JSON_TYPE),
-        Response.Status.CREATED.getStatusCode());
+    // Create a cluster with same name in a different namespace
+    put(String.format("/clusters/%s", testClusterName), null,
+        Entity.entity("", MediaType.APPLICATION_JSON_TYPE), 
Response.Status.CREATED.getStatusCode());
     get(String.format("/clusters/%s", testClusterName), null, 
Response.Status.OK.getStatusCode(), false);
 
     // Modify cluster in default namespace
@@ -96,7 +91,6 @@ public class TestNamespacedAPIAccess extends 
AbstractTestClass {
     get(String.format("/clusters/%s", testClusterName), null, 
Response.Status.OK.getStatusCode(), false);
     // Remove empty test clusters. Otherwise, it could fail ClusterAccessor 
tests
     delete(String.format("/clusters/%s", testClusterName), 
Response.Status.OK.getStatusCode());
-    System.out.println("End test :" + TestHelper.getTestMethodName());
   }
 
   @Test(dependsOnMethods = "testNamespacedCRUD")
@@ -136,16 +130,8 @@ public class TestNamespacedAPIAccess extends 
AbstractTestClass {
     }
     Assert.assertTrue(expectedNamespaceNames.isEmpty());
 
-    // Accessing root of namespaced API endpoint shall return information of 
that namespace
-    body = get(String.format("/namespaces/%s", 
HelixRestNamespace.DEFAULT_NAMESPACE_NAME), null,
-        Response.Status.OK.getStatusCode(), true);
-    Map<String, String> namespace = _mapper.readValue(body,
-        _mapper.getTypeFactory().constructMapType(Map.class, String.class, 
String.class));
-    
Assert.assertEquals(namespace.get(HelixRestNamespace.HelixRestNamespaceProperty.NAME.name()),
-        HelixRestNamespace.DEFAULT_NAMESPACE_NAME);
-    Assert.assertTrue(Boolean.parseBoolean(
-        
namespace.get(HelixRestNamespace.HelixRestNamespaceProperty.IS_DEFAULT.name())));
-    System.out.println("End test :" + TestHelper.getTestMethodName());
+    // "/namespaces/default" is disabled.
+    get(String.format("/namespaces/%s", 
HelixRestNamespace.DEFAULT_NAMESPACE_NAME), null,
+        Response.Status.NOT_FOUND.getStatusCode(), false);
   }
-
 }

Reply via email to