|
9 | 9 | package org.opensearch.plugin.wlm.action; |
10 | 10 |
|
11 | 11 | import org.opensearch.action.support.ActionFilters; |
12 | | -import org.opensearch.action.support.HandledTransportAction; |
| 12 | +import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; |
| 13 | +import org.opensearch.cluster.ClusterState; |
| 14 | +import org.opensearch.cluster.block.ClusterBlockException; |
| 15 | +import org.opensearch.cluster.block.ClusterBlockLevel; |
| 16 | +import org.opensearch.cluster.metadata.IndexNameExpressionResolver; |
13 | 17 | import org.opensearch.common.inject.Inject; |
14 | 18 | import org.opensearch.core.action.ActionListener; |
| 19 | +import org.opensearch.core.common.io.stream.StreamInput; |
15 | 20 | import org.opensearch.plugin.wlm.service.QueryGroupPersistenceService; |
16 | | -import org.opensearch.tasks.Task; |
| 21 | +import org.opensearch.threadpool.ThreadPool; |
17 | 22 | import org.opensearch.transport.TransportService; |
18 | 23 |
|
| 24 | +import java.io.IOException; |
| 25 | + |
| 26 | +import static org.opensearch.threadpool.ThreadPool.Names.SAME; |
| 27 | + |
19 | 28 | /** |
20 | 29 | * Transport action to create QueryGroup |
21 | 30 | * |
22 | 31 | * @opensearch.experimental |
23 | 32 | */ |
24 | | -public class TransportCreateQueryGroupAction extends HandledTransportAction<CreateQueryGroupRequest, CreateQueryGroupResponse> { |
| 33 | +public class TransportCreateQueryGroupAction extends TransportClusterManagerNodeAction<CreateQueryGroupRequest, CreateQueryGroupResponse> { |
25 | 34 |
|
26 | 35 | private final QueryGroupPersistenceService queryGroupPersistenceService; |
27 | 36 |
|
28 | 37 | /** |
29 | 38 | * Constructor for TransportCreateQueryGroupAction |
30 | 39 | * |
31 | | - * @param actionName - action name |
| 40 | + * @param threadPool - {@link ThreadPool} object |
32 | 41 | * @param transportService - a {@link TransportService} object |
33 | 42 | * @param actionFilters - a {@link ActionFilters} object |
| 43 | + * @param indexNameExpressionResolver - {@link IndexNameExpressionResolver} object |
34 | 44 | * @param queryGroupPersistenceService - a {@link QueryGroupPersistenceService} object |
35 | 45 | */ |
36 | 46 | @Inject |
37 | 47 | public TransportCreateQueryGroupAction( |
38 | | - String actionName, |
| 48 | + ThreadPool threadPool, |
39 | 49 | TransportService transportService, |
40 | 50 | ActionFilters actionFilters, |
| 51 | + IndexNameExpressionResolver indexNameExpressionResolver, |
41 | 52 | QueryGroupPersistenceService queryGroupPersistenceService |
42 | 53 | ) { |
43 | | - super(CreateQueryGroupAction.NAME, transportService, actionFilters, CreateQueryGroupRequest::new); |
| 54 | + super( |
| 55 | + CreateQueryGroupAction.NAME, |
| 56 | + transportService, |
| 57 | + queryGroupPersistenceService.getClusterService(), |
| 58 | + threadPool, |
| 59 | + actionFilters, |
| 60 | + CreateQueryGroupRequest::new, |
| 61 | + indexNameExpressionResolver |
| 62 | + ); |
44 | 63 | this.queryGroupPersistenceService = queryGroupPersistenceService; |
45 | 64 | } |
46 | 65 |
|
47 | 66 | @Override |
48 | | - protected void doExecute(Task task, CreateQueryGroupRequest request, ActionListener<CreateQueryGroupResponse> listener) { |
| 67 | + protected void clusterManagerOperation( |
| 68 | + CreateQueryGroupRequest request, |
| 69 | + ClusterState clusterState, |
| 70 | + ActionListener<CreateQueryGroupResponse> listener |
| 71 | + ) { |
49 | 72 | queryGroupPersistenceService.persistInClusterStateMetadata(request.getQueryGroup(), listener); |
50 | 73 | } |
| 74 | + |
| 75 | + @Override |
| 76 | + protected String executor() { |
| 77 | + return SAME; |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + protected CreateQueryGroupResponse read(StreamInput in) throws IOException { |
| 82 | + return new CreateQueryGroupResponse(in); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + protected ClusterBlockException checkBlock(CreateQueryGroupRequest request, ClusterState state) { |
| 87 | + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); |
| 88 | + } |
| 89 | + |
51 | 90 | } |
0 commit comments