Skip to content

Commit ed65482

Browse files
authored
Add Delete QueryGroup API Logic (#14735)
* Add Delete QueryGroup API Logic Signed-off-by: Ruirui Zhang <[email protected]> * modify changelog Signed-off-by: Ruirui Zhang <[email protected]> * include comments from create pr Signed-off-by: Ruirui Zhang <[email protected]> * remove delete all Signed-off-by: Ruirui Zhang <[email protected]> * rebase and address comments Signed-off-by: Ruirui Zhang <[email protected]> * rebase Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * add UT coverage Signed-off-by: Ruirui Zhang <[email protected]>
1 parent d5a6c0b commit ed65482

17 files changed

+636
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
- Fix for hasInitiatedFetching to fix allocation explain and manual reroute APIs (([#14972](https://github.com/opensearch-project/OpenSearch/pull/14972))
1010
- [Workload Management] Add queryGroupId to Task ([14708](https://github.com/opensearch-project/OpenSearch/pull/14708))
1111
- Add setting to ignore throttling nodes for allocation of unassigned primaries in remote restore ([#14991](https://github.com/opensearch-project/OpenSearch/pull/14991))
12+
- [Workload Management] Add Delete QueryGroup API Logic ([#14735](https://github.com/opensearch-project/OpenSearch/pull/14735))
1213
- [Streaming Indexing] Enhance RestClient with a new streaming API support ([#14437](https://github.com/opensearch-project/OpenSearch/pull/14437))
1314
- Add basic aggregation support for derived fields ([#14618](https://github.com/opensearch-project/OpenSearch/pull/14618))
1415
- [Workload Management] Add Create QueryGroup API Logic ([#14680](https://github.com/opensearch-project/OpenSearch/pull/14680))- [Workload Management] Add Create QueryGroup API Logic ([#14680](https://github.com/opensearch-project/OpenSearch/pull/14680))

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/WorkloadManagementPlugin.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@
1111
import org.opensearch.action.ActionRequest;
1212
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
1313
import org.opensearch.cluster.node.DiscoveryNodes;
14+
import org.opensearch.common.inject.Module;
1415
import org.opensearch.common.settings.ClusterSettings;
1516
import org.opensearch.common.settings.IndexScopedSettings;
1617
import org.opensearch.common.settings.Setting;
1718
import org.opensearch.common.settings.Settings;
1819
import org.opensearch.common.settings.SettingsFilter;
1920
import org.opensearch.core.action.ActionResponse;
2021
import org.opensearch.plugin.wlm.action.CreateQueryGroupAction;
22+
import org.opensearch.plugin.wlm.action.DeleteQueryGroupAction;
2123
import org.opensearch.plugin.wlm.action.GetQueryGroupAction;
2224
import org.opensearch.plugin.wlm.action.TransportCreateQueryGroupAction;
25+
import org.opensearch.plugin.wlm.action.TransportDeleteQueryGroupAction;
2326
import org.opensearch.plugin.wlm.action.TransportGetQueryGroupAction;
2427
import org.opensearch.plugin.wlm.rest.RestCreateQueryGroupAction;
28+
import org.opensearch.plugin.wlm.rest.RestDeleteQueryGroupAction;
2529
import org.opensearch.plugin.wlm.rest.RestGetQueryGroupAction;
2630
import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService;
2731
import org.opensearch.plugins.ActionPlugin;
2832
import org.opensearch.plugins.Plugin;
2933
import org.opensearch.rest.RestController;
3034
import org.opensearch.rest.RestHandler;
3135

36+
import java.util.Collection;
3237
import java.util.List;
3338
import java.util.function.Supplier;
3439

@@ -46,7 +51,8 @@ public WorkloadManagementPlugin() {}
4651
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
4752
return List.of(
4853
new ActionPlugin.ActionHandler<>(CreateQueryGroupAction.INSTANCE, TransportCreateQueryGroupAction.class),
49-
new ActionPlugin.ActionHandler<>(GetQueryGroupAction.INSTANCE, TransportGetQueryGroupAction.class)
54+
new ActionPlugin.ActionHandler<>(GetQueryGroupAction.INSTANCE, TransportGetQueryGroupAction.class),
55+
new ActionPlugin.ActionHandler<>(DeleteQueryGroupAction.INSTANCE, TransportDeleteQueryGroupAction.class)
5056
);
5157
}
5258

@@ -60,11 +66,16 @@ public List<RestHandler> getRestHandlers(
6066
IndexNameExpressionResolver indexNameExpressionResolver,
6167
Supplier<DiscoveryNodes> nodesInCluster
6268
) {
63-
return List.of(new RestCreateQueryGroupAction(), new RestGetQueryGroupAction());
69+
return List.of(new RestCreateQueryGroupAction(), new RestGetQueryGroupAction(), new RestDeleteQueryGroupAction());
6470
}
6571

6672
@Override
6773
public List<Setting<?>> getSettings() {
6874
return List.of(QueryGroupPersistenceService.MAX_QUERY_GROUP_COUNT);
6975
}
76+
77+
@Override
78+
public Collection<Module> createGuiceModules() {
79+
return List.of(new WorkloadManagementPluginModule());
80+
}
7081
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.wlm;
10+
11+
import org.opensearch.common.inject.AbstractModule;
12+
import org.opensearch.common.inject.Singleton;
13+
import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService;
14+
15+
/**
16+
* Guice Module to manage WorkloadManagement related objects
17+
*/
18+
public class WorkloadManagementPluginModule extends AbstractModule {
19+
20+
/**
21+
* Constructor for WorkloadManagementPluginModule
22+
*/
23+
public WorkloadManagementPluginModule() {}
24+
25+
@Override
26+
protected void configure() {
27+
// Bind QueryGroupPersistenceService as a singleton to ensure a single instance is used,
28+
// preventing multiple throttling key registrations in the constructor.
29+
bind(QueryGroupPersistenceService.class).in(Singleton.class);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.wlm.action;
10+
11+
import org.opensearch.action.ActionType;
12+
import org.opensearch.action.support.master.AcknowledgedResponse;
13+
14+
/**
15+
* Transport action for delete QueryGroup
16+
*
17+
* @opensearch.experimental
18+
*/
19+
public class DeleteQueryGroupAction extends ActionType<AcknowledgedResponse> {
20+
21+
/**
22+
/**
23+
* An instance of DeleteQueryGroupAction
24+
*/
25+
public static final DeleteQueryGroupAction INSTANCE = new DeleteQueryGroupAction();
26+
27+
/**
28+
* Name for DeleteQueryGroupAction
29+
*/
30+
public static final String NAME = "cluster:admin/opensearch/wlm/query_group/_delete";
31+
32+
/**
33+
* Default constructor
34+
*/
35+
private DeleteQueryGroupAction() {
36+
super(NAME, AcknowledgedResponse::new);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.wlm.action;
10+
11+
import org.opensearch.action.ActionRequestValidationException;
12+
import org.opensearch.action.support.master.AcknowledgedRequest;
13+
import org.opensearch.core.common.io.stream.StreamInput;
14+
import org.opensearch.core.common.io.stream.StreamOutput;
15+
16+
import java.io.IOException;
17+
18+
/**
19+
* Request for delete QueryGroup
20+
*
21+
* @opensearch.experimental
22+
*/
23+
public class DeleteQueryGroupRequest extends AcknowledgedRequest<DeleteQueryGroupRequest> {
24+
private final String name;
25+
26+
/**
27+
* Default constructor for DeleteQueryGroupRequest
28+
* @param name - name for the QueryGroup to get
29+
*/
30+
public DeleteQueryGroupRequest(String name) {
31+
this.name = name;
32+
}
33+
34+
/**
35+
* Constructor for DeleteQueryGroupRequest
36+
* @param in - A {@link StreamInput} object
37+
*/
38+
public DeleteQueryGroupRequest(StreamInput in) throws IOException {
39+
super(in);
40+
name = in.readOptionalString();
41+
}
42+
43+
@Override
44+
public ActionRequestValidationException validate() {
45+
if (name == null) {
46+
ActionRequestValidationException actionRequestValidationException = new ActionRequestValidationException();
47+
actionRequestValidationException.addValidationError("QueryGroup name is missing");
48+
return actionRequestValidationException;
49+
}
50+
return null;
51+
}
52+
53+
/**
54+
* Name getter
55+
*/
56+
public String getName() {
57+
return name;
58+
}
59+
60+
@Override
61+
public void writeTo(StreamOutput out) throws IOException {
62+
super.writeTo(out);
63+
out.writeOptionalString(name);
64+
}
65+
}

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/action/TransportCreateQueryGroupAction.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.opensearch.core.action.ActionListener;
1515
import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService;
1616
import org.opensearch.tasks.Task;
17-
import org.opensearch.threadpool.ThreadPool;
1817
import org.opensearch.transport.TransportService;
1918

2019
/**
@@ -24,7 +23,6 @@
2423
*/
2524
public class TransportCreateQueryGroupAction extends HandledTransportAction<CreateQueryGroupRequest, CreateQueryGroupResponse> {
2625

27-
private final ThreadPool threadPool;
2826
private final QueryGroupPersistenceService queryGroupPersistenceService;
2927

3028
/**
@@ -33,25 +31,21 @@ public class TransportCreateQueryGroupAction extends HandledTransportAction<Crea
3331
* @param actionName - action name
3432
* @param transportService - a {@link TransportService} object
3533
* @param actionFilters - a {@link ActionFilters} object
36-
* @param threadPool - a {@link ThreadPool} object
3734
* @param queryGroupPersistenceService - a {@link QueryGroupPersistenceService} object
3835
*/
3936
@Inject
4037
public TransportCreateQueryGroupAction(
4138
String actionName,
4239
TransportService transportService,
4340
ActionFilters actionFilters,
44-
ThreadPool threadPool,
4541
QueryGroupPersistenceService queryGroupPersistenceService
4642
) {
4743
super(CreateQueryGroupAction.NAME, transportService, actionFilters, CreateQueryGroupRequest::new);
48-
this.threadPool = threadPool;
4944
this.queryGroupPersistenceService = queryGroupPersistenceService;
5045
}
5146

5247
@Override
5348
protected void doExecute(Task task, CreateQueryGroupRequest request, ActionListener<CreateQueryGroupResponse> listener) {
54-
threadPool.executor(ThreadPool.Names.SAME)
55-
.execute(() -> queryGroupPersistenceService.persistInClusterStateMetadata(request.getQueryGroup(), listener));
49+
queryGroupPersistenceService.persistInClusterStateMetadata(request.getQueryGroup(), listener);
5650
}
5751
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.wlm.action;
10+
11+
import org.opensearch.action.support.ActionFilters;
12+
import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction;
13+
import org.opensearch.action.support.master.AcknowledgedResponse;
14+
import org.opensearch.cluster.ClusterState;
15+
import org.opensearch.cluster.block.ClusterBlockException;
16+
import org.opensearch.cluster.block.ClusterBlockLevel;
17+
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
18+
import org.opensearch.cluster.service.ClusterService;
19+
import org.opensearch.common.inject.Inject;
20+
import org.opensearch.core.action.ActionListener;
21+
import org.opensearch.core.common.io.stream.StreamInput;
22+
import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService;
23+
import org.opensearch.threadpool.ThreadPool;
24+
import org.opensearch.transport.TransportService;
25+
26+
import java.io.IOException;
27+
28+
/**
29+
* Transport action for delete QueryGroup
30+
*
31+
* @opensearch.experimental
32+
*/
33+
public class TransportDeleteQueryGroupAction extends TransportClusterManagerNodeAction<DeleteQueryGroupRequest, AcknowledgedResponse> {
34+
35+
private final QueryGroupPersistenceService queryGroupPersistenceService;
36+
37+
/**
38+
* Constructor for TransportDeleteQueryGroupAction
39+
*
40+
* @param clusterService - a {@link ClusterService} object
41+
* @param transportService - a {@link TransportService} object
42+
* @param actionFilters - a {@link ActionFilters} object
43+
* @param threadPool - a {@link ThreadPool} object
44+
* @param indexNameExpressionResolver - a {@link IndexNameExpressionResolver} object
45+
* @param queryGroupPersistenceService - a {@link QueryGroupPersistenceService} object
46+
*/
47+
@Inject
48+
public TransportDeleteQueryGroupAction(
49+
ClusterService clusterService,
50+
TransportService transportService,
51+
ActionFilters actionFilters,
52+
ThreadPool threadPool,
53+
IndexNameExpressionResolver indexNameExpressionResolver,
54+
QueryGroupPersistenceService queryGroupPersistenceService
55+
) {
56+
super(
57+
DeleteQueryGroupAction.NAME,
58+
transportService,
59+
clusterService,
60+
threadPool,
61+
actionFilters,
62+
DeleteQueryGroupRequest::new,
63+
indexNameExpressionResolver
64+
);
65+
this.queryGroupPersistenceService = queryGroupPersistenceService;
66+
}
67+
68+
@Override
69+
protected void clusterManagerOperation(
70+
DeleteQueryGroupRequest request,
71+
ClusterState state,
72+
ActionListener<AcknowledgedResponse> listener
73+
) throws Exception {
74+
queryGroupPersistenceService.deleteInClusterStateMetadata(request, listener);
75+
}
76+
77+
@Override
78+
protected String executor() {
79+
return ThreadPool.Names.SAME;
80+
}
81+
82+
@Override
83+
protected AcknowledgedResponse read(StreamInput in) throws IOException {
84+
return new AcknowledgedResponse(in);
85+
}
86+
87+
@Override
88+
protected ClusterBlockException checkBlock(DeleteQueryGroupRequest request, ClusterState state) {
89+
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.wlm.rest;
10+
11+
import org.opensearch.client.node.NodeClient;
12+
import org.opensearch.plugin.wlm.action.DeleteQueryGroupAction;
13+
import org.opensearch.plugin.wlm.action.DeleteQueryGroupRequest;
14+
import org.opensearch.rest.BaseRestHandler;
15+
import org.opensearch.rest.RestRequest;
16+
import org.opensearch.rest.action.RestToXContentListener;
17+
18+
import java.io.IOException;
19+
import java.util.List;
20+
21+
import static org.opensearch.rest.RestRequest.Method.DELETE;
22+
23+
/**
24+
* Rest action to delete a QueryGroup
25+
*
26+
* @opensearch.experimental
27+
*/
28+
public class RestDeleteQueryGroupAction extends BaseRestHandler {
29+
30+
/**
31+
* Constructor for RestDeleteQueryGroupAction
32+
*/
33+
public RestDeleteQueryGroupAction() {}
34+
35+
@Override
36+
public String getName() {
37+
return "delete_query_group";
38+
}
39+
40+
/**
41+
* The list of {@link Route}s that this RestHandler is responsible for handling.
42+
*/
43+
@Override
44+
public List<Route> routes() {
45+
return List.of(new Route(DELETE, "_wlm/query_group/{name}"));
46+
}
47+
48+
@Override
49+
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
50+
DeleteQueryGroupRequest deleteQueryGroupRequest = new DeleteQueryGroupRequest(request.param("name"));
51+
deleteQueryGroupRequest.clusterManagerNodeTimeout(
52+
request.paramAsTime("cluster_manager_timeout", deleteQueryGroupRequest.clusterManagerNodeTimeout())
53+
);
54+
deleteQueryGroupRequest.timeout(request.paramAsTime("timeout", deleteQueryGroupRequest.timeout()));
55+
return channel -> client.execute(DeleteQueryGroupAction.INSTANCE, deleteQueryGroupRequest, new RestToXContentListener<>(channel));
56+
}
57+
}

0 commit comments

Comments
 (0)