Skip to content

Commit b9fe907

Browse files
authored
[Transform] Ensure transform updates only modify the expected transform task (#102934) (#102941)
(cherry picked from commit 67ab4b4) # Conflicts: # x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/action/UpdateTransformActionRequestTests.java
1 parent dbd82ac commit b9fe907

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docs/changelog/102934.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 102934
2+
summary: Ensure transform updates only modify the expected transform task
3+
area: Transform
4+
type: bug
5+
issues:
6+
- 102933

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.io.stream.StreamInput;
1616
import org.elasticsearch.common.io.stream.StreamOutput;
1717
import org.elasticsearch.core.TimeValue;
18+
import org.elasticsearch.tasks.Task;
1819
import org.elasticsearch.xcontent.ToXContentObject;
1920
import org.elasticsearch.xcontent.XContentBuilder;
2021
import org.elasticsearch.xcontent.XContentParser;
@@ -178,6 +179,15 @@ public boolean equals(Object obj) {
178179
&& Objects.equals(config, other.config)
179180
&& getTimeout().equals(other.getTimeout());
180181
}
182+
183+
@Override
184+
public boolean match(Task task) {
185+
if (task.getDescription().startsWith(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX)) {
186+
String taskId = task.getDescription().substring(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX.length());
187+
return taskId.equals(this.id);
188+
}
189+
return false;
190+
}
181191
}
182192

183193
public static class Response extends BaseTasksResponse implements ToXContentObject {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.Version;
1111
import org.elasticsearch.common.io.stream.Writeable;
1212
import org.elasticsearch.core.TimeValue;
13+
import org.elasticsearch.persistent.AllocatedPersistentTask;
1314
import org.elasticsearch.xpack.core.transform.action.UpdateTransformAction.Request;
1415
import org.elasticsearch.xpack.core.transform.action.compat.UpdateTransformActionPre78;
1516
import org.elasticsearch.xpack.core.transform.transforms.TransformConfigTests;
@@ -85,6 +86,14 @@ protected Request mutateInstance(Request instance) throws IOException {
8586
return new Request(update, id, deferValidation, timeout);
8687
}
8788

89+
public void testMatch() {
90+
Request request = new Request(randomTransformConfigUpdate(), "my-transform-7", false, null);
91+
assertTrue(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-7", null, null)));
92+
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-", null, null)));
93+
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-77", null, null)));
94+
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "my-transform-7", null, null)));
95+
}
96+
8897
public void testBWCPre78() throws IOException {
8998
Request newRequest = createTestInstance();
9099
UpdateTransformActionPre78.Request oldRequest = writeAndReadBWCObject(
@@ -134,5 +143,4 @@ public void testBWCPre78() throws IOException {
134143
assertEquals(newRequest.getUpdate().getSyncConfig(), newRequestFromOld.getUpdate().getSyncConfig());
135144
assertEquals(newRequest.isDeferValidation(), newRequestFromOld.isDeferValidation());
136145
}
137-
138146
}

0 commit comments

Comments
 (0)