nevdmitry commented on code in PR #5080: URL: https://github.com/apache/ignite-3/pull/5080#discussion_r1925359943
########## modules/rest/src/main/java/org/apache/ignite/internal/rest/sql/SqlQueryController.java: ########## @@ -0,0 +1,125 @@ +/* + * 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 java.util.function.Predicate; +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(uuid -> uuid.equals(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)); + } + + private static CompletableFuture<Void> handleOperationResult(UUID queryId, @Nullable Boolean result) { + if (result != null && !result) { + return failedFuture(new SqlQueryNotFoundException(queryId.toString())); + } else { + return nullCompletedFuture(); + } + } + + @Override + public void cleanResources() { + igniteSql = null; + killHandlerRegistry = null; + } + + private List<SqlQueryInfo> sqlQueryInfos() { + return sqlQueryInfos(null); + } + + private List<SqlQueryInfo> sqlQueryInfos(Predicate<UUID> predicate) { Review Comment: nice catch, updated ########## 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. Review Comment: done -- 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