-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(webserver): move taskrun operations to a dedicated endpoint (#1759
- Loading branch information
1 parent
123a977
commit 9fd38a2
Showing
3 changed files
with
128 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
webserver/src/main/java/io/kestra/webserver/controllers/TaskRunController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.kestra.webserver.controllers; | ||
|
||
import io.kestra.core.models.executions.TaskRun; | ||
import io.kestra.core.models.flows.State; | ||
import io.kestra.core.repositories.ExecutionRepositoryInterface; | ||
import io.kestra.webserver.responses.PagedResults; | ||
import io.kestra.webserver.utils.PageableUtils; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.annotation.Nullable; | ||
import io.micronaut.core.convert.format.Format; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Get; | ||
import io.micronaut.http.annotation.QueryValue; | ||
import io.micronaut.scheduling.TaskExecutors; | ||
import io.micronaut.scheduling.annotation.ExecuteOn; | ||
import io.swagger.v3.oas.annotations.Hidden; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import jakarta.inject.Inject; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
|
||
@Controller("/api/v1/taskruns") | ||
@Requires(property = "kestra.repository.type", value = "elasticsearch") | ||
public class TaskRunController { | ||
@Inject | ||
protected ExecutionRepositoryInterface executionRepository; | ||
|
||
@ExecuteOn(TaskExecutors.IO) | ||
@Get(uri = "/search", produces = MediaType.TEXT_JSON) | ||
@Operation(tags = {"Executions"}, summary = "Search for taskruns") | ||
public PagedResults<TaskRun> findTaskRun( | ||
@Parameter(description = "The current page") @QueryValue(defaultValue = "1") int page, | ||
@Parameter(description = "The current page size") @QueryValue(defaultValue = "10") int size, | ||
@Parameter(description = "The sort of current page") @Nullable @QueryValue List<String> sort, | ||
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query, | ||
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace, | ||
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId, | ||
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate, | ||
@Parameter(description = "The end datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime endDate, | ||
@Parameter(description = "A state filter") @Nullable @QueryValue List<State.Type> state | ||
) { | ||
return PagedResults.of(executionRepository.findTaskRun( | ||
PageableUtils.from(page, size, sort, executionRepository.sortMapping()), | ||
query, | ||
namespace, | ||
flowId, | ||
startDate, | ||
endDate, | ||
state | ||
)); | ||
} | ||
|
||
@ExecuteOn(TaskExecutors.IO) | ||
@Get(uri = "/maxTaskRunSetting") | ||
@Hidden | ||
public Integer maxTaskRunSetting() { | ||
return executionRepository.maxTaskRunSetting(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
webserver/src/test/java/io/kestra/webserver/controllers/TaskRunControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.kestra.webserver.controllers; | ||
|
||
import io.kestra.webserver.controllers.h2.JdbcH2ControllerTest; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.http.client.exceptions.HttpClientResponseException; | ||
import io.micronaut.rxjava2.http.client.RxHttpClient; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class TaskRunControllerTest extends JdbcH2ControllerTest { | ||
@Inject | ||
@Client("/") | ||
private RxHttpClient client; | ||
|
||
@Test | ||
void search() { | ||
HttpClientResponseException e = assertThrows( | ||
HttpClientResponseException.class, | ||
() -> client.toBlocking().retrieve(HttpRequest.GET("/api/v1/taskruns/search")) | ||
); | ||
|
||
assertThat(e.getStatus(), is(HttpStatus.NOT_FOUND)); | ||
} | ||
|
||
@Test | ||
void maxTaskRunSetting() { | ||
HttpClientResponseException e = assertThrows( | ||
HttpClientResponseException.class, | ||
() -> client.toBlocking().retrieve(HttpRequest.GET("/api/v1/taskruns/maxTaskRunSetting")) | ||
); | ||
|
||
assertThat(e.getStatus(), is(HttpStatus.NOT_FOUND)); | ||
} | ||
} |