From 905bce270985e5737510a05b9d30c4df39d63edf Mon Sep 17 00:00:00 2001 From: Bharathwaj G Date: Wed, 31 Aug 2022 10:59:28 +0530 Subject: [PATCH] addressing review comment Signed-off-by: Bharathwaj G --- .../action/search/GetAllPitNodesResponse.java | 16 +++++++++++----- .../action/search/TransportDeletePitAction.java | 7 ++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/search/GetAllPitNodesResponse.java b/server/src/main/java/org/opensearch/action/search/GetAllPitNodesResponse.java index 98feb4a30f764..209591fcb2989 100644 --- a/server/src/main/java/org/opensearch/action/search/GetAllPitNodesResponse.java +++ b/server/src/main/java/org/opensearch/action/search/GetAllPitNodesResponse.java @@ -52,6 +52,17 @@ public GetAllPitNodesResponse( ); } + /** + * Copy constructor that explicitly sets the list pit infos + */ + public GetAllPitNodesResponse( + List listPitInfos, + GetAllPitNodesResponse response + ) { + super(response.getClusterName(), response.getNodes(), response.failures()); + pitInfos.addAll(listPitInfos); + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); @@ -77,9 +88,4 @@ public void writeNodesTo(StreamOutput out, List nodes) th public List getPitInfos() { return Collections.unmodifiableList(new ArrayList<>(pitInfos)); } - - public void clearAndSetPitInfos(List listPitInfos) { - pitInfos.clear(); - pitInfos.addAll(listPitInfos); - } } diff --git a/server/src/main/java/org/opensearch/action/search/TransportDeletePitAction.java b/server/src/main/java/org/opensearch/action/search/TransportDeletePitAction.java index f9e36c479dd54..f9ee714408d22 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportDeletePitAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportDeletePitAction.java @@ -57,7 +57,12 @@ public TransportDeletePitAction( @Override protected void doExecute(Task task, DeletePitRequest request, ActionListener listener) { List pitIds = request.getPitIds(); - if (pitIds.size() == 1 && "_all".equals(pitIds.get(0))) { + // when security plugin intercepts the request, if PITs are empty in the cluster the PIT IDs in request will be empty + // and in this case return empty response + if(pitIds.isEmpty()) { + listener.onResponse(new DeletePitResponse(new ArrayList<>())); + } + else if (pitIds.size() == 1 && "_all".equals(pitIds.get(0))) { deleteAllPits(listener); } else { deletePits(listener, request);