ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject incubator-ranger git commit: RANGER-602: Solr client in SolrCloud mode should work with zookeeper settings also
Date Tue, 24 Nov 2015 20:39:32 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master ad45c554f -> 428afbce3


RANGER-602: Solr client in SolrCloud mode should work with zookeeper
settings also

Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/428afbce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/428afbce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/428afbce

Branch: refs/heads/master
Commit: 428afbce3b80d0bbcdb079ee7b0f9ed072fe8919
Parents: ad45c55
Author: Don Bosco Durai <bosco@apache.org>
Authored: Tue Nov 24 05:20:14 2015 -0800
Committer: Don Bosco Durai <bosco@apache.org>
Committed: Tue Nov 24 05:20:14 2015 -0800

----------------------------------------------------------------------
 .../java/org/apache/ranger/solr/SolrMgr.java    | 100 ++++++++++++++-----
 1 file changed, 74 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/428afbce/security-admin/src/main/java/org/apache/ranger/solr/SolrMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/solr/SolrMgr.java b/security-admin/src/main/java/org/apache/ranger/solr/SolrMgr.java
index 2a57fa1..603e46a 100644
--- a/security-admin/src/main/java/org/apache/ranger/solr/SolrMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/solr/SolrMgr.java
@@ -26,6 +26,7 @@ import org.apache.ranger.biz.RangerBizUtil;
 import org.apache.ranger.common.PropertiesUtil;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.impl.BinaryRequestWriter;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -49,6 +50,9 @@ public class SolrMgr {
 	volatile boolean initDone = false;
 
 	final static String SOLR_URLS_PROP = "ranger.audit.solr.urls";
+	final static String SOLR_ZK_HOSTS = "ranger.audit.solr.zookeepers";
+	final static String SOLR_COLLECTION_NAME = "ranger.audit.solr.collection.name";
+	public static final String DEFAULT_COLLECTION_NAME = "ranger_audits";
 
 	public SolrMgr() {
 
@@ -59,6 +63,17 @@ public class SolrMgr {
 			synchronized (lock) {
 				if (!initDone) {
 					if (rangerBizUtil.getAuditDBType().equalsIgnoreCase("solr")) {
+						String zkHosts = PropertiesUtil
+								.getProperty(SOLR_ZK_HOSTS);
+						if (zkHosts == null) {
+							zkHosts = PropertiesUtil
+									.getProperty("ranger.audit.solr.zookeeper");
+						}
+						if (zkHosts == null) {
+							zkHosts = PropertiesUtil
+									.getProperty("ranger.solr.zookeeper");
+						}
+
 						String solrURL = PropertiesUtil
 								.getProperty(SOLR_URLS_PROP);
 
@@ -72,38 +87,71 @@ public class SolrMgr {
 							solrURL = PropertiesUtil
 									.getProperty("ranger.solr.url");
 						}
-						if (solrURL == null || solrURL.isEmpty()
-								|| solrURL.equalsIgnoreCase("none")) {
-							logger.fatal("Solr URL for Audit is empty. Please set property "
-									+ SOLR_URLS_PROP);
-						} else {
-							try {
-								solrClient = new HttpSolrClient(solrURL);
-								if (solrClient == null) {
-									logger.fatal("Can't connect to Solr. URL="
-											+ solrURL);
-								} else {
-									if (solrClient instanceof HttpSolrClient) {
-										HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient;
-										httpSolrClient
-												.setAllowCompression(true);
-										httpSolrClient
-												.setConnectionTimeout(1000);
-										// httpSolrClient.setSoTimeout(10000);
-										httpSolrClient.setMaxRetries(1);
-										httpSolrClient
-												.setRequestWriter(new BinaryRequestWriter());
-									}
-									initDone = true;
-								}
 
+						if (zkHosts != null && !zkHosts.trim().equals("")
+								&& !zkHosts.trim().equals("none")) {
+							zkHosts = zkHosts.trim();
+							String collectionName = PropertiesUtil
+									.getProperty(SOLR_COLLECTION_NAME);
+							if (collectionName == null
+									|| collectionName.equalsIgnoreCase("none")) {
+								collectionName = DEFAULT_COLLECTION_NAME;
+							}
+
+							logger.info("Solr zkHosts=" + zkHosts
+									+ ", collectionName=" + collectionName);
+
+							try {
+								// Instantiate
+								CloudSolrClient solrCloudClient = new CloudSolrClient(
+										zkHosts);
+								solrCloudClient
+										.setDefaultCollection(collectionName);
+								solrClient = solrCloudClient;
 							} catch (Throwable t) {
 								logger.fatal(
-										"Can't connect to Solr server. URL="
-												+ solrURL, t);
+										"Can't connect to Solr server. ZooKeepers="
+												+ zkHosts + ", collection="
+												+ collectionName, t);
+							}
+
+						} else {
+							if (solrURL == null || solrURL.isEmpty()
+									|| solrURL.equalsIgnoreCase("none")) {
+								logger.fatal("Solr ZKHosts and URL for Audit are empty. Please set property "
+										+ SOLR_ZK_HOSTS
+										+ " or "
+										+ SOLR_URLS_PROP);
+							} else {
+								try {
+									solrClient = new HttpSolrClient(solrURL);
+									if (solrClient == null) {
+										logger.fatal("Can't connect to Solr. URL="
+												+ solrURL);
+									} else {
+										if (solrClient instanceof HttpSolrClient) {
+											HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient;
+											httpSolrClient
+													.setAllowCompression(true);
+											httpSolrClient
+													.setConnectionTimeout(1000);
+											// httpSolrClient.setSoTimeout(10000);
+											httpSolrClient.setMaxRetries(1);
+											httpSolrClient
+													.setRequestWriter(new BinaryRequestWriter());
+										}
+										initDone = true;
+									}
+
+								} catch (Throwable t) {
+									logger.fatal(
+											"Can't connect to Solr server. URL="
+													+ solrURL, t);
+								}
 							}
 						}
 					}
+
 				}
 			}
 		}


Mime
View raw message