18
18
import org .elasticsearch .common .unit .TimeValue ;
19
19
import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
20
20
import org .elasticsearch .index .reindex .ReindexPlugin ;
21
+ import org .elasticsearch .ingest .common .IngestCommonPlugin ;
21
22
import org .elasticsearch .persistent .PersistentTaskParams ;
22
23
import org .elasticsearch .persistent .PersistentTaskState ;
23
24
import org .elasticsearch .plugins .Plugin ;
25
+ import org .elasticsearch .script .IngestScript ;
26
+ import org .elasticsearch .script .MockScriptEngine ;
27
+ import org .elasticsearch .script .MockScriptPlugin ;
28
+ import org .elasticsearch .script .ScoreScript ;
29
+ import org .elasticsearch .script .ScriptContext ;
30
+ import org .elasticsearch .script .ScriptEngine ;
24
31
import org .elasticsearch .search .SearchModule ;
25
32
import org .elasticsearch .test .ESIntegTestCase ;
26
33
import org .elasticsearch .test .SecuritySettingsSourceField ;
35
42
import org .elasticsearch .xpack .core .ilm .LifecycleType ;
36
43
import org .elasticsearch .xpack .core .ilm .RolloverAction ;
37
44
import org .elasticsearch .xpack .core .ilm .TimeseriesLifecycleType ;
45
+ import org .elasticsearch .xpack .core .ml .MlMetaIndex ;
38
46
import org .elasticsearch .xpack .core .ml .MlMetadata ;
39
47
import org .elasticsearch .xpack .core .ml .MlTasks ;
40
48
import org .elasticsearch .xpack .core .ml .action .DeleteExpiredDataAction ;
41
- import org .elasticsearch .xpack .core .ml .action .GetFiltersAction ;
42
49
import org .elasticsearch .xpack .core .ml .action .OpenJobAction ;
43
50
import org .elasticsearch .xpack .core .ml .action .PutFilterAction ;
44
51
import org .elasticsearch .xpack .core .ml .action .SetUpgradeModeAction ;
45
52
import org .elasticsearch .xpack .core .ml .action .StartDataFrameAnalyticsAction ;
46
53
import org .elasticsearch .xpack .core .ml .action .StartDatafeedAction ;
47
54
import org .elasticsearch .xpack .core .ml .datafeed .DatafeedState ;
48
55
import org .elasticsearch .xpack .core .ml .dataframe .DataFrameAnalyticsTaskState ;
56
+ import org .elasticsearch .xpack .core .ml .inference .persistence .InferenceIndexConstants ;
49
57
import org .elasticsearch .xpack .core .ml .job .config .JobTaskState ;
50
58
import org .elasticsearch .xpack .core .ml .job .config .MlFilter ;
59
+ import org .elasticsearch .xpack .core .ml .job .persistence .AnomalyDetectorsIndex ;
60
+ import org .elasticsearch .xpack .core .ml .job .persistence .AnomalyDetectorsIndexFields ;
61
+ import org .elasticsearch .xpack .core .ml .notifications .NotificationsIndex ;
51
62
import org .elasticsearch .xpack .core .security .SecurityField ;
52
63
import org .elasticsearch .xpack .core .security .authc .TokenMetadata ;
64
+ import org .elasticsearch .xpack .core .slm .history .SnapshotLifecycleTemplateRegistry ;
53
65
import org .elasticsearch .xpack .ilm .IndexLifecycle ;
54
66
55
67
import java .io .IOException ;
59
71
import java .util .Arrays ;
60
72
import java .util .Collection ;
61
73
import java .util .Collections ;
74
+ import java .util .HashSet ;
62
75
import java .util .List ;
63
76
import java .util .Map ;
77
+ import java .util .Set ;
78
+ import java .util .function .Function ;
64
79
65
80
import static org .elasticsearch .test .XContentTestUtils .convertToMap ;
66
81
import static org .elasticsearch .test .XContentTestUtils .differenceBetweenMapsIgnoringArrayOrder ;
@@ -82,6 +97,11 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
82
97
return Arrays .asList (
83
98
LocalStateCompositeXPackPlugin .class ,
84
99
Netty4Plugin .class ,
100
+ // The monitoring plugin requires script and gsub processors to be loaded
101
+ IngestCommonPlugin .class ,
102
+ // The monitoring plugin script processor references painless. Include this for script compilation.
103
+ // This is to reduce log spam
104
+ MockPainlessScriptEngine .TestPlugin .class ,
85
105
// ILM is required for .ml-state template index settings
86
106
IndexLifecycle .class );
87
107
}
@@ -110,7 +130,9 @@ protected Settings externalClusterClientSettings() {
110
130
builder .put (NetworkModule .TRANSPORT_TYPE_KEY , SecurityField .NAME4 );
111
131
builder .put (SecurityField .USER_SETTING .getKey (), "x_pack_rest_user:" + SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING );
112
132
builder .put (XPackSettings .MACHINE_LEARNING_ENABLED .getKey (), true );
133
+ builder .put (XPackSettings .WATCHER_ENABLED .getKey (), false );
113
134
builder .put (LifecycleSettings .LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING .getKey (), false );
135
+ builder .put (LifecycleSettings .SLM_HISTORY_INDEX_ENABLED_SETTING .getKey (), false );
114
136
builder .put ("xpack.security.transport.ssl.enabled" , true );
115
137
builder .put ("xpack.security.transport.ssl.key" , key .toAbsolutePath ().toString ());
116
138
builder .put ("xpack.security.transport.ssl.certificate" , certificate .toAbsolutePath ().toString ());
@@ -125,6 +147,18 @@ protected void cleanUp() {
125
147
waitForPendingTasks ();
126
148
}
127
149
150
+ @ Override
151
+ protected Set <String > excludeTemplates () {
152
+ return new HashSet <>(Arrays .asList (
153
+ NotificationsIndex .NOTIFICATIONS_INDEX ,
154
+ MlMetaIndex .INDEX_NAME ,
155
+ AnomalyDetectorsIndexFields .STATE_INDEX_PREFIX ,
156
+ AnomalyDetectorsIndex .jobResultsIndexPrefix (),
157
+ InferenceIndexConstants .LATEST_INDEX_NAME ,
158
+ SnapshotLifecycleTemplateRegistry .SLM_TEMPLATE_NAME
159
+ ));
160
+ }
161
+
128
162
protected abstract void cleanUpResources ();
129
163
130
164
private void waitForPendingTasks () {
@@ -166,10 +200,6 @@ protected PutFilterAction.Response putMlFilter(MlFilter filter) {
166
200
return client ().execute (PutFilterAction .INSTANCE , new PutFilterAction .Request (filter )).actionGet ();
167
201
}
168
202
169
- protected GetFiltersAction .Response getMlFilters () {
170
- return client ().execute (GetFiltersAction .INSTANCE , new GetFiltersAction .Request ()).actionGet ();
171
- }
172
-
173
203
@ Override
174
204
protected void ensureClusterStateConsistency () throws IOException {
175
205
if (cluster () != null && cluster ().size () > 0 ) {
@@ -228,4 +258,42 @@ protected void ensureClusterStateConsistency() throws IOException {
228
258
}
229
259
}
230
260
}
261
+
262
+ public static class MockPainlessScriptEngine extends MockScriptEngine {
263
+
264
+ public static final String NAME = "painless" ;
265
+
266
+ public static class TestPlugin extends MockScriptPlugin {
267
+ @ Override
268
+ public ScriptEngine getScriptEngine (Settings settings , Collection <ScriptContext <?>> contexts ) {
269
+ return new MockPainlessScriptEngine ();
270
+ }
271
+
272
+ @ Override
273
+ protected Map <String , Function <Map <String , Object >, Object >> pluginScripts () {
274
+ return Collections .emptyMap ();
275
+ }
276
+ }
277
+
278
+ @ Override
279
+ public String getType () {
280
+ return NAME ;
281
+ }
282
+
283
+ @ Override
284
+ public <T > T compile (String name , String script , ScriptContext <T > context , Map <String , String > options ) {
285
+ if (context .instanceClazz .equals (ScoreScript .class )) {
286
+ return context .factoryClazz .cast (new MockScoreScript (p -> 0.0 ));
287
+ }
288
+ if (context .name .equals ("ingest" )) {
289
+ IngestScript .Factory factory = vars -> new IngestScript (vars ) {
290
+ @ Override
291
+ public void execute (Map <String , Object > ctx ) {
292
+ }
293
+ };
294
+ return context .factoryClazz .cast (factory );
295
+ }
296
+ throw new IllegalArgumentException ("mock painless does not know how to handle context [" + context .name + "]" );
297
+ }
298
+ }
231
299
}
0 commit comments