You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by bo...@apache.org on 2015/04/27 20:44:23 UTC

[2/2] incubator-ranger git commit: RANGER-397 Review feedback

RANGER-397 Review feedback

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

Branch: refs/heads/master
Commit: 7dea108754afe93500e097b7be2c13f96ddff119
Parents: b8fe3e9
Author: Don Bosco Durai <bo...@apache.org>
Authored: Mon Apr 27 10:55:06 2015 -0700
Committer: Don Bosco Durai <bo...@apache.org>
Committed: Mon Apr 27 10:55:06 2015 -0700

----------------------------------------------------------------------
 .../audit/destination/SolrAuditDestination.java | 65 ++++++++++----------
 1 file changed, 31 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7dea1087/agents-audit/src/main/java/org/apache/ranger/audit/destination/SolrAuditDestination.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/destination/SolrAuditDestination.java b/agents-audit/src/main/java/org/apache/ranger/audit/destination/SolrAuditDestination.java
index 2164d9c..06ce4d7 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/destination/SolrAuditDestination.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/destination/SolrAuditDestination.java
@@ -44,10 +44,7 @@ public class SolrAuditDestination extends AuditDestination {
 	public static final String PROP_SOLR_URLS = "urls";
 	public static final String PROP_SOLR_ZK = "zookeepers";
 
-	static final Object lock = new Object();
 	SolrClient solrClient = null;
-	List<String> solrURLs = new ArrayList<String>();
-	String zkHosts = null;
 
 	public SolrAuditDestination() {
 	}
@@ -56,44 +53,44 @@ public class SolrAuditDestination extends AuditDestination {
 	public void init(Properties props, String propPrefix) {
 		LOG.info("init() called");
 		super.init(props, propPrefix);
-
-		String urls = MiscUtil.getStringProperty(props, propPrefix + "."
-				+ PROP_SOLR_URLS);
-		if (urls != null && urls.equalsIgnoreCase("NONE")) {
-			urls = null;
-		}
-		solrURLs = MiscUtil.toArray(urls, ",");
-		zkHosts = MiscUtil.getStringProperty(props, propPrefix + "."
-				+ PROP_SOLR_ZK);
-		if (zkHosts != null && zkHosts.equalsIgnoreCase("NONE")) {
-			zkHosts = null;
-		}
 		connect();
 	}
 
-	void connect() {
+	synchronized void connect() {
 		if (solrClient == null) {
-			synchronized (lock) {
+			if (solrClient == null) {
+				String urls = MiscUtil.getStringProperty(props, propPrefix
+						+ "." + PROP_SOLR_URLS);
+				if (urls != null && urls.equalsIgnoreCase("NONE")) {
+					urls = null;
+				}
 
-				if (solrClient == null) {
-					try {
-						if (zkHosts != null && !zkHosts.isEmpty()) {
-							// Instantiate
-							solrClient = new CloudSolrClient(zkHosts);
-						} else if (solrURLs == null || !solrURLs.isEmpty()) {
-							LBHttpSolrClient lbSolrClient = new LBHttpSolrClient(
-									solrURLs.get(0));
-							lbSolrClient.setConnectionTimeout(1000);
-
-							for (int i = 1; i < solrURLs.size(); i++) {
-								lbSolrClient.addSolrServer(solrURLs.get(i));
-							}
-							solrClient = lbSolrClient;
+				List<String> solrURLs = new ArrayList<String>();
+				String zkHosts = null;
+				solrURLs = MiscUtil.toArray(urls, ",");
+				zkHosts = MiscUtil.getStringProperty(props, propPrefix + "."
+						+ PROP_SOLR_ZK);
+				if (zkHosts != null && zkHosts.equalsIgnoreCase("NONE")) {
+					zkHosts = null;
+				}
+
+				try {
+					if (zkHosts != null && !zkHosts.isEmpty()) {
+						// Instantiate
+						solrClient = new CloudSolrClient(zkHosts);
+					} else if (solrURLs != null && !solrURLs.isEmpty()) {
+						LBHttpSolrClient lbSolrClient = new LBHttpSolrClient(
+								solrURLs.get(0));
+						lbSolrClient.setConnectionTimeout(1000);
+
+						for (int i = 1; i < solrURLs.size(); i++) {
+							lbSolrClient.addSolrServer(solrURLs.get(i));
 						}
-					} catch (Throwable t) {
-						LOG.fatal("Can't connect to Solr server. URL="
-								+ solrURLs, t);
+						solrClient = lbSolrClient;
 					}
+				} catch (Throwable t) {
+					LOG.fatal("Can't connect to Solr server. URL=" + solrURLs,
+							t);
 				}
 			}
 		}