Skip to content

Commit

Permalink
Delete API for weighted round robin search routing
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <anshukag@amazon.com>
  • Loading branch information
Anshu Agarwal committed Sep 3, 2022
1 parent 97b2931 commit 8ce5255
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import org.opensearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsAction;
import org.opensearch.action.admin.cluster.shards.TransportClusterSearchShardsAction;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsAction;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.TransportDeleteWRRWeightsAction;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsAction;
import org.opensearch.action.admin.cluster.shards.routing.wrr.put.ClusterPutWRRWeightsAction;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.TransportGetWRRWeightsAction;
Expand Down Expand Up @@ -298,6 +300,7 @@
import org.opensearch.rest.action.admin.cluster.RestClearVotingConfigExclusionsAction;
import org.opensearch.rest.action.admin.cluster.RestCloneSnapshotAction;
import org.opensearch.rest.action.admin.cluster.RestClusterAllocationExplainAction;
import org.opensearch.rest.action.admin.cluster.RestClusterDeleteWRRWeightsAction;
import org.opensearch.rest.action.admin.cluster.RestClusterGetSettingsAction;
import org.opensearch.rest.action.admin.cluster.RestClusterGetWRRWeightsAction;
import org.opensearch.rest.action.admin.cluster.RestClusterHealthAction;
Expand Down Expand Up @@ -571,6 +574,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(SnapshotsStatusAction.INSTANCE, TransportSnapshotsStatusAction.class);
actions.register(ClusterPutWRRWeightsAction.INSTANCE, TransportPutWRRWeightsAction.class);
actions.register(ClusterGetWRRWeightsAction.INSTANCE, TransportGetWRRWeightsAction.class);
actions.register(ClusterDeleteWRRWeightsAction.INSTANCE, TransportDeleteWRRWeightsAction.class);
actions.register(IndicesStatsAction.INSTANCE, TransportIndicesStatsAction.class);
actions.register(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class);
actions.register(IndicesShardStoresAction.INSTANCE, TransportIndicesShardStoresAction.class);
Expand Down Expand Up @@ -755,6 +759,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestAddIndexBlockAction());
registerHandler.accept(new RestClusterPutWRRWeightsAction());
registerHandler.accept(new RestClusterGetWRRWeightsAction());
registerHandler.accept(new RestClusterDeleteWRRWeightsAction());

registerHandler.accept(new RestUpdateSettingsAction());
registerHandler.accept(new RestGetSettingsAction());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.action.admin.cluster.shards.routing.wrr.delete;

import org.opensearch.action.ActionType;

