-
Notifications
You must be signed in to change notification settings - Fork 41
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
- Loading branch information
1 parent
015c1c5
commit 9c6585c
Showing
7 changed files
with
268 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
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
/* | ||
* 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.NrtsearchClient; | ||
import java.util.concurrent.Callable; | ||
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"; | ||
|
||
@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 { | ||
// Call the appropriate method to send the custom request | ||
client.custom(requestBuilder.build()); | ||
} 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; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
/* | ||
* 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 java.util.concurrent.Callable; | ||
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"; | ||
|
||
@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(); | ||
} finally { | ||
client.shutdown(); | ||
} | ||
return 0; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
/* | ||
* 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 java.util.concurrent.Callable; | ||
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"; | ||
|
||
@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(); | ||
} finally { | ||
client.shutdown(); | ||
} | ||
return 0; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
/* | ||
* 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 java.util.concurrent.Callable; | ||
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"; | ||
|
||
@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(); | ||
} 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