diff --git a/server/src/main/java/org/elasticsearch/script/UpdateScript.java b/server/src/main/java/org/elasticsearch/script/UpdateScript.java index e1eaf14bcb943..9b9e79c7b74ba 100644 --- a/server/src/main/java/org/elasticsearch/script/UpdateScript.java +++ b/server/src/main/java/org/elasticsearch/script/UpdateScript.java @@ -20,8 +20,6 @@ package org.elasticsearch.script; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; /** @@ -31,17 +29,6 @@ public abstract class UpdateScript { public static final String[] PARAMETERS = { }; - private static final Map DEPRECATIONS; - static { - Map deprecations = new HashMap<>(); - deprecations.put( - "ctx", - "Accessing variable [ctx] via [params.ctx] from within a update script " + - "is deprecated in favor of directly accessing [ctx]." - ); - DEPRECATIONS = Collections.unmodifiableMap(deprecations); - } - /** The context used to compile {@link UpdateScript} factories. */ public static final ScriptContext CONTEXT = new ScriptContext<>("update", Factory.class); @@ -52,9 +39,7 @@ public abstract class UpdateScript { private final Map ctx; public UpdateScript(Map params, Map ctx) { - Map paramsWithCtx = new HashMap<>(params); - paramsWithCtx.put("ctx", ctx); - this.params = new ParameterMap(paramsWithCtx, DEPRECATIONS); + this.params = params; this.ctx = ctx; } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/WatcherConditionScript.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/WatcherConditionScript.java index 1148cc6a58eb5..1a5c8718bbd45 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/WatcherConditionScript.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/WatcherConditionScript.java @@ -5,43 +5,26 @@ */ package org.elasticsearch.xpack.watcher.condition; -import org.elasticsearch.script.ParameterMap; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.support.Variables; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; /** * A script to determine whether a watch should be run. */ public abstract class WatcherConditionScript { - public static final String[] PARAMETERS = {}; - - private static final Map DEPRECATIONS; - static { - Map deprecations = new HashMap<>(); - deprecations.put( - "ctx", - "Accessing variable [ctx] via [params.ctx] from within a watcher_condition script " + - "is deprecated in favor of directly accessing [ctx]." - ); - DEPRECATIONS = Collections.unmodifiableMap(deprecations); - } + public static final String[] PARAMETERS = {}; private final Map params; // TODO: ctx should have its members extracted into execute parameters, but it needs to be a member for bwc access in params private final Map ctx; public WatcherConditionScript(Map params, WatchExecutionContext watcherContext) { - Map paramsWithCtx = new HashMap<>(params); - Map ctx = Variables.createCtx(watcherContext, watcherContext.payload()); - paramsWithCtx.put("ctx", ctx); - this.params = new ParameterMap(Collections.unmodifiableMap(paramsWithCtx), DEPRECATIONS); - this.ctx = ctx; + this.params = params; + this.ctx = Variables.createCtx(watcherContext, watcherContext.payload()); } public abstract boolean execute(); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/script/WatcherTransformScript.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/script/WatcherTransformScript.java index 6d84c32578bc0..57ee1e9f35c5d 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/script/WatcherTransformScript.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/script/WatcherTransformScript.java @@ -5,44 +5,27 @@ */ package org.elasticsearch.xpack.watcher.transform.script; -import org.elasticsearch.script.ParameterMap; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.support.Variables; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; /** * A script to transform the results of a watch execution. */ public abstract class WatcherTransformScript { - public static final String[] PARAMETERS = {}; - - private static final Map DEPRECATIONS; - static { - Map deprecations = new HashMap<>(); - deprecations.put( - "ctx", - "Accessing variable [ctx] via [params.ctx] from within a watcher_transform script " + - "is deprecated in favor of directly accessing [ctx]." - ); - DEPRECATIONS = Collections.unmodifiableMap(deprecations); - } + public static final String[] PARAMETERS = {}; private final Map params; // TODO: ctx should have its members extracted into execute parameters, but it needs to be a member bwc access in params private final Map ctx; public WatcherTransformScript(Map params, WatchExecutionContext watcherContext, Payload payload) { - Map paramsWithCtx = new HashMap<>(params); - Map ctx = Variables.createCtx(watcherContext, payload); - paramsWithCtx.put("ctx", ctx); - this.params = new ParameterMap(Collections.unmodifiableMap(paramsWithCtx), DEPRECATIONS); - this.ctx = ctx; + this.params = params; + this.ctx = Variables.createCtx(watcherContext, payload); } public abstract Object execute(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java index 1787904e98f0a..72ab01009bb99 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java @@ -30,10 +30,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.condition.ExecutableCondition; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; -import org.elasticsearch.xpack.core.watcher.execution.Wid; -import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Payload; -import org.elasticsearch.xpack.core.watcher.watch.Watch; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.xpack.watcher.test.WatcherMockScriptPlugin; import org.joda.time.DateTime; @@ -41,7 +38,6 @@ import org.junit.Before; import java.io.IOException; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -54,8 +50,6 @@ import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.mockExecutionContext; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class ScriptConditionTests extends ESTestCase { @@ -206,25 +200,6 @@ public void testScriptConditionAccessCtx() throws Exception { assertThat(condition.execute(ctx).met(), is(true)); } - public void testParamsCtxDeprecated() throws Exception { - WatchExecutionContext watcherContext = mock(WatchExecutionContext.class); - when(watcherContext.id()).thenReturn(mock(Wid.class)); - when(watcherContext.watch()).thenReturn(mock(Watch.class)); - when(watcherContext.triggerEvent()).thenReturn(mock(TriggerEvent.class)); - DateTime now = DateTime.now(DateTimeZone.UTC); - when(watcherContext.executionTime()).thenReturn(now); - WatcherConditionScript watcherScript = new WatcherConditionScript(Collections.emptyMap(), watcherContext) { - @Override - public boolean execute() { - assertThat(getParams().get("ctx"), is(getCtx())); - return true; - } - }; - watcherScript.execute(); - assertWarnings("Accessing variable [ctx] via [params.ctx] from within a watcher_condition script " + - "is deprecated in favor of directly accessing [ctx]."); - } - private static XContentBuilder createConditionContent(String script, String scriptLang, ScriptType scriptType) throws IOException { XContentBuilder builder = jsonBuilder(); if (scriptType == null) { diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java index 077e168c547ee..3e2ec780fa4c0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java @@ -16,14 +16,9 @@ import org.elasticsearch.script.ScriptType; 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.transform.Transform; -import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.core.watcher.watch.Payload; -import org.elasticsearch.xpack.core.watcher.watch.Watch; import org.elasticsearch.xpack.watcher.Watcher; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; import java.util.Collections; import java.util.HashMap; @@ -188,25 +183,6 @@ public void testScriptConditionParserBadLang() throws Exception { assertThat(e.getMessage(), containsString("script_lang not supported [not_a_valid_lang]")); } - public void testParamsCtxDeprecated() throws Exception { - WatchExecutionContext watcherContext = mock(WatchExecutionContext.class); - when(watcherContext.id()).thenReturn(mock(Wid.class)); - when(watcherContext.watch()).thenReturn(mock(Watch.class)); - when(watcherContext.triggerEvent()).thenReturn(mock(TriggerEvent.class)); - DateTime now = DateTime.now(DateTimeZone.UTC); - when(watcherContext.executionTime()).thenReturn(now); - Payload payload = mock(Payload.class); - WatcherTransformScript watcherScript = new WatcherTransformScript(Collections.emptyMap(), watcherContext, payload) { - @Override - public Object execute() { - return getParams().get("ctx"); - } - }; - assertThat(watcherScript.execute(), is(watcherScript.getCtx())); - assertWarnings("Accessing variable [ctx] via [params.ctx] from within a watcher_transform script " + - "is deprecated in favor of directly accessing [ctx]."); - } - static String scriptTypeField(ScriptType type) { switch (type) { case INLINE: return "source";