asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Murtadha Hubail (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: [NO ISSUE][API] Add NC Query Cancellation API
Date Wed, 25 Oct 2017 12:07:45 GMT
Murtadha Hubail has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2103

Change subject: [NO ISSUE][API] Add NC Query Cancellation API
......................................................................

[NO ISSUE][API] Add NC Query Cancellation API

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Introduce NCQueryCancellationServlet that uses NC<->CC
  messaging to cancel queries.

Change-Id: I75d326b6987ed87ccc4b58c171bd45cab33a4009
---
A asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryCancellationServlet.java
M asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryCancellationServlet.java
2 files changed, 73 insertions(+), 1 deletion(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/03/2103/1

diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryCancellationServlet.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryCancellationServlet.java
new file mode 100644
index 0000000..191ef22
--- /dev/null
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryCancellationServlet.java
@@ -0,0 +1,72 @@
+/*
+ * 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.asterix.api.http.server;
+
+import java.io.IOException;
+import java.util.concurrent.ConcurrentMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.asterix.app.message.CancelQueryRequest;
+import org.apache.asterix.common.messaging.api.INCMessageBroker;
+import org.apache.asterix.common.messaging.api.MessageFuture;
+import org.apache.hyracks.api.application.INCServiceContext;
+import org.apache.hyracks.http.api.IServletRequest;
+import org.apache.hyracks.http.api.IServletResponse;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+
+/**
+ * The servlet provides a REST API on an NC for cancelling an on-going query.
+ */
+public class NCQueryCancellationServlet extends QueryCancellationServlet {
+    private static final Logger LOGGER = Logger.getLogger(NCQueryCancellationServlet.class.getName());
+    private final INCServiceContext serviceCtx;
+    private final INCMessageBroker messageBroker;
+
+    public NCQueryCancellationServlet(ConcurrentMap<String, Object> ctx, String...
paths) {
+        super(ctx, paths);
+        this.serviceCtx = (INCServiceContext) ctx.get(ServletConstants.SERVICE_CONTEXT_ATTR);
+        messageBroker = (INCMessageBroker) serviceCtx.getMessageBroker();
+    }
+
+    @Override
+    protected void delete(IServletRequest request, IServletResponse response) throws IOException
{
+        // gets the parameter client_context_id from the request.
+        String clientContextId = request.getParameter(CLIENT_CONTEXT_ID);
+        if (clientContextId == null) {
+            response.setStatus(HttpResponseStatus.BAD_REQUEST);
+            return;
+        }
+        final MessageFuture cancelQueryFuture = messageBroker.registerMessageFuture();
+        try {
+            CancelQueryRequest cancelQueryMessage =
+                    new CancelQueryRequest(serviceCtx.getNodeId(), cancelQueryFuture.getFutureId(),
clientContextId);
+            messageBroker.sendMessageToCC(cancelQueryMessage);
+            response.setStatus(HttpResponseStatus.OK);
+        } catch (Exception e) {
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.log(Level.SEVERE, "Unexpected exception while canceling query", e);
+            }
+            response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
+        } finally {
+            messageBroker.deregisterMessageFuture(cancelQueryFuture.getFutureId());
+        }
+    }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryCancellationServlet.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryCancellationServlet.java
index 3f07151..96ff71c 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryCancellationServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryCancellationServlet.java
@@ -37,7 +37,7 @@
  */
 public class QueryCancellationServlet extends AbstractServlet {
     private static final Logger LOGGER = Logger.getLogger(QueryCancellationServlet.class.getName());
-    private static final String CLIENT_CONTEXT_ID = "client_context_id";
+    protected static final String CLIENT_CONTEXT_ID = "client_context_id";
 
     public QueryCancellationServlet(ConcurrentMap<String, Object> ctx, String... paths)
{
         super(ctx, paths);

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2103
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I75d326b6987ed87ccc4b58c171bd45cab33a4009
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Murtadha Hubail <mhubail@apache.org>

Mime
View raw message