Search in sources :

Example 11 with Template

use of io.kestra.core.models.templates.Template in project kestra by kestra-io.

the class ElasticSearchTemplateRepository method findById.

@Override
public Optional<Template> findById(String namespace, String id) {
    BoolQueryBuilder bool = this.defaultFilter().must(QueryBuilders.termQuery("namespace", namespace)).must(QueryBuilders.termQuery("id", id));
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(bool).size(1);
    List<Template> query = this.query(INDEX_NAME, sourceBuilder);
    return query.size() > 0 ? Optional.of(query.get(0)) : Optional.empty();
}
Also used : BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) Template(io.kestra.core.models.templates.Template)

Example 12 with Template

use of io.kestra.core.models.templates.Template in project kestra by kestra-io.

the class TemplateControllerTest method listDistinctNamespace.

@Test
void listDistinctNamespace() {
    List<String> namespaces = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/distinct-namespaces"), Argument.listOf(String.class));
    assertThat(namespaces.size(), is(0));
    Template t1 = Template.builder().id(IdUtils.create()).namespace("kestra.template.custom").tasks(Arrays.asList(Return.builder().id("task").type(Return.class.getName()).format("test").build())).build();
    client.toBlocking().retrieve(POST("/api/v1/templates", t1), Template.class);
    client.toBlocking().retrieve(POST("/api/v1/templates", createTemplate()), Template.class);
    client.toBlocking().retrieve(POST("/api/v1/templates", createTemplate()), Template.class);
    namespaces = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/distinct-namespaces"), Argument.listOf(String.class));
    assertThat(namespaces.size(), is(2));
}
Also used : Template(io.kestra.core.models.templates.Template) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Aggregations

Template (io.kestra.core.models.templates.Template)12 Test (org.junit.jupiter.api.Test)9 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)5 AbstractMemoryRunnerTest (io.kestra.core.runners.AbstractMemoryRunnerTest)4 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)2 Task (io.kestra.core.models.tasks.Task)1 TemplateRepositoryInterface (io.kestra.core.repositories.TemplateRepositoryInterface)1 Return (io.kestra.core.tasks.debugs.Return)1 ArrayList (java.util.ArrayList)1 BoolQueryBuilder (org.opensearch.index.query.BoolQueryBuilder)1 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)1