This is an automated email from the ASF dual-hosted git repository.
xyuanlu 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 a9e678f8d Fix for parallel instances stoppable API incorrectly
reordering the zoneList when a user provides their own zone_order.(#2566)
a9e678f8d is described below
commit a9e678f8da04ad7c28171139bc1bd64e8e221ff8
Author: Zachary Pinto <[email protected]>
AuthorDate: Thu Jul 20 14:11:27 2023 -0700
Fix for parallel instances stoppable API incorrectly reordering the
zoneList when a user provides their own zone_order.(#2566)
---
.../server/resources/helix/InstancesAccessor.java | 4 ++-
.../helix/rest/server/TestInstancesAccessor.java | 41 ++++++++++++++++++----
2 files changed, 37 insertions(+), 8 deletions(-)
diff --git
a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstancesAccessor.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstancesAccessor.java
index 22e03145b..d4f8f90af 100644
---
a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstancesAccessor.java
+++
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstancesAccessor.java
@@ -298,10 +298,12 @@ public class InstancesAccessor extends
AbstractHelixResource {
private List<String> getZoneBasedInstances(List<String> instances,
List<String> orderedZones,
Map<String, Set<String>> zoneMapping) {
+ // If the orderedZones is not specified, we will order all zones in
alphabetical order.
if (orderedZones == null) {
orderedZones = new ArrayList<>(zoneMapping.keySet());
+ Collections.sort(orderedZones);
}
- Collections.sort(orderedZones);
+
if (orderedZones.isEmpty()) {
return orderedZones;
}
diff --git
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstancesAccessor.java
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstancesAccessor.java
index f0a97bbae..fa059ad30 100644
---
a/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstancesAccessor.java
+++
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstancesAccessor.java
@@ -46,6 +46,34 @@ public class TestInstancesAccessor extends AbstractTestClass
{
private final static String CLUSTER_NAME = "TestCluster_0";
@Test
+ public void testInstanceStoppable_zoneBased_zoneOrder() throws IOException {
+ System.out.println("Start test :" + TestHelper.getTestMethodName());
+ // Select instances with zone based
+ String content = String.format(
+ "{\"%s\":\"%s\",\"%s\":[\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",
\"%s\"], \"%s\":[\"%s\",\"%s\"]}",
+ InstancesAccessor.InstancesProperties.selection_base.name(),
+ InstancesAccessor.InstanceHealthSelectionBase.zone_based.name(),
+ InstancesAccessor.InstancesProperties.instances.name(), "instance0",
"instance1",
+ "instance2", "instance3", "instance4", "instance5", "invalidInstance",
+ InstancesAccessor.InstancesProperties.zone_order.name(), "zone2",
"zone1");
+ Response response =
+ new
JerseyUriRequestBuilder("clusters/{}/instances?command=stoppable").format(
+ STOPPABLE_CLUSTER).post(this, Entity.entity(content,
MediaType.APPLICATION_JSON_TYPE));
+ JsonNode jsonNode =
OBJECT_MAPPER.readTree(response.readEntity(String.class));
+ Assert.assertFalse(
+
jsonNode.withArray(InstancesAccessor.InstancesProperties.instance_stoppable_parallel.name())
+ .elements().hasNext());
+ JsonNode nonStoppableInstances = jsonNode.get(
+
InstancesAccessor.InstancesProperties.instance_not_stoppable_with_reasons.name());
+ Assert.assertEquals(getStringSet(nonStoppableInstances, "instance5"),
+ ImmutableSet.of("HELIX:EMPTY_RESOURCE_ASSIGNMENT",
"HELIX:INSTANCE_NOT_ALIVE",
+ "HELIX:INSTANCE_NOT_STABLE"));
+ Assert.assertEquals(getStringSet(nonStoppableInstances, "invalidInstance"),
+ ImmutableSet.of("HELIX:INSTANCE_NOT_EXIST"));
+ System.out.println("End test :" + TestHelper.getTestMethodName());
+ }
+
+ @Test(dependsOnMethods = "testInstanceStoppable_zoneBased_zoneOrder")
public void testInstancesStoppable_zoneBased() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
// Select instances with zone based
@@ -55,15 +83,15 @@ public class TestInstancesAccessor extends
AbstractTestClass {
InstancesAccessor.InstanceHealthSelectionBase.zone_based.name(),
InstancesAccessor.InstancesProperties.instances.name(),
"instance0", "instance1",
"instance2", "instance3", "instance4", "instance5",
"invalidInstance");
- Response response = new
JerseyUriRequestBuilder("clusters/{}/instances?command=stoppable")
- .format(STOPPABLE_CLUSTER)
- .post(this, Entity.entity(content, MediaType.APPLICATION_JSON_TYPE));
+ Response response =
+ new
JerseyUriRequestBuilder("clusters/{}/instances?command=stoppable").format(
+ STOPPABLE_CLUSTER).post(this, Entity.entity(content,
MediaType.APPLICATION_JSON_TYPE));
JsonNode jsonNode =
OBJECT_MAPPER.readTree(response.readEntity(String.class));
Assert.assertFalse(
jsonNode.withArray(InstancesAccessor.InstancesProperties.instance_stoppable_parallel.name())
.elements().hasNext());
- JsonNode nonStoppableInstances = jsonNode
-
.get(InstancesAccessor.InstancesProperties.instance_not_stoppable_with_reasons.name());
+ JsonNode nonStoppableInstances = jsonNode.get(
+
InstancesAccessor.InstancesProperties.instance_not_stoppable_with_reasons.name());
Assert.assertEquals(getStringSet(nonStoppableInstances, "instance0"),
ImmutableSet.of("HELIX:MIN_ACTIVE_REPLICA_CHECK_FAILED"));
Assert.assertEquals(getStringSet(nonStoppableInstances, "instance1"),
@@ -76,8 +104,7 @@ public class TestInstancesAccessor extends AbstractTestClass
{
Assert.assertEquals(getStringSet(nonStoppableInstances, "instance4"),
ImmutableSet.of("HELIX:EMPTY_RESOURCE_ASSIGNMENT",
"HELIX:INSTANCE_NOT_ALIVE",
"HELIX:INSTANCE_NOT_STABLE"));
- Assert.assertEquals(getStringSet(nonStoppableInstances, "invalidInstance"),
- ImmutableSet.of("HELIX:INSTANCE_NOT_EXIST"));
+ Assert.assertEquals(getStringSet(nonStoppableInstances,
"invalidInstance"), ImmutableSet.of("HELIX:INSTANCE_NOT_EXIST"));
System.out.println("End test :" + TestHelper.getTestMethodName());
}