xtern commented on code in PR #5080:
URL: https://github.com/apache/ignite-3/pull/5080#discussion_r1925478878


##########
modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/sql/ItSqlQueryControllerTest.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.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.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
+import org.apache.ignite.internal.rest.api.sql.SqlQueryInfo;
+import org.apache.ignite.sql.IgniteSql;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.SqlRow;
+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() {
+        String sql = "SELECT x FROM TABLE(SYSTEM_RANGE(1, 100));";
+
+        IgniteSql igniteSql = CLUSTER.aliveNode().sql();
+        // run query with results pageSize=1
+        ResultSet<SqlRow> rs = CLUSTER.aliveNode().sql()

Review Comment:
   Up to you, but I suggest to extract these common lines into a separate method
   
   ```
       private static ResultSet<SqlRow> runQuery(String sql) {
           IgniteSql igniteSql = CLUSTER.aliveNode().sql();
           Statement stmt = 
igniteSql.statementBuilder().query(sql).pageSize(1).build();
   
           return CLUSTER.aliveNode().sql().execute(null, stmt);
       }
   ```



##########
modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/transaction/ItTransactionControllerTest.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.transaction;
+
+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.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.aMapWithSize;
+import static org.hamcrest.Matchers.greaterThan;
+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.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
+import org.apache.ignite.internal.rest.api.transaction.TransactionInfo;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.tx.Transaction;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link TransactionController}.
+ */
+@MicronautTest
+public class ItTransactionControllerTest extends 
ClusterPerClassIntegrationTest {
+    private static final String TRANSACTIONURL = "/management/v1/transaction/";
+
+    @Inject
+    @Client("http://localhost:10300"; + TRANSACTIONURL)
+    HttpClient client;
+
+    @Test
+    void shouldReturnAllTransactions() {

Review Comment:
   I suggest to rework this test a bit
   ```
           Transaction roTx = node(0).transactions().begin(new 
TransactionOptions().readOnly(true));
           Transaction rwTx = node(0).transactions().begin(new 
TransactionOptions().readOnly(false));
   
           Map<UUID, TransactionInfo> transactions = getTransactions(client);
   
           {
               TransactionInfo transactionInfo = 
transactions.get(((InternalTransaction) roTx).id());
   
               assertThat(transactionInfo, notNullValue());
               assertThat(transactionInfo.type(), is("READ_ONLY"));
               assertThat(transactionInfo.state(), nullValue());
               assertThat(transactionInfo.priority(), is("NORMAL"));
   
               roTx.rollback();
           }
   
           {
               TransactionInfo transactionInfo = 
transactions.get(((InternalTransaction) rwTx).id());
   
               assertThat(transactionInfo, notNullValue());
               assertThat(transactionInfo.type(), is("READ_WRITE"));
               assertThat(transactionInfo.state(), is("PENDING"));
               assertThat(transactionInfo.priority(), is("NORMAL"));
   
               rwTx.rollback();
           }
   ```



##########
modules/rest/src/main/java/org/apache/ignite/internal/rest/sql/SqlQueryController.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+
+import io.micronaut.http.annotation.Controller;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.rest.ResourceHolder;
+import org.apache.ignite.internal.rest.api.sql.SqlQueryApi;
+import org.apache.ignite.internal.rest.api.sql.SqlQueryInfo;
+import org.apache.ignite.internal.rest.sql.exception.SqlQueryNotFoundException;
+import org.apache.ignite.internal.sql.engine.api.kill.CancellableOperationType;
+import org.apache.ignite.internal.sql.engine.api.kill.KillHandlerRegistry;
+import org.apache.ignite.sql.IgniteSql;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.SqlRow;
+import org.apache.ignite.sql.Statement;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * REST endpoint allows to manage sql queries.
+ */
+@Controller("/management/v1/sql")
+public class SqlQueryController implements SqlQueryApi, ResourceHolder {
+
+    private IgniteSql igniteSql;
+
+    private KillHandlerRegistry killHandlerRegistry;
+
+    public SqlQueryController(IgniteSql igniteSql, KillHandlerRegistry 
killHandlerRegistry) {
+        this.igniteSql = igniteSql;
+        this.killHandlerRegistry = killHandlerRegistry;
+    }
+
+    @Override
+    public CompletableFuture<Collection<SqlQueryInfo>> queries() {
+        return completedFuture(sqlQueryInfos());
+    }
+
+    @Override
+    public CompletableFuture<SqlQueryInfo> query(UUID queryId) {
+        return completedFuture(sqlQueryInfos(queryId)).thenApply(queryInfo -> {
+            if (queryInfo.isEmpty()) {
+                throw new SqlQueryNotFoundException(queryId.toString());
+            } else {
+                return queryInfo.get(0);
+            }
+        });
+    }
+
+    @Override
+    public CompletableFuture<Void> cancelQuery(UUID queryId) {
+        return 
killHandlerRegistry.handler(CancellableOperationType.QUERY).cancelAsync(queryId.toString())
+                .thenCompose(result -> handleOperationResult(queryId, result));

Review Comment:
   why not `thenApply` as in method `query(UUID queryId)`?



##########
modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/transaction/ItTransactionControllerTest.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.transaction;
+
+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.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.aMapWithSize;
+import static org.hamcrest.Matchers.greaterThan;
+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.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
+import org.apache.ignite.internal.rest.api.transaction.TransactionInfo;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.tx.Transaction;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link TransactionController}.
+ */
+@MicronautTest
+public class ItTransactionControllerTest extends 
ClusterPerClassIntegrationTest {
+    private static final String TRANSACTIONURL = "/management/v1/transaction/";
+
+    @Inject
+    @Client("http://localhost:10300"; + TRANSACTIONURL)
+    HttpClient client;
+
+    @Test
+    void shouldReturnAllTransactions() {
+        Transaction tx = node(0).transactions().begin();
+
+        sql(tx, "SELECT 1");
+
+        // Check count of transactions
+        await().untilAsserted(() -> {
+            Map<UUID, TransactionInfo> transactions = getTransactions(client);
+
+            assertThat(transactions, aMapWithSize(greaterThan(1)));
+            TransactionInfo transactionInfo = 
transactions.entrySet().iterator().next().getValue();
+
+            assertThat(transactionInfo.type(), is("READ_WRITE"));
+            assertThat(transactionInfo.state(), is("PENDING"));
+            assertThat(transactionInfo.priority(), is("NORMAL"));
+        });
+    }
+
+    @Test
+    void shouldReturnTransactionById() {
+        Transaction tx = node(0).transactions().begin();
+
+        sql(tx, "SELECT 1");

Review Comment:
   do we really need this? :thinking: 



##########
modules/rest/src/main/java/org/apache/ignite/internal/rest/transaction/TransactionController.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.transaction;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+
+import io.micronaut.http.annotation.Controller;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.rest.ResourceHolder;
+import org.apache.ignite.internal.rest.api.transaction.TransactionApi;
+import org.apache.ignite.internal.rest.api.transaction.TransactionInfo;
+import 
org.apache.ignite.internal.rest.transaction.exception.TransactionNotFoundException;
+import org.apache.ignite.sql.IgniteSql;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.SqlRow;
+import org.apache.ignite.sql.Statement;
+
+/**
+ * REST endpoint allows to manage transactions.
+ */
+@Controller("/management/v1/transaction")
+public class TransactionController implements TransactionApi, ResourceHolder {
+
+    private IgniteSql igniteSql;
+
+    public TransactionController(IgniteSql igniteSql) {
+        this.igniteSql = igniteSql;
+    }
+
+    @Override
+    public CompletableFuture<Collection<TransactionInfo>> transactions() {
+        return completedFuture(transactionInfos());
+    }
+
+    @Override
+    public CompletableFuture<TransactionInfo> transaction(UUID transactionId) {
+        return 
completedFuture(transactionInfos(transactionId)).thenApply(transactionInfos -> {
+            if (transactionInfos.isEmpty()) {
+                throw new 
TransactionNotFoundException(transactionId.toString());
+            } else {
+                return transactionInfos.get(0);
+            }
+        });
+    }
+
+    @Override
+    public CompletableFuture<Void> cancelTransaction(UUID transactionId) {
+        // Waiting https://issues.apache.org/jira/browse/IGNITE-23488

Review Comment:
   Firstly, I think comment should start from "TODO",
   Secondly, I think it's worth creating a separate JIRA issue that will be 
blocked by IGNITE-23488, and the link should be to that issue.



##########
modules/rest/src/main/java/org/apache/ignite/internal/rest/sql/exception/SqlQueryCancelException.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.exception;
+
+import static org.apache.ignite.lang.ErrorGroups.Common.ILLEGAL_ARGUMENT_ERR;
+
+import org.apache.ignite.internal.lang.IgniteInternalException;
+
+/**
+ * Thrown when sql query cancel failed.
+ */
+public class SqlQueryCancelException extends IgniteInternalException {

Review Comment:
   I probably don't understand how this works, but when does this exception 
occur?



##########
modules/sql-engine-api/src/main/java/org/apache/ignite/internal/sql/engine/api/kill/KillHandlerRegistry.java:
##########
@@ -28,4 +28,12 @@ public interface KillHandlerRegistry {
      * @param handler Handler to register.
      */
     void register(OperationKillHandler handler);
+
+    /**
+     * Returns operation kill handler for specified operation type.
+     *
+     * @param type operation type.

Review Comment:
   ```suggestion
        * @param type Operation type.
   ```
   
   Also remove `@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")` class 
annotation



##########
modules/sql-engine-api/src/main/java/org/apache/ignite/internal/sql/engine/api/kill/KillHandlerRegistry.java:
##########
@@ -28,4 +28,12 @@ public interface KillHandlerRegistry {
      * @param handler Handler to register.
      */
     void register(OperationKillHandler handler);
+
+    /**
+     * Returns operation kill handler for specified operation type.
+     *
+     * @param type operation type.
+     * @return operation kill handler for specified operation type.

Review Comment:
   ```suggestion
        * @return Operation kill handler for specified operation type.
   ```



-- 
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

Reply via email to