-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Delete QueryGroup API Logic #14735
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
Changes from all commits
6c0c086
ceaaff5
ce5139e
2fd577a
d2ee6e3
431d510
a48adcd
a64985a
ebb2397
ff9a93e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.common.inject.AbstractModule; | ||
import org.opensearch.common.inject.Singleton; | ||
import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService; | ||
|
||
/** | ||
* Guice Module to manage WorkloadManagement related objects | ||
*/ | ||
public class WorkloadManagementPluginModule extends AbstractModule { | ||
|
||
/** | ||
* Constructor for WorkloadManagementPluginModule | ||
*/ | ||
public WorkloadManagementPluginModule() {} | ||
Check warning on line 23 in plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/WorkloadManagementPluginModule.java
|
||
|
||
@Override | ||
protected void configure() { | ||
// Bind QueryGroupPersistenceService as a singleton to ensure a single instance is used, | ||
// preventing multiple throttling key registrations in the constructor. | ||
bind(QueryGroupPersistenceService.class).in(Singleton.class); | ||
} | ||
Check warning on line 30 in plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/WorkloadManagementPluginModule.java
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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; | ||
import org.opensearch.action.support.master.AcknowledgedResponse; | ||
|
||
/** | ||
* Transport action for delete QueryGroup | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class DeleteQueryGroupAction extends ActionType<AcknowledgedResponse> { | ||
|
||
/** | ||
/** | ||
* An instance of DeleteQueryGroupAction | ||
*/ | ||
public static final DeleteQueryGroupAction INSTANCE = new DeleteQueryGroupAction(); | ||
|
||
/** | ||
* Name for DeleteQueryGroupAction | ||
*/ | ||
public static final String NAME = "cluster:admin/opensearch/wlm/query_group/_delete"; | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
private DeleteQueryGroupAction() { | ||
super(NAME, AcknowledgedResponse::new); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.master.AcknowledgedRequest; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Request for delete QueryGroup | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class DeleteQueryGroupRequest extends AcknowledgedRequest<DeleteQueryGroupRequest> { | ||
private final String name; | ||
|
||
/** | ||
* Default constructor for DeleteQueryGroupRequest | ||
* @param name - name for the QueryGroup to get | ||
*/ | ||
public DeleteQueryGroupRequest(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Constructor for DeleteQueryGroupRequest | ||
* @param in - A {@link StreamInput} object | ||
*/ | ||
public DeleteQueryGroupRequest(StreamInput in) throws IOException { | ||
super(in); | ||
name = in.readOptionalString(); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (name == null) { | ||
ActionRequestValidationException actionRequestValidationException = new ActionRequestValidationException(); | ||
actionRequestValidationException.addValidationError("QueryGroup name is missing"); | ||
return actionRequestValidationException; | ||
} | ||
return null; | ||
Check warning on line 50 in plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/action/DeleteQueryGroupRequest.java
|
||
} | ||
|
||
/** | ||
* Name getter | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalString(name); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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.clustermanager.TransportClusterManagerNodeAction; | ||
import org.opensearch.action.support.master.AcknowledgedResponse; | ||
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.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.plugin.wlm.service.QueryGroupPersistenceService; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Transport action for delete QueryGroup | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class TransportDeleteQueryGroupAction extends TransportClusterManagerNodeAction<DeleteQueryGroupRequest, AcknowledgedResponse> { | ||
|
||
private final QueryGroupPersistenceService queryGroupPersistenceService; | ||
|
||
/** | ||
* Constructor for TransportDeleteQueryGroupAction | ||
* | ||
* @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 | ||
* @param queryGroupPersistenceService - a {@link QueryGroupPersistenceService} object | ||
*/ | ||
@Inject | ||
public TransportDeleteQueryGroupAction( | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
ThreadPool threadPool, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
QueryGroupPersistenceService queryGroupPersistenceService | ||
) { | ||
super( | ||
DeleteQueryGroupAction.NAME, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
DeleteQueryGroupRequest::new, | ||
indexNameExpressionResolver | ||
); | ||
this.queryGroupPersistenceService = queryGroupPersistenceService; | ||
} | ||
|
||
@Override | ||
protected void clusterManagerOperation( | ||
DeleteQueryGroupRequest request, | ||
ClusterState state, | ||
ActionListener<AcknowledgedResponse> listener | ||
) throws Exception { | ||
queryGroupPersistenceService.deleteInClusterStateMetadata(request, listener); | ||
} | ||
|
||
@Override | ||
protected String executor() { | ||
return ThreadPool.Names.SAME; | ||
} | ||
|
||
@Override | ||
protected AcknowledgedResponse read(StreamInput in) throws IOException { | ||
return new AcknowledgedResponse(in); | ||
Check warning on line 84 in plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/action/TransportDeleteQueryGroupAction.java
|
||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(DeleteQueryGroupRequest request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
Check warning on line 89 in plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/action/TransportDeleteQueryGroupAction.java
|
||
} | ||
} |
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.rest; | ||
|
||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.plugin.wlm.action.DeleteQueryGroupAction; | ||
import org.opensearch.plugin.wlm.action.DeleteQueryGroupRequest; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.action.RestToXContentListener; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.opensearch.rest.RestRequest.Method.DELETE; | ||
|
||
/** | ||
* Rest action to delete a QueryGroup | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class RestDeleteQueryGroupAction extends BaseRestHandler { | ||
|
||
/** | ||
* Constructor for RestDeleteQueryGroupAction | ||
*/ | ||
public RestDeleteQueryGroupAction() {} | ||
|
||
@Override | ||
public String getName() { | ||
return "delete_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(DELETE, "_wlm/query_group/{name}")); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
DeleteQueryGroupRequest deleteQueryGroupRequest = new DeleteQueryGroupRequest(request.param("name")); | ||
deleteQueryGroupRequest.clusterManagerNodeTimeout( | ||
request.paramAsTime("cluster_manager_timeout", deleteQueryGroupRequest.clusterManagerNodeTimeout()) | ||
); | ||
deleteQueryGroupRequest.timeout(request.paramAsTime("timeout", deleteQueryGroupRequest.timeout())); | ||
return channel -> client.execute(DeleteQueryGroupAction.INSTANCE, deleteQueryGroupRequest, new RestToXContentListener<>(channel)); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.