-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add Get QueryGroup API Logic #14709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Get QueryGroup API Logic #14709
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d497882
Add Get QueryGroup API Logic
ruai0511 61953f0
add to changelog
ruai0511 82fc7be
fix javadoc
ruai0511 f08004f
change GetQueryGroupAction NAME and add more tests
ruai0511 0752ed8
add more unit tests
ruai0511 9d23d08
fix spotlessapply
ruai0511 186380c
addressed comments
ruai0511 b4fbe96
incorperate comments from create api PR
ruai0511 94fd684
use clustermanager to get the most recent querygroups
ruai0511 1a96416
address comments
ruai0511 384314b
rebase with main
ruai0511 cdf1925
add IT
ruai0511 23bd5b5
address comments
ruai0511 d4615c7
fix IT
ruai0511 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
...rkload-management/src/main/java/org/opensearch/plugin/wlm/action/GetQueryGroupAction.java
This file contains hidden or 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,36 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.plugin.wlm.action; | ||
|
|
||
| import org.opensearch.action.ActionType; | ||
|
|
||
| /** | ||
| * Transport action to get QueryGroup | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class GetQueryGroupAction extends ActionType<GetQueryGroupResponse> { | ||
|
|
||
| /** | ||
| * An instance of GetQueryGroupAction | ||
| */ | ||
| public static final GetQueryGroupAction INSTANCE = new GetQueryGroupAction(); | ||
|
|
||
| /** | ||
| * Name for GetQueryGroupAction | ||
| */ | ||
| public static final String NAME = "cluster:admin/opensearch/wlm/query_group/_get"; | ||
|
|
||
| /** | ||
| * Default constructor | ||
| */ | ||
| private GetQueryGroupAction() { | ||
| super(NAME, GetQueryGroupResponse::new); | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
...kload-management/src/main/java/org/opensearch/plugin/wlm/action/GetQueryGroupRequest.java
This file contains hidden or 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,64 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.plugin.wlm.action; | ||
|
|
||
| import org.opensearch.action.ActionRequestValidationException; | ||
| import org.opensearch.action.support.clustermanager.ClusterManagerNodeReadRequest; | ||
| import org.opensearch.cluster.metadata.QueryGroup; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Request for get QueryGroup | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class GetQueryGroupRequest extends ClusterManagerNodeReadRequest<GetQueryGroupRequest> { | ||
| final String name; | ||
|
|
||
| /** | ||
| * Default constructor for GetQueryGroupRequest | ||
| * @param name - name for the QueryGroup to get | ||
| */ | ||
| public GetQueryGroupRequest(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor for GetQueryGroupRequest | ||
| * @param in - A {@link StreamInput} object | ||
| */ | ||
| public GetQueryGroupRequest(StreamInput in) throws IOException { | ||
| super(in); | ||
| name = in.readOptionalString(); | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| if (name != null) { | ||
| QueryGroup.validateName(name); | ||
| } | ||
| return null; | ||
ruai0511 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeOptionalString(name); | ||
| } | ||
|
|
||
| /** | ||
| * Name getter | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
...load-management/src/main/java/org/opensearch/plugin/wlm/action/GetQueryGroupResponse.java
This file contains hidden or 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,82 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.plugin.wlm.action; | ||
|
|
||
| import org.opensearch.cluster.metadata.QueryGroup; | ||
| import org.opensearch.core.action.ActionResponse; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
| import org.opensearch.core.rest.RestStatus; | ||
| import org.opensearch.core.xcontent.ToXContent; | ||
| import org.opensearch.core.xcontent.ToXContentObject; | ||
| import org.opensearch.core.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * Response for the get API for QueryGroup | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class GetQueryGroupResponse extends ActionResponse implements ToXContent, ToXContentObject { | ||
| private final Collection<QueryGroup> queryGroups; | ||
| private final RestStatus restStatus; | ||
|
|
||
| /** | ||
| * Constructor for GetQueryGroupResponse | ||
| * @param queryGroups - The QueryGroup list to be fetched | ||
| * @param restStatus - The rest status of the request | ||
| */ | ||
| public GetQueryGroupResponse(final Collection<QueryGroup> queryGroups, RestStatus restStatus) { | ||
| this.queryGroups = queryGroups; | ||
| this.restStatus = restStatus; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor for GetQueryGroupResponse | ||
| * @param in - A {@link StreamInput} object | ||
| */ | ||
| public GetQueryGroupResponse(StreamInput in) throws IOException { | ||
| this.queryGroups = in.readList(QueryGroup::new); | ||
| restStatus = RestStatus.readFrom(in); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeCollection(queryGroups); | ||
| RestStatus.writeTo(out, restStatus); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.startArray("query_groups"); | ||
| for (QueryGroup group : queryGroups) { | ||
| group.toXContent(builder, params); | ||
| } | ||
| builder.endArray(); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| /** | ||
| * queryGroups getter | ||
| */ | ||
| public Collection<QueryGroup> getQueryGroups() { | ||
| return queryGroups; | ||
| } | ||
|
|
||
| /** | ||
| * restStatus getter | ||
| */ | ||
| public RestStatus getRestStatus() { | ||
| return restStatus; | ||
| } | ||
| } |
98 changes: 98 additions & 0 deletions
98
...nagement/src/main/java/org/opensearch/plugin/wlm/action/TransportGetQueryGroupAction.java
This file contains hidden or 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,98 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.plugin.wlm.action; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.opensearch.ResourceNotFoundException; | ||
| import org.opensearch.action.support.ActionFilters; | ||
| import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeReadAction; | ||
| import org.opensearch.cluster.ClusterState; | ||
| import org.opensearch.cluster.block.ClusterBlockException; | ||
| import org.opensearch.cluster.block.ClusterBlockLevel; | ||
| import org.opensearch.cluster.metadata.IndexNameExpressionResolver; | ||
| import org.opensearch.cluster.metadata.QueryGroup; | ||
| import org.opensearch.cluster.service.ClusterService; | ||
| import org.opensearch.common.inject.Inject; | ||
| import org.opensearch.core.action.ActionListener; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.rest.RestStatus; | ||
| import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService; | ||
| import org.opensearch.search.pipeline.SearchPipelineService; | ||
| import org.opensearch.threadpool.ThreadPool; | ||
| import org.opensearch.transport.TransportService; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * Transport action to get QueryGroup | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class TransportGetQueryGroupAction extends TransportClusterManagerNodeReadAction<GetQueryGroupRequest, GetQueryGroupResponse> { | ||
| private static final Logger logger = LogManager.getLogger(SearchPipelineService.class); | ||
|
|
||
| /** | ||
| * Constructor for TransportGetQueryGroupAction | ||
| * | ||
| * @param clusterService - a {@link ClusterService} object | ||
| * @param transportService - a {@link TransportService} object | ||
| * @param actionFilters - a {@link ActionFilters} object | ||
| * @param threadPool - a {@link ThreadPool} object | ||
| * @param indexNameExpressionResolver - a {@link IndexNameExpressionResolver} object | ||
| */ | ||
| @Inject | ||
| public TransportGetQueryGroupAction( | ||
| ClusterService clusterService, | ||
| TransportService transportService, | ||
| ActionFilters actionFilters, | ||
| ThreadPool threadPool, | ||
| IndexNameExpressionResolver indexNameExpressionResolver | ||
| ) { | ||
| super( | ||
| GetQueryGroupAction.NAME, | ||
| transportService, | ||
| clusterService, | ||
| threadPool, | ||
| actionFilters, | ||
| GetQueryGroupRequest::new, | ||
| indexNameExpressionResolver, | ||
| true | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| protected String executor() { | ||
| return ThreadPool.Names.SAME; | ||
| } | ||
|
|
||
| @Override | ||
| protected GetQueryGroupResponse read(StreamInput in) throws IOException { | ||
| return new GetQueryGroupResponse(in); | ||
| } | ||
|
|
||
| @Override | ||
| protected ClusterBlockException checkBlock(GetQueryGroupRequest request, ClusterState state) { | ||
| return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); | ||
| } | ||
|
|
||
| @Override | ||
| protected void clusterManagerOperation(GetQueryGroupRequest request, ClusterState state, ActionListener<GetQueryGroupResponse> listener) | ||
| throws Exception { | ||
| final String name = request.getName(); | ||
| final Collection<QueryGroup> resultGroups = QueryGroupPersistenceService.getFromClusterStateMetadata(name, state); | ||
|
|
||
| if (resultGroups.isEmpty() && name != null && !name.isEmpty()) { | ||
| logger.warn("No QueryGroup exists with the provided name: {}", name); | ||
jed326 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw new ResourceNotFoundException("No QueryGroup exists with the provided name: " + name); | ||
| } | ||
| listener.onResponse(new GetQueryGroupResponse(resultGroups, RestStatus.OK)); | ||
| } | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
...load-management/src/main/java/org/opensearch/plugin/wlm/rest/RestGetQueryGroupAction.java
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.plugin.wlm.rest; | ||
|
|
||
| import org.opensearch.client.node.NodeClient; | ||
| import org.opensearch.core.rest.RestStatus; | ||
| import org.opensearch.core.xcontent.ToXContent; | ||
| import org.opensearch.plugin.wlm.action.GetQueryGroupAction; | ||
| import org.opensearch.plugin.wlm.action.GetQueryGroupRequest; | ||
| import org.opensearch.plugin.wlm.action.GetQueryGroupResponse; | ||
| import org.opensearch.rest.BaseRestHandler; | ||
| import org.opensearch.rest.BytesRestResponse; | ||
| import org.opensearch.rest.RestChannel; | ||
| import org.opensearch.rest.RestRequest; | ||
| import org.opensearch.rest.RestResponse; | ||
| import org.opensearch.rest.action.RestResponseListener; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| import static org.opensearch.rest.RestRequest.Method.GET; | ||
|
|
||
| /** | ||
| * Rest action to get a QueryGroup0 | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class RestGetQueryGroupAction extends BaseRestHandler { | ||
|
|
||
| /** | ||
| * Constructor for RestGetQueryGroupAction | ||
| */ | ||
| public RestGetQueryGroupAction() {} | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "get_query_group"; | ||
| } | ||
|
|
||
| /** | ||
| * The list of {@link Route}s that this RestHandler is responsible for handling. | ||
| */ | ||
| @Override | ||
| public List<Route> routes() { | ||
| return List.of(new Route(GET, "_wlm/query_group/{name}"), new Route(GET, "_wlm/query_group/")); | ||
| } | ||
|
|
||
| @Override | ||
| protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
| final GetQueryGroupRequest getQueryGroupRequest = new GetQueryGroupRequest(request.param("name")); | ||
| return channel -> client.execute(GetQueryGroupAction.INSTANCE, getQueryGroupRequest, getQueryGroupResponse(channel)); | ||
| } | ||
|
|
||
| private RestResponseListener<GetQueryGroupResponse> getQueryGroupResponse(final RestChannel channel) { | ||
| return new RestResponseListener<>(channel) { | ||
| @Override | ||
| public RestResponse buildResponse(final GetQueryGroupResponse response) throws Exception { | ||
| return new BytesRestResponse(RestStatus.OK, response.toXContent(channel.newBuilder(), ToXContent.EMPTY_PARAMS)); | ||
| } | ||
| }; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.