From 4f275cc44b8562c7c22bb4a610ee7eaa7edf75f0 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Wed, 23 Dec 2015 10:51:50 +0200 Subject: [PATCH] StorageService: format the describering output The describeRingJMX method, returns a formated output. The output should be similiar to origin as oppose to the current implementation that returns a json representation. After the change an example of nodetool describering: $ nodetool describering keyspace1 Schema Version:1074c31b-1f39-3df2-90ff-7f0b64bb3ea4 TokenRange: TokenRange(start_token:7485973865401664349, end_token:-338297331236877217, endpoints:[127.0.0.1], rpc_endpoints:[127.0.0.1], endpoint_details:[EndpointDetails(host:127.0.0.1, datacenter:datacenter1, rack:rack1)]) TokenRange(start_token:-338297331236877217, end_token:7485973865401664349, endpoints:[127.0.0.2], rpc_endpoints:[127.0.0.2], endpoint_details:[EndpointDetails(host:127.0.0.2, datacenter:datacenter1, rack:rack1)]) On sycall-jmx: Fixes #21 Signed-off-by: Amnon Heiman --- .../cassandra/service/StorageService.java | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/cassandra/service/StorageService.java b/src/main/java/org/apache/cassandra/service/StorageService.java index eaa58ed..ab811e0 100644 --- a/src/main/java/org/apache/cassandra/service/StorageService.java +++ b/src/main/java/org/apache/cassandra/service/StorageService.java @@ -262,12 +262,48 @@ public class StorageService extends NotificationBroadcasterSupport List res = new ArrayList(); for (int i = 0; i < arr.size(); i++) { - StringWriter stringWriter = new StringWriter(); - JsonWriter writer = Json.createWriter(stringWriter); JsonObject obj = arr.getJsonObject(i); - writer.writeObject(obj); - writer.close(); - res.add(stringWriter.getBuffer().toString()); + StringBuilder sb = new StringBuilder(); + sb.append("TokenRange("); + sb.append("start_token:"); + sb.append(obj.getString("start_token")); + sb.append(", end_token:"); + sb.append(obj.getString("end_token")); + sb.append(", endpoints:["); + JsonArray endpoints = obj.getJsonArray("endpoints"); + for (int j = 0; j < endpoints.size(); j++) { + if (j > 0) { + sb.append(", "); + } + sb.append(endpoints.getString(j)); + } + sb.append("], rpc_endpoints:["); + JsonArray rpc_endpoints = obj.getJsonArray("rpc_endpoints"); + for (int j = 0; j < rpc_endpoints.size(); j++) { + if (j > 0) { + sb.append(", "); + } + sb.append(rpc_endpoints.getString(j)); + } + + sb.append("], endpoint_details:["); + JsonArray endpoint_details = obj.getJsonArray("endpoint_details"); + for (int j = 0; j < endpoint_details.size(); j++) { + JsonObject detail = endpoint_details.getJsonObject(j); + if (j > 0) { + sb.append(", "); + } + sb.append("EndpointDetails("); + sb.append("host:"); + sb.append(detail.getString("host")); + sb.append(", datacenter:"); + sb.append(detail.getString("datacenter")); + sb.append(", rack:"); + sb.append(detail.getString("rack")); + sb.append(')'); + } + sb.append("])"); + res.add(sb.toString()); } return res; }