Skip to content

Commit 025a0d5

Browse files
authored
Remove type from Watcher IndexAction (#47986)
Type information is ignored at index time, so is no longer required in Watcher. This commit removes the deprecated IndexAction constructors and builders that take types. Relates to #41059
1 parent 64c1dfa commit 025a0d5

File tree

10 files changed

+20
-106
lines changed

10 files changed

+20
-106
lines changed

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionBuilders.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ public static EmailAction.Builder emailAction(EmailTemplate email) {
3333
return EmailAction.builder(email);
3434
}
3535

36-
/**
37-
* Types are deprecated and should not be used. use {@link #indexAction(String)}
38-
*/
39-
@Deprecated
40-
public static IndexAction.Builder indexAction(String index, String type) {
41-
return IndexAction.builder(index, type);
42-
}
43-
4436
public static IndexAction.Builder indexAction(String index) {
4537
return IndexAction.builder(index);
4638
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/ExecutableIndexAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.common.unit.TimeValue;
1818
import org.elasticsearch.common.xcontent.XContentBuilder;
1919
import org.elasticsearch.common.xcontent.XContentType;
20-
import org.elasticsearch.index.mapper.MapperService;
2120
import org.elasticsearch.xpack.core.ClientHelper;
2221
import org.elasticsearch.xpack.core.watcher.actions.Action;
2322
import org.elasticsearch.xpack.core.watcher.actions.Action.Result.Status;
@@ -92,7 +91,7 @@ public Action.Result execute(String actionId, WatchExecutionContext ctx, Payload
9291
}
9392

9493
if (ctx.simulateAction(actionId)) {
95-
return new IndexAction.Simulated(indexRequest.index(), MapperService.SINGLE_MAPPING_NAME, indexRequest.id(),
94+
return new IndexAction.Simulated(indexRequest.index(), indexRequest.id(),
9695
action.refreshPolicy, new XContentSource(indexRequest.source(), XContentType.JSON));
9796
}
9897

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
*/
66
package org.elasticsearch.xpack.watcher.actions.index;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.ElasticsearchParseException;
109
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
1110
import org.elasticsearch.common.Nullable;
1211
import org.elasticsearch.common.ParseField;
13-
import org.elasticsearch.common.logging.DeprecationLogger;
1412
import org.elasticsearch.common.time.DateUtils;
1513
import org.elasticsearch.common.unit.TimeValue;
1614
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -29,31 +27,17 @@ public class IndexAction implements Action {
2927

3028
public static final String TYPE = "index";
3129

32-
@Nullable @Deprecated final String docType;
3330
@Nullable final String index;
3431
@Nullable final String docId;
3532
@Nullable final String executionTimeField;
3633
@Nullable final TimeValue timeout;
3734
@Nullable final ZoneId dynamicNameTimeZone;
3835
@Nullable final RefreshPolicy refreshPolicy;
3936

40-
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(IndexAction.class));
41-
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in a watcher index action is deprecated.";
42-
4337
public IndexAction(@Nullable String index, @Nullable String docId,
4438
@Nullable String executionTimeField,
4539
@Nullable TimeValue timeout, @Nullable ZoneId dynamicNameTimeZone, @Nullable RefreshPolicy refreshPolicy) {
46-
this(index, null, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
47-
}
48-
/**
49-
* Document types are deprecated, use constructor without docType
50-
*/
51-
@Deprecated
52-
public IndexAction(@Nullable String index, @Nullable String docType, @Nullable String docId,
53-
@Nullable String executionTimeField,
54-
@Nullable TimeValue timeout, @Nullable ZoneId dynamicNameTimeZone, @Nullable RefreshPolicy refreshPolicy) {
5540
this.index = index;
56-
this.docType = docType;
5741
this.docId = docId;
5842
this.executionTimeField = executionTimeField;
5943
this.timeout = timeout;
@@ -70,10 +54,6 @@ public String getIndex() {
7054
return index;
7155
}
7256

73-
public String getDocType() {
74-
return docType;
75-
}
76-
7757
public String getDocId() {
7858
return docId;
7959
}
@@ -97,7 +77,7 @@ public boolean equals(Object o) {
9777

9878
IndexAction that = (IndexAction) o;
9979

100-
return Objects.equals(index, that.index) && Objects.equals(docType, that.docType) && Objects.equals(docId, that.docId)
80+
return Objects.equals(index, that.index) && Objects.equals(docId, that.docId)
10181
&& Objects.equals(executionTimeField, that.executionTimeField)
10282
&& Objects.equals(timeout, that.timeout)
10383
&& Objects.equals(dynamicNameTimeZone, that.dynamicNameTimeZone)
@@ -106,7 +86,7 @@ public boolean equals(Object o) {
10686

10787
@Override
10888
public int hashCode() {
109-
return Objects.hash(index, docType, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
89+
return Objects.hash(index, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
11090
}
11191

11292
@Override
@@ -115,9 +95,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
11595
if (index != null) {
11696
builder.field(Field.INDEX.getPreferredName(), index);
11797
}
118-
if (docType != null) {
119-
builder.field(Field.DOC_TYPE.getPreferredName(), docType);
120-
}
12198
if (docId != null) {
12299
builder.field(Field.DOC_ID.getPreferredName(), docId);
123100
}
@@ -138,7 +115,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
138115

139116
public static IndexAction parse(String watchId, String actionId, XContentParser parser) throws IOException {
140117
String index = null;
141-
String docType = null;
142118
String docId = null;
143119
String executionTimeField = null;
144120
TimeValue timeout = null;
@@ -165,10 +141,7 @@ public static IndexAction parse(String watchId, String actionId, XContentParser
165141
watchId, actionId, currentFieldName);
166142
}
167143
} else if (token == XContentParser.Token.VALUE_STRING) {
168-
if (Field.DOC_TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
169-
deprecationLogger.deprecatedAndMaybeLog("watcher_index_action", TYPES_DEPRECATION_MESSAGE);
170-
docType = parser.text();
171-
} else if (Field.DOC_ID.match(currentFieldName, parser.getDeprecationHandler())) {
144+
if (Field.DOC_ID.match(currentFieldName, parser.getDeprecationHandler())) {
172145
docId = parser.text();
173146
} else if (Field.EXECUTION_TIME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
174147
executionTimeField = parser.text();
@@ -194,15 +167,7 @@ public static IndexAction parse(String watchId, String actionId, XContentParser
194167
}
195168
}
196169

197-
return new IndexAction(index, docType, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
198-
}
199-
200-
/**
201-
* Document types are deprecated, use {@link #builder(java.lang.String)}
202-
*/
203-
@Deprecated
204-
public static Builder builder(String index, String docType) {
205-
return new Builder(index, docType);
170+
return new IndexAction(index, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
206171
}
207172

208173
public static Builder builder(String index) {
@@ -233,16 +198,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
233198
static class Simulated extends Action.Result {
234199

235200
private final String index;
236-
private final String docType;
237201
@Nullable private final String docId;
238202
@Nullable private final RefreshPolicy refreshPolicy;
239203
private final XContentSource source;
240204

241-
protected Simulated(String index, String docType, @Nullable String docId, @Nullable RefreshPolicy refreshPolicy,
205+
protected Simulated(String index, @Nullable String docId, @Nullable RefreshPolicy refreshPolicy,
242206
XContentSource source) {
243207
super(TYPE, Status.SIMULATED);
244208
this.index = index;
245-
this.docType = docType;
246209
this.docId = docId;
247210
this.source = source;
248211
this.refreshPolicy = refreshPolicy;
@@ -252,10 +215,6 @@ public String index() {
252215
return index;
253216
}
254217

255-
public String docType() {
256-
return docType;
257-
}
258-
259218
public String docId() {
260219
return docId;
261220
}
@@ -268,8 +227,7 @@ public XContentSource source() {
268227
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
269228
builder.startObject(type)
270229
.startObject(Field.REQUEST.getPreferredName())
271-
.field(Field.INDEX.getPreferredName(), index)
272-
.field(Field.DOC_TYPE.getPreferredName(), docType);
230+
.field(Field.INDEX.getPreferredName(), index);
273231

274232
if (docId != null) {
275233
builder.field(Field.DOC_ID.getPreferredName(), docId);
@@ -288,25 +246,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
288246
public static class Builder implements Action.Builder<IndexAction> {
289247

290248
final String index;
291-
final String docType;
292249
String docId;
293250
String executionTimeField;
294251
TimeValue timeout;
295252
ZoneId dynamicNameTimeZone;
296253
RefreshPolicy refreshPolicy;
297254

298-
/**
299-
* Document types are deprecated and should not be used. Use: {@link Builder#Builder(java.lang.String)}
300-
*/
301-
@Deprecated
302-
private Builder(String index, String docType) {
303-
this.index = index;
304-
this.docType = docType;
305-
}
306-
307255
private Builder(String index) {
308256
this.index = index;
309-
this.docType = null;
310257
}
311258

312259
public Builder setDocId(String docId) {
@@ -336,13 +283,12 @@ public Builder setRefreshPolicy(RefreshPolicy refreshPolicy) {
336283

337284
@Override
338285
public IndexAction build() {
339-
return new IndexAction(index, docType, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
286+
return new IndexAction(index, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
340287
}
341288
}
342289

343290
interface Field {
344291
ParseField INDEX = new ParseField("index");
345-
ParseField DOC_TYPE = new ParseField("doc_type");
346292
ParseField DOC_ID = new ParseField("doc_id");
347293
ParseField EXECUTION_TIME_FIELD = new ParseField("execution_time_field");
348294
ParseField SOURCE = new ParseField("source");

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherConcreteIndexTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void testCanUseAnyConcreteIndexName() throws Exception {
3838
.trigger(schedule(interval("3s")))
3939
.input(noneInput())
4040
.condition(InternalAlwaysCondition.INSTANCE)
41-
.addAction("indexer", indexAction(watchResultsIndex, "_doc")))
41+
.addAction("indexer", indexAction(watchResultsIndex)))
4242
.get();
4343

4444
assertTrue(putWatchResponse.isCreated());

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/ActionErrorIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void testErrorInAction() throws Exception {
4040
// adding an action that throws an error and is associated with a 60 minute throttle period
4141
// with such a period, on successful execution we other executions of the watch will be
4242
// throttled within the hour... but on failed execution there should be no throttling
43-
.addAction("_action", TimeValue.timeValueMinutes(60), IndexAction.builder("foo", "bar")))
43+
.addAction("_action", TimeValue.timeValueMinutes(60), IndexAction.builder("foo")))
4444
.get();
4545

4646
assertThat(putWatchResponse.isCreated(), is(true));

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,8 @@ public void testParser() throws Exception {
105105
assertThat(executable.action().timeout, equalTo(writeTimeout));
106106
}
107107

108-
public void testDeprecationTypes() throws Exception {
109-
XContentBuilder builder = jsonBuilder();
110-
builder.startObject();
111-
builder.field(IndexAction.Field.DOC_TYPE.getPreferredName(), "test-type");
112-
builder.endObject();
113-
IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, client);
114-
XContentParser parser = createParser(builder);
115-
parser.nextToken();
116-
ExecutableIndexAction executable = actionParser.parseExecutable(randomAlphaOfLength(5), randomAlphaOfLength(3), parser);
117-
assertThat(executable.action().docType, equalTo("test-type"));
118-
assertWarnings(IndexAction.TYPES_DEPRECATION_MESSAGE);
119-
}
120-
121108
public void testParserFailure() throws Exception {
122109
// wrong type for field
123-
expectParseFailure(jsonBuilder()
124-
.startObject()
125-
.field(IndexAction.Field.DOC_TYPE.getPreferredName(), 1234)
126-
.endObject());
127-
128110
expectParseFailure(jsonBuilder()
129111
.startObject()
130112
.field(IndexAction.Field.TIMEOUT.getPreferredName(), "1234")
@@ -161,7 +143,7 @@ private void expectFailure(Class clazz, XContentBuilder builder) throws Exceptio
161143
}
162144

163145
public void testUsingParameterIdWithBulkOrIdFieldThrowsIllegalState() {
164-
final IndexAction action = new IndexAction("test-index", "test-type", "123", null, null, null, refreshPolicy);
146+
final IndexAction action = new IndexAction("test-index", "123", null, null, null, refreshPolicy);
165147
final ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client,
166148
TimeValue.timeValueSeconds(30), TimeValue.timeValueSeconds(30));
167149
final Map<String, Object> docWithId = Map.of(
@@ -196,23 +178,18 @@ public void testUsingParameterIdWithBulkOrIdFieldThrowsIllegalState() {
196178

197179
public void testThatIndexTypeIdDynamically() throws Exception {
198180
boolean configureIndexDynamically = randomBoolean();
199-
boolean configureTypeDynamically = randomBoolean();
200-
boolean configureIdDynamically = (configureTypeDynamically == false && configureIndexDynamically == false) || randomBoolean();
181+
boolean configureIdDynamically = configureIndexDynamically == false || randomBoolean();
201182

202183
var entries = new ArrayList<Map.Entry<String, Object>>(4);
203184
entries.add(entry("foo", "bar"));
204185
if (configureIdDynamically) {
205186
entries.add(entry("_id", "my_dynamic_id"));
206187
}
207-
if (configureTypeDynamically) {
208-
entries.add(entry("_type", "my_dynamic_type"));
209-
}
210188
if (configureIndexDynamically) {
211189
entries.add(entry("_index", "my_dynamic_index"));
212190
}
213191

214192
final IndexAction action = new IndexAction(configureIndexDynamically ? null : "my_index",
215-
configureTypeDynamically ? null : "my_type",
216193
configureIdDynamically ? null : "my_id",
217194
null, null, null, refreshPolicy);
218195
final ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client,
@@ -234,7 +211,7 @@ public void testThatIndexTypeIdDynamically() throws Exception {
234211
}
235212

236213
public void testThatIndexActionCanBeConfiguredWithDynamicIndexNameAndBulk() throws Exception {
237-
final IndexAction action = new IndexAction(null, "my-type", null, null, null, null, refreshPolicy);
214+
final IndexAction action = new IndexAction(null, null, null, null, null, refreshPolicy);
238215
final ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client,
239216
TimeValue.timeValueSeconds(30), TimeValue.timeValueSeconds(30));
240217

@@ -281,7 +258,7 @@ public void testIndexActionExecuteSingleDoc() throws Exception {
281258
String docId = randomAlphaOfLength(5);
282259
String timestampField = randomFrom("@timestamp", null);
283260

284-
IndexAction action = new IndexAction("test-index", "test-type", docIdAsParam ? docId : null, timestampField, null, null,
261+
IndexAction action = new IndexAction("test-index", docIdAsParam ? docId : null, timestampField, null, null,
285262
refreshPolicy);
286263
ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client, TimeValue.timeValueSeconds(30),
287264
TimeValue.timeValueSeconds(30));
@@ -331,7 +308,7 @@ public void testIndexActionExecuteSingleDoc() throws Exception {
331308
}
332309

333310
public void testFailureResult() throws Exception {
334-
IndexAction action = new IndexAction("test-index", "test-type", null, "@timestamp", null, null, refreshPolicy);
311+
IndexAction action = new IndexAction("test-index", null, "@timestamp", null, null, refreshPolicy);
335312
ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, client,
336313
TimeValue.timeValueSeconds(30), TimeValue.timeValueSeconds(30));
337314

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public String type() {
394394
INDEX {
395395
@Override
396396
public Action.Builder<IndexAction> action() throws Exception {
397-
return IndexAction.builder("test_index", "test_type");
397+
return IndexAction.builder("test_index");
398398
}
399399

400400
@Override

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecuteWatchQueuedStatsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testQueuedStats() throws ExecutionException, InterruptedException {
6969
.addAction(
7070
"action",
7171
TimeValue.timeValueSeconds(1),
72-
IndexAction.builder("test_index", "acknowledgement").setDocId("id")))
72+
IndexAction.builder("test_index").setDocId("id")))
7373
.get();
7474

7575
final int numberOfIterations = 128 - scaledRandomIntBetween(0, 128);

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void testSearchTransform() throws Exception {
170170
.trigger(schedule(interval("5s")))
171171
.input(searchInput(inputRequest))
172172
.transform(searchTransform(transformRequest))
173-
.addAction("_id", indexAction("output1", "result"))
173+
.addAction("_id", indexAction("output1"))
174174
).get();
175175
assertThat(putWatchResponse.isCreated(), is(true));
176176
putWatchResponse = new PutWatchRequestBuilder(client(), "_id2")

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,14 @@ private List<ActionWrapper> randomActions() {
585585
randomFrom(DataAttachment.JSON, DataAttachment.YAML), EmailAttachments.EMPTY_ATTACHMENTS);
586586
list.add(new ActionWrapper("_email_" + randomAlphaOfLength(8), randomThrottler(),
587587
AlwaysConditionTests.randomCondition(scriptService), randomTransform(),
588-
new ExecutableEmailAction(action, logger, emailService, templateEngine, htmlSanitizer,
588+
new ExecutableEmailAction(action, logger, emailService, templateEngine, htmlSanitizer,
589589
Collections.emptyMap()), null, null));
590590
}
591591
if (randomBoolean()) {
592592
ZoneOffset timeZone = randomBoolean() ? ZoneOffset.UTC : null;
593593
TimeValue timeout = randomBoolean() ? timeValueSeconds(between(1, 10000)) : null;
594594
WriteRequest.RefreshPolicy refreshPolicy = randomBoolean() ? null : randomFrom(WriteRequest.RefreshPolicy.values());
595-
IndexAction action = new IndexAction("_index", null, randomBoolean() ? "123" : null, null, timeout, timeZone,
595+
IndexAction action = new IndexAction("_index", randomBoolean() ? "123" : null, null, timeout, timeZone,
596596
refreshPolicy);
597597
list.add(new ActionWrapper("_index_" + randomAlphaOfLength(8), randomThrottler(),
598598
AlwaysConditionTests.randomCondition(scriptService), randomTransform(),

0 commit comments

Comments
 (0)