From 601a3c78be84cdb32fb124e0e10a506867b72f7d Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 4 Oct 2018 12:45:13 +0100 Subject: [PATCH 01/20] broekn --- .../client/WatcherRequestConverters.java | 26 +++ .../client/watcher/ExecuteWatchRequest.java | 168 ++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java index 3b52d1c7b9943..2c8f728bc5f7f 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java @@ -20,9 +20,11 @@ package org.elasticsearch.client; import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; +import org.elasticsearch.client.watcher.ExecuteWatchRequest; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; @@ -59,4 +61,28 @@ static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) { Request request = new Request(HttpDelete.METHOD_NAME, endpoint); return request; } + + static Request executeWatch(ExecuteWatchRequest executeWatchRequest) { + RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder() + .addPathPart("_xpack", "watcher", "watch"); + if (executeWatchRequest.getId() != null) { + builder.addPathPart(executeWatchRequest.getId()); + } + String endpoint = builder.addPathPart("_execute").build(); + + Request request = new Request(HttpPost.METHOD_NAME, endpoint); + RequestConverters.Params params = new RequestConverters.Params(request); + if (executeWatchRequest.isDebug()) { + params.putParam("debug", "true"); + } + if (executeWatchRequest.isIgnoreCondition()) { + params.putParam("ignore_condition", "true"); + } + if (executeWatchRequest.isRecordExecution()) { + params.putParam("record_execution", "true"); + } + + request.setEntity(executeWatchRequest.toHttpEntity()); + return request; + } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java new file mode 100644 index 0000000000000..6f1d13bcbd853 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java @@ -0,0 +1,168 @@ +package org.elasticsearch.client.watcher; + +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ValidateActions; +import org.elasticsearch.client.Validatable; +import org.elasticsearch.client.ValidationException; +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentType; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * An execute watch request to execute a watch by id + */ +public class ExecuteWatchRequest { + + public enum ActionExecutionMode { + SIMULATE, FORCE_SIMULATE, EXECUTE, FORCE_EXECUTE, SKIP + } + + private final String id; + private final BytesReference watchSource; + + private boolean ignoreCondition = false; + private boolean recordExecution = false; + private boolean debug = false; + + @Nullable + private Map triggerData = null; + @Nullable private Map alternativeInput = null; + private Map actionModes = new HashMap<>(); + + public ExecuteWatchRequest(BytesReference watchSource) { + this.id = null; + this.watchSource = Objects.requireNonNull(watchSource, "Watch source cannot be null"); + } + + /** + * @param id the id of the watch to execute + */ + public ExecuteWatchRequest(String id) { + this.id = Objects.requireNonNull(id, "Watch id cannot be null"); + this.watchSource = null; + } + + /** + * @return The id of the watch to be executed + */ + public String getId() { + return id; + } + + /** + * @return Should the condition for this execution be ignored + */ + public boolean isIgnoreCondition() { + return ignoreCondition; + } + + /** + * @param ignoreCondition set if the condition for this execution be ignored + */ + public void setIgnoreCondition(boolean ignoreCondition) { + this.ignoreCondition = ignoreCondition; + } + + /** + * @return Should this execution be recorded in the history index + */ + public boolean isRecordExecution() { + return recordExecution; + } + + /** + * @param recordExecution Sets if this execution be recorded in the history index + */ + public void setRecordExecution(boolean recordExecution) { + if (watchSource != null) { + throw new IllegalArgumentException("The execution of an line watch cannot be recorded"); + } + this.recordExecution = recordExecution; + } + + /** + * @return The alertnative input to use (may be null) + */ + public Map getAlternativeInput() { + return alternativeInput; + } + + /** + * @param alternativeInput Set's the alternative input + */ + public void setAlternativeInput(Map alternativeInput) { + this.alternativeInput = alternativeInput; + } + + /** + * @param data The data that should be associated with the trigger event. + */ + public void setTriggerData(Map data) throws IOException { + this.triggerData = data; + } + + /** + * @return the trigger to use + */ + public Map getTriggerData() { + return triggerData; + } + + /** + * @return the source of the watch to execute + */ + public BytesReference getWatchSource() { + return watchSource; + } + + /** + * @return the execution modes for the actions. These modes determine the nature of the execution + * of the watch actions while the watch is executing. + */ + public Map getActionModes() { + return actionModes; + } + + /** + * Sets the action execution mode for the give action (identified by its id). + * + * @param actionId the action id. + * @param actionMode the execution mode of the action. + */ + public void setActionMode(String actionId, ActionExecutionMode actionMode) { + Objects.requireNonNull(actionId, "actionId cannot be null"); + actionModes.put(actionId, actionMode); + } + + /** + * @return whether the watch should execute in debug mode. In debug mode the execution {@code vars} + * will be returned as part of the watch record. + */ + public boolean isDebug() { + return debug; + } + + /** + * @param debug indicates whether the watch should execute in debug mode. In debug mode the + * returned watch record will hold the execution {@code vars} + */ + public void setDebug(boolean debug) { + this.debug = debug; + } + + @Override + public String toString() { + return "execute[" + id + "]"; + } +} + From 3262fcd4926bd928ca91fb59bad7752b84bd0672 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 18 Oct 2018 14:33:38 +0100 Subject: [PATCH 02/20] WIP --- .../elasticsearch/client/WatcherClient.java | 12 ++++++ .../client/watcher/ExecuteWatchRequest.java | 7 +++- .../client/watcher/ExecuteWatchResponse.java | 40 +++++++++++++++++++ .../org/elasticsearch/client/WatcherIT.java | 11 +++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java index cfa5e6e61fa1f..f9f0cd3c49e94 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java @@ -23,6 +23,8 @@ import org.elasticsearch.client.watcher.ActivateWatchResponse; import org.elasticsearch.client.watcher.AckWatchRequest; import org.elasticsearch.client.watcher.AckWatchResponse; +import org.elasticsearch.client.watcher.ExecuteWatchRequest; +import org.elasticsearch.client.watcher.ExecuteWatchResponse; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; @@ -150,4 +152,14 @@ public void activateWatchAsync(ActivateWatchRequest request, RequestOptions opti ActivateWatchResponse::fromXContent, listener, singleton(404)); } + public ExecuteWatchResponse executeWatch(ExecuteWatchRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, WatcherRequestConverters::executeWatch, options, + ExecuteWatchResponse::fromXContent, singleton(404)); + } + + public void executeWatchAsync(ExecuteWatchRequest request, RequestOptions options, ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, WatcherRequestConverters::executeWatch, options, + ExecuteWatchResponse::fromXContent, listener, singleton(404)); + } + } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java index 6f1d13bcbd853..756f36932ec23 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java @@ -1,5 +1,6 @@ package org.elasticsearch.client.watcher; +import org.apache.http.HttpEntity; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ValidateActions; @@ -21,7 +22,11 @@ /** * An execute watch request to execute a watch by id */ -public class ExecuteWatchRequest { +public class ExecuteWatchRequest implements Validatable { + + public HttpEntity toHttpEntity() { + return null; + } public enum ActionExecutionMode { SIMULATE, FORCE_SIMULATE, EXECUTE, FORCE_EXECUTE, SKIP diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java new file mode 100644 index 0000000000000..f4dd6818c3592 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java @@ -0,0 +1,40 @@ +package org.elasticsearch.client.watcher; + +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; + +import java.io.IOException; + +public class ExecuteWatchResponse { + + private String recordId; + private XContentSource recordSource; + + public ExecuteWatchResponse() { + } + + public ExecuteWatchResponse(String recordId, BytesReference recordSource, XContentType contentType) { + this.recordId = recordId; + this.recordSource = new XContentSource(recordSource, contentType); + } + + /** + * @return The id of the watch record holding the watch execution result. + */ + public String getRecordId() { + return recordId; + } + + /** + * @return The watch record source + */ + public XContentSource getRecordSource() { + return recordSource; + } + + public static ExecuteWatchResponse fromXContent(XContentParser parser) throws IOException { + return null; + } + +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java index 4ea462efb02a0..9e97b41151dd4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java @@ -25,6 +25,8 @@ import org.elasticsearch.client.watcher.AckWatchResponse; import org.elasticsearch.client.watcher.ActionStatus; import org.elasticsearch.client.watcher.ActionStatus.AckStatus; +import org.elasticsearch.client.watcher.ExecuteWatchRequest; +import org.elasticsearch.client.watcher.ExecuteWatchResponse; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentType; @@ -133,4 +135,13 @@ public void testActivateWatchThatDoesNotExist() throws Exception { highLevelClient().watcher().activateWatch(new ActivateWatchRequest(watchId), RequestOptions.DEFAULT)); assertEquals(RestStatus.NOT_FOUND, exception.status()); } + + public void testExecuteWatchById() throws Exception { + String watchId = randomAlphaOfLength(10); + createWatch(watchId); + + ExecuteWatchResponse response = highLevelClient().watcher().executeWatch(new ExecuteWatchRequest(watchId), + RequestOptions.DEFAULT); + + } } From 7a462dfb56d91f12c98b12a59bee85134d3c157b Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 24 Oct 2018 13:28:45 +0100 Subject: [PATCH 03/20] Move ObjectPath, XContentSoure and XContentUtils to core --- .../common}/xcontent/ObjectPath.java | 45 +++++++++++-------- .../common}/xcontent/XContentSource.java | 30 ++++++++----- .../common/xcontent/XContentUtils.java | 26 +++++++---- .../common}/xcontent/MapPathTests.java | 22 ++++++--- .../common}/xcontent/XContentSourceTests.java | 26 +++++++---- .../expressiondsl/ExpressionParser.java | 2 +- .../watcher/client/WatchSourceBuilder.java | 2 +- .../actions/execute/ExecuteWatchResponse.java | 2 +- .../actions/get/GetWatchResponse.java | 2 +- .../expressiondsl/ExpressionParserTests.java | 2 +- .../ml/MachineLearningFeatureSetTests.java | 2 +- .../security/SecurityFeatureSetTests.java | 2 +- .../actions/index/ExecutableIndexAction.java | 2 +- .../watcher/actions/index/IndexAction.java | 2 +- .../condition/AbstractCompareCondition.java | 2 +- .../condition/ArrayCompareCondition.java | 4 +- .../watcher/condition/CompareCondition.java | 4 +- .../slack/message/DynamicAttachments.java | 2 +- .../xpack/watcher/WatcherFeatureSetTests.java | 4 +- .../actions/ActionErrorIntegrationTests.java | 2 +- .../actions/TimeThrottleIntegrationTests.java | 2 +- .../actions/index/IndexActionTests.java | 2 +- .../throttler/ActionThrottleTests.java | 2 +- .../webhook/WebhookHttpsIntegrationTests.java | 2 +- .../webhook/WebhookIntegrationTests.java | 2 +- .../execution/ExecutionServiceTests.java | 2 +- .../HistoryTemplateHttpMappingsTests.java | 2 +- .../watcher/input/http/HttpInputTests.java | 2 +- .../email/EmailSecretsIntegrationTests.java | 2 +- .../watcher/support/FilterXContentTests.java | 2 +- .../xpack/watcher/support/VariablesTests.java | 2 +- .../AbstractWatcherIntegrationTestCase.java | 2 +- .../xpack/watcher/test/WatcherTestUtils.java | 2 +- .../test/integration/BasicWatcherTests.java | 2 +- .../ExecutionVarsIntegrationTests.java | 4 +- .../integration/HistoryIntegrationTests.java | 2 +- .../HttpSecretsIntegrationTests.java | 2 +- .../test/integration/WatchMetadataTests.java | 2 +- .../action/activate/ActivateWatchTests.java | 2 +- .../action/delete/DeleteWatchTests.java | 2 +- .../action/execute/ExecuteWatchTests.java | 2 +- .../transport/action/get/GetWatchTests.java | 2 +- .../watch/WatchStatusIntegrationTests.java | 2 +- .../xpack/restart/FullClusterRestartIT.java | 2 +- .../elasticsearch/multi_node/RollupIT.java | 2 +- .../upgrades/RollupIDUpgradeIT.java | 2 +- 46 files changed, 142 insertions(+), 97 deletions(-) rename {x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support => server/src/main/java/org/elasticsearch/common}/xcontent/ObjectPath.java (53%) rename {x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support => server/src/main/java/org/elasticsearch/common}/xcontent/XContentSource.java (81%) rename {x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher => server/src/main/java/org/elasticsearch}/common/xcontent/XContentUtils.java (62%) rename {x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support => server/src/test/java/org/elasticsearch/common}/xcontent/MapPathTests.java (72%) rename {x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support => server/src/test/java/org/elasticsearch/common}/xcontent/XContentSourceTests.java (62%) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java b/server/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java similarity index 53% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java rename to server/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java index 67ef405238aba..fc184675eff25 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.watcher.support.xcontent; +package org.elasticsearch.common.xcontent; import org.elasticsearch.common.Strings; @@ -11,11 +24,20 @@ import java.util.List; import java.util.Map; -public class ObjectPath { +/** + * Helper class for navigating arbitrary nested maps and lists using dot + * notation + */ +public final class ObjectPath { private ObjectPath() { } + /** + * Extracts the value at a dot notation location in the given object + * @return {@code null} if the location does not exist, otherwise the relevant value + */ + @SuppressWarnings("unchecked") public static T eval(String path, Object object) { return (T) evalContext(path, object); } @@ -24,25 +46,16 @@ private static Object evalContext(String path, Object ctx) { final String[] parts; if (path == null || path.isEmpty()) parts = Strings.EMPTY_ARRAY; else parts = path.split("\\."); - StringBuilder resolved = new StringBuilder(); for (String part : parts) { if (ctx == null) { return null; } if (ctx instanceof Map) { ctx = ((Map) ctx).get(part); - if (resolved.length() != 0) { - resolved.append("."); - } - resolved.append(part); } else if (ctx instanceof List) { try { int index = Integer.parseInt(part); ctx = ((List) ctx).get(index); - if (resolved.length() != 0) { - resolved.append("."); - } - resolved.append(part); } catch (NumberFormatException nfe) { return null; } @@ -50,10 +63,6 @@ private static Object evalContext(String path, Object ctx) { try { int index = Integer.parseInt(part); ctx = Array.get(ctx, index); - if (resolved.length() != 0) { - resolved.append("."); - } - resolved.append(part); } catch (NumberFormatException nfe) { return null; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java b/server/src/main/java/org/elasticsearch/common/xcontent/XContentSource.java similarity index 81% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java rename to server/src/main/java/org/elasticsearch/common/xcontent/XContentSource.java index 059718973201c..9908a4f011d6e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/XContentSource.java @@ -1,22 +1,28 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.watcher.support.xcontent; +package org.elasticsearch.common.xcontent; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; import java.io.IOException; import java.io.InputStream; @@ -24,7 +30,7 @@ import java.util.Map; /** - * Encapsulates the xcontent source + * Encapsulates arbitrary XContent source */ public class XContentSource implements ToXContent { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java b/server/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java similarity index 62% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java rename to server/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java index da8ac3ef9d8f1..9a159880e1efa 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java @@ -1,20 +1,30 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.watcher.common.xcontent; - -import org.elasticsearch.common.xcontent.XContentParser; +package org.elasticsearch.common.xcontent; import java.io.IOException; -public class XContentUtils { +public final class XContentUtils { private XContentUtils() { } - // TODO open this up in core public static Object readValue(XContentParser parser, XContentParser.Token token) throws IOException { if (token == XContentParser.Token.VALUE_NULL) { return null; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java b/server/src/test/java/org/elasticsearch/common/xcontent/MapPathTests.java similarity index 72% rename from x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java rename to server/src/test/java/org/elasticsearch/common/xcontent/MapPathTests.java index f89552a637726..3de379fe11626 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java +++ b/server/src/test/java/org/elasticsearch/common/xcontent/MapPathTests.java @@ -1,12 +1,24 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.watcher.support.xcontent; +package org.elasticsearch.common.xcontent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import java.util.ArrayList; import java.util.Arrays; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/XContentSourceTests.java b/server/src/test/java/org/elasticsearch/common/xcontent/XContentSourceTests.java similarity index 62% rename from x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/XContentSourceTests.java rename to server/src/test/java/org/elasticsearch/common/xcontent/XContentSourceTests.java index 5fe451458e025..d0a8df09573c1 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/XContentSourceTests.java +++ b/server/src/test/java/org/elasticsearch/common/xcontent/XContentSourceTests.java @@ -1,17 +1,25 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.watcher.support.xcontent; - +package org.elasticsearch.common.xcontent; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.smileBuilder; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java index d2392b3d172aa..4778b10dae007 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import java.io.IOException; import java.io.InputStream; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java index 001a430ddb1e6..c8e490da9d076 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java @@ -22,7 +22,7 @@ import org.elasticsearch.xpack.core.watcher.input.none.NoneInput; import org.elasticsearch.xpack.core.watcher.support.Exceptions; import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transform.Transform; import org.elasticsearch.xpack.core.watcher.trigger.Trigger; import org.elasticsearch.xpack.core.watcher.watch.WatchField; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java index c0eac9b3c61d2..1ed51f594432a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java @@ -10,7 +10,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import java.io.IOException; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java index 7b94b446ffefa..fe33b27463ac2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java @@ -11,7 +11,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.WatchStatus; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java index 070f36b72e920..c4f1efd1dd9e8 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.XPackClientPlugin; import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldValue; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import java.io.IOException; import java.io.StringWriter; diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java index 6a2f25f6a3046..55c8de75c5c4f 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java @@ -45,7 +45,7 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import org.elasticsearch.xpack.core.ml.stats.ForecastStats; import org.elasticsearch.xpack.core.ml.stats.ForecastStatsTests; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.junit.Before; import java.util.Arrays; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java index 2944cd3134a79..05bf51a9b3d40 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java @@ -20,7 +20,7 @@ import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.security.SecurityFeatureSetUsage; import org.elasticsearch.xpack.core.security.user.AnonymousUser; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.security.authc.Realms; import org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore; import org.elasticsearch.xpack.security.authz.store.CompositeRolesStore; 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 a156e68a4b1ed..13b6d70cca6c4 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 @@ -23,7 +23,7 @@ import org.elasticsearch.xpack.core.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.support.ArrayObjectIterator; import org.joda.time.DateTime; 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 ceb6ac88f17f6..55354a6c96ca7 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 @@ -14,7 +14,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.joda.time.DateTimeZone; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java index 81e3eb464e69b..7b0c176927d8d 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java @@ -9,7 +9,7 @@ import org.elasticsearch.xpack.core.watcher.condition.ExecutableCondition; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.support.Variables; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java index c1c458b1d661a..47af1bf13d820 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java @@ -8,8 +8,8 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.XContentUtils; +import org.elasticsearch.common.xcontent.ObjectPath; import java.io.IOException; import java.time.Clock; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java index a3b21dec295d2..7c990e6582ea2 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java @@ -8,8 +8,8 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.XContentUtils; +import org.elasticsearch.common.xcontent.ObjectPath; import java.io.IOException; import java.time.Clock; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java index 4c53fc767c788..3a5eae2eb56dd 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java index e1e8b5b2ddd7d..e6eec4fac9f6b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java @@ -23,8 +23,8 @@ import org.elasticsearch.xpack.core.watcher.WatcherFeatureSetUsage; import org.elasticsearch.xpack.core.watcher.WatcherMetaData; import org.elasticsearch.xpack.core.watcher.common.stats.Counters; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; import org.junit.Before; 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 6590d6c271b26..e6654f7e127db 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 @@ -9,7 +9,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.watcher.actions.index.IndexAction; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java index 9b851131d7d6d..a753bf05b8229 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import java.util.Map; 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 346b2d0e85cdf..7c5dafc721760 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 @@ -28,7 +28,7 @@ import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.actions.Action.Result.Status; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.test.WatcherTestUtils; import org.joda.time.DateTime; 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 b2a1e7bb2cd58..ccb25de61e46e 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 @@ -15,7 +15,7 @@ import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchRequestBuilder; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java index 4e62eedd221d2..90856f1296a17 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.ssl.TestsSSLService; import org.elasticsearch.xpack.core.watcher.history.WatchRecord; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.watcher.actions.ActionBuilders; import org.elasticsearch.xpack.watcher.common.http.HttpMethod; import org.elasticsearch.xpack.watcher.common.http.HttpRequestTemplate; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java index d26d07a8fbdb6..7e93587711b77 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java @@ -15,7 +15,7 @@ import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.xpack.core.watcher.history.WatchRecord; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.watcher.actions.ActionBuilders; import org.elasticsearch.xpack.watcher.common.http.HttpMethod; import org.elasticsearch.xpack.watcher.common.http.HttpRequestTemplate; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java index 069dca8f2b187..13761948adccf 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java @@ -53,7 +53,7 @@ import org.elasticsearch.xpack.core.watcher.history.WatchRecord; import org.elasticsearch.xpack.core.watcher.input.ExecutableInput; import org.elasticsearch.xpack.core.watcher.input.Input; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transform.ExecutableTransform; import org.elasticsearch.xpack.core.watcher.transform.Transform; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index 0e120793fbc18..a93b1e94ce957 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.common.http.HttpMethod; import org.elasticsearch.xpack.watcher.common.http.HttpRequestTemplate; import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java index c29b3e1f8b458..42788b2ea7ad1 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.common.http.HttpClient; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java index 02a2128e112fb..a8252e6c4e66e 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.xpack.core.watcher.crypto.CryptoService; import org.elasticsearch.xpack.core.watcher.crypto.CryptoServiceTests; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java index eadf739b175a3..fbe0b98f4ca63 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.hamcrest.Matchers; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java index 4ab5b7b7b87aa..cd544c85b30bb 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java @@ -8,7 +8,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.test.WatcherTestUtils; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 40e87af1f0b26..5174ecc3c3c61 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -45,7 +45,7 @@ import org.elasticsearch.xpack.core.watcher.execution.TriggeredWatchStoreField; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; import org.elasticsearch.xpack.core.watcher.support.WatcherIndexTemplateRegistryField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; import org.elasticsearch.xpack.core.watcher.watch.ClockMock; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java index bb5a6eabdd5b9..1ca78a3b7920d 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java @@ -21,7 +21,7 @@ import org.elasticsearch.xpack.core.watcher.common.secret.Secret; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java index c07e6ba3db113..f0eaf804243dd 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java index 90b14233b8d27..5b111877cbbc6 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java @@ -10,8 +10,8 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.watcher.condition.ScriptCondition; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java index 5c9dafeaca001..79c35caf5e259 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java @@ -17,7 +17,7 @@ import org.elasticsearch.xpack.core.watcher.actions.ActionStatus; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.core.watcher.input.Input; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.WatchStatus; import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java index 0de8fc1ee4bc0..59082aa1b37ef 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java @@ -17,7 +17,7 @@ import org.elasticsearch.xpack.core.watcher.crypto.CryptoService; import org.elasticsearch.xpack.core.watcher.crypto.CryptoServiceTests; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java index 87c10c97c8fc6..143f760f23c1e 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java index 1080880ea8bbb..87d9da1451ea5 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.activate.ActivateWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java index 065981a426039..b0c3f6359b52b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java @@ -12,7 +12,7 @@ import org.elasticsearch.test.http.MockResponse; import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java index c743922a4d715..df361566678ed 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java @@ -11,7 +11,7 @@ import org.elasticsearch.xpack.core.watcher.client.WatcherClient; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchRequestBuilder; import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java index 226879b5e3047..b39be5b6d9e64 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.test.junit.annotations.TestLogging; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchRequest; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java index 9f738d8daa6b2..7687a9d052470 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java @@ -8,7 +8,7 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; -import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; +import org.elasticsearch.common.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.watcher.condition.NeverCondition; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index c112709bbe04b..254fa37f94463 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -19,7 +19,7 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.security.support.SecurityIndexManager; import org.elasticsearch.xpack.test.rest.XPackRestTestHelper; import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction; diff --git a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java index 3ea1b8e67471c..d4f35c5099064 100644 --- a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java +++ b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java @@ -20,7 +20,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import java.io.IOException; import java.time.Instant; diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java index 0da79b27bfaf6..f51835af7196b 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.hamcrest.Matcher; import java.io.IOException; From c0bb8c396ef00cc0efdc19f2b6a032d46aa6aedf Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 26 Oct 2018 14:50:03 +0100 Subject: [PATCH 04/20] Revert "Move ObjectPath, XContentSoure and XContentUtils to core" This reverts commit 7a462dfb56d91f12c98b12a59bee85134d3c157b. --- .../expressiondsl/ExpressionParser.java | 2 +- .../watcher/client/WatchSourceBuilder.java | 2 +- .../common/xcontent/XContentUtils.java | 26 ++++------- .../watcher/support}/xcontent/ObjectPath.java | 45 ++++++++----------- .../support}/xcontent/XContentSource.java | 30 +++++-------- .../actions/execute/ExecuteWatchResponse.java | 2 +- .../actions/get/GetWatchResponse.java | 2 +- .../expressiondsl/ExpressionParserTests.java | 2 +- .../ml/MachineLearningFeatureSetTests.java | 2 +- .../security/SecurityFeatureSetTests.java | 2 +- .../actions/index/ExecutableIndexAction.java | 2 +- .../watcher/actions/index/IndexAction.java | 2 +- .../condition/AbstractCompareCondition.java | 2 +- .../condition/ArrayCompareCondition.java | 4 +- .../watcher/condition/CompareCondition.java | 4 +- .../slack/message/DynamicAttachments.java | 2 +- .../xpack/watcher/WatcherFeatureSetTests.java | 4 +- .../actions/ActionErrorIntegrationTests.java | 2 +- .../actions/TimeThrottleIntegrationTests.java | 2 +- .../actions/index/IndexActionTests.java | 2 +- .../throttler/ActionThrottleTests.java | 2 +- .../webhook/WebhookHttpsIntegrationTests.java | 2 +- .../webhook/WebhookIntegrationTests.java | 2 +- .../execution/ExecutionServiceTests.java | 2 +- .../HistoryTemplateHttpMappingsTests.java | 2 +- .../watcher/input/http/HttpInputTests.java | 2 +- .../email/EmailSecretsIntegrationTests.java | 2 +- .../watcher/support/FilterXContentTests.java | 2 +- .../xpack/watcher/support/VariablesTests.java | 2 +- .../support}/xcontent/MapPathTests.java | 22 +++------ .../xcontent/XContentSourceTests.java | 26 ++++------- .../AbstractWatcherIntegrationTestCase.java | 2 +- .../xpack/watcher/test/WatcherTestUtils.java | 2 +- .../test/integration/BasicWatcherTests.java | 2 +- .../ExecutionVarsIntegrationTests.java | 4 +- .../integration/HistoryIntegrationTests.java | 2 +- .../HttpSecretsIntegrationTests.java | 2 +- .../test/integration/WatchMetadataTests.java | 2 +- .../action/activate/ActivateWatchTests.java | 2 +- .../action/delete/DeleteWatchTests.java | 2 +- .../action/execute/ExecuteWatchTests.java | 2 +- .../transport/action/get/GetWatchTests.java | 2 +- .../watch/WatchStatusIntegrationTests.java | 2 +- .../xpack/restart/FullClusterRestartIT.java | 2 +- .../elasticsearch/multi_node/RollupIT.java | 2 +- .../upgrades/RollupIDUpgradeIT.java | 2 +- 46 files changed, 97 insertions(+), 142 deletions(-) rename {server/src/main/java/org/elasticsearch => x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher}/common/xcontent/XContentUtils.java (62%) rename {server/src/main/java/org/elasticsearch/common => x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support}/xcontent/ObjectPath.java (53%) rename {server/src/main/java/org/elasticsearch/common => x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support}/xcontent/XContentSource.java (81%) rename {server/src/test/java/org/elasticsearch/common => x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support}/xcontent/MapPathTests.java (72%) rename {server/src/test/java/org/elasticsearch/common => x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support}/xcontent/XContentSourceTests.java (62%) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java index 4778b10dae007..d2392b3d172aa 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import java.io.IOException; import java.io.InputStream; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java index c8e490da9d076..001a430ddb1e6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/client/WatchSourceBuilder.java @@ -22,7 +22,7 @@ import org.elasticsearch.xpack.core.watcher.input.none.NoneInput; import org.elasticsearch.xpack.core.watcher.support.Exceptions; import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transform.Transform; import org.elasticsearch.xpack.core.watcher.trigger.Trigger; import org.elasticsearch.xpack.core.watcher.watch.WatchField; diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java similarity index 62% rename from server/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java index 9a159880e1efa..da8ac3ef9d8f1 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java @@ -1,30 +1,20 @@ /* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.common.xcontent; +package org.elasticsearch.xpack.core.watcher.common.xcontent; + +import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -public final class XContentUtils { +public class XContentUtils { private XContentUtils() { } + // TODO open this up in core public static Object readValue(XContentParser parser, XContentParser.Token token) throws IOException { if (token == XContentParser.Token.VALUE_NULL) { return null; diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java similarity index 53% rename from server/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java index fc184675eff25..67ef405238aba 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java @@ -1,22 +1,9 @@ /* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.common.xcontent; +package org.elasticsearch.xpack.core.watcher.support.xcontent; import org.elasticsearch.common.Strings; @@ -24,20 +11,11 @@ import java.util.List; import java.util.Map; -/** - * Helper class for navigating arbitrary nested maps and lists using dot - * notation - */ -public final class ObjectPath { +public class ObjectPath { private ObjectPath() { } - /** - * Extracts the value at a dot notation location in the given object - * @return {@code null} if the location does not exist, otherwise the relevant value - */ - @SuppressWarnings("unchecked") public static T eval(String path, Object object) { return (T) evalContext(path, object); } @@ -46,16 +24,25 @@ private static Object evalContext(String path, Object ctx) { final String[] parts; if (path == null || path.isEmpty()) parts = Strings.EMPTY_ARRAY; else parts = path.split("\\."); + StringBuilder resolved = new StringBuilder(); for (String part : parts) { if (ctx == null) { return null; } if (ctx instanceof Map) { ctx = ((Map) ctx).get(part); + if (resolved.length() != 0) { + resolved.append("."); + } + resolved.append(part); } else if (ctx instanceof List) { try { int index = Integer.parseInt(part); ctx = ((List) ctx).get(index); + if (resolved.length() != 0) { + resolved.append("."); + } + resolved.append(part); } catch (NumberFormatException nfe) { return null; } @@ -63,6 +50,10 @@ private static Object evalContext(String path, Object ctx) { try { int index = Integer.parseInt(part); ctx = Array.get(ctx, index); + if (resolved.length() != 0) { + resolved.append("."); + } + resolved.append(part); } catch (NumberFormatException nfe) { return null; } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/XContentSource.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java similarity index 81% rename from server/src/main/java/org/elasticsearch/common/xcontent/XContentSource.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java index 9908a4f011d6e..059718973201c 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/XContentSource.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java @@ -1,28 +1,22 @@ /* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.common.xcontent; +package org.elasticsearch.xpack.core.watcher.support.xcontent; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; import java.io.IOException; import java.io.InputStream; @@ -30,7 +24,7 @@ import java.util.Map; /** - * Encapsulates arbitrary XContent source + * Encapsulates the xcontent source */ public class XContentSource implements ToXContent { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java index 1ed51f594432a..c0eac9b3c61d2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java @@ -10,7 +10,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import java.io.IOException; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java index fe33b27463ac2..7b94b446ffefa 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java @@ -11,7 +11,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.WatchStatus; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java index c4f1efd1dd9e8..070f36b72e920 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.XPackClientPlugin; import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldValue; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import java.io.IOException; import java.io.StringWriter; diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java index 55c8de75c5c4f..6a2f25f6a3046 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningFeatureSetTests.java @@ -45,7 +45,7 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import org.elasticsearch.xpack.core.ml.stats.ForecastStats; import org.elasticsearch.xpack.core.ml.stats.ForecastStatsTests; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.junit.Before; import java.util.Arrays; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java index 05bf51a9b3d40..2944cd3134a79 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityFeatureSetTests.java @@ -20,7 +20,7 @@ import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.security.SecurityFeatureSetUsage; import org.elasticsearch.xpack.core.security.user.AnonymousUser; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.security.authc.Realms; import org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore; import org.elasticsearch.xpack.security.authz.store.CompositeRolesStore; 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 13b6d70cca6c4..a156e68a4b1ed 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 @@ -23,7 +23,7 @@ import org.elasticsearch.xpack.core.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.support.ArrayObjectIterator; import org.joda.time.DateTime; 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 55354a6c96ca7..ceb6ac88f17f6 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 @@ -14,7 +14,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.joda.time.DateTimeZone; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java index 7b0c176927d8d..81e3eb464e69b 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java @@ -9,7 +9,7 @@ import org.elasticsearch.xpack.core.watcher.condition.ExecutableCondition; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.support.Variables; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java index 47af1bf13d820..c1c458b1d661a 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java @@ -8,8 +8,8 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentUtils; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import java.io.IOException; import java.time.Clock; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java index 7c990e6582ea2..a3b21dec295d2 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java @@ -8,8 +8,8 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentUtils; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import java.io.IOException; import java.time.Clock; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java index 3a5eae2eb56dd..4c53fc767c788 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java index e6eec4fac9f6b..e1e8b5b2ddd7d 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java @@ -23,8 +23,8 @@ import org.elasticsearch.xpack.core.watcher.WatcherFeatureSetUsage; import org.elasticsearch.xpack.core.watcher.WatcherMetaData; import org.elasticsearch.xpack.core.watcher.common.stats.Counters; -import org.elasticsearch.common.xcontent.ObjectPath; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; import org.junit.Before; 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 e6654f7e127db..6590d6c271b26 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 @@ -9,7 +9,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.watcher.actions.index.IndexAction; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java index a753bf05b8229..9b851131d7d6d 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import java.util.Map; 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 7c5dafc721760..346b2d0e85cdf 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 @@ -28,7 +28,7 @@ import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.actions.Action.Result.Status; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.test.WatcherTestUtils; import org.joda.time.DateTime; 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 ccb25de61e46e..b2a1e7bb2cd58 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 @@ -15,7 +15,7 @@ import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchRequestBuilder; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java index 90856f1296a17..4e62eedd221d2 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.ssl.TestsSSLService; import org.elasticsearch.xpack.core.watcher.history.WatchRecord; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.watcher.actions.ActionBuilders; import org.elasticsearch.xpack.watcher.common.http.HttpMethod; import org.elasticsearch.xpack.watcher.common.http.HttpRequestTemplate; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java index 7e93587711b77..d26d07a8fbdb6 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java @@ -15,7 +15,7 @@ import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.xpack.core.watcher.history.WatchRecord; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.watcher.actions.ActionBuilders; import org.elasticsearch.xpack.watcher.common.http.HttpMethod; import org.elasticsearch.xpack.watcher.common.http.HttpRequestTemplate; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java index 13761948adccf..069dca8f2b187 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java @@ -53,7 +53,7 @@ import org.elasticsearch.xpack.core.watcher.history.WatchRecord; import org.elasticsearch.xpack.core.watcher.input.ExecutableInput; import org.elasticsearch.xpack.core.watcher.input.Input; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transform.ExecutableTransform; import org.elasticsearch.xpack.core.watcher.transform.Transform; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index a93b1e94ce957..0e120793fbc18 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.common.http.HttpMethod; import org.elasticsearch.xpack.watcher.common.http.HttpRequestTemplate; import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java index 42788b2ea7ad1..c29b3e1f8b458 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.common.http.HttpClient; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java index a8252e6c4e66e..02a2128e112fb 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/EmailSecretsIntegrationTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.xpack.core.watcher.crypto.CryptoService; import org.elasticsearch.xpack.core.watcher.crypto.CryptoServiceTests; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java index fbe0b98f4ca63..eadf739b175a3 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.hamcrest.Matchers; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java index cd544c85b30bb..4ab5b7b7b87aa 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java @@ -8,7 +8,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.test.WatcherTestUtils; diff --git a/server/src/test/java/org/elasticsearch/common/xcontent/MapPathTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java similarity index 72% rename from server/src/test/java/org/elasticsearch/common/xcontent/MapPathTests.java rename to x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java index 3de379fe11626..f89552a637726 100644 --- a/server/src/test/java/org/elasticsearch/common/xcontent/MapPathTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java @@ -1,24 +1,12 @@ /* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.common.xcontent; +package org.elasticsearch.xpack.watcher.support.xcontent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import java.util.ArrayList; import java.util.Arrays; diff --git a/server/src/test/java/org/elasticsearch/common/xcontent/XContentSourceTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/XContentSourceTests.java similarity index 62% rename from server/src/test/java/org/elasticsearch/common/xcontent/XContentSourceTests.java rename to x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/XContentSourceTests.java index d0a8df09573c1..5fe451458e025 100644 --- a/server/src/test/java/org/elasticsearch/common/xcontent/XContentSourceTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/XContentSourceTests.java @@ -1,25 +1,17 @@ /* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.common.xcontent; +package org.elasticsearch.xpack.watcher.support.xcontent; + import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.smileBuilder; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 5174ecc3c3c61..40e87af1f0b26 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -45,7 +45,7 @@ import org.elasticsearch.xpack.core.watcher.execution.TriggeredWatchStoreField; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; import org.elasticsearch.xpack.core.watcher.support.WatcherIndexTemplateRegistryField; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; import org.elasticsearch.xpack.core.watcher.watch.ClockMock; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java index 1ca78a3b7920d..bb5a6eabdd5b9 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java @@ -21,7 +21,7 @@ import org.elasticsearch.xpack.core.watcher.common.secret.Secret; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java index f0eaf804243dd..c07e6ba3db113 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java index 5b111877cbbc6..90b14233b8d27 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java @@ -10,8 +10,8 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; -import org.elasticsearch.common.xcontent.ObjectPath; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.watcher.condition.ScriptCondition; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java index 79c35caf5e259..5c9dafeaca001 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java @@ -17,7 +17,7 @@ import org.elasticsearch.xpack.core.watcher.actions.ActionStatus; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.core.watcher.input.Input; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.watch.WatchStatus; import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java index 59082aa1b37ef..0de8fc1ee4bc0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java @@ -17,7 +17,7 @@ import org.elasticsearch.xpack.core.watcher.crypto.CryptoService; import org.elasticsearch.xpack.core.watcher.crypto.CryptoServiceTests; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java index 143f760f23c1e..87c10c97c8fc6 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java index 87d9da1451ea5..1080880ea8bbb 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.activate.ActivateWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java index b0c3f6359b52b..065981a426039 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java @@ -12,7 +12,7 @@ import org.elasticsearch.test.http.MockResponse; import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java index df361566678ed..c743922a4d715 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java @@ -11,7 +11,7 @@ import org.elasticsearch.xpack.core.watcher.client.WatcherClient; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchRequestBuilder; import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java index b39be5b6d9e64..226879b5e3047 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.test.junit.annotations.TestLogging; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchRequest; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java index 7687a9d052470..9f738d8daa6b2 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java @@ -8,7 +8,7 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; -import org.elasticsearch.common.xcontent.XContentSource; +import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.xpack.watcher.condition.NeverCondition; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index 254fa37f94463..c112709bbe04b 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -19,7 +19,7 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.security.support.SecurityIndexManager; import org.elasticsearch.xpack.test.rest.XPackRestTestHelper; import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction; diff --git a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java index d4f35c5099064..3ea1b8e67471c 100644 --- a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java +++ b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java @@ -20,7 +20,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import java.io.IOException; import java.time.Instant; diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java index f51835af7196b..0da79b27bfaf6 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.common.xcontent.ObjectPath; +import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.hamcrest.Matcher; import java.io.IOException; From 6330da1b78cd35e0872a542a8d5595826b71a16d Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 26 Oct 2018 14:57:57 +0100 Subject: [PATCH 05/20] Move ObjectPath and XContentUtils into lib/x-content --- .../common}/xcontent/ObjectPath.java | 17 ++++++++++++----- .../common/xcontent/XContentUtils.java | 10 +++++----- .../support/xcontent/XContentSource.java | 3 ++- .../condition/AbstractCompareCondition.java | 2 +- .../condition/ArrayCompareCondition.java | 4 ++-- .../watcher/condition/CompareCondition.java | 4 ++-- .../slack/message/DynamicAttachments.java | 2 +- .../xpack/watcher/WatcherFeatureSetTests.java | 2 +- .../actions/TimeThrottleIntegrationTests.java | 2 +- .../actions/throttler/ActionThrottleTests.java | 2 +- .../execution/ExecutionServiceTests.java | 2 +- .../HistoryTemplateHttpMappingsTests.java | 2 +- .../watcher/input/http/HttpInputTests.java | 2 +- .../watcher/support/FilterXContentTests.java | 2 +- .../xpack/watcher/support/VariablesTests.java | 2 +- .../watcher/support/xcontent/MapPathTests.java | 2 +- .../ExecutionVarsIntegrationTests.java | 2 +- .../test/integration/WatchMetadataTests.java | 2 +- .../action/delete/DeleteWatchTests.java | 2 +- .../xpack/restart/FullClusterRestartIT.java | 2 +- .../org/elasticsearch/multi_node/RollupIT.java | 2 +- .../upgrades/RollupIDUpgradeIT.java | 2 +- 22 files changed, 40 insertions(+), 32 deletions(-) rename {x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support => libs/x-content/src/main/java/org/elasticsearch/common}/xcontent/ObjectPath.java (82%) rename {x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher => libs/x-content/src/main/java/org/elasticsearch}/common/xcontent/XContentUtils.java (90%) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java similarity index 82% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java rename to libs/x-content/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java index 67ef405238aba..5cf439fcbfc32 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/ObjectPath.java +++ b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/ObjectPath.java @@ -3,26 +3,33 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.core.watcher.support.xcontent; - -import org.elasticsearch.common.Strings; +package org.elasticsearch.common.xcontent; import java.lang.reflect.Array; import java.util.List; import java.util.Map; -public class ObjectPath { +/** + * Helper class to navigate nested objects using dot notation + */ +public final class ObjectPath { + + private static final String[] EMPTY_ARRAY = new String[0]; private ObjectPath() { } + /** + * Return the value within a given object at the specified path, or + * {@code null} if the path does not exist + */ public static T eval(String path, Object object) { return (T) evalContext(path, object); } private static Object evalContext(String path, Object ctx) { final String[] parts; - if (path == null || path.isEmpty()) parts = Strings.EMPTY_ARRAY; + if (path == null || path.isEmpty()) parts = EMPTY_ARRAY; else parts = path.split("\\."); StringBuilder resolved = new StringBuilder(); for (String part : parts) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java similarity index 90% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java rename to libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java index da8ac3ef9d8f1..2c9ac1718b20a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/common/xcontent/XContentUtils.java +++ b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentUtils.java @@ -3,18 +3,18 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.core.watcher.common.xcontent; - -import org.elasticsearch.common.xcontent.XContentParser; +package org.elasticsearch.common.xcontent; import java.io.IOException; -public class XContentUtils { +public final class XContentUtils { private XContentUtils() { } - // TODO open this up in core + /** + * Convert a {@link XContentParser.Token} to a value + */ public static Object readValue(XContentParser parser, XContentParser.Token token) throws IOException { if (token == XContentParser.Token.VALUE_NULL) { return null; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java index 059718973201c..e0724795c297c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java @@ -12,11 +12,12 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; +import org.elasticsearch.common.xcontent.XContentUtils; import java.io.IOException; import java.io.InputStream; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java index 81e3eb464e69b..7b0c176927d8d 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/AbstractCompareCondition.java @@ -9,7 +9,7 @@ import org.elasticsearch.xpack.core.watcher.condition.ExecutableCondition; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.support.Variables; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java index c1c458b1d661a..47af1bf13d820 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareCondition.java @@ -8,8 +8,8 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.XContentUtils; +import org.elasticsearch.common.xcontent.ObjectPath; import java.io.IOException; import java.time.Clock; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java index a3b21dec295d2..7c990e6582ea2 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/CompareCondition.java @@ -8,8 +8,8 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.watcher.common.xcontent.XContentUtils; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.XContentUtils; +import org.elasticsearch.common.xcontent.ObjectPath; import java.io.IOException; import java.time.Clock; diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java index 4c53fc767c788..3a5eae2eb56dd 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/slack/message/DynamicAttachments.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java index e1e8b5b2ddd7d..46b0fc0c30e7b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherFeatureSetTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.xpack.core.watcher.WatcherFeatureSetUsage; import org.elasticsearch.xpack.core.watcher.WatcherMetaData; import org.elasticsearch.xpack.core.watcher.common.stats.Counters; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java index 9b851131d7d6d..a753bf05b8229 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import java.util.Map; 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 b2a1e7bb2cd58..ccb25de61e46e 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 @@ -15,7 +15,7 @@ import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchRequestBuilder; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.Watch; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java index 069dca8f2b187..13761948adccf 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java @@ -53,7 +53,7 @@ import org.elasticsearch.xpack.core.watcher.history.WatchRecord; import org.elasticsearch.xpack.core.watcher.input.ExecutableInput; import org.elasticsearch.xpack.core.watcher.input.Input; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transform.ExecutableTransform; import org.elasticsearch.xpack.core.watcher.transform.Transform; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index 0e120793fbc18..a93b1e94ce957 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.watcher.common.http.HttpMethod; import org.elasticsearch.xpack.watcher.common.http.HttpRequestTemplate; import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java index c29b3e1f8b458..42788b2ea7ad1 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.common.http.HttpClient; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java index eadf739b175a3..fbe0b98f4ca63 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/FilterXContentTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.hamcrest.Matchers; import java.io.IOException; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java index 4ab5b7b7b87aa..cd544c85b30bb 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java @@ -8,7 +8,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.test.WatcherTestUtils; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java index f89552a637726..f55f9862696cb 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/xcontent/MapPathTests.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.watcher.support.xcontent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import java.util.ArrayList; import java.util.Arrays; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java index 90b14233b8d27..9b92294a07022 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.watcher.condition.ScriptCondition; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java index 87c10c97c8fc6..143f760f23c1e 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.xpack.core.watcher.execution.ActionExecutionMode; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction; diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java index 065981a426039..b0c3f6359b52b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java @@ -12,7 +12,7 @@ import org.elasticsearch.test.http.MockResponse; import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index c112709bbe04b..254fa37f94463 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -19,7 +19,7 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.xpack.security.support.SecurityIndexManager; import org.elasticsearch.xpack.test.rest.XPackRestTestHelper; import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction; diff --git a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java index 3ea1b8e67471c..d4f35c5099064 100644 --- a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java +++ b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java @@ -20,7 +20,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import java.io.IOException; import java.time.Instant; diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java index 0da79b27bfaf6..f51835af7196b 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RollupIDUpgradeIT.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; +import org.elasticsearch.common.xcontent.ObjectPath; import org.hamcrest.Matcher; import java.io.IOException; From 9c0aaed043c08aa8c230636b54f6740e0d3a09aa Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 20 Nov 2018 09:11:43 +0000 Subject: [PATCH 06/20] WIP --- .../client/WatcherRequestConverters.java | 16 +++-- .../client/watcher/ExecuteWatchRequest.java | 61 ++++++++++++++++--- .../org/elasticsearch/client/WatcherIT.java | 2 + 3 files changed, 66 insertions(+), 13 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java index d4c480115d6bd..f67b1b856bc4c 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java @@ -35,6 +35,11 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.client.watcher.DeleteWatchRequest; import org.elasticsearch.client.watcher.PutWatchRequest; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; + +import java.io.IOException; final class WatcherRequestConverters { @@ -98,7 +103,7 @@ static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) { return request; } - static Request executeWatch(ExecuteWatchRequest executeWatchRequest) { + static Request executeWatch(ExecuteWatchRequest executeWatchRequest) throws IOException { RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder() .addPathPart("_xpack", "watcher", "watch"); if (executeWatchRequest.getId() != null) { @@ -111,14 +116,17 @@ static Request executeWatch(ExecuteWatchRequest executeWatchRequest) { if (executeWatchRequest.isDebug()) { params.putParam("debug", "true"); } - if (executeWatchRequest.isIgnoreCondition()) { + if (executeWatchRequest.ignoreCondition()) { params.putParam("ignore_condition", "true"); } - if (executeWatchRequest.isRecordExecution()) { + if (executeWatchRequest.recordExecution()) { params.putParam("record_execution", "true"); } - request.setEntity(executeWatchRequest.toHttpEntity()); + ContentType contentType = RequestConverters.createContentType(XContentType.JSON); + XContentBuilder xcontentBuilder = XContentFactory.jsonBuilder(); + BytesReference source = BytesReference.bytes(executeWatchRequest.toXContent(xcontentBuilder, null)); + request.setEntity(new ByteArrayEntity(source.toBytesRef().bytes, 0, source.length(), contentType)); return request; } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java index 4dca7f565bf83..e0ad3adf22f0a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java @@ -26,26 +26,22 @@ */ public class ExecuteWatchRequest implements Validatable, ToXContentObject { - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return null; - } - public enum ActionExecutionMode { SIMULATE, FORCE_SIMULATE, EXECUTE, FORCE_EXECUTE, SKIP } private final String id; + private final BytesReference watchContent; private boolean ignoreCondition = false; private boolean recordExecution = false; private boolean debug = false; @Nullable - private XContentBuilder triggerData = null; + private BytesReference triggerData = null; @Nullable - private XContentBuilder alternativeInput = null; + private BytesReference alternativeInput = null; private Map actionModes = new HashMap<>(); @@ -54,6 +50,16 @@ public enum ActionExecutionMode { */ public ExecuteWatchRequest(String id) { this.id = Objects.requireNonNull(id, "Watch id cannot be null"); + this.watchContent = null; + } + + public ExecuteWatchRequest(BytesReference watchContent) { + this.id = null; + this.watchContent = Objects.requireNonNull(watchContent, "Watch content cannot be null"); + } + + public String getId() { + return this.id; } /** @@ -63,6 +69,10 @@ public void setIgnoreCondition(boolean ignoreCondition) { this.ignoreCondition = ignoreCondition; } + public boolean ignoreCondition() { + return ignoreCondition; + } + /** * @param recordExecution Sets if this execution be recorded in the history index */ @@ -70,17 +80,21 @@ public void setRecordExecution(boolean recordExecution) { this.recordExecution = recordExecution; } + public boolean recordExecution() { + return recordExecution; + } + /** * @param alternativeInput Set's the alternative input */ - public void setAlternativeInput(XContentBuilder alternativeInput) { + public void setAlternativeInput(BytesReference alternativeInput) { this.alternativeInput = alternativeInput; } /** * @param data The data that should be associated with the trigger event. */ - public void setTriggerData(XContentBuilder data) throws IOException { + public void setTriggerData(BytesReference data) { this.triggerData = data; } @@ -95,6 +109,10 @@ public void setActionMode(String actionId, ActionExecutionMode actionMode) { actionModes.put(actionId, actionMode); } + public Map getActionModes() { + return this.actionModes; + } + /** * @param debug indicates whether the watch should execute in debug mode. In debug mode the * returned watch record will hold the execution {@code vars} @@ -103,9 +121,34 @@ public void setDebug(boolean debug) { this.debug = debug; } + public boolean isDebug() { + return debug; + } + @Override public String toString() { return "execute[" + id + "]"; } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + if (triggerData != null) { + builder.rawField("trigger_data", triggerData.streamInput(), XContentType.JSON); + } + if (alternativeInput != null) { + builder.rawField("alternative_input", alternativeInput.streamInput(), XContentType.JSON); + } + if (actionModes.size() > 0) { + builder.startObject("action_modes"); + builder.map(actionModes); + builder.endObject(); + } + if (watchContent != null) { + builder.rawField("watch", watchContent.streamInput(), XContentType.JSON); + } + builder.endObject(); + return builder; + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java index 7eb0555fa7eac..94062b53f951c 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java @@ -44,6 +44,7 @@ import org.elasticsearch.client.watcher.PutWatchResponse; import org.elasticsearch.rest.RestStatus; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThan; @@ -192,6 +193,7 @@ public void testExecuteWatchById() throws Exception { ExecuteWatchResponse response = highLevelClient().watcher().executeWatch(new ExecuteWatchRequest(watchId), RequestOptions.DEFAULT); + assertThat(response.getRecordId(), containsString(watchId)); } From d5a4db82c25a58e0fcd8492d8d68c41551f491a9 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 21 Nov 2018 09:47:21 +0000 Subject: [PATCH 07/20] warnings --- .../java/org/elasticsearch/client/common/XContentSource.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java index 25573bf1a150e..eecec3e2675bc 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java @@ -43,6 +43,7 @@ public boolean isMap() { /** * @return The source as a map */ + @SuppressWarnings("unchecked") public Map getAsMap() { return (Map) data; } @@ -57,6 +58,7 @@ public boolean isList() { /** * @return The source as a list */ + @SuppressWarnings("unchecked") public List getAsList() { return (List) data; } @@ -67,6 +69,7 @@ public List getAsList() { * @param path a dot notation path to the requested value * @return The extracted value or {@code null} if no value is associated with the given path */ + @SuppressWarnings("unchecked") public T getValue(String path) { return (T) ObjectPath.eval(path, data); } From 54225cab5be06617e7566385f65b17220a27f9fc Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 21 Nov 2018 15:47:35 +0000 Subject: [PATCH 08/20] WIP --- .../client/watcher/ExecuteWatchResponse.java | 8 ++- .../client/watcher/WatchRecord.java | 14 +++++ .../watcher/ExecuteWatchResponseTests.java | 59 +++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java index e89d7f219e172..4e6d2dd1c0a40 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java @@ -11,6 +11,9 @@ public class ExecuteWatchResponse { + public static final ParseField ID_FIELD = new ParseField("_id"); + public static final ParseField WATCH_FIELD = new ParseField("watch_record"); + private String recordId; private XContentSource recordSource; @@ -40,9 +43,8 @@ public XContentSource getRecordSource() { = new ConstructingObjectParser<>("x_pack_execute_watch_response", true, (fields) -> new ExecuteWatchResponse((String)fields[0], (XContentSource)fields[1])); static { - PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField("_id")); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), - (p, c) -> new XContentSource(p), new ParseField("watch_record")); + PARSER.declareString(ConstructingObjectParser.constructorArg(), ID_FIELD); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> new XContentSource(p), WATCH_FIELD); } public static ExecuteWatchResponse fromXContent(XContentParser parser) throws IOException { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java new file mode 100644 index 0000000000000..9d4fa3e5d25c4 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java @@ -0,0 +1,14 @@ +package org.elasticsearch.client.watcher; + +public class WatchRecord { + + /* + private final String id; + private final String node; + private final String[] messages; + private final TriggerEvent triggerEvent; + private final ExecutionState state; + private final WatchStatus status; + */ + +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java new file mode 100644 index 0000000000000..906d7bc033689 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java @@ -0,0 +1,59 @@ +package org.elasticsearch.client.watcher; + +import org.elasticsearch.client.common.XContentSource; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.test.ESTestCase; + +import java.io.IOException; + +import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; + +public class ExecuteWatchResponseTests extends ESTestCase { + + public void testFromXContent() throws IOException { + xContentTester(this::createParser, this::createTestInstance, this::toXContent, + ExecuteWatchResponse::fromXContent).test(); + } + + private void toXContent(ExecuteWatchResponse response, XContentBuilder builder) throws IOException { + builder.startObject(); + builder.field(ExecuteWatchResponse.ID_FIELD.getPreferredName(), response.getRecordId()); + builder.field(ExecuteWatchResponse.WATCH_FIELD.getPreferredName(), + (b, params) -> b.value(response.getRecordSource().getAsMap())); + builder.endObject(); + } + + protected ExecuteWatchResponse createTestInstance() { + String id = "my_watch_0-2015-06-02T23:17:55.124Z"; + try { + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + builder.startObject("watch_record"); + builder.field("watch_id", "my_watch"); + builder.field("node", "my_node"); + builder.startArray("messages"); + builder.endArray(); + builder.startObject("trigger_event"); + builder.field("type", "manual"); + builder.endObject(); + builder.field("state", "executed"); + builder.endObject(); + builder.endObject(); + BytesReference bytes = BytesReference.bytes(builder); + XContentParser parser = XContentType.JSON.xContent() + .createParser(NamedXContentRegistry.EMPTY, null, bytes.streamInput()); + + return new ExecuteWatchResponse(id, new XContentSource(parser)); + } + catch (IOException e) { + throw new AssertionError(e); + } + } + +} From e8ddc04bc26f8d5d3987771b5143b40c9c236f2a Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 22 Nov 2018 10:32:02 +0000 Subject: [PATCH 09/20] WIP --- .../java/org/elasticsearch/client/common/XContentSource.java | 2 +- .../elasticsearch/client/watcher/ExecuteWatchResponse.java | 5 ++++- .../java/org/elasticsearch/client/watcher/WatchRecord.java | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java index eecec3e2675bc..ea2bb8fc3a334 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java @@ -27,7 +27,7 @@ public class XContentSource { private final Object data; /** - * Constructs a new XContentSource out of the given bytes reference. + * Constructs a new XContentSource out of the given parser */ public XContentSource(XContentParser parser) throws IOException { this.data = XContentUtils.readValue(parser, parser.nextToken()); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java index 4e6d2dd1c0a40..aec68531bacbc 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java @@ -44,7 +44,10 @@ public XContentSource getRecordSource() { (fields) -> new ExecuteWatchResponse((String)fields[0], (XContentSource)fields[1])); static { PARSER.declareString(ConstructingObjectParser.constructorArg(), ID_FIELD); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> new XContentSource(p), WATCH_FIELD); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> { + p.nextToken(); + return new XContentSource(p); + }, WATCH_FIELD); } public static ExecuteWatchResponse fromXContent(XContentParser parser) throws IOException { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java index 9d4fa3e5d25c4..50048194b8341 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java @@ -1,14 +1,15 @@ package org.elasticsearch.client.watcher; +import java.util.Map; + public class WatchRecord { - /* private final String id; private final String node; private final String[] messages; private final TriggerEvent triggerEvent; private final ExecutionState state; private final WatchStatus status; - */ + private final Map input; } From 696fb6bc2991a90f3e59fdd923b0e917790acbdd Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 23 Nov 2018 11:21:39 +0000 Subject: [PATCH 10/20] HLRC comparison tests --- .../client/watcher/ExecuteWatchResponse.java | 30 +++--- .../client/watcher/WatchRecord.java | 93 ++++++++++++++++++- .../watcher/ExecuteWatchResponseTests.java | 59 ------------ .../support/xcontent/XContentSource.java | 18 ++++ .../actions/execute/ExecuteWatchResponse.java | 60 +++++++++++- .../watcher/ExecuteWatchResponseTests.java | 58 ++++++++++++ 6 files changed, 244 insertions(+), 74 deletions(-) delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java create mode 100644 x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java index aec68531bacbc..d72f54b965ff0 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java @@ -1,11 +1,11 @@ package org.elasticsearch.client.watcher; -import org.elasticsearch.client.common.XContentSource; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; @@ -15,14 +15,14 @@ public class ExecuteWatchResponse { public static final ParseField WATCH_FIELD = new ParseField("watch_record"); private String recordId; - private XContentSource recordSource; + private BytesReference contentSource; public ExecuteWatchResponse() { } - public ExecuteWatchResponse(String recordId, XContentSource source) { + public ExecuteWatchResponse(String recordId, BytesReference contentSource) { this.recordId = recordId; - this.recordSource = source; + this.contentSource = contentSource; } /** @@ -35,23 +35,27 @@ public String getRecordId() { /** * @return The watch record source */ - public XContentSource getRecordSource() { - return recordSource; + public BytesReference getRecord() { + return contentSource; } private static final ConstructingObjectParser PARSER - = new ConstructingObjectParser<>("x_pack_execute_watch_response", true, - (fields) -> new ExecuteWatchResponse((String)fields[0], (XContentSource)fields[1])); + = new ConstructingObjectParser<>("x_pack_execute_watch_response", false, + (fields) -> new ExecuteWatchResponse((String)fields[0], (BytesReference) fields[1])); static { PARSER.declareString(ConstructingObjectParser.constructorArg(), ID_FIELD); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> { - p.nextToken(); - return new XContentSource(p); - }, WATCH_FIELD); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> readBytesReference(p), WATCH_FIELD); } public static ExecuteWatchResponse fromXContent(XContentParser parser) throws IOException { return PARSER.parse(parser, null); } + private static BytesReference readBytesReference(XContentParser parser) throws IOException { + try (XContentBuilder builder = XContentFactory.jsonBuilder()) { + builder.copyCurrentStructure(parser); + return BytesReference.bytes(builder); + } + } + } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java index 50048194b8341..1ff89426a4611 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java @@ -1,15 +1,106 @@ package org.elasticsearch.client.watcher; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; + import java.util.Map; public class WatchRecord { + public static final ParseField WATCH_ID = new ParseField("watch_id"); + public static final ParseField NODE = new ParseField("node"); + public static final ParseField MESSAGES = new ParseField("messages"); + public static final ParseField TRIGGER_EVENT = new ParseField("trigger_event"); + public static final ParseField STATUS = new ParseField("status"); + public static final ParseField STATE = new ParseField("state"); + public static final ParseField INPUT = new ParseField("input"); + public static final ParseField CONDITION = new ParseField("condition"); + public static final ParseField RESULT = new ParseField("result"); + private final String id; private final String node; private final String[] messages; - private final TriggerEvent triggerEvent; + private final Map triggerEvent; private final ExecutionState state; private final WatchStatus status; private final Map input; + private final Map condition; + private final Map result; + + public WatchRecord(String id, String node, String[] messages, Map triggerEvent, + ExecutionState state, WatchStatus status, Map input, + Map condition, Map result) { + this.id = id; + this.node = node; + this.messages = messages; + this.triggerEvent = triggerEvent; + this.state = state; + this.status = status; + this.input = input; + this.condition = condition; + this.result = result; + } + + public String getId() { + return id; + } + + public String getNode() { + return node; + } + + public String[] getMessages() { + return messages; + } + + public Map getTriggerEvent() { + return triggerEvent; + } + + public ExecutionState getState() { + return state; + } + + public WatchStatus getStatus() { + return status; + } + + public Map getInput() { + return input; + } + + public Map getCondition() { + return condition; + } + + public Map getResult() { + return result; + } + @SuppressWarnings("unchecked") + public static final ConstructingObjectParser PARSER = + new ConstructingObjectParser<>("watch_record", false, + (fields) -> { + String id = (String) fields[0]; + String node = (String) fields[1]; + String[] messages = (String[]) fields[2]; + Map triggerEvent = (Map) fields[3]; + ExecutionState state = (ExecutionState) fields[4]; + WatchStatus status = (WatchStatus) fields[5]; + Map input = (Map) fields[6]; + Map condition = (Map) fields[7]; + Map result = (Map) fields[8]; + return new WatchRecord(id, node, messages, triggerEvent, state, status, input, condition, result); + }); + static { + PARSER.declareString(ConstructingObjectParser.constructorArg(), WATCH_ID); + PARSER.declareString(ConstructingObjectParser.constructorArg(), NODE); + PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), MESSAGES); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), TRIGGER_EVENT); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> ExecutionState.resolve(p.text()), STATE); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> WatchStatus.parse(p), STATUS); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), INPUT); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), CONDITION); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), RESULT); + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java deleted file mode 100644 index 906d7bc033689..0000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/ExecuteWatchResponseTests.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.elasticsearch.client.watcher; - -import org.elasticsearch.client.common.XContentSource; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.test.ESTestCase; - -import java.io.IOException; - -import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; - -public class ExecuteWatchResponseTests extends ESTestCase { - - public void testFromXContent() throws IOException { - xContentTester(this::createParser, this::createTestInstance, this::toXContent, - ExecuteWatchResponse::fromXContent).test(); - } - - private void toXContent(ExecuteWatchResponse response, XContentBuilder builder) throws IOException { - builder.startObject(); - builder.field(ExecuteWatchResponse.ID_FIELD.getPreferredName(), response.getRecordId()); - builder.field(ExecuteWatchResponse.WATCH_FIELD.getPreferredName(), - (b, params) -> b.value(response.getRecordSource().getAsMap())); - builder.endObject(); - } - - protected ExecuteWatchResponse createTestInstance() { - String id = "my_watch_0-2015-06-02T23:17:55.124Z"; - try { - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - builder.startObject("watch_record"); - builder.field("watch_id", "my_watch"); - builder.field("node", "my_node"); - builder.startArray("messages"); - builder.endArray(); - builder.startObject("trigger_event"); - builder.field("type", "manual"); - builder.endObject(); - builder.field("state", "executed"); - builder.endObject(); - builder.endObject(); - BytesReference bytes = BytesReference.bytes(builder); - XContentParser parser = XContentType.JSON.xContent() - .createParser(NamedXContentRegistry.EMPTY, null, bytes.streamInput()); - - return new ExecuteWatchResponse(id, new XContentSource(parser)); - } - catch (IOException e) { - throw new AssertionError(e); - } - } - -} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java index e0724795c297c..254fc86367e57 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/XContentSource.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Encapsulates the xcontent source @@ -133,4 +134,21 @@ private Object data() { return data; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + XContentSource that = (XContentSource) o; + return Objects.equals(data(), that.data()); + } + + @Override + public int hashCode() { + return Objects.hash(data()); + } + + @Override + public String toString() { + return bytes.utf8ToString(); + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java index c0eac9b3c61d2..251b994f76e58 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchResponse.java @@ -6,18 +6,28 @@ package org.elasticsearch.xpack.core.watcher.transport.actions.execute; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import java.io.IOException; +import java.util.Objects; /** * This class contains the WatchHistory generated by running the watch */ -public class ExecuteWatchResponse extends ActionResponse { +public class ExecuteWatchResponse extends ActionResponse implements ToXContentObject { + + public static final ParseField ID_FIELD = new ParseField("_id"); + public static final ParseField WATCH_FIELD = new ParseField("watch_record"); private String recordId; private XContentSource recordSource; @@ -30,6 +40,25 @@ public ExecuteWatchResponse(String recordId, BytesReference recordSource, XConte this.recordSource = new XContentSource(recordSource, contentType); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ExecuteWatchResponse that = (ExecuteWatchResponse) o; + return Objects.equals(recordId, that.recordId) && + Objects.equals(recordSource, that.recordSource); + } + + @Override + public int hashCode() { + return Objects.hash(recordId, recordSource); + } + + @Override + public String toString() { + return recordId + ":" + recordSource; + } + /** * @return The id of the watch record holding the watch execution result. */ @@ -57,4 +86,33 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(recordId); XContentSource.writeTo(recordSource, out); } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.field("_id", recordId); + builder.field("watch_record"); + recordSource.toXContent(builder, params); + builder.endObject(); + return builder; + } + + private static final ConstructingObjectParser PARSER + = new ConstructingObjectParser<>("x_pack_execute_watch_response", false, + (fields) -> new ExecuteWatchResponse((String)fields[0], (BytesReference) fields[1], XContentType.JSON)); + static { + PARSER.declareString(ConstructingObjectParser.constructorArg(), ID_FIELD); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> readBytesReference(p), WATCH_FIELD); + } + + public static ExecuteWatchResponse fromXContent(XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } + + private static BytesReference readBytesReference(XContentParser parser) throws IOException { + try (XContentBuilder builder = XContentFactory.jsonBuilder()) { + builder.copyCurrentStructure(parser); + return BytesReference.bytes(builder); + } + } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java new file mode 100644 index 0000000000000..beaedecbdd40d --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java @@ -0,0 +1,58 @@ +package org.elasticsearch.protocol.xpack.watcher; + +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; +import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; + +import java.io.IOException; + +public class ExecuteWatchResponseTests + extends AbstractHlrcXContentTestCase { + + @Override + public org.elasticsearch.client.watcher.ExecuteWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException { + return org.elasticsearch.client.watcher.ExecuteWatchResponse.fromXContent(parser); + } + + @Override + public ExecuteWatchResponse convertHlrcToInternal(org.elasticsearch.client.watcher.ExecuteWatchResponse instance) { + return new ExecuteWatchResponse(instance.getRecordId(), instance.getRecord(), XContentType.JSON); + } + + @Override + protected ExecuteWatchResponse createTestInstance() { + String id = "my_watch_0-2015-06-02T23:17:55.124Z"; + try { + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + builder.field("watch_id", "my_watch"); + builder.field("node", "my_node"); + builder.startArray("messages"); + builder.endArray(); + builder.startObject("trigger_event"); + builder.field("type", "manual"); + builder.endObject(); + builder.field("state", "executed"); + builder.endObject(); + BytesReference bytes = BytesReference.bytes(builder); + return new ExecuteWatchResponse(id, bytes, XContentType.JSON); + } + catch (IOException e) { + throw new AssertionError(e); + } + } + + @Override + protected ExecuteWatchResponse doParseInstance(XContentParser parser) throws IOException { + return ExecuteWatchResponse.fromXContent(parser); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } +} From aaadc9fe56d347f1481d70ff71e0f289884daa7c Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 23 Nov 2018 16:50:59 +0000 Subject: [PATCH 11/20] Tests; docs --- .../elasticsearch/client/WatcherClient.java | 18 ++- .../client/WatcherRequestConverters.java | 5 +- .../client/watcher/ExecuteWatchRequest.java | 38 +++--- .../client/watcher/ExecuteWatchResponse.java | 28 +++++ .../client/watcher/WatchRecord.java | 106 ----------------- .../org/elasticsearch/client/WatcherIT.java | 35 ++++-- .../client/WatcherRequestConvertersTests.java | 102 ++++++++++++++++ .../documentation/WatcherDocumentationIT.java | 110 ++++++++++++++++++ .../high-level/supported-apis.asciidoc | 2 + .../high-level/watcher/execute-watch.asciidoc | 87 ++++++++++++++ 10 files changed, 397 insertions(+), 134 deletions(-) delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java create mode 100644 docs/java-rest/high-level/watcher/execute-watch.asciidoc diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java index ddde08d506aa8..8071165f4c601 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java @@ -241,12 +241,28 @@ public void activateWatchAsync(ActivateWatchRequest request, RequestOptions opti ActivateWatchResponse::fromXContent, listener, singleton(404)); } - + /** + * Execute a watch on the cluster + * See + * the docs for more. + * @param request the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @return the response + * @throws IOException if there is a problem sending the request or parsing the response + */ public ExecuteWatchResponse executeWatch(ExecuteWatchRequest request, RequestOptions options) throws IOException { return restHighLevelClient.performRequestAndParseEntity(request, WatcherRequestConverters::executeWatch, options, ExecuteWatchResponse::fromXContent, singleton(404)); } + /** + * Asynchronously execute a watch on the cluster + * See + * the docs for more. + * @param request the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @param listener the listener to be notifed upon request completion + */ public void executeWatchAsync(ExecuteWatchRequest request, RequestOptions options, ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity(request, WatcherRequestConverters::executeWatch, options, ExecuteWatchResponse::fromXContent, listener, singleton(404)); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java index f67b1b856bc4c..26784c1c08ced 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java @@ -123,10 +123,7 @@ static Request executeWatch(ExecuteWatchRequest executeWatchRequest) throws IOEx params.putParam("record_execution", "true"); } - ContentType contentType = RequestConverters.createContentType(XContentType.JSON); - XContentBuilder xcontentBuilder = XContentFactory.jsonBuilder(); - BytesReference source = BytesReference.bytes(executeWatchRequest.toXContent(xcontentBuilder, null)); - request.setEntity(new ByteArrayEntity(source.toBytesRef().bytes, 0, source.length(), contentType)); + request.setEntity(RequestConverters.createEntity(executeWatchRequest, XContentType.JSON)); return request; } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java index e0ad3adf22f0a..6f8ffc523356a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java @@ -7,6 +7,7 @@ import org.elasticsearch.client.Validatable; import org.elasticsearch.client.ValidationException; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -46,16 +47,25 @@ public enum ActionExecutionMode { private Map actionModes = new HashMap<>(); /** + * Execute an existing watch on the cluster + * * @param id the id of the watch to execute */ - public ExecuteWatchRequest(String id) { - this.id = Objects.requireNonNull(id, "Watch id cannot be null"); - this.watchContent = null; + public static ExecuteWatchRequest byId(String id) { + return new ExecuteWatchRequest(Objects.requireNonNull(id, "Watch id cannot be null"), null); + } + + /** + * Execute an inline watch + * @param watchContent the JSON definition of the watch + */ + public static ExecuteWatchRequest inline(String watchContent) { + return new ExecuteWatchRequest(null, Objects.requireNonNull(watchContent, "Watch content cannot be null")); } - public ExecuteWatchRequest(BytesReference watchContent) { - this.id = null; - this.watchContent = Objects.requireNonNull(watchContent, "Watch content cannot be null"); + private ExecuteWatchRequest(String id, String watchContent) { + this.id = id; + this.watchContent = watchContent == null ? null : new BytesArray(watchContent); } public String getId() { @@ -85,17 +95,17 @@ public boolean recordExecution() { } /** - * @param alternativeInput Set's the alternative input + * @param alternativeInput Sets the alternative input */ - public void setAlternativeInput(BytesReference alternativeInput) { - this.alternativeInput = alternativeInput; + public void setAlternativeInput(String alternativeInput) { + this.alternativeInput = new BytesArray(alternativeInput); } /** - * @param data The data that should be associated with the trigger event. + * @param data A JSON string representing the data that should be associated with the trigger event. */ - public void setTriggerData(BytesReference data) { - this.triggerData = data; + public void setTriggerData(String data) { + this.triggerData = new BytesArray(data); } /** @@ -140,9 +150,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.rawField("alternative_input", alternativeInput.streamInput(), XContentType.JSON); } if (actionModes.size() > 0) { - builder.startObject("action_modes"); - builder.map(actionModes); - builder.endObject(); + builder.field("action_modes", actionModes); } if (watchContent != null) { builder.rawField("watch", watchContent.streamInput(), XContentType.JSON); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java index d72f54b965ff0..2539c1206f028 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java @@ -1,13 +1,20 @@ package org.elasticsearch.client.watcher; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.client.common.XContentSource; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.XContentUtils; import java.io.IOException; +import java.io.InputStream; +import java.util.Map; public class ExecuteWatchResponse { @@ -17,6 +24,8 @@ public class ExecuteWatchResponse { private String recordId; private BytesReference contentSource; + private Map data; + public ExecuteWatchResponse() { } @@ -39,6 +48,25 @@ public BytesReference getRecord() { return contentSource; } + /** + * Returns the watch record as a map + * + * Use {@link org.elasticsearch.common.xcontent.ObjectPath} to navigate through the data + */ + @SuppressWarnings("unchecked") + public Map getRecordAsMap() { + if (data == null) { + // EMPTY is safe here because we never use namedObject + try (InputStream stream = contentSource.streamInput(); + XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, null, stream)) { + data = (Map) XContentUtils.readValue(parser, parser.nextToken()); + } catch (IOException ex) { + throw new ElasticsearchException("failed to read value", ex); + } + } + return data; + } + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("x_pack_execute_watch_response", false, (fields) -> new ExecuteWatchResponse((String)fields[0], (BytesReference) fields[1])); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java deleted file mode 100644 index 1ff89426a4611..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/WatchRecord.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.elasticsearch.client.watcher; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; - -import java.util.Map; - -public class WatchRecord { - - public static final ParseField WATCH_ID = new ParseField("watch_id"); - public static final ParseField NODE = new ParseField("node"); - public static final ParseField MESSAGES = new ParseField("messages"); - public static final ParseField TRIGGER_EVENT = new ParseField("trigger_event"); - public static final ParseField STATUS = new ParseField("status"); - public static final ParseField STATE = new ParseField("state"); - public static final ParseField INPUT = new ParseField("input"); - public static final ParseField CONDITION = new ParseField("condition"); - public static final ParseField RESULT = new ParseField("result"); - - private final String id; - private final String node; - private final String[] messages; - private final Map triggerEvent; - private final ExecutionState state; - private final WatchStatus status; - private final Map input; - private final Map condition; - private final Map result; - - public WatchRecord(String id, String node, String[] messages, Map triggerEvent, - ExecutionState state, WatchStatus status, Map input, - Map condition, Map result) { - this.id = id; - this.node = node; - this.messages = messages; - this.triggerEvent = triggerEvent; - this.state = state; - this.status = status; - this.input = input; - this.condition = condition; - this.result = result; - } - - public String getId() { - return id; - } - - public String getNode() { - return node; - } - - public String[] getMessages() { - return messages; - } - - public Map getTriggerEvent() { - return triggerEvent; - } - - public ExecutionState getState() { - return state; - } - - public WatchStatus getStatus() { - return status; - } - - public Map getInput() { - return input; - } - - public Map getCondition() { - return condition; - } - - public Map getResult() { - return result; - } - - @SuppressWarnings("unchecked") - public static final ConstructingObjectParser PARSER = - new ConstructingObjectParser<>("watch_record", false, - (fields) -> { - String id = (String) fields[0]; - String node = (String) fields[1]; - String[] messages = (String[]) fields[2]; - Map triggerEvent = (Map) fields[3]; - ExecutionState state = (ExecutionState) fields[4]; - WatchStatus status = (WatchStatus) fields[5]; - Map input = (Map) fields[6]; - Map condition = (Map) fields[7]; - Map result = (Map) fields[8]; - return new WatchRecord(id, node, messages, triggerEvent, state, status, input, condition, result); - }); - static { - PARSER.declareString(ConstructingObjectParser.constructorArg(), WATCH_ID); - PARSER.declareString(ConstructingObjectParser.constructorArg(), NODE); - PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), MESSAGES); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), TRIGGER_EVENT); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> ExecutionState.resolve(p.text()), STATE); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> WatchStatus.parse(p), STATUS); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), INPUT); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), CONDITION); - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> p.map(), RESULT); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java index 94062b53f951c..b4b7316b27ee1 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java @@ -20,6 +20,7 @@ import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.client.common.XContentSource; import org.elasticsearch.client.watcher.AckWatchRequest; import org.elasticsearch.client.watcher.AckWatchResponse; import org.elasticsearch.client.watcher.ActionStatus; @@ -37,18 +38,23 @@ import org.elasticsearch.client.watcher.WatcherStatsResponse; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.client.watcher.DeleteWatchRequest; import org.elasticsearch.client.watcher.DeleteWatchResponse; import org.elasticsearch.client.watcher.PutWatchRequest; import org.elasticsearch.client.watcher.PutWatchResponse; import org.elasticsearch.rest.RestStatus; +import org.hamcrest.Matchers; + +import java.util.Map; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.not; +import static org.hamcrest.core.IsNull.notNullValue; public class WatcherIT extends ESRestHighLevelClientTestCase { @@ -82,13 +88,14 @@ public void testPutWatch() throws Exception { assertThat(putWatchResponse.getVersion(), is(1L)); } + private static final String WATCH_JSON = "{ \n" + + " \"trigger\": { \"schedule\": { \"interval\": \"10h\" } },\n" + + " \"input\": { \"none\": {} },\n" + + " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + + "}"; + private PutWatchResponse createWatch(String watchId) throws Exception { - String json = "{ \n" + - " \"trigger\": { \"schedule\": { \"interval\": \"10h\" } },\n" + - " \"input\": { \"none\": {} },\n" + - " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + - "}"; - BytesReference bytesReference = new BytesArray(json); + BytesReference bytesReference = new BytesArray(WATCH_JSON); PutWatchRequest putWatchRequest = new PutWatchRequest(watchId, bytesReference, XContentType.JSON); return highLevelClient().watcher().putWatch(putWatchRequest, RequestOptions.DEFAULT); } @@ -191,10 +198,22 @@ public void testExecuteWatchById() throws Exception { String watchId = randomAlphaOfLength(10); createWatch(watchId); - ExecuteWatchResponse response = highLevelClient().watcher().executeWatch(new ExecuteWatchRequest(watchId), - RequestOptions.DEFAULT); + ExecuteWatchResponse response = highLevelClient().watcher() + .executeWatch(ExecuteWatchRequest.byId(watchId), RequestOptions.DEFAULT); assertThat(response.getRecordId(), containsString(watchId)); + Map source = response.getRecordAsMap(); + assertThat(ObjectPath.eval("trigger_event.type", source), is("manual")); + + } + + public void testExecuteInlineWatch() throws Exception { + ExecuteWatchResponse response = highLevelClient().watcher() + .executeWatch(ExecuteWatchRequest.inline(WATCH_JSON), RequestOptions.DEFAULT); + assertThat(response.getRecordId(), containsString("_inlined_")); + + Map source = response.getRecordAsMap(); + assertThat(ObjectPath.eval("trigger_event.type", source), is("manual")); } public void testWatcherStatsMetrics() throws Exception { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java index 2712dbc0438db..a3a740a6f27bb 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.client; +import org.apache.http.HttpEntity; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; @@ -27,6 +28,7 @@ import org.elasticsearch.client.watcher.ActivateWatchRequest; import org.elasticsearch.client.watcher.DeactivateWatchRequest; import org.elasticsearch.client.watcher.DeleteWatchRequest; +import org.elasticsearch.client.watcher.ExecuteWatchRequest; import org.elasticsearch.client.watcher.PutWatchRequest; import org.elasticsearch.client.watcher.StartWatchServiceRequest; import org.elasticsearch.client.watcher.StopWatchServiceRequest; @@ -37,12 +39,15 @@ import org.elasticsearch.test.ESTestCase; import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.StringJoiner; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.hasSize; @@ -52,6 +57,12 @@ public class WatcherRequestConvertersTests extends ESTestCase { + private static String toString(HttpEntity entity) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + entity.writeTo(baos); + return baos.toString(StandardCharsets.UTF_8.name()); + } + public void testStartWatchService() { Request request = WatcherRequestConverters.startWatchService(new StartWatchServiceRequest()); assertEquals(HttpPost.METHOD_NAME, request.getMethod()); @@ -166,4 +177,95 @@ public void testWatcherStatsRequest() { } assertThat(request.getEntity(), nullValue()); } + + public void testExecuteWatchByIdRequest() throws IOException { + + boolean ignoreCondition = randomBoolean(); + boolean recordExecution = randomBoolean(); + boolean debug = randomBoolean(); + + ExecuteWatchRequest request = ExecuteWatchRequest.byId("my_id"); + request.setIgnoreCondition(ignoreCondition); + request.setRecordExecution(recordExecution); + request.setDebug(debug); + + request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); + + String triggerData = "{ \"entry1\" : \"blah\", \"entry2\" : \"blah\" }"; + request.setTriggerData(triggerData); + + String alternativeInput = "{ \"foo\" : \"bar\" }"; + request.setAlternativeInput(alternativeInput); + + Request req = WatcherRequestConverters.executeWatch(request); + assertThat(req.getEndpoint(), equalTo("/_xpack/watcher/watch/my_id/_execute")); + assertThat(req.getMethod(), equalTo(HttpPost.METHOD_NAME)); + + if (ignoreCondition) { + assertThat(req.getParameters(), hasKey("ignore_condition")); + assertThat(req.getParameters().get("ignore_condition"), is("true")); + } + + if (recordExecution) { + assertThat(req.getParameters(), hasKey("record_execution")); + assertThat(req.getParameters().get("record_execution"), is("true")); + } + + if (debug) { + assertThat(req.getParameters(), hasKey("debug")); + assertThat(req.getParameters().get("debug"), is("true")); + } + + String body = toString(req.getEntity()); + assertThat(body, containsString("\"action_modes\":{\"action1\":\"SIMULATE\"}")); + assertThat(body, containsString("\"trigger_data\":" + triggerData)); + assertThat(body, containsString("\"alternative_input\":" + alternativeInput)); + assertThat(body, not(containsString("\"watch\":"))); + + } + + private static final String WATCH_JSON = "{ \n" + + " \"trigger\": { \"schedule\": { \"interval\": \"10h\" } },\n" + + " \"input\": { \"none\": {} },\n" + + " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + + "}"; + + public void testExecuteInlineWatchRequest() throws IOException { + boolean ignoreCondition = randomBoolean(); + boolean recordExecution = randomBoolean(); + + ExecuteWatchRequest request = ExecuteWatchRequest.inline(WATCH_JSON); + request.setIgnoreCondition(ignoreCondition); + request.setRecordExecution(recordExecution); + + request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); + + String triggerData = "{ \"entry1\" : \"blah\", \"entry2\" : \"blah\" }"; + request.setTriggerData(triggerData); + + String alternativeInput = "{ \"foo\" : \"bar\" }"; + request.setAlternativeInput(alternativeInput); + + Request req = WatcherRequestConverters.executeWatch(request); + assertThat(req.getEndpoint(), equalTo("/_xpack/watcher/watch/_execute")); + assertThat(req.getMethod(), equalTo(HttpPost.METHOD_NAME)); + + if (ignoreCondition) { + assertThat(req.getParameters(), hasKey("ignore_condition")); + assertThat(req.getParameters().get("ignore_condition"), is("true")); + } + + if (recordExecution) { + assertThat(req.getParameters(), hasKey("record_execution")); + assertThat(req.getParameters().get("record_execution"), is("true")); + } + + String body = toString(req.getEntity()); + assertThat(body, containsString("\"action_modes\":{\"action1\":\"SIMULATE\"}")); + assertThat(body, containsString("\"trigger_data\":" + triggerData)); + assertThat(body, containsString("\"alternative_input\":" + alternativeInput)); + assertThat(body, containsString("\"watch\":" + WATCH_JSON)); + + + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java index 74562a1d17fd0..1737cf61fad8a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java @@ -34,6 +34,8 @@ import org.elasticsearch.client.watcher.ActionStatus.AckStatus; import org.elasticsearch.client.watcher.DeactivateWatchRequest; import org.elasticsearch.client.watcher.DeactivateWatchResponse; +import org.elasticsearch.client.watcher.ExecuteWatchRequest; +import org.elasticsearch.client.watcher.ExecuteWatchResponse; import org.elasticsearch.client.watcher.StartWatchServiceRequest; import org.elasticsearch.client.watcher.StopWatchServiceRequest; import org.elasticsearch.client.watcher.WatchStatus; @@ -41,6 +43,7 @@ import org.elasticsearch.client.watcher.WatcherStatsResponse; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.client.watcher.DeleteWatchRequest; import org.elasticsearch.client.watcher.DeleteWatchResponse; @@ -49,6 +52,7 @@ import org.elasticsearch.rest.RestStatus; import java.util.List; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -197,6 +201,52 @@ public void onFailure(Exception e) { assertTrue(latch.await(30L, TimeUnit.SECONDS)); } + { + // tag::x-pack-execute-watch-by-id + ExecuteWatchRequest request = ExecuteWatchRequest.byId("my_watch_id"); + request.setAlternativeInput("\"{ \"foo\" : \"bar\" }"); // <1> + request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); // <2> + request.setRecordExecution(true); // <3> + request.setIgnoreCondition(true); // <4> + request.setTriggerData("{\"triggered_time\":\"now\"}"); // <5> + request.setDebug(true); // <6> + ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT); + // end::x-pack-execute-watch-by-id + + // tag::x-pack-execute-watch-by-id-response + String id = response.getRecordId(); // <1> + Map watch = response.getRecordAsMap(); // <2> + String watch_id = ObjectPath.eval("watch_record.watch_id", watch); // <3> + // end::x-pack-execute-watch-by-id-response + } + + { + ExecuteWatchRequest request = ExecuteWatchRequest.byId("my_watch_id"); + // tag::x-pack-execute-watch-by-id-execute-listener + ActionListener listener = new ActionListener() { + @Override + public void onResponse(ExecuteWatchResponse response) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::x-pack-execute-watch-by-id-execute-listener + + // Replace the empty listener by a blocking listener in test + final CountDownLatch latch = new CountDownLatch(1); + listener = new LatchedActionListener<>(listener, latch); + + // tag::x-pack-execute-watch-by-id-execute-async + client.watcher().executeWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> + // end::x-pack-execute-watch-by-id-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } + { //tag::x-pack-delete-watch-execute DeleteWatchRequest request = new DeleteWatchRequest("my_watch_id"); @@ -238,6 +288,66 @@ public void onFailure(Exception e) { } } + public void testExecuteInlineWatch() throws Exception { + RestHighLevelClient client = highLevelClient(); + + { + // tag::x-pack-execute-inline-watch + String watchJson = "{ \n" + + " \"trigger\": { \"schedule\": { \"interval\": \"10h\" } },\n" + + " \"input\": { \"none\": {} },\n" + + " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + + "}"; + ExecuteWatchRequest request = ExecuteWatchRequest.inline(watchJson); + request.setAlternativeInput("\"{ \"foo\" : \"bar\" }"); // <1> + request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); // <2> + request.setRecordExecution(true); // <3> + request.setIgnoreCondition(true); // <4> + request.setTriggerData("{\"triggered_time\":\"now\"}"); // <5> + request.setDebug(true); // <6> + ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT); + // end::x-pack-execute-inline-watch + + // tag::x-pack-execute-watch-by-id-response + String id = response.getRecordId(); // <1> + Map watch = response.getRecordAsMap(); // <2> + String watch_id = ObjectPath.eval("watch_record.watch_id", watch); // <3> + // end::x-pack-execute-watch-by-id-response + } + + { + String watchJson = "{ \n" + + " \"trigger\": { \"schedule\": { \"interval\": \"10h\" } },\n" + + " \"input\": { \"none\": {} },\n" + + " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + + "}"; + ExecuteWatchRequest request = ExecuteWatchRequest.inline(watchJson); + // tag::x-pack-execute-inline-watch-execute-listener + ActionListener listener = new ActionListener() { + @Override + public void onResponse(ExecuteWatchResponse response) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::x-pack-execute-inline-watch-execute-listener + + // Replace the empty listener by a blocking listener in test + final CountDownLatch latch = new CountDownLatch(1); + listener = new LatchedActionListener<>(listener, latch); + + // tag::x-pack-execute-inline-watch-execute-async + client.watcher().executeWatchAsync(request, RequestOptions.DEFAULT, listener); // <1> + // end::x-pack-execute-inline-watch-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } + } + public void testAckWatch() throws Exception { RestHighLevelClient client = highLevelClient(); diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 02158673da210..5d572f4942140 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -412,6 +412,7 @@ The Java High Level REST Client supports the following Watcher APIs: * <> * <<{upid}-ack-watch>> * <<{upid}-activate-watch>> +* <<{upid}-execute-watch>> * <<{upid}-watcher-stats>> include::watcher/start-watch-service.asciidoc[] @@ -421,6 +422,7 @@ include::watcher/delete-watch.asciidoc[] include::watcher/ack-watch.asciidoc[] include::watcher/deactivate-watch.asciidoc[] include::watcher/activate-watch.asciidoc[] +include::watcher/execute-watch.asciidoc[] include::watcher/watcher-stats.asciidoc[] == Graph APIs diff --git a/docs/java-rest/high-level/watcher/execute-watch.asciidoc b/docs/java-rest/high-level/watcher/execute-watch.asciidoc new file mode 100644 index 0000000000000..c14274768317d --- /dev/null +++ b/docs/java-rest/high-level/watcher/execute-watch.asciidoc @@ -0,0 +1,87 @@ +-- +:api: execute-watch +:request: ExecuteWatchRequest +:response: ExecuteWatchResponse +-- +[id="{upid}-{api}"] +=== Execute Watch API + +The execute watch API allows clients to immediately execute a watch, either +one that has been previously added via the +{ref}/put-watch.html[Put Watch API] or inline as part of the request. + +[id="{upid}-{api}-request-by-id"] +==== Execute by id + +Submit the following request to execute a previously added watch: + +["source","java",subs="attributes,callouts,macros"] +--------------------------------------------------- +include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id] +--------------------------------------------------- +<1> Alternative input for the watch to use in json format +<2> Set the mode for action "action1" to SIMULATE +<3> Record this execution in watcher history +<4> Execute the watch regardless of the watch's condition +<5> Set the trigger data for the watch in json format +<6> Enable debug mode + +[id="{upid}-{api}-response-by-id"] +==== Execute by id Response + +The returned `Response` contains details of the execution: + +["source","java",subs="attributes,callouts,macros"] +--------------------------------------------------- +include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-response] +--------------------------------------------------- +<1> The record ID for this execution +<2> The execution response as a java `Map` +<3> Extract information from the response map using `ObjectPath` + +[id="{upid}-{api}-response-by-id-async"] +==== Asynchronous execution by id + +This request can be executed asynchronously: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-execute-async] +-------------------------------------------------- +<1> The `ExecuteWatchRequest` to execute and the `ActionListener` to use when +the execution completes + +The asynchronous method does not block and returns immediately. Once it is +completed the `ActionListener` is called back using the `onResponse` method +if the execution successfully completed or using the `onFailure` method if +it failed. + +A typical listener for `ExecuteWatchResponse` looks like: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-execute-listener] +-------------------------------------------------- +<1> Called when the execution is successfully completed. The response is +provided as an argument +<2> Called in case of failure. The raised exception is provided as an argument + + +[id="{upid}-{api}-request-inline"] +==== Execute inline + +Submit the following request to execute a watch defined as part of the request: + +["source","java",subs="attributes,callouts,macros"] +--------------------------------------------------- +include-tagged::{doc-tests-file}[x-pack-execute-watch-inline] +--------------------------------------------------- +<1> Alternative input for the watch to use in json format +<2> Set the mode for action "action1" to SIMULATE +<3> Record this execution in watcher history +<4> Execute the watch regardless of the watch's condition +<5> Set the trigger data for the watch in json format +<6> Enable debug mode + +The response format and asynchronous execution methods are the same as for the +Execute Watch by ID API. \ No newline at end of file From 933bc40eba82b65e1a4cdb61301af7d1131c61da Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 23 Nov 2018 16:52:36 +0000 Subject: [PATCH 12/20] javadoc --- .../org/elasticsearch/client/watcher/ExecuteWatchRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java index 6f8ffc523356a..e90616a48938b 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java @@ -23,7 +23,7 @@ import java.util.Optional; /** - * An execute watch request to execute a watch by id + * An execute watch request to execute a watch by id or inline */ public class ExecuteWatchRequest implements Validatable, ToXContentObject { From 3e90aa95168861dcfde0782bcfdbf03ec6eac949 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 26 Nov 2018 18:18:32 +0000 Subject: [PATCH 13/20] license headers; imports --- .../client/common/XContentSource.java | 30 ++++++++++++------- .../client/watcher/ExecuteWatchRequest.java | 28 +++++++++++------ .../client/watcher/ExecuteWatchResponse.java | 20 ++++++++++++- .../watcher/ExecuteWatchResponseTests.java | 19 ++++++++++++ 4 files changed, 76 insertions(+), 21 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java index ea2bb8fc3a334..689f82f18b9a6 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java @@ -1,21 +1,29 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.elasticsearch.client.common; -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ObjectPath; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentUtils; import java.io.IOException; -import java.io.InputStream; import java.util.List; import java.util.Map; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java index e90616a48938b..0ddd62b09d3c2 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java @@ -1,26 +1,36 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.elasticsearch.client.watcher; -import org.apache.http.HttpEntity; -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.ValidateActions; import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.Optional; /** * An execute watch request to execute a watch by id or inline diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java index 2539c1206f028..cf5313d56ae57 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchResponse.java @@ -1,7 +1,25 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.elasticsearch.client.watcher; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.client.common.XContentSource; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ConstructingObjectParser; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java index beaedecbdd40d..f72fce7e0702e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java @@ -1,3 +1,22 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.elasticsearch.protocol.xpack.watcher; import org.elasticsearch.common.bytes.BytesReference; From c6117440dd40c783f4a27760eb6d961c59624c74 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 27 Nov 2018 12:01:28 +0000 Subject: [PATCH 14/20] imports --- .../client/WatcherRequestConverters.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java index 26784c1c08ced..504fc07cd15fc 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java @@ -25,18 +25,16 @@ import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; -import org.elasticsearch.client.watcher.ExecuteWatchRequest; -import org.elasticsearch.client.watcher.DeactivateWatchRequest; -import org.elasticsearch.client.watcher.ActivateWatchRequest; import org.elasticsearch.client.watcher.AckWatchRequest; +import org.elasticsearch.client.watcher.ActivateWatchRequest; +import org.elasticsearch.client.watcher.DeactivateWatchRequest; +import org.elasticsearch.client.watcher.DeleteWatchRequest; +import org.elasticsearch.client.watcher.ExecuteWatchRequest; +import org.elasticsearch.client.watcher.PutWatchRequest; import org.elasticsearch.client.watcher.StartWatchServiceRequest; import org.elasticsearch.client.watcher.StopWatchServiceRequest; import org.elasticsearch.client.watcher.WatcherStatsRequest; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.client.watcher.DeleteWatchRequest; -import org.elasticsearch.client.watcher.PutWatchRequest; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; From a1dfd0aed8e400f7230c12ebdf4ab631bd6d9f13 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 27 Nov 2018 12:04:51 +0000 Subject: [PATCH 15/20] imports --- .../org/elasticsearch/client/WatcherIT.java | 11 ++++------- .../watcher/ExecuteWatchResponseTests.java | 19 +++---------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java index b4b7316b27ee1..5304267a940eb 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java @@ -20,7 +20,6 @@ import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.common.XContentSource; import org.elasticsearch.client.watcher.AckWatchRequest; import org.elasticsearch.client.watcher.AckWatchResponse; import org.elasticsearch.client.watcher.ActionStatus; @@ -29,8 +28,12 @@ import org.elasticsearch.client.watcher.ActivateWatchResponse; import org.elasticsearch.client.watcher.DeactivateWatchRequest; import org.elasticsearch.client.watcher.DeactivateWatchResponse; +import org.elasticsearch.client.watcher.DeleteWatchRequest; +import org.elasticsearch.client.watcher.DeleteWatchResponse; import org.elasticsearch.client.watcher.ExecuteWatchRequest; import org.elasticsearch.client.watcher.ExecuteWatchResponse; +import org.elasticsearch.client.watcher.PutWatchRequest; +import org.elasticsearch.client.watcher.PutWatchResponse; import org.elasticsearch.client.watcher.StartWatchServiceRequest; import org.elasticsearch.client.watcher.StopWatchServiceRequest; import org.elasticsearch.client.watcher.WatcherState; @@ -40,12 +43,7 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.client.watcher.DeleteWatchRequest; -import org.elasticsearch.client.watcher.DeleteWatchResponse; -import org.elasticsearch.client.watcher.PutWatchRequest; -import org.elasticsearch.client.watcher.PutWatchResponse; import org.elasticsearch.rest.RestStatus; -import org.hamcrest.Matchers; import java.util.Map; @@ -54,7 +52,6 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.not; -import static org.hamcrest.core.IsNull.notNullValue; public class WatcherIT extends ESRestHighLevelClientTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java index f72fce7e0702e..47fd4a33dc955 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java @@ -1,20 +1,7 @@ /* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ package org.elasticsearch.protocol.xpack.watcher; From c4e3fe41277b91413656aadfcdcfb41e8c9d4f0e Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 28 Nov 2018 14:23:37 +0000 Subject: [PATCH 16/20] Fix docs test --- .../client/watcher/ExecuteWatchRequest.java | 3 +++ .../client/WatcherRequestConvertersTests.java | 2 -- .../client/documentation/WatcherDocumentationIT.java | 11 +++++------ .../high-level/watcher/execute-watch.asciidoc | 9 +++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java index 0ddd62b09d3c2..ac96fcc519287 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.java @@ -97,6 +97,9 @@ public boolean ignoreCondition() { * @param recordExecution Sets if this execution be recorded in the history index */ public void setRecordExecution(boolean recordExecution) { + if (watchContent != null && recordExecution) { + throw new IllegalArgumentException("The execution of an inline watch cannot be recorded"); + } this.recordExecution = recordExecution; } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java index a3a740a6f27bb..ea6461a0a9abe 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java @@ -265,7 +265,5 @@ public void testExecuteInlineWatchRequest() throws IOException { assertThat(body, containsString("\"trigger_data\":" + triggerData)); assertThat(body, containsString("\"alternative_input\":" + alternativeInput)); assertThat(body, containsString("\"watch\":" + WATCH_JSON)); - - } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java index 1737cf61fad8a..e0b5ce61d4b80 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/WatcherDocumentationIT.java @@ -204,7 +204,7 @@ public void onFailure(Exception e) { { // tag::x-pack-execute-watch-by-id ExecuteWatchRequest request = ExecuteWatchRequest.byId("my_watch_id"); - request.setAlternativeInput("\"{ \"foo\" : \"bar\" }"); // <1> + request.setAlternativeInput("{ \"foo\" : \"bar\" }"); // <1> request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); // <2> request.setRecordExecution(true); // <3> request.setIgnoreCondition(true); // <4> @@ -299,12 +299,11 @@ public void testExecuteInlineWatch() throws Exception { " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + "}"; ExecuteWatchRequest request = ExecuteWatchRequest.inline(watchJson); - request.setAlternativeInput("\"{ \"foo\" : \"bar\" }"); // <1> + request.setAlternativeInput("{ \"foo\" : \"bar\" }"); // <1> request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); // <2> - request.setRecordExecution(true); // <3> - request.setIgnoreCondition(true); // <4> - request.setTriggerData("{\"triggered_time\":\"now\"}"); // <5> - request.setDebug(true); // <6> + request.setIgnoreCondition(true); // <3> + request.setTriggerData("{\"triggered_time\":\"now\"}"); // <4> + request.setDebug(true); // <5> ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT); // end::x-pack-execute-inline-watch diff --git a/docs/java-rest/high-level/watcher/execute-watch.asciidoc b/docs/java-rest/high-level/watcher/execute-watch.asciidoc index c14274768317d..1af93f0cd6c9b 100644 --- a/docs/java-rest/high-level/watcher/execute-watch.asciidoc +++ b/docs/java-rest/high-level/watcher/execute-watch.asciidoc @@ -78,10 +78,11 @@ include-tagged::{doc-tests-file}[x-pack-execute-watch-inline] --------------------------------------------------- <1> Alternative input for the watch to use in json format <2> Set the mode for action "action1" to SIMULATE -<3> Record this execution in watcher history -<4> Execute the watch regardless of the watch's condition -<5> Set the trigger data for the watch in json format -<6> Enable debug mode +<3> Execute the watch regardless of the watch's condition +<4> Set the trigger data for the watch in json format +<5> Enable debug mode + +Note that inline watches cannot be recorded. The response format and asynchronous execution methods are the same as for the Execute Watch by ID API. \ No newline at end of file From ba11a6f867d5d26f13e96263d2e672f7b73b6c77 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 28 Nov 2018 15:29:29 +0000 Subject: [PATCH 17/20] Check record-execution validation --- .../client/WatcherRequestConvertersTests.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java index ea6461a0a9abe..4cee45757695d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java @@ -232,11 +232,13 @@ public void testExecuteWatchByIdRequest() throws IOException { public void testExecuteInlineWatchRequest() throws IOException { boolean ignoreCondition = randomBoolean(); - boolean recordExecution = randomBoolean(); ExecuteWatchRequest request = ExecuteWatchRequest.inline(WATCH_JSON); request.setIgnoreCondition(ignoreCondition); - request.setRecordExecution(recordExecution); + + expectThrows(IllegalArgumentException.class, () -> { + request.setRecordExecution(true); + }); request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); @@ -255,11 +257,6 @@ public void testExecuteInlineWatchRequest() throws IOException { assertThat(req.getParameters().get("ignore_condition"), is("true")); } - if (recordExecution) { - assertThat(req.getParameters(), hasKey("record_execution")); - assertThat(req.getParameters().get("record_execution"), is("true")); - } - String body = toString(req.getEntity()); assertThat(body, containsString("\"action_modes\":{\"action1\":\"SIMULATE\"}")); assertThat(body, containsString("\"trigger_data\":" + triggerData)); From a8abe2bf201812a96ebfeaeff3dfbf50419a41c7 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 3 Dec 2018 17:55:30 +0000 Subject: [PATCH 18/20] Remove 404 exclusions --- .../main/java/org/elasticsearch/client/WatcherClient.java | 4 ++-- .../src/test/java/org/elasticsearch/client/WatcherIT.java | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java index 8071165f4c601..51d60f0c4b869 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherClient.java @@ -252,7 +252,7 @@ public void activateWatchAsync(ActivateWatchRequest request, RequestOptions opti */ public ExecuteWatchResponse executeWatch(ExecuteWatchRequest request, RequestOptions options) throws IOException { return restHighLevelClient.performRequestAndParseEntity(request, WatcherRequestConverters::executeWatch, options, - ExecuteWatchResponse::fromXContent, singleton(404)); + ExecuteWatchResponse::fromXContent, emptySet()); } /** @@ -265,7 +265,7 @@ public ExecuteWatchResponse executeWatch(ExecuteWatchRequest request, RequestOpt */ public void executeWatchAsync(ExecuteWatchRequest request, RequestOptions options, ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity(request, WatcherRequestConverters::executeWatch, options, - ExecuteWatchResponse::fromXContent, listener, singleton(404)); + ExecuteWatchResponse::fromXContent, listener, emptySet()); } /** diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java index 5304267a940eb..cb9da0af66995 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherIT.java @@ -204,6 +204,14 @@ public void testExecuteWatchById() throws Exception { } + public void testExecuteWatchThatDoesNotExist() throws Exception { + String watchId = randomAlphaOfLength(10); + // exception when activating a not existing watcher + ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> + highLevelClient().watcher().executeWatch(ExecuteWatchRequest.byId(watchId), RequestOptions.DEFAULT)); + assertEquals(RestStatus.NOT_FOUND, exception.status()); + } + public void testExecuteInlineWatch() throws Exception { ExecuteWatchResponse response = highLevelClient().watcher() .executeWatch(ExecuteWatchRequest.inline(WATCH_JSON), RequestOptions.DEFAULT); From c779b34615d2ca2555c98d7a2e9c21a72467d8e8 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 4 Dec 2018 10:13:56 +0000 Subject: [PATCH 19/20] feedback --- .../client/WatcherRequestConverters.java | 6 +- .../client/WatcherRequestConvertersTests.java | 72 +++++++++++++++---- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java index 5d08ceb053472..fe563b2a9add4 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java @@ -114,10 +114,8 @@ static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) { static Request executeWatch(ExecuteWatchRequest executeWatchRequest) throws IOException { RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder() - .addPathPart("_xpack", "watcher", "watch"); - if (executeWatchRequest.getId() != null) { - builder.addPathPart(executeWatchRequest.getId()); - } + .addPathPartAsIs("_xpack", "watcher", "watch"); + builder.addPathPart(executeWatchRequest.getId()); // will ignore if ID is null String endpoint = builder.addPathPart("_execute").build(); Request request = new Request(HttpPost.METHOD_NAME, endpoint); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java index a96c72e7b7640..3b7d533a18140 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java @@ -200,13 +200,22 @@ public void testExecuteWatchByIdRequest() throws IOException { request.setRecordExecution(recordExecution); request.setDebug(debug); - request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); + boolean setActionMode = randomBoolean(); + if (setActionMode) { + request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); + } + boolean useTriggerData = randomBoolean(); String triggerData = "{ \"entry1\" : \"blah\", \"entry2\" : \"blah\" }"; - request.setTriggerData(triggerData); + if (useTriggerData) { + request.setTriggerData(triggerData); + } + boolean useAlternativeInput = randomBoolean(); String alternativeInput = "{ \"foo\" : \"bar\" }"; - request.setAlternativeInput(alternativeInput); + if (useAlternativeInput) { + request.setAlternativeInput(alternativeInput); + } Request req = WatcherRequestConverters.executeWatch(request); assertThat(req.getEndpoint(), equalTo("/_xpack/watcher/watch/my_id/_execute")); @@ -228,9 +237,24 @@ public void testExecuteWatchByIdRequest() throws IOException { } String body = toString(req.getEntity()); - assertThat(body, containsString("\"action_modes\":{\"action1\":\"SIMULATE\"}")); - assertThat(body, containsString("\"trigger_data\":" + triggerData)); - assertThat(body, containsString("\"alternative_input\":" + alternativeInput)); + if (setActionMode) { + assertThat(body, containsString("\"action_modes\":{\"action1\":\"SIMULATE\"}")); + } + else { + assertThat(body, not(containsString("action_modes"))); + } + if (useTriggerData) { + assertThat(body, containsString("\"trigger_data\":" + triggerData)); + } + else { + assertThat(body, not(containsString("trigger_data"))); + } + if (useAlternativeInput) { + assertThat(body, containsString("\"alternative_input\":" + alternativeInput)); + } + else { + assertThat(body, not(containsString("alternative_input"))); + } assertThat(body, not(containsString("\"watch\":"))); } @@ -251,13 +275,22 @@ public void testExecuteInlineWatchRequest() throws IOException { request.setRecordExecution(true); }); - request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); + boolean setActionMode = randomBoolean(); + if (setActionMode) { + request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); + } + boolean useTriggerData = randomBoolean(); String triggerData = "{ \"entry1\" : \"blah\", \"entry2\" : \"blah\" }"; - request.setTriggerData(triggerData); + if (useTriggerData) { + request.setTriggerData(triggerData); + } + boolean useAlternativeInput = randomBoolean(); String alternativeInput = "{ \"foo\" : \"bar\" }"; - request.setAlternativeInput(alternativeInput); + if (useAlternativeInput) { + request.setAlternativeInput(alternativeInput); + } Request req = WatcherRequestConverters.executeWatch(request); assertThat(req.getEndpoint(), equalTo("/_xpack/watcher/watch/_execute")); @@ -269,9 +302,24 @@ public void testExecuteInlineWatchRequest() throws IOException { } String body = toString(req.getEntity()); - assertThat(body, containsString("\"action_modes\":{\"action1\":\"SIMULATE\"}")); - assertThat(body, containsString("\"trigger_data\":" + triggerData)); - assertThat(body, containsString("\"alternative_input\":" + alternativeInput)); + if (setActionMode) { + assertThat(body, containsString("\"action_modes\":{\"action1\":\"SIMULATE\"}")); + } + else { + assertThat(body, not(containsString("action_modes"))); + } + if (useTriggerData) { + assertThat(body, containsString("\"trigger_data\":" + triggerData)); + } + else { + assertThat(body, not(containsString("trigger_data"))); + } + if (useAlternativeInput) { + assertThat(body, containsString("\"alternative_input\":" + alternativeInput)); + } + else { + assertThat(body, not(containsString("alternative_input"))); + } assertThat(body, containsString("\"watch\":" + WATCH_JSON)); } } From 5b231e7f82b21a61d88de96544666b0be32a372b Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 4 Dec 2018 20:31:26 +0000 Subject: [PATCH 20/20] feedback --- .../elasticsearch/client/WatcherRequestConverters.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java index fe563b2a9add4..3cc6826e837dc 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java @@ -113,10 +113,10 @@ static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) { } static Request executeWatch(ExecuteWatchRequest executeWatchRequest) throws IOException { - RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_xpack", "watcher", "watch"); - builder.addPathPart(executeWatchRequest.getId()); // will ignore if ID is null - String endpoint = builder.addPathPart("_execute").build(); + String endpoint = new RequestConverters.EndpointBuilder() + .addPathPartAsIs("_xpack", "watcher", "watch") + .addPathPart(executeWatchRequest.getId()) // will ignore if ID is null + .addPathPartAsIs("_execute").build(); Request request = new Request(HttpPost.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(request);