Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Transform] Ensure transform _schedule_now API only triggers the expected transform task #102958

Merged
merged 2 commits into from Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/changelog/102958.yaml
@@ -0,0 +1,7 @@
pr: 102958
summary: Ensure transform `_schedule_now` API only triggers the expected transform
task
area: Transform
type: bug
issues:
- 102956
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.transform.TransformField;
Expand Down Expand Up @@ -94,6 +95,15 @@ public boolean equals(Object obj) {
// the base class does not implement equals, therefore we need to check timeout ourselves
return this.id.equals(other.id) && 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 Writeable, ToXContentObject {
Expand Down
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.persistent.AllocatedPersistentTask;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.transform.action.ScheduleNowTransformAction.Request;

Expand Down Expand Up @@ -55,4 +56,12 @@ public void testValidationFailure() {
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), contains("_schedule_now API does not support _all wildcard"));
}

public void testMatch() {
Request request = new Request("my-transform-7", TimeValue.timeValueSeconds(5));
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)));
}
}