ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [1/3] git commit: ARGUS-17: updated retrieval of error message from REST response
Date Wed, 27 Aug 2014 03:39:38 GMT
Repository: incubator-argus
Updated Branches:
  refs/heads/master 3aaaf186e -> 90f8628a9


ARGUS-17: updated retrieval of error message from REST response

Project: http://git-wip-us.apache.org/repos/asf/incubator-argus/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-argus/commit/5f3c1d58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-argus/tree/5f3c1d58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-argus/diff/5f3c1d58

Branch: refs/heads/master
Commit: 5f3c1d58ead703c731d4ba75712eeceba15fd0bd
Parents: 4274838
Author: mneethiraj <mneethiraj@hortonworks.com>
Authored: Tue Aug 26 17:32:14 2014 -0700
Committer: mneethiraj <mneethiraj@hortonworks.com>
Committed: Tue Aug 26 17:32:14 2014 -0700

----------------------------------------------------------------------
 .../admin/client/XaAdminRESTClient.java         |  18 +-
 .../admin/client/datatype/RESTResponse.java     | 191 +++++++++++++++++++
 .../hive/authorizer/XaSecureHiveAuthorizer.java |  15 +-
 3 files changed, 205 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/5f3c1d58/agents-common/src/main/java/com/xasecure/admin/client/XaAdminRESTClient.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/com/xasecure/admin/client/XaAdminRESTClient.java
b/agents-common/src/main/java/com/xasecure/admin/client/XaAdminRESTClient.java
index 7e1c9aa..9d92592 100644
--- a/agents-common/src/main/java/com/xasecure/admin/client/XaAdminRESTClient.java
+++ b/agents-common/src/main/java/com/xasecure/admin/client/XaAdminRESTClient.java
@@ -34,6 +34,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 
 import com.xasecure.admin.client.datatype.GrantRevokeData;
+import com.xasecure.admin.client.datatype.RESTResponse;
 import com.xasecure.authorization.utils.StringUtil;
 import com.xasecure.authorization.hadoop.config.XaSecureConfiguration;
 import com.xasecure.authorization.hadoop.utils.XaSecureCredentialProvider;
