From 81382262ec5c692ce4c7d022e143ecc860ba864c Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Thu, 21 Jul 2016 14:25:22 +0200 Subject: [PATCH] Watcher: Hardcode index names for auto index create validation (elastic/elasticsearch#2834) This is broken in 2.x and returns a wrong index name. We should just use the indices, that are hardcoded in the error message. Relates elastic/elasticsearch#2831 Original commit: elastic/x-pack-elasticsearch@457be61013954718aaa462da16510112baff5e0e --- .../messy/tests/IndexActionIT.java | 2 +- .../elasticsearch/messy/tests/WatchAckIT.java | 4 +- .../elasticsearch/xpack/watcher/Watcher.java | 5 ++- .../xpack/watcher/history/HistoryStore.java | 5 ++- .../xpack/watcher/WatcherPluginTests.java | 41 ++++++++----------- .../actions/TimeThrottleIntegrationTests.java | 6 +-- .../index/IndexActionIntegrationTests.java | 2 +- .../execution/ManualExecutionTests.java | 4 +- .../HistoryTemplateEmailMappingsTests.java | 5 +-- .../HistoryTemplateHttpMappingsTests.java | 2 +- ...storyTemplateIndexActionMappingsTests.java | 2 +- ...storyTemplateSearchInputMappingsTests.java | 2 +- .../input/http/HttpInputIntegrationTests.java | 2 +- .../AbstractWatcherIntegrationTestCase.java | 24 ++++++----- .../bench/WatcherScheduleEngineBenchmark.java | 6 +-- .../test/integration/BootStrapTests.java | 2 +- .../test/integration/WatchMetadataTests.java | 2 +- 17 files changed, 55 insertions(+), 61 deletions(-) diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/IndexActionIT.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/IndexActionIT.java index 6cb442b82ca..74b9aeab263 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/IndexActionIT.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/IndexActionIT.java @@ -145,7 +145,7 @@ public class IndexActionIT extends AbstractWatcherIntegrationTestCase { assertThat(client().admin().indices().prepareExists("idx").get().isExists(), is(false)); - assertThat(docCount(HistoryStore.INDEX_PREFIX + "*", HistoryStore.DOC_TYPE, searchSource() + assertThat(docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", HistoryStore.DOC_TYPE, searchSource() .query(matchQuery("result.actions.status", "failure"))), is(1L)); } diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/WatchAckIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/WatchAckIT.java index 77774111be4..0669ae7ad43 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/WatchAckIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/WatchAckIT.java @@ -158,7 +158,7 @@ public class WatchAckIT extends AbstractWatcherIntegrationTestCase { assertThat(parsedWatch.status().actionStatus("_a2").ackStatus().state(), is(ActionStatus.AckStatus.State.AWAITS_SUCCESSFUL_EXECUTION)); - long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null, + long throttledCount = docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", null, matchQuery(WatchRecord.Field.STATE.getPreferredName(), ExecutionState.THROTTLED.id())); assertThat(throttledCount, greaterThan(0L)); } @@ -240,7 +240,7 @@ public class WatchAckIT extends AbstractWatcherIntegrationTestCase { assertThat(parsedWatch.status().actionStatus("_a2").ackStatus().state(), is(ActionStatus.AckStatus.State.AWAITS_SUCCESSFUL_EXECUTION)); - long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null, + long throttledCount = docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", null, matchQuery(WatchRecord.Field.STATE.getPreferredName(), ExecutionState.THROTTLED.id())); assertThat(throttledCount, greaterThan(0L)); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index f2935bae084..e284c08ccbe 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -11,7 +11,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.LoggerMessageFormat; @@ -32,6 +31,7 @@ import org.elasticsearch.xpack.watcher.condition.ConditionModule; import org.elasticsearch.xpack.watcher.execution.ExecutionModule; import org.elasticsearch.xpack.watcher.execution.ExecutionService; import org.elasticsearch.xpack.watcher.execution.InternalWatchExecutor; +import org.elasticsearch.xpack.watcher.execution.TriggeredWatchStore; import org.elasticsearch.xpack.watcher.history.HistoryModule; import org.elasticsearch.xpack.watcher.history.HistoryStore; import org.elasticsearch.xpack.watcher.input.InputModule; @@ -66,6 +66,7 @@ import org.elasticsearch.xpack.watcher.transport.actions.stats.WatcherStatsActio import org.elasticsearch.xpack.watcher.trigger.TriggerModule; import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleModule; import org.elasticsearch.xpack.watcher.watch.WatchModule; +import org.elasticsearch.xpack.watcher.watch.WatchStore; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -216,7 +217,7 @@ public class Watcher implements ActionPlugin { String errorMessage = LoggerMessageFormat.format("the [action.auto_create_index] setting value [{}] is too" + " restrictive. disable [action.auto_create_index] or set it to " + - "[.watches,.triggered_watches,.watcher-history*]", (Object) value); + "[{}, {}, {}*]", (Object) value, WatchStore.INDEX, TriggeredWatchStore.INDEX_NAME, HistoryStore.INDEX_PREFIX); if (Booleans.isExplicitFalse(value)) { throw new IllegalArgumentException(errorMessage); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java index ab54842f46e..44c8ef07792 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java @@ -32,7 +32,8 @@ import static org.elasticsearch.xpack.watcher.support.Exceptions.ioException; */ public class HistoryStore extends AbstractComponent { - public static final String INDEX_PREFIX = ".watcher-history-" + WatcherIndexTemplateRegistry.INDEX_TEMPLATE_VERSION + "-"; + public static final String INDEX_PREFIX = ".watcher-history-"; + public static final String INDEX_PREFIX_WITH_TEMPLATE = INDEX_PREFIX + WatcherIndexTemplateRegistry.INDEX_TEMPLATE_VERSION + "-"; public static final String DOC_TYPE = "watch_record"; static final DateTimeFormatter indexTimeFormat = DateTimeFormat.forPattern("YYYY.MM.dd"); @@ -123,7 +124,7 @@ public class HistoryStore extends AbstractComponent { * Calculates the correct history index name for a given time */ public static String getHistoryIndexNameForTime(DateTime time) { - return INDEX_PREFIX + indexTimeFormat.print(time); + return INDEX_PREFIX_WITH_TEMPLATE + indexTimeFormat.print(time); } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java index 2a60917218b..7becc40a6e2 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java @@ -15,34 +15,27 @@ public class WatcherPluginTests extends ESTestCase { public void testValidAutoCreateIndex() { Watcher.validAutoCreateIndex(Settings.EMPTY); Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", true).build()); - try { - Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", false).build()); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("[.watches,.triggered_watches,.watcher-history*]")); - } + + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", false).build())); + assertThat(exception.getMessage(), containsString("[.watches, .triggered_watches, .watcher-history-*]")); + Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".watches,.triggered_watches,.watcher-history*").build()); Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", "*w*").build()); Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".w*,.t*").build()); - try { - Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".watches").build()); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("[.watches,.triggered_watches,.watcher-history*]")); - } - try { - Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".triggered_watch").build()); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("[.watches,.triggered_watches,.watcher-history*]")); - } - try { - Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".watcher-history*").build()); - fail("IllegalArgumentException expected"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("[.watches,.triggered_watches,.watcher-history*]")); - } + + exception = expectThrows(IllegalArgumentException.class, + () -> Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".watches").build())); + assertThat(exception.getMessage(), containsString("[.watches, .triggered_watches, .watcher-history-*]")); + + exception = expectThrows(IllegalArgumentException.class, + () -> Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".triggered_watch").build())); + assertThat(exception.getMessage(), containsString("[.watches, .triggered_watches, .watcher-history-*]")); + + exception = expectThrows(IllegalArgumentException.class, + () -> Watcher.validAutoCreateIndex(Settings.builder().put("action.auto_create_index", ".watcher-history-*").build())); + assertThat(exception.getMessage(), containsString("[.watches, .triggered_watches, .watcher-history-*]")); } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java index bdff9a6f66a..b6e2225cf51 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java @@ -95,7 +95,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest actionsCount = docCount("actions", "action", matchAllQuery()); assertThat(actionsCount, is(2L)); - long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null, + long throttledCount = docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", null, matchQuery(WatchRecord.Field.STATE.getPreferredName(), ExecutionState.THROTTLED.id())); assertThat(throttledCount, is(1L)); @@ -119,7 +119,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest long actionsCount = docCount("actions", "action", matchAllQuery()); assertThat(actionsCount, is(1L)); - long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null, + long throttledCount = docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", null, matchQuery(WatchRecord.Field.STATE.getPreferredName(), ExecutionState.THROTTLED.id())); assertThat(throttledCount, greaterThanOrEqualTo(1L)); } @@ -168,7 +168,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest actionsCount = docCount("actions", "action", matchAllQuery()); assertThat(actionsCount, is(2L)); - long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null, + long throttledCount = docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", null, matchQuery(WatchRecord.Field.STATE.getPreferredName(), ExecutionState.THROTTLED.id())); assertThat(throttledCount, is(1L)); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionIntegrationTests.java index 4bbae26cc62..d2d08775b36 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionIntegrationTests.java @@ -135,7 +135,7 @@ public class IndexActionIntegrationTests extends AbstractWatcherIntegrationTestC assertThat(client().admin().indices().prepareExists("idx").get().isExists(), is(false)); - assertThat(docCount(HistoryStore.INDEX_PREFIX + "*", HistoryStore.DOC_TYPE, searchSource() + assertThat(docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", HistoryStore.DOC_TYPE, searchSource() .query(matchQuery("result.actions.status", "failure"))), is(1L)); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java index 084a52b78a4..8e51e3cf5bb 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java @@ -109,13 +109,13 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase { ManualExecutionContext ctx = ctxBuilder.build(); refresh(); - long oldRecordCount = docCount(HistoryStore.INDEX_PREFIX + "*", HistoryStore.DOC_TYPE, matchAllQuery()); + long oldRecordCount = docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", HistoryStore.DOC_TYPE, matchAllQuery()); WatchRecord watchRecord = executionService().execute(ctx); refresh(); - long newRecordCount = docCount(HistoryStore.INDEX_PREFIX + "*", HistoryStore.DOC_TYPE, matchAllQuery()); + long newRecordCount = docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", HistoryStore.DOC_TYPE, matchAllQuery()); long expectedCount = oldRecordCount + (recordExecution ? 1 : 0); assertThat("the expected count of history records should be [" + expectedCount + "]", newRecordCount, equalTo(expectedCount)); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java index b39cdca5695..27f0605259a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.watcher.history; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.search.aggregations.Aggregations; @@ -17,9 +16,7 @@ import org.elasticsearch.xpack.notification.email.support.EmailServer; import org.elasticsearch.xpack.watcher.execution.ExecutionState; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse; -import org.junit.After; import org.junit.AfterClass; -import org.junit.Before; import org.junit.BeforeClass; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; @@ -107,7 +104,7 @@ public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegratio // the action should fail as no email server is available assertWatchWithMinimumActionsCount("_id", ExecutionState.EXECUTED, 1); - SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*").setSource(searchSource() + SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource() .aggregation(terms("from").field("result.actions.email.message.from")) .aggregation(terms("to").field("result.actions.email.message.to")) .aggregation(terms("cc").field("result.actions.email.message.cc")) diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index 82a6f14920b..167e1a53a99 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -93,7 +93,7 @@ public class HistoryTemplateHttpMappingsTests extends AbstractWatcherIntegration // the action should fail as no email server is available assertWatchWithMinimumActionsCount("_id", ExecutionState.EXECUTED, 1); - SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*").setSource(searchSource() + SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource() .aggregation(terms("input_result_path").field("result.input.http.request.path")) .aggregation(terms("input_result_host").field("result.input.http.request.host")) .aggregation(terms("webhook_path").field("result.actions.webhook.request.path"))) diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java index b54257c759e..001a108a3c8 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateIndexActionMappingsTests.java @@ -55,7 +55,7 @@ public class HistoryTemplateIndexActionMappingsTests extends AbstractWatcherInte flush(); refresh(); - SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*").setSource(searchSource() + SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource() .aggregation(terms("index_action_indices").field("result.actions.index.response.index")) .aggregation(terms("index_action_types").field("result.actions.index.response.type"))) .get(); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java index 6267319158f..065ba7f2a15 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java @@ -66,7 +66,7 @@ public class HistoryTemplateSearchInputMappingsTests extends AbstractWatcherInte // the action should fail as no email server is available assertWatchWithMinimumActionsCount("_id", ExecutionState.EXECUTED, 1); - SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*").setSource(searchSource() + SearchResponse response = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource() .aggregation(terms("input_search_type").field("result.input.search.request.search_type")) .aggregation(terms("input_indices").field("result.input.search.request.indices")) .aggregation(terms("input_types").field("result.input.search.request.types")) diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java index 7b51d0ca49b..79cbb23b523 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java @@ -149,7 +149,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas // Check that the input result payload has been filtered refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(matchQuery("watch_id", "_name1")) .setSize(1) diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index e0b387ab721..d79bccbb720 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -312,7 +312,8 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase protected long watchRecordCount(QueryBuilder query) { refresh(); - return docCount(HistoryStore.INDEX_PREFIX + "*", HistoryStore.DOC_TYPE, SearchSourceBuilder.searchSource().query(query)); + return docCount(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*", + HistoryStore.DOC_TYPE, SearchSourceBuilder.searchSource().query(query)); } protected long docCount(String index, String type, SearchSourceBuilder source) { @@ -324,7 +325,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } protected SearchResponse searchHistory(SearchSourceBuilder builder) { - return client().prepareSearch(HistoryStore.INDEX_PREFIX + "*").setSource(builder).get(); + return client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(builder).get(); } protected T getInstanceFromMaster(Class type) { @@ -398,7 +399,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase assertBusy(() -> { ClusterState state = client().admin().cluster().prepareState().get().getState(); String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, - IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*"); + IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*"); assertThat(watchHistoryIndices, not(emptyArray())); for (String index : watchHistoryIndices) { IndexRoutingTable routingTable = state.getRoutingTable().index(index); @@ -407,7 +408,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", ExecutionState.EXECUTED.id()))) @@ -432,14 +433,15 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } protected SearchResponse searchWatchRecords(Callback requestBuilderCallback) { - SearchRequestBuilder builder = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*").setTypes(HistoryStore.DOC_TYPE); + SearchRequestBuilder builder = + client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").setTypes(HistoryStore.DOC_TYPE); requestBuilderCallback.handle(builder); return builder.get(); } protected long historyRecordsCount(String watchName) { refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setSize(0) .setQuery(matchQuery("watch_id", watchName)) @@ -449,7 +451,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase protected long findNumberOfPerformedActions(String watchName) { refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", ExecutionState.EXECUTED.id()))) .get(); @@ -465,7 +467,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase // so we to check first is this index is created and shards are started ClusterState state = client().admin().cluster().prepareState().get().getState(); String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, - IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*"); + IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*"); assertThat(watchHistoryIndices, not(emptyArray())); for (String index : watchHistoryIndices) { IndexRoutingTable routingTable = state.getRoutingTable().index(index); @@ -473,7 +475,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase assertThat(routingTable.allPrimaryShardsActive(), is(true)); } refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", ExecutionState.EXECUTION_NOT_NEEDED.id()))) @@ -497,7 +499,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase assertBusy(() -> { ClusterState state = client().admin().cluster().prepareState().get().getState(); String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), - HistoryStore.INDEX_PREFIX + "*"); + HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*"); assertThat(watchHistoryIndices, not(emptyArray())); for (String index : watchHistoryIndices) { IndexRoutingTable routingTable = state.getRoutingTable().index(index); @@ -506,7 +508,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", recordState.id()))) .get(); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java index 67466b83212..8dbd6cafd98 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java @@ -140,7 +140,7 @@ public class WatcherScheduleEngineBenchmark { try (Node node = new MockNode(settings, Arrays.asList(XPackPlugin.class, XPackPlugin.class))) { try (final Client client = node.client()) { client.admin().cluster().prepareHealth().setWaitForNodes("2").get(); - client.admin().indices().prepareDelete(HistoryStore.INDEX_PREFIX + "*").get(); + client.admin().indices().prepareDelete(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").get(); client.admin().cluster().prepareHealth(WatchStore.INDEX, "test").setWaitForYellowStatus().get(); Clock clock = node.injector().getInstance(Clock.class); @@ -185,10 +185,10 @@ public class WatcherScheduleEngineBenchmark { } } } - client.admin().indices().prepareRefresh(HistoryStore.INDEX_PREFIX + "*").get(); + client.admin().indices().prepareRefresh(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").get(); Script script = new Script("doc['trigger_event.schedule.triggered_time'].value - doc['trigger_event.schedule" + ".scheduled_time'].value"); - SearchResponse searchResponse = client.prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client.prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setQuery(QueryBuilders.rangeQuery("trigger_event.schedule.scheduled_time").gte(startTime).lte(endTime)) .addAggregation(terms("state").field("state")) .addAggregation(histogram("delay") diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java index 0bf7a796cfb..1b8665300da 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java @@ -208,7 +208,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { startWatcher(); refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*").get(); + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*").get(); assertHitCount(searchResponse, 1); assertThat(searchResponse.getHits().getAt(0).id(), Matchers.equalTo(wid.value())); assertThat(searchResponse.getHits().getAt(0).sourceAsMap().get(WatchRecord.Field.STATE.getPreferredName()).toString(), diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java index b458cce21aa..3829dead86d 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java @@ -71,7 +71,7 @@ public class WatchMetadataTests extends AbstractWatcherIntegrationTestCase { } refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*") .setQuery(termQuery("metadata.foo", "bar")) .get(); assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L));