Skip to content

Commit

Permalink
[Bug] Add exists check for IOCs index. (#1392)
Browse files Browse the repository at this point in the history
* Added check to prevent resource_already_exists_exception when indexing more than 10k iocs.

Signed-off-by: AWSHurneyt <[email protected]>

* Changed log message.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>
(cherry picked from commit 4432b36)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Oct 25, 2024
1 parent 286cae3 commit 8e3b50b
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchException;
import org.opensearch.ResourceAlreadyExistsException;
import org.opensearch.action.DocWriteRequest;
import org.opensearch.action.StepListener;
import org.opensearch.action.admin.indices.create.CreateIndexRequest;
Expand All @@ -35,6 +36,7 @@
import org.opensearch.securityanalytics.threatIntel.common.StashedThreadContext;
import org.opensearch.securityanalytics.threatIntel.model.DefaultIocStoreConfig;
import org.opensearch.securityanalytics.threatIntel.model.SATIFSourceConfig;
import org.opensearch.transport.RemoteTransportException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -250,6 +252,11 @@ private void initFeedIndex(String feedIndexName, ActionListener<CreateIndexRespo
listener.onResponse(r);
},
e -> {
if (e instanceof ResourceAlreadyExistsException || (e instanceof RemoteTransportException && e.getCause() instanceof ResourceAlreadyExistsException)) {
log.debug("index {} already exist", feedIndexName);
listener.onResponse(null);
return;

Check warning on line 258 in src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java#L256-L258

Added lines #L256 - L258 were not covered by tests
}
log.error("Failed to create system index {}", feedIndexName);
listener.onFailure(e);
}
Expand Down

0 comments on commit 8e3b50b

Please sign in to comment.