Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fix threat intel multinode tests #1279

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchException;
import org.opensearch.action.DocWriteRequest;
import org.opensearch.action.StepListener;
import org.opensearch.action.admin.indices.create.CreateIndexRequest;
import org.opensearch.action.admin.indices.create.CreateIndexResponse;
import org.opensearch.action.bulk.BulkRequest;
@@ -80,7 +81,6 @@
this.baseListener = listener;
batchSize = clusterService.getClusterSettings().get(SecurityAnalyticsSettings.BATCH_SIZE);
newActiveIndex = getNewActiveIndex(saTifSourceConfig.getId());
initSourceConfigIndexes();
}

@Override
@@ -113,7 +113,15 @@
}

public void indexIocs(List<STIX2IOC> iocs) throws IOException {
bulkIndexIocs(iocs, newActiveIndex);
StepListener<Void> initSourceConfigIndexesListener = new StepListener<>();
initSourceConfigIndexes(initSourceConfigIndexesListener);
initSourceConfigIndexesListener.whenComplete(r -> {
bulkIndexIocs(iocs, newActiveIndex);
}, e -> {
log.error("Failed to init source config indexes");
baseListener.onFailure(e);
});

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

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java#L121-L123

Added lines #L121 - L123 were not covered by tests

}

private void bulkIndexIocs(List<STIX2IOC> iocs, String activeIndex) throws IOException {
@@ -197,7 +205,7 @@
return saTifSourceConfig;
}

private void initSourceConfigIndexes() {
private void initSourceConfigIndexes(StepListener<Void> stepListener) {
String iocIndexPattern = getAllIocIndexPatternById(saTifSourceConfig.getId());
initFeedIndex(newActiveIndex, ActionListener.wrap(
r -> {
@@ -214,10 +222,10 @@
((DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig()).getIocToIndexDetails().add(iocToIndexDetails);
}
});

stepListener.onResponse(null);
}, e-> {
log.error("Failed to initialize the IOC index and save the IOCs", e);
baseListener.onFailure(e);
stepListener.onFailure(e);

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

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java#L228

Added line #L228 was not covered by tests
}
));
}
@@ -237,6 +245,8 @@
listener.onFailure(e);
}
));
} else {
listener.onResponse(null);

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

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java#L249

Added line #L249 was not covered by tests
}
}
}