Commit fba82bc
committed
WIP > XPack, Update Core and X-Pack test setup
* Do not delete X-Pack templates
* Use context timeouts
* Check pending tasks
// ----------------------------------------------------------------------------------------------------
// https://github.com/elastic/elasticsearch/blob/master/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java
ensureNoInitializingShards();
wipeCluster();
waitForClusterStateUpdatesToFinish();
logIfThereAreRunningTasks();
wipeCluster() {
if (hasXPack) {
wipeRollupJobs();
waitForPendingRollupTasks();
}
wipeSnapshots();
adminClient().performRequest(new Request("DELETE", "*"));
if (hasXPack) {
Request request = new Request("GET", "_cat/templates");
request.addParameter("h", "name");
if (isXPackTemplate(template)) continue;
adminClient().performRequest(new Request("DELETE", "_template/" + template));
} else {
adminClient().performRequest(new Request("DELETE", "_template/*"));
}
wipeClusterSettings();
if (hasXPack) {
deleteAllPolicies();
}
wipeRollupJobs() {
Response response = adminClient().performRequest(new Request("GET", "/_rollup/job/_all"));
for (Map<String, Object> jobConfig : jobConfigs) {
String jobId = (String) ((Map<String, Object>) jobConfig.get("config")).get("id");
Request request = new Request("POST", "/_rollup/job/" + jobId + "/_stop");
request.addParameter("ignore", "404");
request.addParameter("wait_for_completion", "true");
request.addParameter("timeout", "10s");
}
for (Map<String, Object> jobConfig : jobConfigs) {
Request request = new Request("DELETE", "/_rollup/job/" + jobId);
request.addParameter("ignore", "404");
}
waitForPendingRollupTasks() {
waitForPendingTasks(adminClient(), taskName -> taskName.startsWith("xpack/rollup/job") == false);
ensureNoInitializingShards() {
Request request = new Request("GET", "/_cluster/health");
request.addParameter("wait_for_no_initializing_shards", "true");
request.addParameter("timeout", "70s");
request.addParameter("level", "shards");
adminClient().performRequest(request);
waitForClusterStateUpdatesToFinish() {
assertBusy(() -> {
Response response = adminClient().performRequest(new Request("GET", "/_cluster/pending_tasks"));
List<?> tasks = (List<?>) entityAsMap(response).get("tasks");
if (false == tasks.isEmpty()) {
fail(message.toString());
}, 30, TimeUnit.SECONDS);
// curl -s -k -X POST 'https://elastic:elastic@localhost:9200/_all/_ilm/remove'
deleteAllPolicies() {
Response response = adminClient().performRequest(new Request("GET", "/_ilm/policy"));
for (String policyName : policies.keySet()) {
adminClient().performRequest(new Request("DELETE", "/_ilm/policy/" + policyName));
}
// elastic/elasticsearch#31642
//
// > At the end of every ESRestTestCase we clean the cluster which includes
// > deleting all of the templates. If xpack is installed it'll automatically
// > recreate a few templates every time they are removed. Which is slow.
//
isXPackTemplate(String name) {
if (name.startsWith(".monitoring-")) {
return true;
}
if (name.startsWith(".watch") || name.startsWith(".triggered_watches")) {
return true;
}
if (name.startsWith(".ml-")) {
return true;
}
switch (name) {
case ".triggered_watches":
case ".watches":
case "logstash-index-template":
case "security_audit_log":
return true;
default:
return false;
}
// ----------------------------------------------------------------------------------------------------
// https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java
setupForTests() {
waitForTemplates();
waitForWatcher();
enableMonitoring();
cleanup()
disableMonitoring();
clearMlState();
if (isWaitForPendingTasks()) {
// This waits for pending tasks to complete, so must go last (otherwise
// it could be waiting for pending tasks while monitoring is still running).
ESRestTestCase.waitForPendingTasks(adminClient(), task -> {
// Don't check rollup jobs because we clear them in the superclass.
return task.contains(RollupJob.NAME);
});
waitForTemplates() {
for (String template : templates) {
awaitCallApi("indices.exists_template", singletonMap("name", template), emptyList(),
response -> true,
() -> "Exception when waiting for [" + template + "] template to be created");
}
waitForWatcher() {
if (isWatcherTest()) {
// ensure watcher is started, so that a test can stop watcher and everything still works fine
enableMonitoring() {
if (isMonitoringTest()) {
// Enable monitoring and waits for monitoring documents to be collected and indexed
clearMlState() {
if (isMachineLearningTest()) {
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
}
isMonitoringTest() {
String testName = getTestName();
return testName != null && (testName.contains("=monitoring/") || testName.contains("=monitoring\\"));
}
isWatcherTest() {
String testName = getTestName();
return testName != null && (testName.contains("=watcher/") || testName.contains("=watcher\\"));
}
isMachineLearningTest() {
String testName = getTestName();
return testName != null && (testName.contains("=ml/") || testName.contains("=ml\\"));
}
// ----------------------------------------------------------------------------------------------------
// https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java
class MlRestTestStateCleaner { ... }
clearMlMetadata() {
deleteAllDatafeeds();
deleteAllJobs();
deleteAllDataFrameAnalytics();
// indices will be deleted by the ESRestTestCase class
deleteAllDatafeeds() {
Request datafeedsRequest = new Request("GET", "/_ml/datafeeds");
datafeedsRequest.addParameter("filter_path", "datafeeds");
datafeeds = (List<Map<String, Object>>) XContentMapValues.extractValue("datafeeds", ESRestTestCase.entityAsMap(datafeedsResponse));
try {
adminClient.performRequest(new Request("POST", "/_ml/datafeeds/_all/_stop"));
} catch (Exception e1) {
logger.warn("failed to stop all datafeeds. Forcing stop", e1);
try {
adminClient.performRequest(new Request("POST", "/_ml/datafeeds/_all/_stop?force=true"));
} catch (Exception e2) {
logger.warn("Force-closing all data feeds failed", e2);
}
throw new RuntimeException(
"Had to resort to force-stopping datafeeds, something went wrong?", e1);
}
for (Map<String, Object> datafeed : datafeeds) {
String datafeedId = (String) datafeed.get("datafeed_id");
adminClient.performRequest(new Request("DELETE", "/_ml/datafeeds/" + datafeedId));
}
deleteAllJobs() {
Request jobsRequest = new Request("GET", "/_ml/anomaly_detectors");
jobsRequest.addParameter("filter_path", "jobs");
jobConfigs = (List<Map<String, Object>>) XContentMapValues.extractValue("jobs", ESRestTestCase.entityAsMap(response));
if (jobConfigs == null) {
return;
}
adminClient.performRequest(new Request("POST", "/_ml/anomaly_detectors/_all/_close"));
for (Map<String, Object> jobConfig : jobConfigs) {
String jobId = (String) jobConfig.get("job_id");
adminClient.performRequest(new Request("DELETE", "/_ml/anomaly_detectors/" + jobId));
}
deleteAllDataFrameAnalytics() {
Request analyticsRequest = new Request("GET", "/_ml/data_frame/analytics?size=10000");
analyticsRequest.addParameter("filter_path", "data_frame_analytics");
analytics = (List<Map<String, Object>>) XContentMapValues.extractValue("data_frame_analytics", ESRestTestCase.entityAsMap(analyticsResponse));
if (analytics == null) {
return;
}
for (Map<String, Object> config : analytics) {
String id = (String) config.get("id");
adminClient.performRequest(new Request("DELETE", "/_ml/data_frame/analytics/" + id));
}1 parent 3f4f7a4 commit fba82bc
1 file changed
+113
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
| |||
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
292 | 300 | | |
293 | 301 | | |
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
297 | 305 | | |
298 | | - | |
299 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
300 | 324 | | |
301 | 325 | | |
302 | 326 | | |
| |||
327 | 351 | | |
328 | 352 | | |
329 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
330 | 361 | | |
331 | 362 | | |
332 | 363 | | |
| |||
338 | 369 | | |
339 | 370 | | |
340 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
341 | 387 | | |
342 | 388 | | |
343 | 389 | | |
| |||
395 | 441 | | |
396 | 442 | | |
397 | 443 | | |
398 | | - | |
399 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
400 | 448 | | |
401 | 449 | | |
402 | 450 | | |
| |||
412 | 460 | | |
413 | 461 | | |
414 | 462 | | |
415 | | - | |
416 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
417 | 467 | | |
418 | 468 | | |
419 | 469 | | |
420 | 470 | | |
421 | | - | |
| 471 | + | |
422 | 472 | | |
423 | 473 | | |
424 | 474 | | |
| |||
438 | 488 | | |
439 | 489 | | |
440 | 490 | | |
441 | | - | |
| 491 | + | |
442 | 492 | | |
443 | 493 | | |
444 | 494 | | |
| |||
457 | 507 | | |
458 | 508 | | |
459 | 509 | | |
460 | | - | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
461 | 536 | | |
| 537 | + | |
462 | 538 | | |
463 | 539 | | |
464 | 540 | | |
465 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
466 | 549 | | |
467 | 550 | | |
468 | 551 | | |
| |||
478 | 561 | | |
479 | 562 | | |
480 | 563 | | |
481 | | - | |
| 564 | + | |
482 | 565 | | |
483 | 566 | | |
484 | 567 | | |
| |||
490 | 573 | | |
491 | 574 | | |
492 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
493 | 596 | | |
494 | 597 | | |
495 | 598 | | |
| |||
0 commit comments