ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhangqi...@apache.org
Subject ranger git commit: RANGER-1678: In different places to achieve the same function using repeat codes, new issue is perhaps generated when these functions are modified.
Date Wed, 12 Jul 2017 00:16:58 GMT
Repository: ranger
Updated Branches:
  refs/heads/master d4f2340a9 -> 05a1a4017


RANGER-1678: In different places to achieve the same function using repeat codes, new issue
is perhaps generated when these functions are modified.

Signed-off-by: peng.jianhua <peng.jianhua@zte.com.cn>


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

Branch: refs/heads/master
Commit: 05a1a40175d6458509e715bb19fd219248e965e1
Parents: d4f2340
Author: 10069681 <peng.jianhua@zte.com.cn>
Authored: Tue Jul 11 10:40:10 2017 +0800
Committer: peng.jianhua <peng.jianhua@zte.com.cn>
Committed: Tue Jul 11 20:16:00 2017 -0400

----------------------------------------------------------------------
 .../audit/destination/SolrAuditDestination.java |  9 +----
 .../audit/provider/solr/SolrAuditProvider.java  | 11 ++----
 .../apache/ranger/audit/utils/SolrAppUtil.java  | 39 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/05a1a401/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 14ad791..329e2f0 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
@@ -25,6 +25,7 @@ import org.apache.ranger.audit.model.AuditEventBase;
 import org.apache.ranger.audit.model.AuthzAuditEvent;
 import org.apache.ranger.audit.provider.MiscUtil;
 import org.apache.ranger.audit.utils.InMemoryJAASConfiguration;
+import org.apache.ranger.audit.utils.SolrAppUtil;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.impl.HttpClientUtil;
@@ -221,13 +222,7 @@ public class SolrAuditDestination extends AuditDestination {
 				docs.add(document);
 			}
 			try {
-				final UpdateResponse response = MiscUtil.executePrivilegedAction(new PrivilegedExceptionAction<UpdateResponse>()
{
-					@Override
-					public UpdateResponse run()  throws Exception {
-						UpdateResponse response = solrClient.add(docs);
-						return response;
-					};
-				});
+				final UpdateResponse response = SolrAppUtil.addDocsToSolr(solrClient, docs);
 
 				if (response.getStatus() != 0) {
 					addFailedCount(events.size());

http://git-wip-us.apache.org/repos/asf/ranger/blob/05a1a401/agents-audit/src/main/java/org/apache/ranger/audit/provider/solr/SolrAuditProvider.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/provider/solr/SolrAuditProvider.java
b/agents-audit/src/main/java/org/apache/ranger/audit/provider/solr/SolrAuditProvider.java
index e0c192c..3a4da5a 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/provider/solr/SolrAuditProvider.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/provider/solr/SolrAuditProvider.java
@@ -21,6 +21,7 @@ package org.apache.ranger.audit.provider.solr;
 
 import java.security.PrivilegedExceptionAction;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
 import java.util.Properties;
 
@@ -30,6 +31,7 @@ import org.apache.ranger.audit.destination.AuditDestination;
 import org.apache.ranger.audit.model.AuditEventBase;
 import org.apache.ranger.audit.model.AuthzAuditEvent;
 import org.apache.ranger.audit.provider.MiscUtil;
+import org.apache.ranger.audit.utils.SolrAppUtil;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.apache.solr.client.solrj.response.UpdateResponse;
@@ -167,13 +169,8 @@ public class SolrAuditProvider extends AuditDestination {
 			}
 			// Convert AuditEventBase to Solr document
 			final SolrInputDocument document = toSolrDoc(authzEvent);
-			final UpdateResponse response = MiscUtil.executePrivilegedAction(new PrivilegedExceptionAction<UpdateResponse>()
{
-				@Override
-				public UpdateResponse run()  throws Exception {
-					UpdateResponse response = solrClient.add(document);
-					return response;
-				};
-			});
+			final Collection<SolrInputDocument> docs = Collections.singletonList(document);
+			final UpdateResponse response = SolrAppUtil.addDocsToSolr(solrClient, docs);
 
 			if (response.getStatus() != 0) {
 				lastFailTime = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/ranger/blob/05a1a401/agents-audit/src/main/java/org/apache/ranger/audit/utils/SolrAppUtil.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/utils/SolrAppUtil.java b/agents-audit/src/main/java/org/apache/ranger/audit/utils/SolrAppUtil.java
new file mode 100644
index 0000000..5cb8b1b
--- /dev/null
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/utils/SolrAppUtil.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.audit.utils;
+
+import org.apache.ranger.audit.provider.MiscUtil;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.common.SolrInputDocument;
+
+import java.security.PrivilegedExceptionAction;
+import java.util.Collection;
+
+public class SolrAppUtil {
+    public static UpdateResponse addDocsToSolr(final SolrClient solrClient, final Collection<SolrInputDocument>
docs) throws Exception {
+        return MiscUtil.executePrivilegedAction(new PrivilegedExceptionAction<UpdateResponse>()
{
+            @Override
+            public UpdateResponse run() throws Exception {
+                return solrClient.add(docs);
+            }
+        });
+    }
+}


Mime
View raw message