Michael Blow has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/2524
Change subject: [NO ISSUE] Cleanup query service exception handling
......................................................................
[NO ISSUE] Cleanup query service exception handling
Change-Id: I1f2828481df055d6c96f1ae1869ef37a065bf576
---
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/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
M
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
M asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
M
hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
6 files changed, 39 insertions(+), 16 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/24/2524/1
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 3564736..d089a49 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
@@ -34,9 +34,9 @@
import org.apache.asterix.common.api.Duration;
import org.apache.asterix.common.api.IApplicationContext;
import org.apache.asterix.common.config.GlobalConfig;
+import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.common.exceptions.ExceptionUtils;
-import org.apache.asterix.common.exceptions.RuntimeDataException;
import org.apache.asterix.common.messaging.api.INCMessageBroker;
import org.apache.asterix.common.messaging.api.MessageFuture;
import org.apache.asterix.om.types.ARecordType;
@@ -98,7 +98,7 @@
cancelQuery(ncMb, ncCtx.getNodeId(), param.clientContextID, e,
false);
throw e;
} catch (TimeoutException exception) {
- RuntimeDataException hde = new
RuntimeDataException(ErrorCode.QUERY_TIMEOUT);
+ AsterixException hde = new
AsterixException(ErrorCode.QUERY_TIMEOUT);
hde.addSuppressed(exception);
// cancel query
cancelQuery(ncMb, ncCtx.getNodeId(), param.clientContextID,
hde, true);
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 1057a73..7061601 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
@@ -18,6 +18,10 @@
*/
package org.apache.asterix.api.http.server;
+import static org.apache.asterix.common.exceptions.ErrorCode.QUERY_TIMEOUT;
+import static
org.apache.asterix.common.exceptions.ErrorCode.REJECT_BAD_CLUSTER_STATE;
+import static
org.apache.asterix.common.exceptions.ErrorCode.REJECT_NODE_UNREGISTERED;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
@@ -35,7 +39,6 @@
import org.apache.asterix.common.context.IStorageComponentProvider;
import org.apache.asterix.common.dataflow.ICcApplicationContext;
import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.compiler.provider.ILangCompilationProvider;
import org.apache.asterix.lang.aql.parser.TokenMgrError;
import org.apache.asterix.lang.common.base.IParser;
@@ -69,7 +72,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
-
import io.netty.handler.codec.http.HttpResponseStatus;
public class QueryServiceServlet extends AbstractQueryApiServlet {
@@ -532,17 +534,28 @@
}
protected void handleExecuteStatementException(Throwable t,
RequestExecutionState execution) {
- if (t instanceof org.apache.asterix.aqlplus.parser.TokenMgrError || t
instanceof TokenMgrError
+ if (t instanceof AsterixException) {
+ int errorCode = ((AsterixException) t).getErrorCode();
+ switch (errorCode) {
+ case QUERY_TIMEOUT:
+ execution.setStatus(ResultStatus.TIMEOUT,
HttpResponseStatus.OK);
+ break;
+ case REJECT_BAD_CLUSTER_STATE:
+ case REJECT_NODE_UNREGISTERED:
+ execution.setStatus(ResultStatus.FATAL,
HttpResponseStatus.SERVICE_UNAVAILABLE);
+ break;
+ default:
+ GlobalConfig.ASTERIX_LOGGER.log(Level.INFO,
t.getMessage(), t);
+ execution.setStatus(ResultStatus.FATAL,
HttpResponseStatus.BAD_REQUEST);
+ break;
+ }
+ } else if (t instanceof
org.apache.asterix.aqlplus.parser.TokenMgrError || t instanceof TokenMgrError
|| t instanceof AlgebricksException) {
GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, t.getMessage(), t);
execution.setStatus(ResultStatus.FATAL,
HttpResponseStatus.BAD_REQUEST);
} else if (t instanceof HyracksException) {
GlobalConfig.ASTERIX_LOGGER.log(Level.WARN, t.getMessage(), t);
- if (((HyracksException) t).getErrorCode() ==
ErrorCode.QUERY_TIMEOUT) {
- execution.setStatus(ResultStatus.TIMEOUT,
HttpResponseStatus.OK);
- } else {
- execution.setStatus(ResultStatus.FATAL,
HttpResponseStatus.INTERNAL_SERVER_ERROR);
- }
+ execution.setStatus(ResultStatus.FATAL,
HttpResponseStatus.INTERNAL_SERVER_ERROR);
} else {
GlobalConfig.ASTERIX_LOGGER.log(Level.WARN, "Unexpected
exception", t);
execution.setStatus(ResultStatus.FATAL,
HttpResponseStatus.INTERNAL_SERVER_ERROR);
diff --git
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
index 31b213e..dcf4eee 100644
---
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
+++
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
@@ -34,6 +34,8 @@
import org.apache.asterix.common.config.GlobalConfig;
import org.apache.asterix.common.context.IStorageComponentProvider;
import org.apache.asterix.common.dataflow.ICcApplicationContext;
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.common.messaging.api.ICcAddressedMessage;
import org.apache.asterix.compiler.provider.ILangCompilationProvider;
import org.apache.asterix.hyracks.bootstrap.CCApplication;
@@ -95,7 +97,7 @@
ClusterControllerService ccSrv = (ClusterControllerService)
ccSrvContext.getControllerService();
CCApplication ccApp = (CCApplication) ccSrv.getApplication();
CCMessageBroker messageBroker = (CCMessageBroker)
ccSrvContext.getMessageBroker();
- final String rejectionReason = getRejectionReason(ccSrv);
+ final AsterixException rejectionReason = getRejectionReason(ccSrv);
if (rejectionReason != null) {
sendRejection(rejectionReason, messageBroker);
return;
@@ -145,22 +147,22 @@
}
}
- private String getRejectionReason(ClusterControllerService ccSrv) {
+ private AsterixException getRejectionReason(ClusterControllerService
ccSrv) {
if (ccSrv.getNodeManager().getNodeControllerState(requestNodeId) ==
null) {
- return "Node is not registerted with the CC";
+ return AsterixException.create(ErrorCode.REJECT_NODE_UNREGISTERED);
}
ICcApplicationContext appCtx = (ICcApplicationContext)
ccSrv.getApplicationContext();
IClusterStateManager csm = appCtx.getClusterStateManager();
final IClusterManagementWork.ClusterState clusterState =
csm.getState();
if (clusterState != IClusterManagementWork.ClusterState.ACTIVE) {
- return "Cannot execute request, cluster is " + clusterState;
+ return AsterixException.create(ErrorCode.REJECT_BAD_CLUSTER_STATE,
clusterState);
}
return null;
}
- private void sendRejection(String reason, CCMessageBroker messageBroker) {
+ private void sendRejection(AsterixException reason, CCMessageBroker
messageBroker) {
ExecuteStatementResponseMessage responseMsg = new
ExecuteStatementResponseMessage(requestMessageId);
- responseMsg.setError(new Exception(reason));
+ responseMsg.setError(reason);
try {
messageBroker.sendApplicationMessageToNC(responseMsg,
requestNodeId);
} catch (Exception e) {
diff --git
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 04054f1..8146797 100644
---
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -72,6 +72,8 @@
public static final int UNKNOWN_DURATION_UNIT = 29;
public static final int QUERY_TIMEOUT = 30;
public static final int INVALID_TYPE_CASTING_MATH_FUNCTION = 31;
+ public static final int REJECT_BAD_CLUSTER_STATE = 32;
+ public static final int REJECT_NODE_UNREGISTERED = 33;
public static final int INSTANTIATION_ERROR = 100;
diff --git
a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index 1fb8480..f9188b8 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -65,6 +65,8 @@
29 = Unknown duration unit %1$s
30 = Query timed out and will be cancelled
31 = Invalid type-casting math function: %1$s for converting %2$s to %3$s
+32 = Cannot execute request, cluster is %1$s
+33 = Node is not registered with the CC
100 = Unable to instantiate class %1$s
diff --git
a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
index d1feb08..adb6c79 100644
---
a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
+++
b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
@@ -97,6 +97,10 @@
return component;
}
+ public int getErrorCode() {
+ return errorCode;
+ }
+
public Object[] getParams() {
return params;
}
--
To view, visit https://asterix-gerrit.ics.uci.edu/2524
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f2828481df055d6c96f1ae1869ef37a065bf576
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: release-0.9.4-pre-rc
Gerrit-Owner: Michael Blow <[email protected]>