This is an automated email from the ASF dual-hosted git repository. jiajunwang pushed a commit to branch helix-0.9.x in repository https://gitbox.apache.org/repos/asf/helix.git
commit 03763dc10049ff17d7199ed43871cc24e220f3b2 Author: Ali Reza Zamani Zadeh Najari <[email protected]> AuthorDate: Fri Mar 13 13:18:07 2020 -0700 Change the REST call for delete CloudConfig (#882) Change the delete CloudConfig Use DELETE instead of POST for deletion of the CloudConfig in REST. --- .../server/resources/helix/ClusterAccessor.java | 12 ++++++--- .../helix/rest/server/TestClusterAccessor.java | 31 +++++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java index f3175e4..4f5bb20 100644 --- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java +++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java @@ -586,6 +586,14 @@ public class ClusterAccessor extends AbstractHelixResource { return notFound(); } + @DELETE + @Path("{clusterId}/cloudconfig") + public Response deleteCloudConfig(@PathParam("clusterId") String clusterId) { + HelixAdmin admin = getHelixAdmin(); + admin.removeCloudConfig(clusterId); + return OK(); + } + @POST @Path("{clusterId}/cloudconfig") public Response updateCloudConfig(@PathParam("clusterId") String clusterId, @@ -619,10 +627,6 @@ public class ClusterAccessor extends AbstractHelixResource { } try { switch (command) { - case delete: { - admin.removeCloudConfig(clusterId); - } - break; case update: { try { CloudConfig cloudConfig = new CloudConfig.Builder(record).build(); diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java index 8102db7..5bb29ce 100644 --- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java +++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java @@ -793,19 +793,32 @@ public class TestClusterAccessor extends AbstractTestClass { @Test(dependsOnMethods = "testAddCloudConfig") public void testDeleteCloudConfig() throws IOException { System.out.println("Start test :" + TestHelper.getTestMethodName()); - _gSetupTool.addCluster("TestCloud", true); - String urlBase = "clusters/TestCloud/cloudconfig/"; + String className = TestHelper.getTestClassName(); + String methodName = TestHelper.getTestMethodName(); + String clusterName = className + "_" + methodName; + + ZNRecord record = new ZNRecord("testZnode"); + record.setBooleanField(CloudConfig.CloudConfigProperty.CLOUD_ENABLED.name(), true); + record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_ID.name(), "TestCloudID"); + record.setSimpleField(CloudConfig.CloudConfigProperty.CLOUD_PROVIDER.name(), + CloudProvider.AZURE.name()); - Map<String, String> map1 = new HashMap<>(); - map1.put("command", AbstractResource.Command.delete.name()); + Map<String, String> map = new HashMap<>(); + map.put("addCloudConfig", "true"); + put("clusters/" + clusterName, map, + Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), + Response.Status.CREATED.getStatusCode()); + // Read CloudConfig from Zookeeper and make sure it has been created + ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); + CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName); + Assert.assertNotNull(cloudConfigFromZk); + String urlBase = "clusters/" + clusterName + "/cloudconfig/"; - ZNRecord record = new ZNRecord("TestCloud"); - post(urlBase, map1, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), - Response.Status.OK.getStatusCode()); + delete(urlBase, Response.Status.OK.getStatusCode()); // Read CloudConfig from Zookeeper and make sure it has been removed - ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); - CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig("TestCloud"); + _configAccessor = new ConfigAccessor(ZK_ADDR); + cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName); Assert.assertNull(cloudConfigFromZk); System.out.println("End test :" + TestHelper.getTestMethodName());