/**
* Action to delete weights for weighted round-robin shard routing policy.
*
* @opensearch.internal
*/
public class ClusterDeleteWRRWeightsAction extends ActionType<ClusterDeleteWRRWeightsResponse> {
public static final ClusterDeleteWRRWeightsAction INSTANCE = new ClusterDeleteWRRWeightsAction();
public static final String NAME = "cluster:admin/routing/awareness/weights/delete";

private ClusterDeleteWRRWeightsAction() {
super(NAME, ClusterDeleteWRRWeightsResponse::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.action.admin.cluster.shards.routing.wrr.delete;

import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;

import java.io.IOException;

/**
* Request to delete weights for weighted round-robin shard routing policy.
*
* @opensearch.internal
*/
public class ClusterDeleteWRRWeightsRequest extends ClusterManagerNodeRequest<ClusterDeleteWRRWeightsRequest> {
public ClusterDeleteWRRWeightsRequest() {
}

public ClusterDeleteWRRWeightsRequest(StreamInput in) throws IOException {
super(in);
}

@Override
public ActionRequestValidationException validate() {
return null;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
}

@Override
public String toString() {
return "ClusterDeleteWRRWeightsRequest";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.action.admin.cluster.shards.routing.wrr.delete;

import org.opensearch.action.support.clustermanager.ClusterManagerNodeOperationRequestBuilder;
import org.opensearch.client.OpenSearchClient;

/**
* Request builder to delete weights for weighted round-robin shard routing policy.
*
* @opensearch.internal
*/
public class ClusterDeleteWRRWeightsRequestBuilder extends ClusterManagerNodeOperationRequestBuilder<
ClusterDeleteWRRWeightsRequest,
ClusterDeleteWRRWeightsResponse,
ClusterDeleteWRRWeightsRequestBuilder> {

public ClusterDeleteWRRWeightsRequestBuilder(OpenSearchClient client, ClusterDeleteWRRWeightsAction action) {
super(client, action, new ClusterDeleteWRRWeightsRequest());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.action.admin.cluster.shards.routing.wrr.delete;

import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.ToXContentObject;

import java.io.IOException;

/**
* Response from deleting weights for weighted round-robin search routing policy.
*
* @opensearch.internal
*/
public class ClusterDeleteWRRWeightsResponse extends AcknowledgedResponse implements ToXContentObject {
ClusterDeleteWRRWeightsResponse(StreamInput in) throws IOException {
super(in);
}

ClusterDeleteWRRWeightsResponse(boolean acknowledged) {
super(acknowledged);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.action.admin.cluster.shards.routing.wrr.delete;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.action.ActionListener;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.block.ClusterBlockException;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.routing.WRRShardRoutingService;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.TransportService;

import java.io.IOException;

/**
* Transport action for deleting weights for weighted round-robin search routing policy
*
* @opensearch.internal
*/
public class TransportDeleteWRRWeightsAction extends TransportClusterManagerNodeAction<
ClusterDeleteWRRWeightsRequest,
ClusterDeleteWRRWeightsResponse> {

private static final Logger logger = LogManager.getLogger(TransportDeleteWRRWeightsAction.class);

private final WRRShardRoutingService wrrShardRoutingService;

@Inject
public TransportDeleteWRRWeightsAction(
TransportService transportService,
ClusterService clusterService,
WRRShardRoutingService wrrShardRoutingService,
ThreadPool threadPool,
ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver
) {
super(
ClusterDeleteWRRWeightsAction.NAME,
transportService,
clusterService,
threadPool,
actionFilters,
ClusterDeleteWRRWeightsRequest::new,
indexNameExpressionResolver
);
this.wrrShardRoutingService = wrrShardRoutingService;
}

@Override
protected String executor() {
return ThreadPool.Names.SAME;
}

@Override
protected ClusterDeleteWRRWeightsResponse read(StreamInput in) throws IOException {
return new ClusterDeleteWRRWeightsResponse(in);
}

@Override
protected ClusterBlockException checkBlock(ClusterDeleteWRRWeightsRequest request, ClusterState state) {
return null;
}

@Override
protected void clusterManagerOperation(
ClusterDeleteWRRWeightsRequest request,
ClusterState state,
ActionListener<ClusterDeleteWRRWeightsResponse> listener
) throws Exception {
wrrShardRoutingService.deleteWRRWeightsMetadata(
request,
ActionListener.delegateFailure(
listener,
(delegatedListener, response) -> {
delegatedListener.onResponse(new ClusterDeleteWRRWeightsResponse(response.isAcknowledged()));
}
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

/** delete weighted-round robin shard routing weights. */
package org.opensearch.action.admin.cluster.shards.routing.wrr.delete;
18 changes: 18 additions & 0 deletions server/src/main/java/org/opensearch/client/ClusterAdminClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsRequest;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsRequest;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsRequestBuilder;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsResponse;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsRequest;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsRequestBuilder;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsResponse;
Expand Down Expand Up @@ -822,4 +825,19 @@ public interface ClusterAdminClient extends OpenSearchClient {
* Gets weights for weighted round-robin search routing policy.
*/
ClusterGetWRRWeightsRequestBuilder prepareGetWRRWeights();

/**
* Deletes weights for weighted round-robin search routing policy.
*/
ActionFuture<ClusterDeleteWRRWeightsResponse> deleteWRRWeights(ClusterDeleteWRRWeightsRequest request);

/**
* Deletes weights for weighted round-robin search routing policy.
*/
void deleteWRRWeights(ClusterDeleteWRRWeightsRequest request, ActionListener<ClusterDeleteWRRWeightsResponse> listener);

/**
* Deletes weights for weighted round-robin search routing policy.
*/
ClusterDeleteWRRWeightsRequestBuilder prepareDeleteWRRWeights();
}
10 changes: 10 additions & 0 deletions server/src/main/java/org/opensearch/client/Requests.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.action.admin.cluster.reroute.ClusterRerouteRequest;
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsRequest;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsRequest;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsRequest;
import org.opensearch.action.admin.cluster.shards.routing.wrr.put.ClusterPutWRRWeightsRequest;
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
Expand Down Expand Up @@ -568,4 +569,13 @@ public static ClusterPutWRRWeightsRequest putWRRWeightsRequest() {
public static ClusterGetWRRWeightsRequest getWRRWeightsRequest() {
return new ClusterGetWRRWeightsRequest();
}

/**
* Deletes weights for weighted round-robin search routing policy
*
* @return delete weight request
*/
public static ClusterDeleteWRRWeightsRequest deleteWRRWeightsRequest() {
return new ClusterDeleteWRRWeightsRequest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsRequest;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsAction;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsRequest;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsRequestBuilder;
import org.opensearch.action.admin.cluster.shards.routing.wrr.delete.ClusterDeleteWRRWeightsResponse;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsAction;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsRequest;
import org.opensearch.action.admin.cluster.shards.routing.wrr.get.ClusterGetWRRWeightsRequestBuilder;
Expand Down Expand Up @@ -1302,6 +1306,21 @@ public ClusterGetWRRWeightsRequestBuilder prepareGetWRRWeights() {
return new ClusterGetWRRWeightsRequestBuilder(this, ClusterGetWRRWeightsAction.INSTANCE);
}

@Override
public ActionFuture<ClusterDeleteWRRWeightsResponse> deleteWRRWeights(ClusterDeleteWRRWeightsRequest request) {
return execute(ClusterDeleteWRRWeightsAction.INSTANCE, request);
}

@Override
public void deleteWRRWeights(ClusterDeleteWRRWeightsRequest request, ActionListener<ClusterDeleteWRRWeightsResponse> listener) {
execute(ClusterDeleteWRRWeightsAction.INSTANCE, request, listener);
}

@Override
public ClusterDeleteWRRWeightsRequestBuilder prepareDeleteWRRWeights() {
return new ClusterDeleteWRRWeightsRequestBuilder(this, ClusterDeleteWRRWeightsAction.INSTANCE);
}

@Override
public void deleteDanglingIndex(DeleteDanglingIndexRequest request, ActionListener<AcknowledgedResponse> listener) {
execute(DeleteDanglingIndexAction.INSTANCE, request, listener);
Expand Down
Loading

0 comments on commit 8ce5255

Please sign in to comment.