10
10
import org .opensearch .action .support .ActionFilters ;
11
11
import org .opensearch .action .support .HandledTransportAction ;
12
12
import org .opensearch .action .support .WriteRequest ;
13
+ import org .opensearch .alerting .monitor .inputs .SampleRemoteDocLevelMonitorInput ;
13
14
import org .opensearch .alerting .monitor .runners .SampleRemoteDocLevelMonitorRunner ;
14
15
import org .opensearch .client .Client ;
15
16
import org .opensearch .cluster .service .ClusterService ;
16
17
import org .opensearch .common .inject .Inject ;
17
18
import org .opensearch .common .settings .Settings ;
18
19
import org .opensearch .commons .alerting .action .DocLevelMonitorFanOutRequest ;
19
20
import org .opensearch .commons .alerting .action .DocLevelMonitorFanOutResponse ;
21
+ import org .opensearch .commons .alerting .model .DocLevelMonitorInput ;
20
22
import org .opensearch .commons .alerting .model .InputRunResults ;
21
23
import org .opensearch .commons .alerting .model .Monitor ;
24
+ import org .opensearch .commons .alerting .model .remote .monitors .RemoteDocLevelMonitorInput ;
22
25
import org .opensearch .core .action .ActionListener ;
26
+ import org .opensearch .core .common .bytes .BytesReference ;
27
+ import org .opensearch .core .common .io .stream .StreamInput ;
23
28
import org .opensearch .core .xcontent .NamedXContentRegistry ;
24
29
import org .opensearch .tasks .Task ;
25
30
import org .opensearch .transport .TransportService ;
@@ -55,30 +60,42 @@ public TransportRemoteDocLevelMonitorFanOutAction(
55
60
56
61
@ Override
57
62
protected void doExecute (Task task , DocLevelMonitorFanOutRequest request , ActionListener <DocLevelMonitorFanOutResponse > actionListener ) {
58
- Monitor monitor = request .getMonitor ();
59
- Map <String , Object > lastRunContext = request .getMonitorMetadata ().getLastRunContext ();
60
- ((Map <String , Object >) lastRunContext .get ("index" )).put ("0" , 0 );
61
- IndexRequest indexRequest = new IndexRequest (SampleRemoteDocLevelMonitorRunner .SAMPLE_REMOTE_DOC_LEVEL_MONITOR_RUNNER_INDEX )
62
- .source (Map .of ("sample" , "record" )).setRefreshPolicy (WriteRequest .RefreshPolicy .WAIT_UNTIL );
63
- this .client .index (indexRequest , new ActionListener <>() {
64
- @ Override
65
- public void onResponse (IndexResponse indexResponse ) {
66
- DocLevelMonitorFanOutResponse response = new DocLevelMonitorFanOutResponse (
67
- clusterService .localNode ().getId (),
68
- request .getExecutionId (),
69
- monitor .getId (),
70
- lastRunContext ,
71
- new InputRunResults (),
72
- new HashMap <>(),
73
- null
74
- );
75
- actionListener .onResponse (response );
76
- }
63
+ try {
64
+ Monitor monitor = request .getMonitor ();
65
+ Map <String , Object > lastRunContext = request .getMonitorMetadata ().getLastRunContext ();
77
66
78
- @ Override
79
- public void onFailure (Exception e ) {
80
- actionListener .onFailure (e );
81
- }
82
- });
67
+ RemoteDocLevelMonitorInput input = (RemoteDocLevelMonitorInput ) monitor .getInputs ().get (0 );
68
+ BytesReference customInputSerialized = input .getInput ();
69
+ StreamInput sin = StreamInput .wrap (customInputSerialized .toBytesRef ().bytes );
70
+ SampleRemoteDocLevelMonitorInput sampleRemoteDocLevelMonitorInput = new SampleRemoteDocLevelMonitorInput (sin );
71
+ DocLevelMonitorInput docLevelMonitorInput = input .getDocLevelMonitorInput ();
72
+ String index = docLevelMonitorInput .getIndices ().get (0 );
73
+
74
+ ((Map <String , Object >) lastRunContext .get (index )).put ("0" , 0 );
75
+ IndexRequest indexRequest = new IndexRequest (SampleRemoteDocLevelMonitorRunner .SAMPLE_REMOTE_DOC_LEVEL_MONITOR_RUNNER_INDEX )
76
+ .source (sampleRemoteDocLevelMonitorInput .getB ()).setRefreshPolicy (WriteRequest .RefreshPolicy .WAIT_UNTIL );
77
+ this .client .index (indexRequest , new ActionListener <>() {
78
+ @ Override
79
+ public void onResponse (IndexResponse indexResponse ) {
80
+ DocLevelMonitorFanOutResponse response = new DocLevelMonitorFanOutResponse (
81
+ clusterService .localNode ().getId (),
82
+ request .getExecutionId (),
83
+ monitor .getId (),
84
+ lastRunContext ,
85
+ new InputRunResults (),
86
+ new HashMap <>(),
87
+ null
88
+ );
89
+ actionListener .onResponse (response );
90
+ }
91
+
92
+ @ Override
93
+ public void onFailure (Exception e ) {
94
+ actionListener .onFailure (e );
95
+ }
96
+ });
97
+ } catch (Exception ex ) {
98
+ actionListener .onFailure (ex );
99
+ }
83
100
}
84
101
}
0 commit comments