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 617010a Pass partitions list to custom client rest (#1570)
617010a is described below
commit 617010a2589d190256f4d01ac937d534c7e3f9cc
Author: Huizhi Lu <[email protected]>
AuthorDate: Tue Dec 1 17:38:58 2020 -0800
Pass partitions list to custom client rest (#1570)
Problem:
CustomRestClientImpl serializes the partitions list to a string before
sending the payloads to the custom client health check Rest API. The custom
client is expecting a list of partitions, but received a string.
So the custom client returns an error 400. But actually the partitions are
healthy. This is caused by the serialization/deserialization inconsistency
between helix rest and custom client rest.
Solution:
Keep the partitions list in the payload without serializing it to a string
when sending post request. So the custom client will get the list of partitions
after deserializing the payloads.
---
.../java/org/apache/helix/rest/client/CustomRestClientImpl.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git
a/helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java
b/helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java
index c7b5ac4..6406f0b 100644
---
a/helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java
+++
b/helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java
@@ -20,6 +20,7 @@ package org.apache.helix.rest.client;
*/
import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -72,7 +73,7 @@ class CustomRestClientImpl implements CustomRestClient {
jsonNode.fields().forEachRemaining(kv -> result.put(kv.getKey(),
kv.getValue().asBoolean()));
return result;
};
- return handleResponse(post(url, customPayloads), jsonConverter);
+ return handleResponse(post(url,
Collections.unmodifiableMap(customPayloads)), jsonConverter);
}
@Override
@@ -87,10 +88,10 @@ class CustomRestClientImpl implements CustomRestClient {
*/
String url = baseUrl + PARTITION_HEALTH_STATUS;
// To avoid ImmutableMap as parameter
- Map<String, String> payLoads = new HashMap<>(customPayloads);
+ Map<String, Object> payLoads = new HashMap<>(customPayloads);
// Add the entry: "partitions" : ["p1", "p3", "p9"]
if (partitions != null) {
- payLoads.put(PARTITIONS, partitions.toString());
+ payLoads.put(PARTITIONS, partitions);
}
JsonConverter jsonConverter = jsonNode -> {
Map<String, Boolean> result = new HashMap<>();
@@ -124,7 +125,7 @@ class CustomRestClientImpl implements CustomRestClient {
}
@VisibleForTesting
- protected HttpResponse post(String url, Map<String, String> payloads) throws
IOException {
+ protected HttpResponse post(String url, Map<String, Object> payloads) throws
IOException {
HttpPost postRequest = new HttpPost(url);
try {
postRequest.setHeader("Accept", ACCEPT_CONTENT_TYPE);