AMBARI-20207. Proper error is not thrown on hive view authorization page. 
(dipayanb)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0712ef69
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0712ef69
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0712ef69

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 0712ef69fd81611e80273259660ef23d49187334
Parents: 561f65d
Author: Dipayan Bhowmick <dipayan.bhowm...@gmail.com>
Authored: Wed Mar 1 12:05:03 2017 +0530
Committer: Dipayan Bhowmick <dipayan.bhowm...@gmail.com>
Committed: Wed Mar 1 12:05:37 2017 +0530

----------------------------------------------------------------------
 .../view/hive20/resources/system/ranger/RangerService.java  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0712ef69/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/system/ranger/RangerService.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/system/ranger/RangerService.java
 
b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/system/ranger/RangerService.java
index d300d9a..816d0e0 100644
--- 
a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/system/ranger/RangerService.java
+++ 
b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/resources/system/ranger/RangerService.java
@@ -115,7 +115,13 @@ public class RangerService {
   }
 
   private List<Policy> parseResponse(String rangerResponse) {
-    JSONArray jsonArray = (JSONArray) JSONValue.parse(rangerResponse);
+    Object parsedResult = JSONValue.parse(rangerResponse);
+    if (parsedResult instanceof JSONObject) {
+      JSONObject obj = (JSONObject) parsedResult;
+      LOG.error("Bad response from Ranger: {}", rangerResponse);
+      throw new RangerException((String)obj.get("msgDesc"), "RANGER_ERROR", 
((Long)obj.get("statusCode")).intValue());
+    }
+    JSONArray jsonArray = (JSONArray) parsedResult;
     if (jsonArray.size() == 0) {
       return new ArrayList<>();
     }
@@ -184,6 +190,7 @@ public class RangerService {
         LOG.error("Ranger returned an empty stream.");
         throw new RangerException("Ranger returned an empty stream.", 
"RANGER_ERROR", 500);
       }
+
       return IOUtils.toString(stream);
     } catch (IOException e) {
       LOG.error("Bad response from Ranger. Exception: {}", e);

Reply via email to