Skip to content

Commit 35ed56d

Browse files
committed
Watcher: Remove deprecated params.ctx
When the script contexts were created in 6, the use of params.ctx was deprecated. This commit cleans up that code and ensures that params.ctx is null in both watcher script contexts. Relates: elastic#34059
1 parent 667c06d commit 35ed56d

File tree

4 files changed

+8
-44
lines changed

4 files changed

+8
-44
lines changed

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/WatcherConditionScript.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,14 @@
1818
* A script to determine whether a watch should be run.
1919
*/
2020
public abstract class WatcherConditionScript {
21-
public static final String[] PARAMETERS = {};
22-
23-
private static final Map<String, String> DEPRECATIONS;
24-
25-
static {
26-
Map<String, String> deprecations = new HashMap<>();
27-
deprecations.put(
28-
"ctx",
29-
"Accessing variable [ctx] via [params.ctx] from within a watcher_condition script " +
30-
"is deprecated in favor of directly accessing [ctx]."
31-
);
32-
DEPRECATIONS = Collections.unmodifiableMap(deprecations);
33-
}
3421

3522
private final Map<String, Object> params;
3623
// TODO: ctx should have its members extracted into execute parameters, but it needs to be a member for bwc access in params
3724
private final Map<String, Object> ctx;
3825

3926
public WatcherConditionScript(Map<String, Object> params, WatchExecutionContext watcherContext) {
40-
Map<String, Object> paramsWithCtx = new HashMap<>(params);
41-
Map<String, Object> ctx = Variables.createCtx(watcherContext, watcherContext.payload());
42-
paramsWithCtx.put("ctx", ctx);
43-
this.params = new ParameterMap(Collections.unmodifiableMap(paramsWithCtx), DEPRECATIONS);
44-
this.ctx = ctx;
27+
this.params = params;
28+
this.ctx = Variables.createCtx(watcherContext, watcherContext.payload());;
4529
}
4630

4731
public abstract boolean execute();

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/script/WatcherTransformScript.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,14 @@
1919
* A script to transform the results of a watch execution.
2020
*/
2121
public abstract class WatcherTransformScript {
22-
public static final String[] PARAMETERS = {};
23-
24-
private static final Map<String, String> DEPRECATIONS;
25-
26-
static {
27-
Map<String, String> deprecations = new HashMap<>();
28-
deprecations.put(
29-
"ctx",
30-
"Accessing variable [ctx] via [params.ctx] from within a watcher_transform script " +
31-
"is deprecated in favor of directly accessing [ctx]."
32-
);
33-
DEPRECATIONS = Collections.unmodifiableMap(deprecations);
34-
}
3522

3623
private final Map<String, Object> params;
3724
// TODO: ctx should have its members extracted into execute parameters, but it needs to be a member bwc access in params
3825
private final Map<String, Object> ctx;
3926

4027
public WatcherTransformScript(Map<String, Object> params, WatchExecutionContext watcherContext, Payload payload) {
41-
Map<String, Object> paramsWithCtx = new HashMap<>(params);
42-
Map<String, Object> ctx = Variables.createCtx(watcherContext, payload);
43-
paramsWithCtx.put("ctx", ctx);
44-
this.params = new ParameterMap(Collections.unmodifiableMap(paramsWithCtx), DEPRECATIONS);
45-
this.ctx = ctx;
28+
this.params = params;
29+
this.ctx = Variables.createCtx(watcherContext, payload);
4630
}
4731

4832
public abstract Object execute();

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void testScriptConditionAccessCtx() throws Exception {
206206
assertThat(condition.execute(ctx).met(), is(true));
207207
}
208208

209-
public void testParamsCtxDeprecated() throws Exception {
209+
public void testParamsCtxNull() throws Exception {
210210
WatchExecutionContext watcherContext = mock(WatchExecutionContext.class);
211211
when(watcherContext.id()).thenReturn(mock(Wid.class));
212212
when(watcherContext.watch()).thenReturn(mock(Watch.class));
@@ -216,13 +216,11 @@ public void testParamsCtxDeprecated() throws Exception {
216216
WatcherConditionScript watcherScript = new WatcherConditionScript(Collections.emptyMap(), watcherContext) {
217217
@Override
218218
public boolean execute() {
219-
assertThat(getParams().get("ctx"), is(getCtx()));
219+
assertNull(getParams().get("ctx"));
220220
return true;
221221
}
222222
};
223-
watcherScript.execute();
224-
assertWarnings("Accessing variable [ctx] via [params.ctx] from within a watcher_condition script " +
225-
"is deprecated in favor of directly accessing [ctx].");
223+
assertTrue(watcherScript.execute());
226224
}
227225

228226
private static XContentBuilder createConditionContent(String script, String scriptLang, ScriptType scriptType) throws IOException {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ public Object execute() {
202202
return getParams().get("ctx");
203203
}
204204
};
205-
assertThat(watcherScript.execute(), is(watcherScript.getCtx()));
206-
assertWarnings("Accessing variable [ctx] via [params.ctx] from within a watcher_transform script " +
207-
"is deprecated in favor of directly accessing [ctx].");
205+
assertNull(watcherScript.execute());
208206
}
209207

210208
static String scriptTypeField(ScriptType type) {

0 commit comments

Comments
 (0)