Skip to content

Commit

Permalink
[Transform] Ensure transform updates only modify the expected transfo…
Browse files Browse the repository at this point in the history
…rm task (#102934)
  • Loading branch information
przemekwitek authored Dec 4, 2023
1 parent c54ce68 commit 67ab4b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/102934.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 102934
summary: Ensure transform updates only modify the expected transform task
area: Transform
type: bug
issues:
- 102933
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
Expand Down Expand Up @@ -186,6 +187,15 @@ public boolean equals(Object obj) {
&& Objects.equals(authState, other.authState)
&& getTimeout().equals(other.getTimeout());
}

@Override
public boolean match(Task task) {
if (task.getDescription().startsWith(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX)) {
String taskId = task.getDescription().substring(TransformField.PERSISTENT_TASK_DESCRIPTION_PREFIX.length());
return taskId.equals(this.id);
}
return false;
}
}

public static class Response extends BaseTasksResponse implements ToXContentObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.persistent.AllocatedPersistentTask;
import org.elasticsearch.xpack.core.transform.action.UpdateTransformAction.Request;
import org.elasticsearch.xpack.core.transform.transforms.AuthorizationStateTests;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfigTests;
Expand Down Expand Up @@ -74,4 +75,12 @@ protected Request mutateInstance(Request instance) {

return new Request(update, id, deferValidation, timeout);
}

public void testMatch() {
Request request = new Request(randomTransformConfigUpdate(), "my-transform-7", false, null);
assertTrue(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-7", null, null)));
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-", null, null)));
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "data_frame_my-transform-77", null, null)));
assertFalse(request.match(new AllocatedPersistentTask(123, "", "", "my-transform-7", null, null)));
}
}

0 comments on commit 67ab4b4

Please sign in to comment.