|
| 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 | +} |
0 commit comments