-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
17 changed files
with
636 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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
31 changes: 31 additions & 0 deletions
31
...ad-management/src/main/java/org/opensearch/plugin/wlm/WorkloadManagementPluginModule.java
This file contains 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,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() {} | ||
|
||
@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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...oad-management/src/main/java/org/opensearch/plugin/wlm/action/DeleteQueryGroupAction.java
This file contains 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,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); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ad-management/src/main/java/org/opensearch/plugin/wlm/action/DeleteQueryGroupRequest.java
This file contains 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,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; | ||
} | ||
|
||
/** | ||
* Name getter | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalString(name); | ||
} | ||
} |
This file contains 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
91 changes: 91 additions & 0 deletions
91
...ement/src/main/java/org/opensearch/plugin/wlm/action/TransportDeleteQueryGroupAction.java
This file contains 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,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); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(DeleteQueryGroupRequest request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...d-management/src/main/java/org/opensearch/plugin/wlm/rest/RestDeleteQueryGroupAction.java
This file contains 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.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)); | ||
} | ||
} |
Oops, something went wrong.