PakhomovAlexander commented on code in PR #5080: URL: https://github.com/apache/ignite-3/pull/5080#discussion_r1923559326
########## modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/transaction/TransactionApi.java: ########## @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.rest.api.transaction; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; +import static org.apache.ignite.internal.rest.constants.MediaType.APPLICATION_JSON; + +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Delete; +import io.micronaut.http.annotation.Get; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Collection; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.rest.api.Problem; + +/** + * API for managing transaction. + */ +@Controller("/management/v1/transactions/") +@Tag(name = "transactions") +public interface TransactionApi { + /** + * Retrieves all in progress transactions. + * + * + * @return A collection of all in progress transactions. + */ + @Operation(summary = "Retrieve all in progress transactions", description = "Fetches all in progress transactions.") + @ApiResponse( + responseCode = "200", + description = "Successfully retrieved in progress transactions.", + content = @Content(mediaType = APPLICATION_JSON, array = @ArraySchema(schema = @Schema(implementation = Transaction.class))) + ) + @Get + CompletableFuture<Collection<Transaction>> transactions(); + + /** + * Retrieves the state of a specific transaction. Review Comment: It seems the "state" here is not the best word because transaction already has a field "state" but we return the "whole" transation. ########## modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/sql/SqlQueryApi.java: ########## @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.rest.api.sql; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; +import static org.apache.ignite.internal.rest.constants.MediaType.APPLICATION_JSON; + +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Delete; +import io.micronaut.http.annotation.Get; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Collection; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.rest.api.Problem; + +/** + * API for managing queries. + */ +@Controller("/management/v1/sql/") +@Tag(name = "sql") +public interface SqlQueryApi { + + /** + * Retrieves all running sql queries. + * + * + * @return A collection of all running sql queries. + */ + @Operation(summary = "Retrieve all all running sql queries.", description = "Fetches all running sql queries.") Review Comment: ```suggestion @Operation(summary = "Retrieve all running sql queries.", description = "Fetches all running sql queries.") ``` ########## modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/sql/ItSqlQueryControllerTest.java: ########## @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.rest.sql; + +import static io.micronaut.http.HttpRequest.DELETE; +import static io.micronaut.http.HttpStatus.NOT_FOUND; +import static org.apache.ignite.internal.rest.matcher.MicronautHttpResponseMatcher.assertThrowsProblem; +import static org.apache.ignite.internal.rest.matcher.ProblemMatcher.isProblem; +import static org.awaitility.Awaitility.await; +import static org.awaitility.Awaitility.waitAtMost; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.aMapWithSize; +import static org.hamcrest.Matchers.is; + +import io.micronaut.core.type.Argument; +import io.micronaut.http.HttpRequest; +import io.micronaut.http.client.HttpClient; +import io.micronaut.http.client.annotation.Client; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.rest.api.sql.SqlQueryInfo; +import org.junit.jupiter.api.Test; + +/** + * Integration tests for {@link SqlQueryController}. + */ +@MicronautTest +public class ItSqlQueryControllerTest extends ClusterPerClassIntegrationTest { + private static final String SQL_QUERY_URL = "/management/v1/sql/"; + + @Inject + @Client("http://localhost:10300" + SQL_QUERY_URL) + HttpClient client; + + @Test + void shouldReturnAllSqlQueries() { + // Create table + sql("CREATE TABLE large_table (id int primary key, value1 DOUBLE, value2 DOUBLE)"); + + // Run long running query async + String sql = "INSERT INTO large_table (id, value1, value2) SELECT x, RAND() * 100, RAND() * 100 FROM TABLE(SYSTEM_RANGE(1, 100));"; + CompletableFuture.runAsync(() -> + sql(sql) + ); + + // Check count + await().untilAsserted(() -> { + Map<UUID, SqlQueryInfo> queries = getSqlQueries(client); + + assertThat(queries, aMapWithSize(1)); + SqlQueryInfo queryInfo = queries.entrySet().iterator().next().getValue(); + + assertThat(queryInfo.sql(), is(sql)); + assertThat(queryInfo.schema(), is("PUBLIC")); + assertThat(queryInfo.type(), is("DML")); + }); + + sql("DROP TABLE large_table"); Review Comment: looks like this statement is "cleaning up" the test state but it might not execute if the assertion fails. Could you move it to `tearDown` method? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org