Search in sources :

Example 6 with Ack

use of org.apache.drill.exec.proto.GeneralRPCProtos.Ack in project drill by apache.

the class ProfileResources method cancelQuery.

@GET
@Path("/profiles/cancel/{queryid}")
@Produces(MediaType.TEXT_PLAIN)
public String cancelQuery(@PathParam("queryid") String queryId) {
    QueryId id = QueryIdHelper.getQueryIdFromString(queryId);
    // Prevent XSS
    String encodedQueryID = forHtml(queryId);
    // first check local running
    if (work.getBee().cancelForeman(id, principal)) {
        return String.format("Cancelled query %s on locally running node.", encodedQueryID);
    }
    // then check remote running
    try {
        final TransientStore<QueryInfo> running = work.getContext().getProfileStoreContext().getRunningProfileStore();
        final QueryInfo info = running.get(queryId);
        checkOrThrowQueryCancelAuthorization(info.getUser(), queryId);
        Ack a = work.getContext().getController().getTunnel(info.getForeman()).requestCancelQuery(id).checkedGet(2, TimeUnit.SECONDS);
        if (a.getOk()) {
            return String.format("Query %s canceled on node %s.", encodedQueryID, info.getForeman().getAddress());
        } else {
            return String.format("Attempted to cancel query %s on %s but the query is no longer active on that node.", encodedQueryID, info.getForeman().getAddress());
        }
    } catch (Exception e) {
        logger.debug("Failure to find query as running profile.", e);
        return String.format("Failure attempting to cancel query %s.  Unable to find information about where query is actively running.", encodedQueryID);
    }
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Ack(org.apache.drill.exec.proto.GeneralRPCProtos.Ack) QueryInfo(org.apache.drill.exec.proto.UserBitShared.QueryInfo) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Ack (org.apache.drill.exec.proto.GeneralRPCProtos.Ack)6 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)5 Response (org.apache.drill.exec.rpc.Response)4 RpcException (org.apache.drill.exec.rpc.RpcException)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 UserException (org.apache.drill.common.exceptions.UserException)2 QueryInfo (org.apache.drill.exec.proto.UserBitShared.QueryInfo)2 CreatePreparedStatementReq (org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq)2 GetCatalogsReq (org.apache.drill.exec.proto.UserProtos.GetCatalogsReq)2 GetColumnsReq (org.apache.drill.exec.proto.UserProtos.GetColumnsReq)2 GetQueryPlanFragments (org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments)2 GetSchemasReq (org.apache.drill.exec.proto.UserProtos.GetSchemasReq)2 GetServerMetaReq (org.apache.drill.exec.proto.UserProtos.GetServerMetaReq)2 GetTablesReq (org.apache.drill.exec.proto.UserProtos.GetTablesReq)2 RunQuery (org.apache.drill.exec.proto.UserProtos.RunQuery)2