Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
aprudhomme committed Oct 28, 2024
1 parent 9c6585c commit 0224f9d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
24 changes: 0 additions & 24 deletions src/main/java/com/yelp/nrtsearch/server/grpc/NrtsearchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import static com.yelp.nrtsearch.server.grpc.ReplicationServerClient.MAX_MESSAGE_BYTES_SIZE;

import com.google.api.HttpBody;
import com.google.protobuf.Empty;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import io.grpc.ManagedChannel;
Expand Down Expand Up @@ -410,28 +408,6 @@ public List<String> getIndices() {
.collect(Collectors.toList());
}

public void nodeInfo() {
NodeInfoResponse response = blockingStub.nodeInfo(NodeInfoRequest.newBuilder().build());
logger.info("Server returned node info: {}", response);
}

public void globalState() {
GlobalStateResponse response =
blockingStub.globalState(GlobalStateRequest.newBuilder().build());
logger.info("Server returned global state: {}", response);
}

public void metrics() {
HttpBody response = blockingStub.metrics(Empty.newBuilder().build());
String metrics = new String(response.getData().toByteArray());
logger.info("Server returned metrics:\n{}", metrics);
}

public void custom(CustomRequest request) {
CustomResponse response = blockingStub.custom(request);
logger.info("Server returned : {}", response);
}

private FieldDefRequest getFieldDefRequest(String jsonStr) {
logger.info(String.format("Converting fields %s to proto FieldDefRequest", jsonStr));
FieldDefRequest.Builder fieldDefRequestBuilder = FieldDefRequest.newBuilder();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/yelp/nrtsearch/tools/cli/CustomCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
package com.yelp.nrtsearch.tools.cli;

import com.yelp.nrtsearch.server.grpc.CustomRequest;
import com.yelp.nrtsearch.server.grpc.CustomResponse;
import com.yelp.nrtsearch.server.grpc.NrtsearchClient;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

@CommandLine.Command(
name = CustomCommand.CUSTOM_COMMAND,
description = "Sends a custom command to endpoint registered by a plugin")
public class CustomCommand implements Callable<Integer> {
public static final String CUSTOM_COMMAND = "custom";
private static final Logger logger = LoggerFactory.getLogger(CustomCommand.class);

@CommandLine.ParentCommand private NrtsearchClientCommand baseCmd;

Expand All @@ -42,8 +46,8 @@ public Integer call() throws Exception {

NrtsearchClient client = baseCmd.getClient();
try {
// Call the appropriate method to send the custom request
client.custom(requestBuilder.build());
CustomResponse response = client.getBlockingStub().custom(requestBuilder.build());
logger.info("Server returned : {}", response);
} finally {
client.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@
*/
package com.yelp.nrtsearch.tools.cli;

import com.yelp.nrtsearch.server.grpc.GlobalStateRequest;
import com.yelp.nrtsearch.server.grpc.GlobalStateResponse;
import com.yelp.nrtsearch.server.grpc.NrtsearchClient;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

@CommandLine.Command(
name = GlobalStateCommand.GLOBAL_STATE,
description = "Get server global state")
public class GlobalStateCommand implements Callable<Integer> {
public static final String GLOBAL_STATE = "globalState";
private static final Logger logger = LoggerFactory.getLogger(GlobalStateCommand.class);

@CommandLine.ParentCommand private NrtsearchClientCommand baseCmd;

@Override
public Integer call() throws Exception {
NrtsearchClient client = baseCmd.getClient();
try {
// Call the appropriate method to get global state
client.globalState();
GlobalStateResponse response =
client.getBlockingStub().globalState(GlobalStateRequest.newBuilder().build());
logger.info("Server returned global state: {}", response);
} finally {
client.shutdown();
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/yelp/nrtsearch/tools/cli/MetricsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@
*/
package com.yelp.nrtsearch.tools.cli;

import com.google.api.HttpBody;
import com.google.protobuf.Empty;
import com.yelp.nrtsearch.server.grpc.NrtsearchClient;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

@CommandLine.Command(
name = MetricsCommand.METRICS,
description = "Get prometheus metrics for the server")
public class MetricsCommand implements Callable<Integer> {
public static final String METRICS = "metrics";
private static final Logger logger = LoggerFactory.getLogger(MetricsCommand.class);

@CommandLine.ParentCommand private NrtsearchClientCommand baseCmd;

@Override
public Integer call() throws Exception {
NrtsearchClient client = baseCmd.getClient();
try {
// Call the appropriate method to get metrics
client.metrics();
HttpBody response = client.getBlockingStub().metrics(Empty.newBuilder().build());
String metrics = new String(response.getData().toByteArray());
logger.info("Server returned metrics:\n{}", metrics);
} finally {
client.shutdown();
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/yelp/nrtsearch/tools/cli/NodeInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@
*/
package com.yelp.nrtsearch.tools.cli;

import com.yelp.nrtsearch.server.grpc.NodeInfoRequest;
import com.yelp.nrtsearch.server.grpc.NodeInfoResponse;
import com.yelp.nrtsearch.server.grpc.NrtsearchClient;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

@CommandLine.Command(
name = NodeInfoCommand.NODE_INFO,
description = "Get node information for the server")
public class NodeInfoCommand implements Callable<Integer> {
public static final String NODE_INFO = "nodeInfo";
private static final Logger logger = LoggerFactory.getLogger(NodeInfoCommand.class);

@CommandLine.ParentCommand private NrtsearchClientCommand baseCmd;

@Override
public Integer call() throws Exception {
NrtsearchClient client = baseCmd.getClient();
try {
// Call the appropriate method to get node information
client.nodeInfo();
NodeInfoResponse response =
client.getBlockingStub().nodeInfo(NodeInfoRequest.newBuilder().build());
logger.info("Server returned node info: {}", response);
} finally {
client.shutdown();
}
Expand Down

0 comments on commit 0224f9d

Please sign in to comment.