-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose more server endpoint through cli commands (#773)
* Expose more server endpoint through cli commands * Address review feedback
- Loading branch information
1 parent
b3fb57a
commit 6a9049a
Showing
7 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/yelp/nrtsearch/tools/cli/CustomCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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; | ||
|
||
@CommandLine.Option( | ||
names = {"-r", "--request"}, | ||
description = | ||
"The custom request to send, CustomRequest protobuf message as json or @file/path", | ||
required = true) | ||
private String request; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
CustomRequest.Builder requestBuilder = CustomRequest.newBuilder(); | ||
CliUtils.mergeBuilderFromParam(request, requestBuilder); | ||
|
||
NrtsearchClient client = baseCmd.getClient(); | ||
try { | ||
CustomResponse response = client.getBlockingStub().custom(requestBuilder.build()); | ||
logger.info("Server returned : {}", response); | ||
} finally { | ||
client.shutdown(); | ||
} | ||
return 0; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/yelp/nrtsearch/tools/cli/DeleteByQueryCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yelp.nrtsearch.tools.cli; | ||
|
||
import com.yelp.nrtsearch.server.grpc.NrtsearchClient; | ||
import com.yelp.nrtsearch.server.grpc.Query; | ||
import java.util.concurrent.Callable; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command( | ||
name = DeleteByQueryCommand.DELETE_BY_QUERY, | ||
description = "Delete all docs that match a query") | ||
public class DeleteByQueryCommand implements Callable<Integer> { | ||
public static final String DELETE_BY_QUERY = "deleteByQuery"; | ||
|
||
@CommandLine.ParentCommand private NrtsearchClientCommand baseCmd; | ||
|
||
@CommandLine.Option( | ||
names = {"-i", "--indexName"}, | ||
description = "Name of the index whose docs are to be deleted", | ||
required = true) | ||
private String indexName; | ||
|
||
@CommandLine.Option( | ||
names = {"-q", "--query"}, | ||
description = "Deletion query, Query protobuf message as json or @file/path", | ||
required = true) | ||
private String query; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
Query.Builder queryBuilder = Query.newBuilder(); | ||
CliUtils.mergeBuilderFromParam(query, queryBuilder); | ||
|
||
NrtsearchClient client = baseCmd.getClient(); | ||
try { | ||
client.deleteByQuery(indexName, queryBuilder.build()); | ||
} finally { | ||
client.shutdown(); | ||
} | ||
return 0; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/yelp/nrtsearch/tools/cli/GlobalStateCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2024 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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 { | ||
GlobalStateResponse response = | ||
client.getBlockingStub().globalState(GlobalStateRequest.newBuilder().build()); | ||
logger.info("Server returned global state: {}", response); | ||
} finally { | ||
client.shutdown(); | ||
} | ||
return 0; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/yelp/nrtsearch/tools/cli/MetricsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2024 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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 { | ||
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(); | ||
} | ||
return 0; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/yelp/nrtsearch/tools/cli/NodeInfoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2024 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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 { | ||
NodeInfoResponse response = | ||
client.getBlockingStub().nodeInfo(NodeInfoRequest.newBuilder().build()); | ||
logger.info("Server returned node info: {}", response); | ||
} finally { | ||
client.shutdown(); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters