Skip to content

Commit 2329efc

Browse files
authored
[Transform] Ensure transform _schedule_now API only triggers the expected transform task (#102958) (#102962)
1 parent 76013fa commit 2329efc

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;
@@ -95,6 +96,15 @@ public boolean equals(Object obj) {
9596
// the base class does not implement equals, therefore we need to check timeout ourselves
9697
return this.id.equals(other.id) && getTimeout().equals(other.getTimeout());
9798
}
99+
100+
@Override
101+
public boolean match(Task task) {
102+
if (task.getDescription().startsWith(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX)) {
103+
String taskId = task.getDescription().substring(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX.length());
104+
return taskId.equals(this.id);
105+
}
106+
return false;
107+
}
98108
}
99109

100110
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)