Skip to content

Commit

Permalink
[CLIENT-2776] Added the new parser for info command response
Browse files Browse the repository at this point in the history
  • Loading branch information
vmsachin committed Jul 5, 2024
1 parent 14c64d1 commit 3349693
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions proxy/src/com/aerospike/client/proxy/InfoCommandProxy.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
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;
import com.aerospike.client.policy.InfoPolicy;
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 {

private final InfoListener listener;
private final String[] commands;
private final InfoPolicy infoPolicy;
private final GrpcCallExecutor executor;
private final MethodDescriptor<Kvs.AerospikeRequestPayload, Kvs.AerospikeResponsePayload> methodDescriptor;
final Policy policy;

public InfoCommandProxy(GrpcCallExecutor executor, InfoListener listener, InfoPolicy policy, String... commands) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -134,17 +130,51 @@ else if (t instanceof StatusRuntimeException) {
}

@Override
void parseResult(Parser parser) {
int resultCode = parser.parseResultCode();
if (resultCode != ResultCode.OK) {
throw new AerospikeException(resultCode);
}
Map<String, String> infoCommandResponse = parser.parseInfoResult();
void onResponse(Kvs.AerospikeResponsePayload response){
String infoResponse = String.valueOf(response.getPayload());
Map<String, String> infoCommandResponse = createInfoMap(infoResponse);
try {
listener.onSuccess(infoCommandResponse);
}
catch (Throwable t) {
logOnSuccessError(t);
}
}

public static Map<String, String> createInfoMap(String byteStringRepresentation) {
Map<String, String> 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) {

}
}

0 comments on commit 3349693

Please sign in to comment.