This is an automated email from the ASF dual-hosted git repository.
jxue pushed a commit to branch ApplicationClusterManager
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/ApplicationClusterManager by
this push:
new 0237ef29d Add on-demand rebalance API (#2601)
0237ef29d is described below
commit 0237ef29dce35e1aa957e311873ec3608eaddf96
Author: Xiaxuan Gao <[email protected]>
AuthorDate: Fri Aug 25 15:41:27 2023 -0700
Add on-demand rebalance API (#2601)
Add on-demand rebalance API
---
.../rest/server/resources/AbstractResource.java | 3 ++-
.../rest/server/resources/helix/ClusterAccessor.java | 9 +++++++++
.../helix/rest/server/TestClusterAccessor.java | 20 ++++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git
a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
index 76733b92a..48b467eaa 100644
---
a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
+++
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
@@ -85,7 +85,8 @@ public class AbstractResource {
purgeOfflineParticipants,
getInstance,
getAllInstances,
- setInstanceOperation // TODO: Name is just a place holder, may change in
future
+ setInstanceOperation, // TODO: Name is just a place holder, may change in
future
+ onDemandRebalance
}
@Context
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 68744cbbe..809d736a0 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
@@ -347,6 +347,15 @@ public class ClusterAccessor extends AbstractHelixResource
{
helixAdmin.purgeOfflineInstances(clusterId, duration);
}
break;
+ case onDemandRebalance:
+ try {
+ helixAdmin.onDemandRebalance(clusterId);
+ } catch (Exception ex) {
+ LOG.error(
+ "Cannot start on-demand rebalance for cluster: {}, Exception:
{}", clusterId, ex);
+ return serverError(ex);
+ }
+ break;
default:
return badRequest("Unsupported command {}." + command);
}
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 86c9d5ae3..e1ed254c8 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
@@ -1414,6 +1414,26 @@ public class TestClusterAccessor extends
AbstractTestClass {
System.out.println("End test :" + TestHelper.getTestMethodName());
}
+ @Test(dependsOnMethods = "testUpdateCustomizedConfig")
+ public void testOnDemandRebalance() throws IOException {
+ System.out.println("Start test :" + TestHelper.getTestMethodName());
+ long currentTime = System.currentTimeMillis();
+ String cluster = "TestCluster_1";
+ new
JerseyUriRequestBuilder("clusters/{}?command=onDemandRebalance").format(cluster)
+ .post(this, Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE));
+
+ ClusterConfig config = _configAccessor.getClusterConfig(cluster);
+ long lastOnDemandRebalanceTime =
config.getLastOnDemandRebalanceTimestamp();
+ Assert.assertFalse(lastOnDemandRebalanceTime == -1L,
+ "The last on-demand rebalance timestamp is not found.");
+ Assert.assertTrue(lastOnDemandRebalanceTime > currentTime, String.format(
+ "The last on-demand rebalance timestamp {} is stale. Expect a
timestamp that is larger than {}.",
+ lastOnDemandRebalanceTime, currentTime));
+ // restore the state
+ config.setLastOnDemandRebalanceTimestamp(-1L);
+ System.out.println("End test :" + TestHelper.getTestMethodName());
+ }
+
@Test
public void testClusterFreezeMode() throws Exception {
String cluster = "TestCluster_0";