You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by hz...@apache.org on 2020/10/02 22:36:56 UTC
[helix] branch master updated: Add getResourceCustomized View REST
API (#1430)
This is an automated email from the ASF dual-hosted git repository.
hzlu 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 215789c Add getResourceCustomized View REST API (#1430)
215789c is described below
commit 215789c08625ff67f7ee7379e4bdb83f52678863
Author: Meng Zhang <mn...@linkedin.com>
AuthorDate: Fri Oct 2 15:36:48 2020 -0700
Add getResourceCustomized View REST API (#1430)
Add getResourceCustomized View REST API
---
.../src/main/java/org/apache/helix/HelixAdmin.java | 3 ++-
.../java/org/apache/helix/manager/zk/ZKHelixAdmin.java | 5 +++--
.../org/apache/helix/manager/zk/TestZkHelixAdmin.java | 3 ++-
.../java/org/apache/helix/mock/MockHelixAdmin.java | 2 +-
.../rest/server/resources/helix/ResourceAccessor.java | 18 ++++++++++++++++++
.../apache/helix/rest/server/TestResourceAccessor.java | 18 ++++++++++++++++++
6 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/helix-core/src/main/java/org/apache/helix/HelixAdmin.java b/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
index 01e7507..3618b12 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixAdmin.java
@@ -458,7 +458,8 @@ public interface HelixAdmin {
* @param resourceName
* @return customized for the resource
*/
- CustomizedView getResourceCustomizedView(String clusterName, String resourceName);
+ CustomizedView getResourceCustomizedView(String clusterName, String resourceName,
+ String customizedStateType);
/**
* Drop a cluster
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
index 38f4220..8129b6c 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
@@ -1087,11 +1087,12 @@ public class ZKHelixAdmin implements HelixAdmin {
}
@Override
- public CustomizedView getResourceCustomizedView(String clusterName, String resourceName) {
+ public CustomizedView getResourceCustomizedView(String clusterName, String resourceName,
+ String customizedStateType) {
HelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
- return accessor.getProperty(keyBuilder.customizedView(resourceName));
+ return accessor.getProperty(keyBuilder.customizedView(customizedStateType, resourceName));
}
@Override
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
index d1a003e..6585439 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
@@ -299,7 +299,8 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
ExternalView resourceExternalView = tool.getResourceExternalView(clusterName, "resource");
AssertJUnit.assertNull(resourceExternalView);
- CustomizedView resourceCustomizedView = tool.getResourceCustomizedView(clusterName, "resource");
+ CustomizedView resourceCustomizedView = tool.getResourceCustomizedView(clusterName,"resource"
+ , "customizedStateType");
AssertJUnit.assertNull(resourceCustomizedView);
// test config support
diff --git a/helix-core/src/test/java/org/apache/helix/mock/MockHelixAdmin.java b/helix-core/src/test/java/org/apache/helix/mock/MockHelixAdmin.java
index aa9f0ce..44cdb0a 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/MockHelixAdmin.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/MockHelixAdmin.java
@@ -375,7 +375,7 @@ public class MockHelixAdmin implements HelixAdmin {
}
@Override public CustomizedView getResourceCustomizedView(String clusterName,
- String resourceName) {
+ String resourceName, String customizedStateType) {
return null;
}
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
index bca0d3b..56c621a 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
@@ -47,6 +47,7 @@ import org.apache.helix.ConfigAccessor;
import org.apache.helix.HelixAdmin;
import org.apache.helix.HelixException;
import org.apache.helix.PropertyPathBuilder;
+import org.apache.helix.model.CustomizedView;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.HelixConfigScope;
import org.apache.helix.model.IdealState;
@@ -527,6 +528,23 @@ public class ResourceAccessor extends AbstractHelixResource {
return notFound();
}
+ @ResponseMetered(name = HttpConstants.READ_REQUEST)
+ @Timed(name = HttpConstants.READ_REQUEST)
+ @GET
+ @Path("{resourceName}/{customizedStateType}/customizedView")
+ public Response getResourceCustomizedView(@PathParam("clusterId") String clusterId,
+ @PathParam("resourceName") String resourceName,
+ @PathParam("customizedStateType") String customizedStateType) {
+ HelixAdmin admin = getHelixAdmin();
+ CustomizedView customizedView =
+ admin.getResourceCustomizedView(clusterId, resourceName, customizedStateType);
+ if (customizedView != null) {
+ return JSONRepresentation(customizedView.getRecord());
+ }
+
+ return notFound();
+ }
+
private Map<String, String> computePartitionHealth(String clusterId, String resourceName) {
HelixAdmin admin = getHelixAdmin();
IdealState idealState = admin.getResourceIdealState(clusterId, resourceName);
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java
index e2e81a2..d194ccb 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java
@@ -44,6 +44,7 @@ import org.apache.helix.PropertyPathBuilder;
import org.apache.helix.TestHelper;
import org.apache.helix.controller.rebalancer.waged.WagedRebalancer;
import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.CustomizedView;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.InstanceConfig;
@@ -58,6 +59,7 @@ public class TestResourceAccessor extends AbstractTestClass {
private final static String CLUSTER_NAME = "TestCluster_0";
private final static String RESOURCE_NAME = CLUSTER_NAME + "_db_0";
private final static String ANY_INSTANCE = "ANY_LIVEINSTANCE";
+ private final static String CUSTOMIZED_STATE_TYPE = "Customized_state_type_0";
@Test
public void testGetResources() throws IOException {
@@ -163,6 +165,22 @@ public class TestResourceAccessor extends AbstractTestClass {
}
@Test(dependsOnMethods = "testExternalView")
+ public void testCustomizedView() throws IOException {
+ System.out.println("Start test :" + TestHelper.getTestMethodName());
+ ZNRecord znRecord = new ZNRecord("test_customizedView");
+ _baseAccessor
+ .set(PropertyPathBuilder.customizedView(CLUSTER_NAME, CUSTOMIZED_STATE_TYPE, RESOURCE_NAME),
+ znRecord, 1);
+ String body =
+ get("clusters/" + CLUSTER_NAME + "/resources/" + RESOURCE_NAME + "/" + CUSTOMIZED_STATE_TYPE
+ + "/customizedView", null, Response.Status.OK.getStatusCode(), true);
+ CustomizedView customizedView = new CustomizedView(toZNRecord(body));
+ Assert.assertEquals(customizedView, _gSetupTool.getClusterManagementTool()
+ .getResourceCustomizedView(CLUSTER_NAME, RESOURCE_NAME, CUSTOMIZED_STATE_TYPE));
+ System.out.println("End test :" + TestHelper.getTestMethodName());
+ }
+
+ @Test(dependsOnMethods = "testExternalView")
public void testPartitionHealth() throws Exception {
System.out.println("Start test :" + TestHelper.getTestMethodName());