From 33496931d23abb566b997ed27098f3801d2b0633 Mon Sep 17 00:00:00 2001 From: "sachin.vm" Date: Fri, 5 Jul 2024 10:00:57 -0700 Subject: [PATCH] [CLIENT-2776] Added the new parser for info command response --- .../client/proxy/InfoCommandProxy.java | 56 ++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/proxy/src/com/aerospike/client/proxy/InfoCommandProxy.java b/proxy/src/com/aerospike/client/proxy/InfoCommandProxy.java index bc82cc1b6..0d0efc3ce 100644 --- a/proxy/src/com/aerospike/client/proxy/InfoCommandProxy.java +++ b/proxy/src/com/aerospike/client/proxy/InfoCommandProxy.java @@ -1,7 +1,6 @@ package com.aerospike.client.proxy; import com.aerospike.client.AerospikeException; -import com.aerospike.client.Log; import com.aerospike.client.ResultCode; import com.aerospike.client.command.Command; import com.aerospike.client.listener.InfoListener; @@ -9,15 +8,14 @@ import com.aerospike.client.policy.Policy; import com.aerospike.client.proxy.grpc.GrpcCallExecutor; import com.aerospike.client.proxy.grpc.GrpcConversions; -import com.aerospike.client.proxy.grpc.GrpcStreamingCall; -import com.aerospike.proxy.client.AboutGrpc; import com.aerospike.proxy.client.Kvs; import com.aerospike.proxy.client.InfoGrpc; import io.grpc.*; -import io.grpc.stub.StreamObserver; +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class InfoCommandProxy extends SingleCommandProxy { @@ -25,7 +23,6 @@ public class InfoCommandProxy extends SingleCommandProxy { private final String[] commands; private final InfoPolicy infoPolicy; private final GrpcCallExecutor executor; - private final MethodDescriptor methodDescriptor; final Policy policy; public InfoCommandProxy(GrpcCallExecutor executor, InfoListener listener, InfoPolicy policy, String... commands) { @@ -34,7 +31,6 @@ public InfoCommandProxy(GrpcCallExecutor executor, InfoListener listener, InfoPo this.infoPolicy = policy; this.listener = listener; this.commands = commands; - this.methodDescriptor = InfoGrpc.getInfoMethod(); this.policy = createPolicy(policy); } @@ -134,12 +130,9 @@ else if (t instanceof StatusRuntimeException) { } @Override - void parseResult(Parser parser) { - int resultCode = parser.parseResultCode(); - if (resultCode != ResultCode.OK) { - throw new AerospikeException(resultCode); - } - Map infoCommandResponse = parser.parseInfoResult(); + void onResponse(Kvs.AerospikeResponsePayload response){ + String infoResponse = String.valueOf(response.getPayload()); + Map infoCommandResponse = createInfoMap(infoResponse); try { listener.onSuccess(infoCommandResponse); } @@ -147,4 +140,41 @@ void parseResult(Parser parser) { logOnSuccessError(t); } } + + public static Map createInfoMap(String byteStringRepresentation) { + Map infoMap = new HashMap<>(); + + String contents = getContents(byteStringRepresentation); + + if (contents != null && !contents.isEmpty()) { + String[] commands = contents.split("\\\\n"); + + for (String command : commands) { + String[] keyValue = command.split("\\\\t", 2); + + if (keyValue.length == 2) { + infoMap.put(keyValue[0], keyValue[1]); + } + } + } + return infoMap; + } + + public static String getContents(String byteStringRepresentation) { + String regex = "contents=\"(.*?)\""; + + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(byteStringRepresentation); + + if (matcher.find()) { + return matcher.group(1); + } + + return null; + } + + @Override + void parseResult(Parser parser) { + + } }