Skip to content

Commit 56170b4

Browse files
authored
[Transform] Ensure transform _schedule_now API only triggers the expected transform task (#102958)
1 parent 2690fe3 commit 56170b4

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

docs/changelog/102958.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pr: 102958
2+
summary: Ensure transform `_schedule_now` API only triggers the expected transform
3+
task
4+
area: Transform
5+
type: bug
6+
issues:
7+
- 102956

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/ScheduleNowTransformAction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.common.io.stream.StreamOutput;
1919
import org.elasticsearch.common.io.stream.Writeable;
2020
import org.elasticsearch.core.TimeValue;
21+
import org.elasticsearch.tasks.Task;
2122
import org.elasticsearch.xcontent.ToXContentObject;
2223
import org.elasticsearch.xcontent.XContentBuilder;
2324
import org.elasticsearch.xpack.core.transform.TransformField;
@@ -94,6 +95,15 @@ public boolean equals(Object obj) {
9495
// the base class does not implement equals, therefore we need to check timeout ourselves
9596
return this.id.equals(other.id) && getTimeout().equals(other.getTimeout());
9697
}
98+
99+
@Override
100+
public boolean match(Task task) {
101+
if (task.getDescription().startsWith(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX)) {
102+
String taskId = task.getDescription().substring(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX.length());
103+
return taskId.equals(this.id);
104+
}
105+
return false;
106+
}
97107
}
98108

99109
public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/action/ScheduleNowTransformActionRequestTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.action.ActionRequestValidationException;
1111
import org.elasticsearch.common.io.stream.Writeable;
1212
import org.elasticsearch.core.TimeValue;
13+
import org.elasticsearch.persistent.AllocatedPersistentTask;
1314
import org.elasticsearch.test.AbstractWireSerializingTestCase;
1415
import org.elasticsearch.xpack.core.transform.action.ScheduleNowTransformAction.Request;
1516

@@ -55,4 +56,12 @@ public void testValidationFailure() {
5556
assertThat(e, is(notNullValue()));
5657
assertThat(e.validationErrors(), contains("_schedule_now API does not support _all wildcard"));
5758
}
59+
60+
public void testMatch() {
61+
Request request = new Request("my-transform-7", TimeValue.timeValueSeconds(5));
62+
assertTrue(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-7", null, null)));
63+
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-", null, null)));
64+
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-77", null, null)));
65+
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "my-transform-7", null, null)));
66+
}
5867
}

0 commit comments

Comments
 (0)