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 b6ae480d2 Fix inconsistent map key formatting in helix-rest
maintenance API (#2583)
b6ae480d2 is described below
commit b6ae480d256fba7705bb8dc8331123eec702eff9
Author: Grant Paláu Spencer <[email protected]>
AuthorDate: Tue Aug 22 14:03:14 2023 -0700
Fix inconsistent map key formatting in helix-rest maintenance API (#2583)
Fix inconsistent map key formatting in helix-rest maintenance API
---------
Co-authored-by: Grant Palau Spencer <[email protected]>
---
.../apache/helix/rest/server/resources/helix/ClusterAccessor.java | 7 ++++++-
.../java/org/apache/helix/rest/server/TestClusterAccessor.java | 7 ++++---
2 files changed, 10 insertions(+), 4 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 68744cbbe..9c563b9c3 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
@@ -321,8 +321,13 @@ public class ClusterAccessor extends AbstractHelixResource
{
customFieldsMap =
OBJECT_MAPPER.readValue(content, new
TypeReference<HashMap<String, String>>() {
});
- // content is given as a KV mapping. Nullify content
+ // content is given as a KV mapping. Nullify content unless
(case-insensitive) reason key present in map
content = null;
+ for (Map.Entry<String, String> entry : customFieldsMap.entrySet()) {
+ if ("reason".equalsIgnoreCase(entry.getKey())) {
+ content = entry.getValue();
+ }
+ }
} catch (Exception e) {
// NOP
}
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..310b989a7 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
@@ -494,10 +494,11 @@ public class TestClusterAccessor extends
AbstractTestClass {
public void testEnableDisableMaintenanceMode() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();
- String reason = "Test reason";
+ String reasonValue = "Test reason";
+ String reasonJSONString = "{\"reason\":\"" + reasonValue + "\"}";
// enable maintenance mode
post("clusters/" + cluster, ImmutableMap.of("command",
"enableMaintenanceMode"),
- Entity.entity(reason, MediaType.APPLICATION_JSON_TYPE),
Response.Status.OK.getStatusCode());
+ Entity.entity(reasonJSONString, MediaType.APPLICATION_JSON_TYPE),
Response.Status.OK.getStatusCode());
// verify is in maintenance mode
Assert.assertTrue(isMaintenanceModeEnabled(cluster));
@@ -506,7 +507,7 @@ public class TestClusterAccessor extends AbstractTestClass {
Map<String, Object> maintenanceSignalMap =
getMapResponseFromRest("clusters/" + cluster +
"/controller/maintenanceSignal");
Assert.assertEquals(maintenanceSignalMap.get("TRIGGERED_BY"), "USER");
- Assert.assertEquals(maintenanceSignalMap.get("REASON"), reason);
+ Assert.assertEquals(maintenanceSignalMap.get("REASON"), reasonValue);
Assert.assertNotNull(maintenanceSignalMap.get("TIMESTAMP"));
Assert.assertEquals(maintenanceSignalMap.get("clusterName"), cluster);