ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject git commit: ARGUS-28:Added getHbaseStatus to fix HBase TestConnection issue and removed log statements
Date Fri, 29 Aug 2014 22:32:25 GMT
Repository: incubator-argus
Updated Branches:
  refs/heads/master 41842dff5 -> 10de28040


ARGUS-28:Added getHbaseStatus to fix HBase TestConnection issue and removed log statements


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

Branch: refs/heads/master
Commit: 10de28040e0ca864868a549a636be3170828b080
Parents: 41842df
Author: vperiasamy <vperiasamy@hortonworks.com>
Authored: Fri Aug 29 14:57:15 2014 -0700
Committer: mneethiraj <mneethiraj@hortonworks.com>
Committed: Fri Aug 29 15:31:05 2014 -0700

----------------------------------------------------------------------
 .../com/xasecure/hbase/client/HBaseClient.java  | 58 +++++++++++++++++++-
 .../main/java/com/xasecure/biz/AssetMgr.java    | 12 ++--
 2 files changed, 59 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/10de2804/lookup-client/src/main/java/com/xasecure/hbase/client/HBaseClient.java
----------------------------------------------------------------------
diff --git a/lookup-client/src/main/java/com/xasecure/hbase/client/HBaseClient.java b/lookup-client/src/main/java/com/xasecure/hbase/client/HBaseClient.java
index 6a19cbf..0dec8f1 100644
--- a/lookup-client/src/main/java/com/xasecure/hbase/client/HBaseClient.java
+++ b/lookup-client/src/main/java/com/xasecure/hbase/client/HBaseClient.java
@@ -4,7 +4,9 @@ import java.io.IOException;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map.Entry;
 
 import javax.security.auth.Subject;
 
@@ -39,7 +41,6 @@ public class HBaseClient extends BaseClient {
 	//TODO: temporary solution - to be added to the UI for HBase 
 	private static HashMap<String,String> addDefaultHBaseProp(HashMap<String,String>
connectionProp) {
 		if (connectionProp != null) {
-			
 			String param = "zookeeper.znode.parent" ;
 			String unsecuredPath = "/hbase-unsecure" ;
 			String authParam = "hadoop.security.authorization" ;
@@ -58,27 +59,78 @@ public class HBaseClient extends BaseClient {
 		return connectionProp;
 	}
 
-	
 	public void initHBase() {
 		try {
 			if (UserGroupInformation.isSecurityEnabled()) {
+				LOG.info("initHBase:security enabled");
 				if (getConfigHolder().getKeyTabFile() == null) {
+					    LOG.info("initHBase: using username/password");
 						subj = SecureClientLogin.loginUserWithPassword(getConfigHolder().getUserName(), getConfigHolder().getPassword())
;
 				}
 				else {
+				    LOG.info("initHBase: using username/keytab");
 					subj = SecureClientLogin.loginUserFromKeytab(getConfigHolder().getUserName() , getConfigHolder().getKeyTabFile())
;
 				}
 			}
 			else {
+			    LOG.info("initHBase: security not enabled, using username");
 				subj = SecureClientLogin.login(getConfigHolder().getUserName()) ;
 			}
 		} catch (IOException e) {
-			LOG.error("Unable to perform secure login to Hive environment [" + getConfigHolder().getDatasourceName()
+ "]", e);
+			LOG.error("Unable to perform secure login to Hbase environment [" + getConfigHolder().getDatasourceName()
+ "]", e);
 		}
 	}
 	
+	public boolean getHBaseStatus() {
+		boolean hbaseStatus = false;
+		
+		if (subj != null) {
+			ClassLoader prevCl = Thread.currentThread().getContextClassLoader() ;
+			try {
+				Thread.currentThread().setContextClassLoader(getConfigHolder().getClassLoader());
 	
+				hbaseStatus = Subject.doAs(subj, new PrivilegedAction<Boolean>() {
+					@Override
+					public Boolean run() {
+						Boolean hbaseStatus1 = false;
+						try {
+						    LOG.info("getHBaseStatus: creating default Hbase configuration");
+							Configuration conf = HBaseConfiguration.create() ;					
+							LOG.info("getHBaseStatus: setting config values from client");
+							setClientConfigValues(conf);						
+						    LOG.info("getHBaseStatus: checking HbaseAvailability with the new config");
+							HBaseAdmin.checkHBaseAvailable(conf);					
+						    LOG.info("getHBaseStatus: no exception: HbaseAvailability true");
+							hbaseStatus1 = true;
+						} catch (Throwable e) {
+							LOG.error("getHBaseStatus: Unable to check availability of Hbase environment [" +
getConfigHolder().getDatasourceName() + "]", e);
+							hbaseStatus1 = false;
+						}
+						return hbaseStatus1;
+					}
+				}) ;
+			} finally {
+				Thread.currentThread().setContextClassLoader(prevCl);
+			}
+		} else {
+			LOG.error("getHBaseStatus: secure login not done, subject is null");
+		}
+		
+		return hbaseStatus;
+	}
 	
+	private void setClientConfigValues(Configuration conf) {
+		if (this.connectionProperties == null) return;
+		Iterator<Entry<String, String>> i =  this.connectionProperties.entrySet().iterator();
+		while (i.hasNext()) {
+			Entry<String, String> e = i.next();
+			String v = conf.get(e.getKey());
+			if (v != null && !v.equalsIgnoreCase(e.getValue())) {
+				conf.set(e.getKey(), e.getValue());
+			}
+		}		
+	}
+
 	public List<String> getTableList(final String tableNameMatching) {
 		List<String> ret = null ;
 		

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/10de2804/security-admin/src/main/java/com/xasecure/biz/AssetMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/com/xasecure/biz/AssetMgr.java b/security-admin/src/main/java/com/xasecure/biz/AssetMgr.java
index 439363e..a4ae899 100644
--- a/security-admin/src/main/java/com/xasecure/biz/AssetMgr.java
+++ b/security-admin/src/main/java/com/xasecure/biz/AssetMgr.java
@@ -21,6 +21,7 @@ import javax.naming.ldap.Rdn;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.hive.com.esotericsoftware.minlog.Log;
 import org.apache.log4j.Logger;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
@@ -1521,14 +1522,9 @@ public class AssetMgr extends AssetMgrBase {
 				HBaseClient connectionObj = new HBaseClient(vXAsset.getName(),
 						configMap);
 				if (connectionObj != null) {
-					connectivityStatus = true;
-					// TODO: A getConnectionStatus() method should be
-					// implemented in HBaseClient class to avoid tables lookup
-					// in HBase
-					List<String> testResult = connectionObj.getTableList(".*");
-					if (testResult != null && testResult.size() != 0) {
-						connectivityStatus = true;
-					}
+					connectivityStatus = connectionObj.getHBaseStatus();
+				} else {
+					Log.error("testConfig: Not able to create HBaseClient");
 				}
 			} else if (assetType == AppConstants.ASSET_KNOX) { 
 				KnoxClient knoxClient = assetConnectionMgr.getKnoxClient(


Mime
View raw message