Dmitry Lychagin has uploaded a new change for review.

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

Change subject: Extensible exception handling in QueryServiceServlet
......................................................................

Extensible exception handling in QueryServiceServlet

Change-Id: If8037a97f3d0b0febb8caf68e099f1fd24e0ac49
---
M asterixdb/asterix-app/pom.xml
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
M asterixdb/pom.xml
4 files changed, 40 insertions(+), 13 deletions(-)


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

diff --git a/asterixdb/asterix-app/pom.xml b/asterixdb/asterix-app/pom.xml
index 01afdcf..beac085 100644
--- a/asterixdb/asterix-app/pom.xml
+++ b/asterixdb/asterix-app/pom.xml
@@ -433,6 +433,10 @@
       <artifactId>hyracks-net</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.hyracks</groupId>
+      <artifactId>hyracks-ipc</artifactId>
+    </dependency>
+    <dependency>
       <groupId>javax.xml.bind</groupId>
       <artifactId>jaxb-api</artifactId>
       <scope>test</scope>
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
index 2b70685..9547514 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
@@ -20,12 +20,16 @@
 package org.apache.asterix.api.http.server;
 
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.TimeoutException;
+import java.util.logging.Level;
 
+import io.netty.handler.codec.http.HttpResponseStatus;
 import org.apache.asterix.algebra.base.ILangExtension;
 import org.apache.asterix.app.message.ExecuteStatementRequestMessage;
 import org.apache.asterix.app.message.ExecuteStatementResponseMessage;
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.common.api.IApplicationContext;
+import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.messaging.api.INCMessageBroker;
 import org.apache.asterix.common.messaging.api.MessageFuture;
 import org.apache.asterix.om.types.ARecordType;
@@ -35,6 +39,7 @@
 import org.apache.hyracks.api.application.INCServiceContext;
 import org.apache.hyracks.api.dataset.ResultSetId;
 import org.apache.hyracks.api.job.JobId;
+import org.apache.hyracks.ipc.exceptions.IPCException;
 
 /**
  * Query service servlet that can run on NC nodes.
@@ -91,4 +96,14 @@
             sessionOutput.out().append(responseMsg.getResult());
         }
     }
+
+    @Override
+    protected HttpResponseStatus handleExecuteStatementException(Throwable t) {
+        if (t instanceof IPCException || t instanceof TimeoutException) {
+            GlobalConfig.ASTERIX_LOGGER.log(Level.WARNING, t.toString(), t);
+            return HttpResponseStatus.SERVICE_UNAVAILABLE;
+        } else {
+            return super.handleExecuteStatementException(t);
+        }
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index ec90ae9..fcacfd9 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -420,21 +420,10 @@
                 ResultUtil.printStatus(sessionOutput, ResultStatus.SUCCESS);
             }
             errorCount = 0;
-        } catch (AlgebricksException | TokenMgrError | 
org.apache.asterix.aqlplus.parser.TokenMgrError pe) {
-            GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, pe.getMessage(), pe);
-            ResultUtil.printError(resultWriter, pe);
-            ResultUtil.printStatus(sessionOutput, ResultStatus.FATAL);
-            status = HttpResponseStatus.BAD_REQUEST;
-        } catch (HyracksException pe) {
-            GlobalConfig.ASTERIX_LOGGER.log(Level.WARNING, pe.getMessage(), 
pe);
-            ResultUtil.printError(resultWriter, pe);
-            ResultUtil.printStatus(sessionOutput, ResultStatus.FATAL);
-            status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
-        } catch (Exception e) {
-            GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, "Unexpected 
exception", e);
+        } catch (Exception | TokenMgrError | 
org.apache.asterix.aqlplus.parser.TokenMgrError e) {
+            status = handleExecuteStatementException(e);
             ResultUtil.printError(resultWriter, e);
             ResultUtil.printStatus(sessionOutput, ResultStatus.FATAL);
-            status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
         } finally {
             if (execStartEnd[0] == -1) {
                 execStartEnd[1] = -1;
@@ -475,4 +464,18 @@
                 param.clientContextID, queryCtx);
         outExecStartEnd[1] = System.nanoTime();
     }
+
+    protected HttpResponseStatus handleExecuteStatementException(Throwable t) {
+        if (t instanceof org.apache.asterix.aqlplus.parser.TokenMgrError | t 
instanceof TokenMgrError
+                | t instanceof AlgebricksException) {
+            GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, t.getMessage(), t);
+            return HttpResponseStatus.BAD_REQUEST;
+        } else if (t instanceof HyracksException) {
+            GlobalConfig.ASTERIX_LOGGER.log(Level.WARNING, t.getMessage(), t);
+            return HttpResponseStatus.INTERNAL_SERVER_ERROR;
+        } else {
+            GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, "Unexpected 
exception", t);
+            return HttpResponseStatus.INTERNAL_SERVER_ERROR;
+        }
+    }
 }
\ No newline at end of file
diff --git a/asterixdb/pom.xml b/asterixdb/pom.xml
index b708187..726eae5 100644
--- a/asterixdb/pom.xml
+++ b/asterixdb/pom.xml
@@ -835,6 +835,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.hyracks</groupId>
+        <artifactId>hyracks-ipc</artifactId>
+        <version>${hyracks.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.hyracks</groupId>
         <artifactId>algebricks-compiler</artifactId>
         <version>${algebricks.version}</version>
       </dependency>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If8037a97f3d0b0febb8caf68e099f1fd24e0ac49
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Dmitry Lychagin <[email protected]>

Reply via email to