Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
Anshu Agarwal committed Oct 6, 2022
1 parent 56fe6af commit e8cda62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ClusterDeleteWeightedRoutingResponse extends AcknowledgedResponse {
super(in);
}

ClusterDeleteWeightedRoutingResponse(boolean acknowledged) {
public ClusterDeleteWeightedRoutingResponse(boolean acknowledged) {
super(acknowledged);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ protected void clusterManagerOperation(
ClusterState state,
ActionListener<ClusterDeleteWeightedRoutingResponse> listener
) throws Exception {
weightedRoutingService.deleteWeightedRoutingMetadata(
request,
ActionListener.delegateFailure(
listener,
(delegatedListener, response) -> {
delegatedListener.onResponse(new ClusterDeleteWeightedRoutingResponse(response.isAcknowledged()));
}
)
);
weightedRoutingService.deleteWeightedRoutingMetadata(request, listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opensearch.action.ActionListener;
import org.opensearch.action.admin.cluster.shards.routing.weighted.delete.ClusterDeleteWeightedRoutingRequest;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.admin.cluster.shards.routing.weighted.delete.ClusterDeleteWeightedRoutingResponse;
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingRequest;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.ClusterStateUpdateTask;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void onFailure(String source, Exception e) {
@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
logger.debug("cluster weighted routing weights metadata change is processed by all the nodes");
listener.onResponse(new ClusterStateUpdateResponse(true));
listener.onResponse(new ClusterDeleteWeightedRoutingResponse(true));
}
});
}
Expand All @@ -109,7 +110,7 @@ private boolean checkIfSameWeightsInMetadata(

public void deleteWeightedRoutingMetadata(
final ClusterDeleteWeightedRoutingRequest request,
final ActionListener<ClusterStateUpdateResponse> listener
final ActionListener<ClusterDeleteWeightedRoutingResponse> listener
) {
clusterService.submitStateUpdateTask("delete_weighted_routing", new ClusterStateUpdateTask(Priority.URGENT) {
@Override
Expand All @@ -122,15 +123,20 @@ public ClusterState execute(ClusterState currentState) {

@Override
public void onFailure(String source, Exception e) {
logger.warn(() -> new ParameterizedMessage("failed to remove weighted routing metadata from cluster state [{}]", e));
logger.error(
() -> new ParameterizedMessage(
"failed to remove weighted routing metadata from cluster state with an exception [{}]",
e
)
);
listener.onFailure(e);
}

@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
logger.debug("cluster weighted routing metadata change is processed by all the nodes");
assert newState.metadata().weightedRoutingMetadata() == null;
listener.onResponse(new ClusterStateUpdateResponse(true));
listener.onResponse(new ClusterDeleteWeightedRoutingResponse(true));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opensearch.action.ActionListener;
import org.opensearch.action.admin.cluster.shards.routing.weighted.delete.ClusterDeleteWeightedRoutingRequest;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.admin.cluster.shards.routing.weighted.delete.ClusterDeleteWeightedRoutingResponse;
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterAddWeightedRoutingAction;
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingRequestBuilder;
import org.opensearch.client.node.NodeClient;
Expand Down Expand Up @@ -243,10 +244,10 @@ public void testDeleteWeightedRoutingMetadata() throws InterruptedException {

ClusterDeleteWeightedRoutingRequest clusterDeleteWeightedRoutingRequest = new ClusterDeleteWeightedRoutingRequest();
final CountDownLatch countDownLatch = new CountDownLatch(1);
ActionListener<ClusterStateUpdateResponse> listener = new ActionListener<ClusterStateUpdateResponse>() {
ActionListener<ClusterDeleteWeightedRoutingResponse> listener = new ActionListener<ClusterDeleteWeightedRoutingResponse>() {
@Override
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
assertTrue(clusterStateUpdateResponse.isAcknowledged());
public void onResponse(ClusterDeleteWeightedRoutingResponse clusterDeleteWeightedRoutingResponse) {
assertTrue(clusterDeleteWeightedRoutingResponse.isAcknowledged());
assertNull(clusterService.state().metadata().weightedRoutingMetadata());
countDownLatch.countDown();
}
Expand Down

0 comments on commit e8cda62

Please sign in to comment.