From 8998aeab54ed7d757817e0130a1cd553a91caaba Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 14 Oct 2019 10:51:23 +0100 Subject: [PATCH] Remove type from Watcher IndexAction --- .../xpack/watcher/actions/ActionBuilders.java | 8 --- .../actions/index/ExecutableIndexAction.java | 3 +- .../watcher/actions/index/IndexAction.java | 68 ++----------------- .../watcher/WatcherConcreteIndexTests.java | 2 +- .../actions/ActionErrorIntegrationTests.java | 2 +- .../actions/index/IndexActionTests.java | 33 ++------- .../throttler/ActionThrottleTests.java | 2 +- .../ExecuteWatchQueuedStatsTests.java | 2 +- .../transform/TransformIntegrationTests.java | 2 +- .../xpack/watcher/watch/WatchTests.java | 4 +- 10 files changed, 20 insertions(+), 106 deletions(-) diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionBuilders.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionBuilders.java index ae2795bf2122c..dc6bc8ae20f94 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionBuilders.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionBuilders.java @@ -33,14 +33,6 @@ public static EmailAction.Builder emailAction(EmailTemplate email) { return EmailAction.builder(email); } - /** - * Types are deprecated and should not be used. use {@link #indexAction(String)} - */ - @Deprecated - public static IndexAction.Builder indexAction(String index, String type) { - return IndexAction.builder(index, type); - } - public static IndexAction.Builder indexAction(String index) { return IndexAction.builder(index); } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/ExecutableIndexAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/ExecutableIndexAction.java index f705c74ded67c..35a3caa68c8f6 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/ExecutableIndexAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/ExecutableIndexAction.java @@ -17,7 +17,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.actions.Action.Result.Status; @@ -92,7 +91,7 @@ public Action.Result execute(String actionId, WatchExecutionContext ctx, Payload } if (ctx.simulateAction(actionId)) { - return new IndexAction.Simulated(indexRequest.index(), MapperService.SINGLE_MAPPING_NAME, indexRequest.id(), + return new IndexAction.Simulated(indexRequest.index(), indexRequest.id(), action.refreshPolicy, new XContentSource(indexRequest.source(), XContentType.JSON)); } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java index ba93d4268baed..389863e44ed56 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java @@ -5,12 +5,10 @@ */ package org.elasticsearch.xpack.watcher.actions.index; -import org.apache.logging.log4j.LogManager; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.time.DateUtils; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -29,7 +27,6 @@ public class IndexAction implements Action { public static final String TYPE = "index"; - @Nullable @Deprecated final String docType; @Nullable final String index; @Nullable final String docId; @Nullable final String executionTimeField; @@ -37,23 +34,10 @@ public class IndexAction implements Action { @Nullable final ZoneId dynamicNameTimeZone; @Nullable final RefreshPolicy refreshPolicy; - private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(IndexAction.class)); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in a watcher index action is deprecated."; - public IndexAction(@Nullable String index, @Nullable String docId, @Nullable String executionTimeField, @Nullable TimeValue timeout, @Nullable ZoneId dynamicNameTimeZone, @Nullable RefreshPolicy refreshPolicy) { - this(index, null, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy); - } - /** - * Document types are deprecated, use constructor without docType - */ - @Deprecated - public IndexAction(@Nullable String index, @Nullable String docType, @Nullable String docId, - @Nullable String executionTimeField, - @Nullable TimeValue timeout, @Nullable ZoneId dynamicNameTimeZone, @Nullable RefreshPolicy refreshPolicy) { this.index = index; - this.docType = docType; this.docId = docId; this.executionTimeField = executionTimeField; this.timeout = timeout; @@ -70,10 +54,6 @@ public String getIndex() { return index; } - public String getDocType() { - return docType; - } - public String getDocId() { return docId; } @@ -97,7 +77,7 @@ public boolean equals(Object o) { IndexAction that = (IndexAction) o; - return Objects.equals(index, that.index) && Objects.equals(docType, that.docType) && Objects.equals(docId, that.docId) + return Objects.equals(index, that.index) && Objects.equals(docId, that.docId) && Objects.equals(executionTimeField, that.executionTimeField) && Objects.equals(timeout, that.timeout) && Objects.equals(dynamicNameTimeZone, that.dynamicNameTimeZone) @@ -106,7 +86,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(index, docType, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy); + return Objects.hash(index, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy); } @Override @@ -115,9 +95,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (index != null) { builder.field(Field.INDEX.getPreferredName(), index); } - if (docType != null) { - builder.field(Field.DOC_TYPE.getPreferredName(), docType); - } if (docId != null) { builder.field(Field.DOC_ID.getPreferredName(), docId); } @@ -138,7 +115,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws public static IndexAction parse(String watchId, String actionId, XContentParser parser) throws IOException { String index = null; - String docType = null; String docId = null; String executionTimeField = null; TimeValue timeout = null; @@ -165,10 +141,7 @@ public static IndexAction parse(String watchId, String actionId, XContentParser watchId, actionId, currentFieldName); } } else if (token == XContentParser.Token.VALUE_STRING) { - if (Field.DOC_TYPE.match(currentFieldName, parser.getDeprecationHandler())) { - deprecationLogger.deprecatedAndMaybeLog("watcher_index_action", TYPES_DEPRECATION_MESSAGE); - docType = parser.text(); - } else if (Field.DOC_ID.match(currentFieldName, parser.getDeprecationHandler())) { + if (Field.DOC_ID.match(currentFieldName, parser.getDeprecationHandler())) { docId = parser.text(); } else if (Field.EXECUTION_TIME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { executionTimeField = parser.text(); @@ -194,15 +167,7 @@ public static IndexAction parse(String watchId, String actionId, XContentParser } } - return new IndexAction(index, docType, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy); - } - - /** - * Document types are deprecated, use {@link #builder(java.lang.String)} - */ - @Deprecated - public static Builder builder(String index, String docType) { - return new Builder(index, docType); + return new IndexAction(index, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy); } public static Builder builder(String index) { @@ -233,16 +198,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws static class Simulated extends Action.Result { private final String index; - private final String docType; @Nullable private final String docId; @Nullable private final RefreshPolicy refreshPolicy; private final XContentSource source; - protected Simulated(String index, String docType, @Nullable String docId, @Nullable RefreshPolicy refreshPolicy, + protected Simulated(String index, @Nullable String docId, @Nullable RefreshPolicy refreshPolicy, XContentSource source) { super(TYPE, Status.SIMULATED); this.index = index; - this.docType = docType; this.docId = docId; this.source = source; this.refreshPolicy = refreshPolicy; @@ -252,10 +215,6 @@ public String index() { return index; } - public String docType() { - return docType; - } - public String docId() { return docId; } @@ -268,8 +227,7 @@ public XContentSource source() { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(type) .startObject(Field.REQUEST.getPreferredName()) - .field(Field.INDEX.getPreferredName(), index) - .field(Field.DOC_TYPE.getPreferredName(), docType); + .field(Field.INDEX.getPreferredName(), index); if (docId != null) { builder.field(Field.DOC_ID.getPreferredName(), docId); @@ -288,25 +246,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws public static class Builder implements Action.Builder { final String index; - final String docType; String docId; String executionTimeField; TimeValue timeout; ZoneId dynamicNameTimeZone; RefreshPolicy refreshPolicy; - /** - * Document types are deprecated and should not be used. Use: {@link Builder#Builder(java.lang.String)} - */ - @Deprecated - private Builder(String index, String docType) { - this.index = index; - this.docType = docType; - } - private Builder(String index) { this.index = index; - this.docType = null; } public Builder setDocId(String docId) { @@ -336,13 +283,12 @@ public Builder setRefreshPolicy(RefreshPolicy refreshPolicy) { @Override public IndexAction build() { - return new IndexAction(index, docType, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy); + return new IndexAction(index, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy); } } interface Field { ParseField INDEX = new ParseField("index"); - ParseField DOC_TYPE = new ParseField("doc_type"); ParseField DOC_ID = new ParseField("doc_id"); ParseField EXECUTION_TIME_FIELD = new ParseField("execution_time_field"); ParseField SOURCE = new ParseField("source"); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherConcreteIndexTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherConcreteIndexTests.java index 5eddbb07884dc..88db8ef8221a0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherConcreteIndexTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherConcreteIndexTests.java @@ -38,7 +38,7 @@ public void testCanUseAnyConcreteIndexName() throws Exception { .trigger(schedule(interval("3s"))) .input(noneInput()) .condition(InternalAlwaysCondition.INSTANCE) - .addAction("indexer", indexAction(watchResultsIndex, "_doc"))) + .addAction("indexer", indexAction(watchResultsIndex))) .get(); assertTrue(putWatchResponse.isCreated()); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/ActionErrorIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/ActionErrorIntegrationTests.java index dbf4da8a7a1a6..17b612a6fa975 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/ActionErrorIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/ActionErrorIntegrationTests.java @@ -40,7 +40,7 @@ public void testErrorInAction() throws Exception { // adding an action that throws an error and is associated with a 60 minute throttle period // with such a period, on successful execution we other executions of the watch will be // throttled within the hour... but on failed execution there should be no throttling - .addAction("_action", TimeValue.timeValueMinutes(60), IndexAction.builder("foo", "bar"))) + .addAction("_action", TimeValue.timeValueMinutes(60), IndexAction.builder("foo"))) .get(); assertThat(putWatchResponse.isCreated(), is(true)); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java index 1ee821a1d53fa..538d5d8ef4719 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java @@ -105,26 +105,8 @@ public void testParser() throws Exception { assertThat(executable.action().timeout, equalTo(writeTimeout)); } - public void testDeprecationTypes() throws Exception { - XContentBuilder builder = jsonBuilder(); - builder.startObject(); - builder.field(IndexAction.Field.DOC_TYPE.getPreferredName(), "test-type"); - builder.endObject(); - IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, client); - XContentParser parser = createParser(builder); - parser.nextToken(); - ExecutableIndexAction executable = actionParser.parseExecutable(randomAlphaOfLength(5), randomAlphaOfLength(3), parser); - assertThat(executable.action().docType, equalTo("test-type")); - assertWarnings(IndexAction.TYPES_DEPRECATION_MESSAGE); - } - public void testParserFailure() throws Exception { // wrong type for field - expectParseFailure(jsonBuilder() - .startObject() - .field(IndexAction.Field.DOC_TYPE.getPreferredName(), 1234) - .endObject()); - expectParseFailure(jsonBuilder() .startObject() .field(IndexAction.Field.TIMEOUT.getPreferredName(), "1234") @@ -161,7 +143,7 @@ private void expectFailure(Class clazz, XContentBuilder builder) throws Exceptio } public void testUsingParameterIdWithBulkOrIdFieldThrowsIllegalState() { - final IndexAction action = new IndexAction("test-index", "test-type", "123", null, null, null, refreshPolicy); + final IndexAction action = new IndexAction("test-index", "123", null, null, null, refreshPolicy); final ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client, TimeValue.timeValueSeconds(30), TimeValue.timeValueSeconds(30)); final Map docWithId = Map.of( @@ -196,23 +178,18 @@ public void testUsingParameterIdWithBulkOrIdFieldThrowsIllegalState() { public void testThatIndexTypeIdDynamically() throws Exception { boolean configureIndexDynamically = randomBoolean(); - boolean configureTypeDynamically = randomBoolean(); - boolean configureIdDynamically = (configureTypeDynamically == false && configureIndexDynamically == false) || randomBoolean(); + boolean configureIdDynamically = configureIndexDynamically == false || randomBoolean(); var entries = new ArrayList>(4); entries.add(entry("foo", "bar")); if (configureIdDynamically) { entries.add(entry("_id", "my_dynamic_id")); } - if (configureTypeDynamically) { - entries.add(entry("_type", "my_dynamic_type")); - } if (configureIndexDynamically) { entries.add(entry("_index", "my_dynamic_index")); } final IndexAction action = new IndexAction(configureIndexDynamically ? null : "my_index", - configureTypeDynamically ? null : "my_type", configureIdDynamically ? null : "my_id", null, null, null, refreshPolicy); final ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client, @@ -234,7 +211,7 @@ public void testThatIndexTypeIdDynamically() throws Exception { } public void testThatIndexActionCanBeConfiguredWithDynamicIndexNameAndBulk() throws Exception { - final IndexAction action = new IndexAction(null, "my-type", null, null, null, null, refreshPolicy); + final IndexAction action = new IndexAction(null, null, null, null, null, refreshPolicy); final ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client, TimeValue.timeValueSeconds(30), TimeValue.timeValueSeconds(30)); @@ -281,7 +258,7 @@ public void testIndexActionExecuteSingleDoc() throws Exception { String docId = randomAlphaOfLength(5); String timestampField = randomFrom("@timestamp", null); - IndexAction action = new IndexAction("test-index", "test-type", docIdAsParam ? docId : null, timestampField, null, null, + IndexAction action = new IndexAction("test-index", docIdAsParam ? docId : null, timestampField, null, null, refreshPolicy); ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client, TimeValue.timeValueSeconds(30), TimeValue.timeValueSeconds(30)); @@ -331,7 +308,7 @@ public void testIndexActionExecuteSingleDoc() throws Exception { } public void testFailureResult() throws Exception { - IndexAction action = new IndexAction("test-index", "test-type", null, "@timestamp", null, null, refreshPolicy); + IndexAction action = new IndexAction("test-index", null, "@timestamp", null, null, refreshPolicy); ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client, TimeValue.timeValueSeconds(30), TimeValue.timeValueSeconds(30)); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java index dd71580490011..86cd201a9330f 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java @@ -394,7 +394,7 @@ public String type() { INDEX { @Override public Action.Builder action() throws Exception { - return IndexAction.builder("test_index", "test_type"); + return IndexAction.builder("test_index"); } @Override diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecuteWatchQueuedStatsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecuteWatchQueuedStatsTests.java index 4e99dc9803027..827651da52dd7 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecuteWatchQueuedStatsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecuteWatchQueuedStatsTests.java @@ -69,7 +69,7 @@ public void testQueuedStats() throws ExecutionException, InterruptedException { .addAction( "action", TimeValue.timeValueSeconds(1), - IndexAction.builder("test_index", "acknowledgement").setDocId("id"))) + IndexAction.builder("test_index").setDocId("id"))) .get(); final int numberOfIterations = 128 - scaledRandomIntBetween(0, 128); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java index 4c3f4ff26524e..214fb5f6df998 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java @@ -170,7 +170,7 @@ public void testSearchTransform() throws Exception { .trigger(schedule(interval("5s"))) .input(searchInput(inputRequest)) .transform(searchTransform(transformRequest)) - .addAction("_id", indexAction("output1", "result")) + .addAction("_id", indexAction("output1")) ).get(); assertThat(putWatchResponse.isCreated(), is(true)); putWatchResponse = new PutWatchRequestBuilder(client(), "_id2") diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java index e810c14615b73..cc0a024351262 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java @@ -585,14 +585,14 @@ private List randomActions() { randomFrom(DataAttachment.JSON, DataAttachment.YAML), EmailAttachments.EMPTY_ATTACHMENTS); list.add(new ActionWrapper("_email_" + randomAlphaOfLength(8), randomThrottler(), AlwaysConditionTests.randomCondition(scriptService), randomTransform(), - new ExecutableEmailAction(action, logger, emailService, templateEngine, htmlSanitizer, + new ExecutableEmailAction(action, logger, emailService, templateEngine, htmlSanitizer, Collections.emptyMap()), null, null)); } if (randomBoolean()) { ZoneOffset timeZone = randomBoolean() ? ZoneOffset.UTC : null; TimeValue timeout = randomBoolean() ? timeValueSeconds(between(1, 10000)) : null; WriteRequest.RefreshPolicy refreshPolicy = randomBoolean() ? null : randomFrom(WriteRequest.RefreshPolicy.values()); - IndexAction action = new IndexAction("_index", null, randomBoolean() ? "123" : null, null, timeout, timeZone, + IndexAction action = new IndexAction("_index", randomBoolean() ? "123" : null, null, timeout, timeZone, refreshPolicy); list.add(new ActionWrapper("_index_" + randomAlphaOfLength(8), randomThrottler(), AlwaysConditionTests.randomCondition(scriptService), randomTransform(),