Skip to content

Commit aa293e9

Browse files
committed
Add Delete QueryGroup API Logic
Signed-off-by: Ruirui Zhang <[email protected]>
1 parent a04cf24 commit aa293e9

22 files changed

+1221
-7
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
opensearchplugin {
13+
description 'OpenSearch Workload Management Plugin.'
14+
classname 'org.opensearch.plugin.wlm.action.WorkloadManagementPlugin'
15+
}
16+
17+
dependencies {
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
13+
/**
14+
* Transport action for delete QueryGroup
15+
*
16+
* @opensearch.api
17+
*/
18+
public class DeleteQueryGroupAction extends ActionType<DeleteQueryGroupResponse> {
19+
20+
/**
21+
/**
22+
* An instance of DeleteQueryGroupAction
23+
*/
24+
public static final DeleteQueryGroupAction INSTANCE = new DeleteQueryGroupAction();
25+
26+
/**
27+
* Name for DeleteQueryGroupAction
28+
*/
29+
public static final String NAME = "cluster:admin/opensearch/wlm/query_group/_delete";
30+
31+
/**
32+
* Default constructor
33+
*/
34+
private DeleteQueryGroupAction() {
35+
super(NAME, DeleteQueryGroupResponse::new);
36+
}
37+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.ActionRequest;
12+
import org.opensearch.action.ActionRequestValidationException;
13+
import org.opensearch.core.common.io.stream.StreamInput;
14+
import org.opensearch.core.common.io.stream.StreamOutput;
15+
import org.opensearch.core.common.io.stream.Writeable;
16+
17+
import java.io.IOException;
18+
19+
/**
20+
* A request for delete QueryGroup
21+
*
22+
* @opensearch.internal
23+
*/
24+
public class DeleteQueryGroupRequest extends ActionRequest implements Writeable.Reader<DeleteQueryGroupRequest> {
25+
String name;
26+
27+
/**
28+
* Default constructor for DeleteQueryGroupRequest
29+
* @param name - name for the QueryGroup to get
30+
*/
31+
public DeleteQueryGroupRequest(String name) {
32+
this.name = name;
33+
}
34+
35+
/**
36+
* Constructor for DeleteQueryGroupRequest
37+
* @param in - A {@link StreamInput} object
38+
*/
39+
public DeleteQueryGroupRequest(StreamInput in) throws IOException {
40+
super(in);
41+
name = in.readOptionalString();
42+
}
43+
44+
@Override
45+
public DeleteQueryGroupRequest read(StreamInput in) throws IOException {
46+
return new DeleteQueryGroupRequest(in);
47+
}
48+
49+
@Override
50+
public ActionRequestValidationException validate() {
51+
return null;
52+
}
53+
54+
/**
55+
* Name getter
56+
*/
57+
public String getName() {
58+
return name;
59+
}
60+
61+
/**
62+
* Name setter
63+
* @param name - name to be set
64+
*/
65+
public void setName(String name) {
66+
this.name = name;
67+
}
68+
69+
@Override
70+
public void writeTo(StreamOutput out) throws IOException {
71+
super.writeTo(out);
72+
out.writeOptionalString(name);
73+
}
74+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.cluster.metadata.QueryGroup;
12+
import org.opensearch.core.action.ActionResponse;
13+
import org.opensearch.core.common.io.stream.StreamInput;
14+
import org.opensearch.core.common.io.stream.StreamOutput;
15+
import org.opensearch.core.rest.RestStatus;
16+
import org.opensearch.core.xcontent.ToXContent;
17+
import org.opensearch.core.xcontent.ToXContentObject;
18+
import org.opensearch.core.xcontent.XContentBuilder;
19+
20+
import java.io.IOException;
21+
import java.util.List;
22+
23+
/**
24+
* Response for the delete API for QueryGroup
25+
*
26+
* @opensearch.internal
27+
*/
28+
public class DeleteQueryGroupResponse extends ActionResponse implements ToXContent, ToXContentObject {
29+
private final List<QueryGroup> queryGroups;
30+
private RestStatus restStatus;
31+
32+
/**
33+
* Constructor for DeleteQueryGroupResponse
34+
* @param queryGroups - The QueryGroup list to be fetched
35+
* @param restStatus - The rest status for this response
36+
*/
37+
public DeleteQueryGroupResponse(final List<QueryGroup> queryGroups, RestStatus restStatus) {
38+
this.queryGroups = queryGroups;
39+
this.restStatus = restStatus;
40+
}
41+
42+
/**
43+
* Constructor for DeleteQueryGroupResponse
44+
* @param in - A {@link StreamInput} object
45+
*/
46+
public DeleteQueryGroupResponse(StreamInput in) throws IOException {
47+
this.queryGroups = in.readList(QueryGroup::new);
48+
this.restStatus = RestStatus.readFrom(in);
49+
}
50+
51+
@Override
52+
public void writeTo(StreamOutput out) throws IOException {
53+
out.writeList(queryGroups);
54+
RestStatus.writeTo(out, restStatus);
55+
}
56+
57+
@Override
58+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
59+
builder.startObject();
60+
builder.startArray("deleted");
61+
for (QueryGroup group : queryGroups) {
62+
group.toXContent(builder, params);
63+
}
64+
builder.endArray();
65+
builder.endObject();
66+
return builder;
67+
}
68+
69+
/**
70+
* queryGroups getter
71+
*/
72+
public List<QueryGroup> getQueryGroups() {
73+
return queryGroups;
74+
}
75+
76+
/**
77+
* restStatus getter
78+
*/
79+
public RestStatus getRestStatus() {
80+
return restStatus;
81+
}
82+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.HandledTransportAction;
13+
import org.opensearch.cluster.metadata.QueryGroup;
14+
import org.opensearch.common.inject.Inject;
15+
import org.opensearch.core.action.ActionListener;
16+
import org.opensearch.plugin.wlm.action.service.Persistable;
17+
import org.opensearch.tasks.Task;
18+
import org.opensearch.threadpool.ThreadPool;
19+
import org.opensearch.transport.TransportService;
20+
21+
/**
22+
* Transport action for delete QueryGroup
23+
*
24+
* @opensearch.internal
25+
*/
26+
public class TransportDeleteQueryGroupAction extends HandledTransportAction<DeleteQueryGroupRequest, DeleteQueryGroupResponse> {
27+
28+
private final ThreadPool threadPool;
29+
private final Persistable<QueryGroup> queryGroupPersistenceService;
30+
31+
/**
32+
* Constructor for TransportDeleteQueryGroupAction
33+
*
34+
* @param actionName - action name
35+
* @param transportService - a {@link TransportService} object
36+
* @param actionFilters - a {@link ActionFilters} object
37+
* @param threadPool - a {@link ThreadPool} object
38+
* @param queryGroupPersistenceService - a {@link Persistable} object
39+
*/
40+
@Inject
41+
public TransportDeleteQueryGroupAction(
42+
String actionName,
43+
TransportService transportService,
44+
ActionFilters actionFilters,
45+
ThreadPool threadPool,
46+
Persistable<QueryGroup> queryGroupPersistenceService
47+
) {
48+
super(DeleteQueryGroupAction.NAME, transportService, actionFilters, DeleteQueryGroupRequest::new);
49+
this.threadPool = threadPool;
50+
this.queryGroupPersistenceService = queryGroupPersistenceService;
51+
}
52+
53+
@Override
54+
protected void doExecute(Task task, DeleteQueryGroupRequest request, ActionListener<DeleteQueryGroupResponse> listener) {
55+
String name = request.getName();
56+
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> queryGroupPersistenceService.delete(name, listener));
57+
}
58+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.ActionRequest;
12+
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
13+
import org.opensearch.cluster.node.DiscoveryNodes;
14+
import org.opensearch.common.inject.Module;
15+
import org.opensearch.common.settings.ClusterSettings;
16+
import org.opensearch.common.settings.IndexScopedSettings;
17+
import org.opensearch.common.settings.Settings;
18+
import org.opensearch.common.settings.SettingsFilter;
19+
import org.opensearch.core.action.ActionResponse;
20+
import org.opensearch.plugin.wlm.action.rest.RestDeleteQueryGroupAction;
21+
import org.opensearch.plugins.ActionPlugin;
22+
import org.opensearch.plugins.Plugin;
23+
import org.opensearch.rest.RestController;
24+
import org.opensearch.rest.RestHandler;
25+
26+
import java.util.Collection;
27+
import java.util.List;
28+
import java.util.function.Supplier;
29+
30+
/**
31+
* Plugin class for WorkloadManagement
32+
*/
33+
public class WorkloadManagementPlugin extends Plugin implements ActionPlugin {
34+
35+
/**
36+
* Default constructor
37+
*/
38+
public WorkloadManagementPlugin() {}
39+
40+
@Override
41+
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
42+
return List.of(new ActionPlugin.ActionHandler<>(DeleteQueryGroupAction.INSTANCE, TransportDeleteQueryGroupAction.class));
43+
}
44+
45+
@Override
46+
public List<RestHandler> getRestHandlers(
47+
Settings settings,
48+
RestController restController,
49+
ClusterSettings clusterSettings,
50+
IndexScopedSettings indexScopedSettings,
51+
SettingsFilter settingsFilter,
52+
IndexNameExpressionResolver indexNameExpressionResolver,
53+
Supplier<DiscoveryNodes> nodesInCluster
54+
) {
55+
return List.of(new RestDeleteQueryGroupAction());
56+
}
57+
58+
@Override
59+
public Collection<Module> createGuiceModules() {
60+
return List.of(new WorkloadManagementPluginModule());
61+
}
62+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.cluster.metadata.QueryGroup;
12+
import org.opensearch.common.inject.AbstractModule;
13+
import org.opensearch.common.inject.TypeLiteral;
14+
import org.opensearch.plugin.wlm.action.service.Persistable;
15+
import org.opensearch.plugin.wlm.action.service.QueryGroupPersistenceService;
16+
17+
/**
18+
* Guice Module to manage WorkloadManagement related objects
19+
*/
20+
public class WorkloadManagementPluginModule extends AbstractModule {
21+
22+
/**
23+
* Constructor for WorkloadManagementPluginModule
24+
*/
25+
public WorkloadManagementPluginModule() {}
26+
27+
@Override
28+
protected void configure() {
29+
bind(new TypeLiteral<Persistable<QueryGroup>>() {
30+
}).to(QueryGroupPersistenceService.class).asEagerSingleton();
31+
}
32+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
/**
10+
* Base Package of CRUD API of QueryGroup
11+
*/
12+
package org.opensearch.plugin.wlm.action;

0 commit comments

Comments
 (0)