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) (#102941)

(cherry picked from commit 67ab4b4)

# Conflicts:
#	x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/action/UpdateTransformActionRequestTests.java
  • Loading branch information
przemekwitek authored Dec 4, 2023
1 parent dbd82ac commit b9fe907
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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 @@ -178,6 +179,15 @@ public boolean equals(Object obj) {
&& Objects.equals(config, other.config)
&& 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 @@ -10,6 +10,7 @@
import org.elasticsearch.Version;
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.action.compat.UpdateTransformActionPre78;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfigTests;
Expand Down Expand Up @@ -85,6 +86,14 @@ protected Request mutateInstance(Request instance) throws IOException {
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)));
}

public void testBWCPre78() throws IOException {
Request newRequest = createTestInstance();
UpdateTransformActionPre78.Request oldRequest = writeAndReadBWCObject(
Expand Down Expand Up @@ -134,5 +143,4 @@ public void testBWCPre78() throws IOException {
assertEquals(newRequest.getUpdate().getSyncConfig(), newRequestFromOld.getUpdate().getSyncConfig());
assertEquals(newRequest.isDeferValidation(), newRequestFromOld.isDeferValidation());
}

}

0 comments on commit b9fe907

Please sign in to comment.