6
6
package org .elasticsearch .xpack .test .rest ;
7
7
8
8
import com .carrotsearch .randomizedtesting .annotations .ParametersFactory ;
9
-
10
9
import org .apache .http .HttpStatus ;
11
10
import org .elasticsearch .ElasticsearchException ;
12
- import org .elasticsearch .client .Request ;
13
- import org .elasticsearch .client .Response ;
14
11
import org .elasticsearch .common .CheckedFunction ;
15
12
import org .elasticsearch .common .settings .Settings ;
16
13
import org .elasticsearch .common .util .concurrent .ThreadContext ;
21
18
import org .elasticsearch .test .rest .yaml .ClientYamlTestCandidate ;
22
19
import org .elasticsearch .test .rest .yaml .ClientYamlTestResponse ;
23
20
import org .elasticsearch .test .rest .yaml .ESClientYamlSuiteTestCase ;
24
- import org .elasticsearch .test .rest .yaml .ObjectPath ;
25
21
import org .elasticsearch .xpack .core .ml .MlMetaIndex ;
26
22
import org .elasticsearch .xpack .core .ml .integration .MlRestTestStateCleaner ;
27
23
import org .elasticsearch .xpack .core .ml .job .persistence .AnomalyDetectorsIndex ;
28
24
import org .elasticsearch .xpack .core .ml .job .persistence .AnomalyDetectorsIndexFields ;
29
25
import org .elasticsearch .xpack .core .ml .notifications .NotificationsIndex ;
30
26
import org .elasticsearch .xpack .core .rollup .job .RollupJob ;
31
- import org .elasticsearch .xpack .core .watcher .support .WatcherIndexTemplateRegistryField ;
32
27
import org .junit .After ;
33
28
import org .junit .Before ;
34
29
50
45
import static org .elasticsearch .xpack .core .security .authc .support .UsernamePasswordToken .basicAuthHeaderValue ;
51
46
import static org .hamcrest .Matchers .equalTo ;
52
47
import static org .hamcrest .Matchers .hasSize ;
53
- import static org .hamcrest .Matchers .is ;
54
48
55
49
/** Runs rest tests against external cluster */
56
50
public class XPackRestIT extends ESClientYamlSuiteTestCase {
@@ -77,7 +71,6 @@ protected Settings restClientSettings() {
77
71
@ Before
78
72
public void setupForTests () throws Exception {
79
73
waitForTemplates ();
80
- waitForWatcher ();
81
74
enableMonitoring ();
82
75
}
83
76
@@ -103,60 +96,7 @@ private void waitForTemplates() throws Exception {
103
96
}
104
97
}
105
98
106
- private void waitForWatcher () throws Exception {
107
- // ensure watcher is started, so that a test can stop watcher and everything still works fine
108
- if (isWatcherTest ()) {
109
- assertBusy (() -> {
110
- ClientYamlTestResponse response =
111
- getAdminExecutionContext ().callApi ("watcher.stats" , emptyMap (), emptyList (), emptyMap ());
112
- String state = (String ) response .evaluate ("stats.0.watcher_state" );
113
-
114
- switch (state ) {
115
- case "stopped" :
116
- ClientYamlTestResponse startResponse =
117
- getAdminExecutionContext ().callApi ("watcher.start" , emptyMap (), emptyList (), emptyMap ());
118
- boolean isAcknowledged = (boolean ) startResponse .evaluate ("acknowledged" );
119
- assertThat (isAcknowledged , is (true ));
120
- throw new AssertionError ("waiting until stopped state reached started state" );
121
- case "stopping" :
122
- throw new AssertionError ("waiting until stopping state reached stopped state to start again" );
123
- case "starting" :
124
- throw new AssertionError ("waiting until starting state reached started state" );
125
- case "started" :
126
- // all good here, we are done
127
- break ;
128
- default :
129
- throw new AssertionError ("unknown state[" + state + "]" );
130
- }
131
- });
132
99
133
- for (String template : WatcherIndexTemplateRegistryField .TEMPLATE_NAMES ) {
134
- awaitCallApi ("indices.exists_template" , singletonMap ("name" , template ), emptyList (),
135
- response -> true ,
136
- () -> "Exception when waiting for [" + template + "] template to be created" );
137
- }
138
-
139
- boolean existsWatcherIndex = adminClient ()
140
- .performRequest (new Request ("HEAD" , ".watches" ))
141
- .getStatusLine ().getStatusCode () == 200 ;
142
- if (existsWatcherIndex == false ) {
143
- return ;
144
- }
145
- Request searchWatchesRequest = new Request ("GET" , ".watches/_search" );
146
- searchWatchesRequest .addParameter (TOTAL_HITS_AS_INT_PARAM , "true" );
147
- searchWatchesRequest .addParameter ("size" , "1000" );
148
- Response response = adminClient ().performRequest (searchWatchesRequest );
149
- ObjectPath objectPathResponse = ObjectPath .createFromResponse (response );
150
- int totalHits = objectPathResponse .evaluate ("hits.total" );
151
- if (totalHits > 0 ) {
152
- List <Map <String , Object >> hits = objectPathResponse .evaluate ("hits.hits" );
153
- for (Map <String , Object > hit : hits ) {
154
- String id = (String ) hit .get ("_id" );
155
- adminClient ().performRequest (new Request ("DELETE" , "_watcher/watch/" + id ));
156
- }
157
- }
158
- }
159
- }
160
100
161
101
/**
162
102
* Enable monitoring and waits for monitoring documents to be collected and indexed in
@@ -314,11 +254,6 @@ protected boolean isMonitoringTest() {
314
254
return testName != null && (testName .contains ("=monitoring/" ) || testName .contains ("=monitoring\\ " ));
315
255
}
316
256
317
- protected boolean isWatcherTest () {
318
- String testName = getTestName ();
319
- return testName != null && (testName .contains ("=watcher/" ) || testName .contains ("=watcher\\ " ));
320
- }
321
-
322
257
protected boolean isMachineLearningTest () {
323
258
String testName = getTestName ();
324
259
return testName != null && (testName .contains ("=ml/" ) || testName .contains ("=ml\\ " ));
0 commit comments