55package org .opensearch .securityanalytics .findings ;
66
77import java .util .ArrayList ;
8- import java .util .Collection ;
98import java .util .HashMap ;
109import java .util .List ;
1110import java .util .Map ;
1413import org .apache .logging .log4j .Logger ;
1514import org .opensearch .OpenSearchStatusException ;
1615import org .opensearch .action .ActionListener ;
17- import org .opensearch .action .support .GroupedActionListener ;
1816import org .opensearch .client .Client ;
1917import org .opensearch .client .node .NodeClient ;
2018import org .opensearch .commons .alerting .AlertingPluginInterface ;
@@ -60,17 +58,15 @@ public void onResponse(GetDetectorResponse getDetectorResponse) {
6058 // Get all monitor ids from detector
6159 Detector detector = getDetectorResponse .getDetector ();
6260 List <String > monitorIds = detector .getMonitorIds ();
63- // Using GroupedActionListener here as we're going to issue one GetFindingsActions for each monitorId
64- ActionListener <GetFindingsResponse > multiGetFindingsListener = new GroupedActionListener <>(new ActionListener <>() {
61+ ActionListener <GetFindingsResponse > getFindingsResponseListener = new ActionListener <>() {
6562 @ Override
66- public void onResponse (Collection < GetFindingsResponse > responses ) {
63+ public void onResponse (GetFindingsResponse resp ) {
6764 Integer totalFindings = 0 ;
6865 List <FindingDto > findings = new ArrayList <>();
6966 // Merge all findings into one response
70- for (GetFindingsResponse resp : responses ) {
71- totalFindings += resp .getTotalFindings ();
72- findings .addAll (resp .getFindings ());
73- }
67+ totalFindings += resp .getTotalFindings ();
68+ findings .addAll (resp .getFindings ());
69+
7470 GetFindingsResponse masterResponse = new GetFindingsResponse (
7571 totalFindings ,
7672 findings
@@ -84,7 +80,7 @@ public void onFailure(Exception e) {
8480 log .error ("Failed to fetch findings for detector " + detectorId , e );
8581 listener .onFailure (SecurityAnalyticsException .wrap (e ));
8682 }
87- }, monitorIds . size ()) ;
83+ };
8884
8985 // monitor --> detectorId mapping
9086 Map <String , String > monitorToDetectorMapping = new HashMap <>();
@@ -97,7 +93,7 @@ public void onFailure(Exception e) {
9793 monitorIds ,
9894 DetectorMonitorConfig .getFindingsIndex (detector .getDetectorType ()),
9995 table ,
100- multiGetFindingsListener
96+ getFindingsResponseListener
10197 );
10298 }
10399
0 commit comments