@@ -136,12 +137,10 @@ public class XaAdminRESTClient implements XaAdminClient {
 
 			ClientResponse response = webResource.accept(REST_EXPECTED_MIME_TYPE).type(REST_EXPECTED_MIME_TYPE).post(ClientResponse.class,
grData.toJson());
 
-			if(response == null) {
-				throw new Exception("grantPrivilege(): unknown failure");
-			} else if(response.getStatus() != 200) {
-				String ret = response.getEntity(String.class);
+			if(response == null || response.getStatus() != 200) {
+				RESTResponse resp = RESTResponse.fromClientResponse(response);
 
-				throw new Exception("grantPrivilege(): HTTPResponse status=" + response.getStatus() +
"; HTTPResponse text=" + ret);
+				throw new Exception(resp.getMessage());
 			}
 		} finally {
 			destroy(client);
@@ -159,18 +158,15 @@ public class XaAdminRESTClient implements XaAdminClient {
 
 			ClientResponse response = webResource.accept(REST_EXPECTED_MIME_TYPE).type(REST_EXPECTED_MIME_TYPE).post(ClientResponse.class,
grData.toJson());
 
-			if(response == null) {
-				throw new Exception("revokePrivilege(): unknown failure");
-			} else if(response.getStatus() != 200) {
-				String ret = response.getEntity(String.class);
+			if(response == null || response.getStatus() != 200) {
+				RESTResponse resp = RESTResponse.fromClientResponse(response);
 
-				throw new Exception("revokePrivilege(): HTTPResponse status=" + response.getStatus()
+ "; HTTPResponse text=" + ret);
+				throw new Exception(resp.getMessage());
 			}
 		} finally {
 			destroy(client);
 		}
 	}
-
 	private void init() {
 		mIsSSL = StringUtil.containsIgnoreCase(mUrl, "https");
 

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/5f3c1d58/agents-common/src/main/java/com/xasecure/admin/client/datatype/RESTResponse.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/com/xasecure/admin/client/datatype/RESTResponse.java
b/agents-common/src/main/java/com/xasecure/admin/client/datatype/RESTResponse.java
new file mode 100644
index 0000000..6c8dc8f
--- /dev/null
+++ b/agents-common/src/main/java/com/xasecure/admin/client/datatype/RESTResponse.java
@@ -0,0 +1,191 @@
+package com.xasecure.admin.client.datatype;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.mortbay.log.Log;
+
+import com.sun.jersey.api.client.ClientResponse;
+import com.xasecure.authorization.utils.StringUtil;
+
+
+@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility
= Visibility.ANY)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RESTResponse {
+	private int           httpStatusCode;
+	private int           statusCode;
+	private String        msgDesc;
+	private List<Message> messageList;
+
+
+	public int getHttpStatusCode() {
+		return httpStatusCode;
+	}
+
+	public void setHttpStatusCode(int httpStatusCode) {
+		this.httpStatusCode = httpStatusCode;
+	}
+
+	public int getStatusCode() {
+		return statusCode;
+	}
+
+	public void setStatusCode(int statusCode) {
+		this.statusCode = statusCode;
+	}
+
+	public String getMsgDesc() {
+		return msgDesc;
+	}
+
+	public void setMsgDesc(String msgDesc) {
+		this.msgDesc = msgDesc;
+	}
+
+	public List<Message> getMessageList() {
+		return messageList;
+	}
+
+	public void setMessageList(List<Message> messageList) {
+		this.messageList = messageList;
+	}
+	
+	public String getMessage() {
+		return StringUtil.isEmpty(msgDesc) ? ("HTTP " + httpStatusCode) : msgDesc;
+	}
+
+	public String toJson() {
+		try {
+			ObjectMapper om = new ObjectMapper();
+
+			return om.writeValueAsString(this);
+		} catch (JsonGenerationException e) {
+			e.printStackTrace();
+		} catch (JsonMappingException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		return "";
+	}
+
+	public static RESTResponse fromClientResponse(ClientResponse response) {
+		RESTResponse ret = null;
+
+		String jsonString = response == null ? null : response.getEntity(String.class);
+		int    httpStatus = response == null ? 0 : response.getStatus();
+
+		if(! StringUtil.isEmpty(jsonString)) {
+			ret = RESTResponse.fromJson(jsonString);
+		}
+
+		if(ret == null) {
+			ret = new RESTResponse();
+		}
+
+		ret.setHttpStatusCode(httpStatus);
+
+		return ret;
+	}
+
+	public static RESTResponse fromJson(String jsonString) {
+		try {
+			ObjectMapper om = new ObjectMapper();
+
+			return om.readValue(jsonString, RESTResponse.class);
+		} catch (Exception e) {
+			Log.warn("fromJson() failed!", e);
+		}
+
+		return null;
+	}
+
+	@Override
+	public String toString() {
+		return toJson();
+	}
+
+	@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE,
fieldVisibility = Visibility.ANY)
+	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+	@JsonIgnoreProperties(ignoreUnknown = true)
+	public static class Message {
+		private String name;
+		private String rbKey;
+		private String message;
+		private Long   objectId;
+		private String fieldName;
+
+		public String getName() {
+			return name;
+		}
+		public void setName(String name) {
+			this.name = name;
+		}
+		public String getRbKey() {
+			return rbKey;
+		}
+		public void setRbKey(String rbKey) {
+			this.rbKey = rbKey;
+		}
+		public String getMessage() {
+			return message;
+		}
+		public void setMessage(String message) {
+			this.message = message;
+		}
+		public Long getObjectId() {
+			return objectId;
+		}
+		public void setObjectId(Long objectId) {
+			this.objectId = objectId;
+		}
+		public String getFieldName() {
+			return fieldName;
+		}
+		public void setFieldName(String fieldName) {
+			this.fieldName = fieldName;
+		}
+
+		public String toJson() {
+			try {
+				ObjectMapper om = new ObjectMapper();
+
+				return om.writeValueAsString(this);
+			} catch (JsonGenerationException e) {
+				e.printStackTrace();
+			} catch (JsonMappingException e) {
+				e.printStackTrace();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+			
+			return "";
+		}
+
+		public static RESTResponse fromJson(String jsonString) {
+			try {
+				ObjectMapper om = new ObjectMapper();
+
+				return om.readValue(jsonString, RESTResponse.class);
+			} catch (Exception e) {
+				// ignore
+			}
+			
+			return null;
+		}
+
+		@Override
+		public String toString() {
+			return toJson();
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/5f3c1d58/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizer.java
----------------------------------------------------------------------
diff --git a/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizer.java
b/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizer.java
index 1308c04..45283b5 100644
--- a/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizer.java
+++ b/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizer.java
@@ -582,16 +582,15 @@ public class XaSecureHiveAuthorizer extends XaSecureHiveAuthorizerBase
{
 				}
 			}
 		}
-		
+
 		UserGroupInformation ugi = this.getCurrentUserGroupInfo();
 
 		logAuditEventForDfs(ugi, dfsCommandParams, false);
 
 		throw new HiveAccessControlException(String.format("Permission denied: user [%s] does not
have privilege for [%s] command",
 											 ugi.getShortUserName(), hiveOpType.name()));
-		
 	}
-	
+
 	private GrantRevokeData createGrantRevokeData(XaHiveObjectAccessInfo objAccessInfo,
 												  List<HivePrincipal>    hivePrincipals,
 												  List<HivePrivilege>    hivePrivileges,
@@ -637,11 +636,11 @@ public class XaSecureHiveAuthorizer extends XaSecureHiveAuthorizerBase
{
 				permMap.addPerm(HiveAccessType.UPDATE.name());
 			}
 		}
-		
+
 		if(grantOption) {
 			permMap.addPerm(HiveAccessType.ADMIN.name());
 		}
-		
+
 		for(HivePrincipal principal : hivePrincipals) {
 			switch(principal.getType()) {
 				case USER:
@@ -664,13 +663,13 @@ public class XaSecureHiveAuthorizer extends XaSecureHiveAuthorizerBase
{
 		permMapList.add(permMap);
 
 		String grantor = grantorPrincipal != null ? grantorPrincipal.getName() : null;
-		
+
 		if(StringUtil.isEmpty(grantor)) {
 			LOG.warn("grantorPrincipal.getName() is null/empty!");
 		}
-		
+
 		grData.setHiveData(grantor, repositoryName, database, table, columns, permMapList);
-		
+
 		return grData;
 	}
 


Mime
View raw message