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 c6844a6 commit 28f0f6e
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 @@ -34,6 +35,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 @@ -241,6 +243,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 249 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#L247-L249

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

0 comments on commit 28f0f6e

Please sign in to comment.