ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [2/8] ambari git commit: AMBARI-14707. Hive view should return 400 (instead of 500) when the hive query cannot be compiled. (Gaurav Nagar via yusaku)
Date Wed, 20 Jan 2016 17:04:00 GMT
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/d32f36eb
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d32f36eb
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d32f36eb

Branch: refs/heads/branch-dev-patch-upgrade
Commit: d32f36eb60180d5de97568487eadfd86d90822b1
Parents: 822be76
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Tue Jan 19 14:20:23 2016 -0800
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Tue Jan 19 14:20:23 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      | 43 ++++++++++++++++++++
 4 files changed, 85 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d32f36eb/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/d32f36eb/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 5b42b1f..c29400d 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
@@ -32,10 +32,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/d32f36eb/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/d32f36eb/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
index de66bef..0dafcb1 100644
--- 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
@@ -17,12 +17,22 @@
  */
 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 testRemoveEmptyStrings() throws Exception {
     String[] arrayWithSomeEmptyStrings = new String[] { "", null, "string1", null, "", "string2",
"" };
@@ -32,4 +42,37 @@ public class UtilsTest {
     assertEquals("string1", expectedStrings[0]);
     assertEquals("string2", expectedStrings[1]);
   }
+
+  @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


Mime
View raw message