-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add Create QueryGroup API Logic #14680
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
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b88ae35
add logic for Create QueryGroup API
ruai0511 3322ab8
remove wildcard imports
ruai0511 8e0930a
change jvm to memeory
ruai0511 4047d0d
modify querygroup
ruai0511 ed6566c
fix javadoc and add more tests
ruai0511 123620b
add more tests
ruai0511 c402351
address comments
ruai0511 e9e8d1b
fix the persist logic
ruai0511 a5d14b6
remove inflight checks as they are not necessary
ruai0511 0c6a609
remove persistable interface
ruai0511 08efbbd
modify QueryGroupServiceSettings
ruai0511 bfaf500
add in an action package in the plugin
ruai0511 8f13d41
modify based on commments
ruai0511 9b8c1ce
address comments on QueryGroupPersistenceService
ruai0511 322b266
address comments on persistence service
ruai0511 e8bf2b8
address comments
ruai0511 1b09c34
fix unit test
ruai0511 494a025
address comments
ruai0511 c4bc6f5
add IT
ruai0511 8e123f7
add coverage
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * 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. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| apply plugin: 'opensearch.yaml-rest-test' | ||
| apply plugin: 'opensearch.internal-cluster-test' | ||
|
|
||
| opensearchplugin { | ||
| description 'OpenSearch Workload Management Plugin.' | ||
| classname 'org.opensearch.plugin.wlm.WorkloadManagementPlugin' | ||
| } | ||
|
|
||
| dependencies { | ||
| } |
64 changes: 64 additions & 0 deletions
64
...workload-management/src/main/java/org/opensearch/plugin/wlm/WorkloadManagementPlugin.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; | ||
|
|
||
| import org.opensearch.action.ActionRequest; | ||
| import org.opensearch.cluster.metadata.IndexNameExpressionResolver; | ||
| import org.opensearch.cluster.node.DiscoveryNodes; | ||
| import org.opensearch.common.settings.ClusterSettings; | ||
| import org.opensearch.common.settings.IndexScopedSettings; | ||
| import org.opensearch.common.settings.Setting; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.common.settings.SettingsFilter; | ||
| import org.opensearch.core.action.ActionResponse; | ||
| import org.opensearch.plugin.wlm.action.CreateQueryGroupAction; | ||
| import org.opensearch.plugin.wlm.action.TransportCreateQueryGroupAction; | ||
| import org.opensearch.plugin.wlm.rest.RestCreateQueryGroupAction; | ||
| import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService; | ||
| import org.opensearch.plugins.ActionPlugin; | ||
| import org.opensearch.plugins.Plugin; | ||
| import org.opensearch.rest.RestController; | ||
| import org.opensearch.rest.RestHandler; | ||
|
|
||
| import java.util.List; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Plugin class for WorkloadManagement | ||
| */ | ||
| public class WorkloadManagementPlugin extends Plugin implements ActionPlugin { | ||
|
|
||
| /** | ||
| * Default constructor | ||
| */ | ||
| public WorkloadManagementPlugin() {} | ||
|
|
||
| @Override | ||
| public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { | ||
| return List.of(new ActionPlugin.ActionHandler<>(CreateQueryGroupAction.INSTANCE, TransportCreateQueryGroupAction.class)); | ||
| } | ||
|
|
||
| @Override | ||
| public List<RestHandler> getRestHandlers( | ||
| Settings settings, | ||
| RestController restController, | ||
| ClusterSettings clusterSettings, | ||
| IndexScopedSettings indexScopedSettings, | ||
| SettingsFilter settingsFilter, | ||
| IndexNameExpressionResolver indexNameExpressionResolver, | ||
| Supplier<DiscoveryNodes> nodesInCluster | ||
| ) { | ||
| return List.of(new RestCreateQueryGroupAction()); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Setting<?>> getSettings() { | ||
| return List.of(QueryGroupPersistenceService.MAX_QUERY_GROUP_COUNT); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...oad-management/src/main/java/org/opensearch/plugin/wlm/action/CreateQueryGroupAction.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 create QueryGroup | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class CreateQueryGroupAction extends ActionType<CreateQueryGroupResponse> { | ||
|
|
||
| /** | ||
| * An instance of CreateQueryGroupAction | ||
| */ | ||
| public static final CreateQueryGroupAction INSTANCE = new CreateQueryGroupAction(); | ||
|
|
||
| /** | ||
| * Name for CreateQueryGroupAction | ||
| */ | ||
| public static final String NAME = "cluster:admin/opensearch/wlm/query_group/_create"; | ||
|
|
||
| /** | ||
| * Default constructor | ||
| */ | ||
| private CreateQueryGroupAction() { | ||
| super(NAME, CreateQueryGroupResponse::new); | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletions
82
...ad-management/src/main/java/org/opensearch/plugin/wlm/action/CreateQueryGroupRequest.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.action.ActionRequest; | ||
| import org.opensearch.action.ActionRequestValidationException; | ||
| import org.opensearch.cluster.metadata.QueryGroup; | ||
| import org.opensearch.common.UUIDs; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
| import org.opensearch.core.xcontent.XContentParser; | ||
| import org.joda.time.Instant; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * A request for create QueryGroup | ||
| * User input schema: | ||
| * { | ||
| * "name": "analytics", | ||
| * "resiliency_mode": "enforced", | ||
| * "resource_limits": { | ||
| * "cpu" : 0.4, | ||
| * "memory" : 0.2 | ||
| * } | ||
| * } | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class CreateQueryGroupRequest extends ActionRequest { | ||
| private final QueryGroup queryGroup; | ||
|
|
||
| /** | ||
| * Constructor for CreateQueryGroupRequest | ||
| * @param queryGroup - A {@link QueryGroup} object | ||
| */ | ||
| public CreateQueryGroupRequest(QueryGroup queryGroup) { | ||
| this.queryGroup = queryGroup; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor for CreateQueryGroupRequest | ||
| * @param in - A {@link StreamInput} object | ||
| */ | ||
| public CreateQueryGroupRequest(StreamInput in) throws IOException { | ||
| super(in); | ||
| queryGroup = new QueryGroup(in); | ||
| } | ||
|
|
||
| /** | ||
| * Generate a CreateQueryGroupRequest from XContent | ||
| * @param parser - A {@link XContentParser} object | ||
| */ | ||
| public static CreateQueryGroupRequest fromXContent(XContentParser parser) throws IOException { | ||
| QueryGroup.Builder builder = QueryGroup.Builder.fromXContent(parser); | ||
| return new CreateQueryGroupRequest(builder._id(UUIDs.randomBase64UUID()).updatedAt(Instant.now().getMillis()).build()); | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| queryGroup.writeTo(out); | ||
| } | ||
|
|
||
| /** | ||
| * QueryGroup getter | ||
| */ | ||
| public QueryGroup getQueryGroup() { | ||
| return queryGroup; | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
...d-management/src/main/java/org/opensearch/plugin/wlm/action/CreateQueryGroupResponse.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,74 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * Response for the create API for QueryGroup | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class CreateQueryGroupResponse extends ActionResponse implements ToXContent, ToXContentObject { | ||
| private final QueryGroup queryGroup; | ||
| private final RestStatus restStatus; | ||
|
|
||
| /** | ||
| * Constructor for CreateQueryGroupResponse | ||
| * @param queryGroup - The QueryGroup to be included in the response | ||
| * @param restStatus - The restStatus for the response | ||
| */ | ||
| public CreateQueryGroupResponse(final QueryGroup queryGroup, RestStatus restStatus) { | ||
| this.queryGroup = queryGroup; | ||
| this.restStatus = restStatus; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor for CreateQueryGroupResponse | ||
| * @param in - A {@link StreamInput} object | ||
| */ | ||
| public CreateQueryGroupResponse(StreamInput in) throws IOException { | ||
| queryGroup = new QueryGroup(in); | ||
| restStatus = RestStatus.readFrom(in); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| queryGroup.writeTo(out); | ||
| RestStatus.writeTo(out, restStatus); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| return queryGroup.toXContent(builder, params); | ||
| } | ||
|
|
||
| /** | ||
| * queryGroup getter | ||
| */ | ||
| public QueryGroup getQueryGroup() { | ||
| return queryGroup; | ||
| } | ||
|
|
||
| /** | ||
| * restStatus getter | ||
| */ | ||
| public RestStatus getRestStatus() { | ||
| return restStatus; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
...ement/src/main/java/org/opensearch/plugin/wlm/action/TransportCreateQueryGroupAction.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,57 @@ | ||
| /* | ||
| * 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.support.ActionFilters; | ||
| import org.opensearch.action.support.HandledTransportAction; | ||
| import org.opensearch.common.inject.Inject; | ||
| import org.opensearch.core.action.ActionListener; | ||
| import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService; | ||
| import org.opensearch.tasks.Task; | ||
| import org.opensearch.threadpool.ThreadPool; | ||
| import org.opensearch.transport.TransportService; | ||
|
|
||
| /** | ||
| * Transport action to create QueryGroup | ||
| * | ||
| * @opensearch.experimental | ||
| */ | ||
| public class TransportCreateQueryGroupAction extends HandledTransportAction<CreateQueryGroupRequest, CreateQueryGroupResponse> { | ||
|
|
||
| private final ThreadPool threadPool; | ||
| private final QueryGroupPersistenceService queryGroupPersistenceService; | ||
|
|
||
| /** | ||
| * Constructor for TransportCreateQueryGroupAction | ||
| * | ||
| * @param actionName - action name | ||
| * @param transportService - a {@link TransportService} object | ||
| * @param actionFilters - a {@link ActionFilters} object | ||
| * @param threadPool - a {@link ThreadPool} object | ||
| * @param queryGroupPersistenceService - a {@link QueryGroupPersistenceService} object | ||
| */ | ||
| @Inject | ||
| public TransportCreateQueryGroupAction( | ||
| String actionName, | ||
| TransportService transportService, | ||
| ActionFilters actionFilters, | ||
| ThreadPool threadPool, | ||
| QueryGroupPersistenceService queryGroupPersistenceService | ||
| ) { | ||
| super(CreateQueryGroupAction.NAME, transportService, actionFilters, CreateQueryGroupRequest::new); | ||
| this.threadPool = threadPool; | ||
| this.queryGroupPersistenceService = queryGroupPersistenceService; | ||
| } | ||
|
|
||
| @Override | ||
| protected void doExecute(Task task, CreateQueryGroupRequest request, ActionListener<CreateQueryGroupResponse> listener) { | ||
| threadPool.executor(ThreadPool.Names.SAME) | ||
| .execute(() -> queryGroupPersistenceService.persistInClusterStateMetadata(request.getQueryGroup(), listener)); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/action/package-info.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,12 @@ | ||
| /* | ||
| * 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 for the action classes of WorkloadManagementPlugin | ||
| */ | ||
| package org.opensearch.plugin.wlm.action; |
12 changes: 12 additions & 0 deletions
12
plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/package-info.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,12 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * Base package for WorkloadManagementPlugin | ||
| */ | ||
| package org.opensearch.plugin.wlm; |
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.