You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2016/01/20 07:45:45 UTC
ambari git commit: AMBARI-14707. Hive view should return 400 (instead
of 500) when the hive query cannot be compiled . (Gaurav Nagar via yusaku)
Repository: ambari
Updated Branches:
refs/heads/branch-2.1.2 f55b6c267 -> 0e8cc3f8d
AMBARI-14707. Hive view should return 400 (instead of 500) when the hive query cannot be compiled
. (Gaurav Nagar via yusaku)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0e8cc3f8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0e8cc3f8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0e8cc3f8
Branch: refs/heads/branch-2.1.2
Commit: 0e8cc3f8d6c7e982f9eb7742d778fe0c3efc277c
Parents: f55b6c2
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Tue Jan 19 22:45:19 2016 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Tue Jan 19 22:45:19 2016 -0800
----------------------------------------------------------------------
.../hive/client/HiveInvalidQueryException.java | 27 ++++++++
.../apache/ambari/view/hive/client/Utils.java | 9 +++
.../hive/utils/ServiceFormattedException.java | 8 ++-
.../ambari/view/hive/client/UtilsTest.java | 68 ++++++++++++++++++++
4 files changed, 110 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e8cc3f8/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveInvalidQueryException.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveInvalidQueryException.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveInvalidQueryException.java
new file mode 100644
index 0000000..473ab65
--- /dev/null
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveInvalidQueryException.java
@@ -0,0 +1,27 @@
+/**
+ * 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.ambari.view.hive.client;
+
+import org.apache.hive.service.cli.thrift.TStatusCode;
+
+public class HiveInvalidQueryException extends HiveClientException {
+ public HiveInvalidQueryException(TStatusCode statusCode, String comment) {
+ super(String.format("%s [%s]", comment, statusCode), null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e8cc3f8/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
index f9efc1c..63a63da 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
@@ -31,10 +31,19 @@ public class Utils {
static final String HIVE_SERVER2_RETRY_TRUE = "true";
static final String HIVE_SERVER2_RETRY_FALSE = "false";
+ static final String HIVE_COMPILE_ERROR_MSG = "Error while compiling statement:";
+
static void verifySuccess(TStatus status, String comment) throws HiveClientException {
if (status.getStatusCode() != TStatusCode.SUCCESS_STATUS &&
status.getStatusCode() != TStatusCode.SUCCESS_WITH_INFO_STATUS) {
String message = (status.getErrorMessage() != null) ? status.getErrorMessage() : "";
+
+ // For schemantic exception Error code is between 10000-19999
+ // https://issues.apache.org/jira/browse/HIVE-3001
+ // https://issues.apache.org/jira/browse/HIVE-12867
+ if((status.getErrorCode() >= 10000 && status.getErrorCode() <= 19999)|| message.contains(HIVE_COMPILE_ERROR_MSG)){
+ throw new HiveInvalidQueryException(status.getStatusCode(),message);
+ }
throw new HiveErrorStatusException(status.getStatusCode(), comment + ". " + message);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e8cc3f8/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java
index eaea2ff..d057cdb 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java
@@ -18,6 +18,7 @@
package org.apache.ambari.view.hive.utils;
+import org.apache.ambari.view.hive.client.HiveInvalidQueryException;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
@@ -63,6 +64,9 @@ public class ServiceFormattedException extends WebApplicationException {
if (exception instanceof AccessControlException) {
status = 403;
}
+ if (exception instanceof HiveInvalidQueryException) {
+ status = 400;
+ }
return status;
}
@@ -92,8 +96,8 @@ public class ServiceFormattedException extends WebApplicationException {
response.put("trace", trace);
response.put("status", status);
- if(message != null) LOG.error(message);
- if(trace != null) LOG.error(trace);
+ if(message != null && status != 400) LOG.error(message);
+ if(trace != null && status != 400) LOG.error(trace);
Response.ResponseBuilder responseBuilder = Response.status(status).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON);
if (header != null)
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e8cc3f8/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java
new file mode 100644
index 0000000..998e659
--- /dev/null
+++ b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.ambari.view.hive.client;
+
+import org.apache.hive.service.cli.thrift.TStatus;
+import org.apache.hive.service.cli.thrift.TStatusCode;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.*;
+
+public class UtilsTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testVerifySuccessWithHiveInvalidQueryException() throws Exception{
+ String msg = "Error in compiling";
+ String comment = "H110 Unable to submit statement";
+
+ TStatus status = createMockTStatus(10000,msg, TStatusCode.ERROR_STATUS);
+ thrown.expect(HiveInvalidQueryException.class);
+ thrown.expectMessage(msg);
+
+ Utils.verifySuccess(status,comment);
+ }
+
+ @Test
+ public void testVerifySuccessWithHiveErrorStatusException() throws Exception{
+ String msg = "Error in compiling";
+ String comment = "H110 Unable to submit statement";
+
+ TStatus status = createMockTStatus(40000,msg,TStatusCode.ERROR_STATUS);
+ thrown.expect(HiveErrorStatusException.class);
+ thrown.expectMessage(String.format("%s. %s",comment,msg));
+
+ Utils.verifySuccess(status,comment);
+ }
+
+ private TStatus createMockTStatus(int errorCode,String msg,TStatusCode tStatusCode){
+ TStatus status = createNiceMock(TStatus.class);
+ expect(status.getErrorCode()).andReturn(errorCode).anyTimes();
+ expect(status.getStatusCode()).andReturn(tStatusCode).anyTimes();
+ expect(status.getErrorMessage()).andReturn(msg).anyTimes();
+ replay(status);
+ return status;
+ }
+}
\ No newline at end of file