ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject [1/5] incubator-ranger git commit: RANGER-1124: Good coding practices
Date Thu, 11 Aug 2016 04:16:36 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/ranger-0.6 11e8d07b7 -> ee47136ab


RANGER-1124: Good coding practices

Signed-off-by: Madhan Neethiraj <madhan@apache.org>
(cherry picked from commit d8e8890ba228a21ea046c70bb4e2ee4c7e6f07b9)


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

Branch: refs/heads/ranger-0.6
Commit: d6912887437e6d3bdb7fa141801a708629363d06
Parents: 11e8d07
Author: Abhay Kulkarni <akulkarni@hortonworks.com>
Authored: Tue Jul 26 13:31:48 2016 -0700
Committer: Velmurugan Periasamy <vel@apache.org>
Committed: Thu Aug 11 09:33:25 2016 +0530

----------------------------------------------------------------------
 .../plugin/audit/RangerDefaultAuditHandler.java       |  4 +++-
 .../conditionevaluator/RangerTimeOfDayMatcher.java    |  3 ++-
 .../model/validation/RangerPolicyValidator.java       |  2 +-
 .../RangerDefaultPolicyResourceMatcher.java           |  2 +-
 .../apache/ranger/plugin/store/file/TagFileStore.java | 14 ++++++++++----
 .../org/apache/ranger/plugin/util/SearchFilter.java   | 12 ------------
 .../ranger/common/RangerServicePoliciesCache.java     |  4 +++-
 .../apache/ranger/common/RangerServiceTagsCache.java  |  4 +++-
 .../tagsync/sink/tagadmin/TagAdminRESTSink.java       |  9 +++++++--
 .../tagsync/source/atlas/AtlasNotificationMapper.java | 14 +++++++++-----
 10 files changed, 39 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
b/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
index 66cee76..60d3b0c 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
@@ -67,7 +67,9 @@ public class RangerDefaultAuditHandler implements RangerAccessResultProcessor
{
 
 		Collection<AuthzAuditEvent> events = getAuthzEvents(results);
 
-		logAuthzAudits(events);
+		if (events != null) {
+			logAuthzAudits(events);
+		}
 
 		if(LOG.isDebugEnabled()) {
 			LOG.debug("<== RangerDefaultAuditHandler.processResults(" + results + ")");

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerTimeOfDayMatcher.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerTimeOfDayMatcher.java
b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerTimeOfDayMatcher.java
index f65f29e..a1ea326 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerTimeOfDayMatcher.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerTimeOfDayMatcher.java
@@ -20,6 +20,7 @@
 package org.apache.ranger.plugin.conditionevaluator;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
@@ -126,7 +127,7 @@ public class RangerTimeOfDayMatcher extends RangerAbstractConditionEvaluator
{
 		}
 
 		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== RangerTimeOfDayMatcher.extractDuration(" + value + "): duration[" +
result + "]");
+			LOG.debug("<== RangerTimeOfDayMatcher.extractDuration(" + value + "): duration:" +
Arrays.toString(result));
 		}
 		return result;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/agents-common/src/main/java/org/apache/ranger/plugin/model/validation/RangerPolicyValidator.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/model/validation/RangerPolicyValidator.java
b/agents-common/src/main/java/org/apache/ranger/plugin/model/validation/RangerPolicyValidator.java
index a89ec19..62bd100 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/model/validation/RangerPolicyValidator.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/model/validation/RangerPolicyValidator.java
@@ -776,7 +776,7 @@ public class RangerPolicyValidator extends RangerValidator {
 		}
 
 		if(LOG.isDebugEnabled()) {
-			LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s): %s", accesses,
failures, serviceDef, valid));
+			LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %b", accesses,
failures, serviceDef, valid));
 		}
 		return valid;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
b/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
index 6ea194d..733049f 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
@@ -162,7 +162,7 @@ public class RangerDefaultPolicyResourceMatcher implements RangerPolicyResourceM
 			String keysString = sb.toString();
 			String serviceDefName = serviceDef == null ? "" : serviceDef.getName();
 			String validHierarchy = "";
-			if (CollectionUtils.isNotEmpty(firstValidResourceDefHierarchy)) {
+			if (serviceDef != null && CollectionUtils.isNotEmpty(firstValidResourceDefHierarchy))
{
 				RangerServiceDefHelper serviceDefHelper = new RangerServiceDefHelper(serviceDef, false);
 				List<String> resourceDefNameOrderedList = serviceDefHelper.getAllResourceNamesOrdered(firstValidResourceDefHierarchy);
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
b/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
index a20a9f8..780d379 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
@@ -195,7 +195,7 @@ public class TagFileStore extends AbstractTagStore {
 
 		RangerTagDef existing = getTagDefByName(name);
 
-		if (existing == null) {
+		if (existing != null) {
 			try {
 				deleteTagDef(existing);
 			} catch (Exception excp) {
@@ -422,7 +422,9 @@ public class TagFileStore extends AbstractTagStore {
 		try {
 			RangerTag tag = getTag(id);
 
-			deleteTag(tag);
+			if (tag != null) {
+				deleteTag(tag);
+			}
 		} catch (Exception excp) {
 			throw new Exception("failed to delete tag with ID=" + id, excp);
 		}
@@ -667,7 +669,9 @@ public class TagFileStore extends AbstractTagStore {
 		try {
 			RangerServiceResource resource = getServiceResource(id);
 
-			deleteServiceResource(resource);
+			if (resource != null) {
+				deleteServiceResource(resource);
+			}
 		} catch (Exception excp) {
 			throw new Exception("failed to delete service-resource with ID=" + id, excp);
 		}
@@ -686,7 +690,9 @@ public class TagFileStore extends AbstractTagStore {
 		try {
 			RangerServiceResource resource = getServiceResourceByGuid(guid);
 
-			deleteServiceResource(resource);
+			if (resource != null) {
+				deleteServiceResource(resource);
+			}
 		} catch (Exception excp) {
 			throw new Exception("failed to delete service-resource with GUID=" + guid, excp);
 		}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/agents-common/src/main/java/org/apache/ranger/plugin/util/SearchFilter.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/util/SearchFilter.java b/agents-common/src/main/java/org/apache/ranger/plugin/util/SearchFilter.java
index cac0181..038c1c1 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/util/SearchFilter.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/util/SearchFilter.java
@@ -96,18 +96,6 @@ public class SearchFilter {
 		return params == null ? null : params.get(name);
 	}
 
-	public Long getParamAsLong(String name) {
-
-		String stringValue =  params == null ? null : params.get(name);
-		Long ret = null;
-		try {
-			ret = Long.valueOf(stringValue);
-		} catch (NumberFormatException exception) {
-			// Ignore
-		}
-		return ret;
-	}
-
 	public void setParam(String name, String value) {
 		if(StringUtils.isEmpty(name) || StringUtils.isEmpty(value)) {
 			return;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/security-admin/src/main/java/org/apache/ranger/common/RangerServicePoliciesCache.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/common/RangerServicePoliciesCache.java
b/security-admin/src/main/java/org/apache/ranger/common/RangerServicePoliciesCache.java
index a68b215..1cc9793 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/RangerServicePoliciesCache.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/RangerServicePoliciesCache.java
@@ -77,7 +77,9 @@ public class RangerServicePoliciesCache {
 				ServicePoliciesWrapper cachedServicePoliciesWrapper = null;
 
 				for (String serviceName : serviceNames) {
-					cachedServicePoliciesWrapper = servicePoliciesMap.get(serviceName);
+					synchronized (this) {
+						cachedServicePoliciesWrapper = servicePoliciesMap.get(serviceName);
+					}
 					if (LOG.isDebugEnabled()) {
 						LOG.debug("serviceName:" + serviceName + ", Cached-MetaData:" + cachedServicePoliciesWrapper);
 					}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/security-admin/src/main/java/org/apache/ranger/common/RangerServiceTagsCache.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/common/RangerServiceTagsCache.java
b/security-admin/src/main/java/org/apache/ranger/common/RangerServiceTagsCache.java
index 66c1562..5521523 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/RangerServiceTagsCache.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/RangerServiceTagsCache.java
@@ -77,7 +77,9 @@ public class RangerServiceTagsCache {
 				ServiceTagsWrapper cachedServiceTagsWrapper = null;
 
 				for (String serviceName : serviceNames) {
-					cachedServiceTagsWrapper = serviceTagsMap.get(serviceName);
+					synchronized (this) {
+						cachedServiceTagsWrapper = serviceTagsMap.get(serviceName);
+					}
 					if (LOG.isDebugEnabled()) {
 						LOG.debug("serviceName:" + serviceName + ", Cached-MetaData:" + cachedServiceTagsWrapper);
 					}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/tagsync/src/main/java/org/apache/ranger/tagsync/sink/tagadmin/TagAdminRESTSink.java
----------------------------------------------------------------------
diff --git a/tagsync/src/main/java/org/apache/ranger/tagsync/sink/tagadmin/TagAdminRESTSink.java
b/tagsync/src/main/java/org/apache/ranger/tagsync/sink/tagadmin/TagAdminRESTSink.java
index dfc3fdb..885b44e 100644
--- a/tagsync/src/main/java/org/apache/ranger/tagsync/sink/tagadmin/TagAdminRESTSink.java
+++ b/tagsync/src/main/java/org/apache/ranger/tagsync/sink/tagadmin/TagAdminRESTSink.java
@@ -247,8 +247,13 @@ public class TagAdminRESTSink implements TagSink, Runnable {
 
 					try {
 						ServiceTags uploaded = doUpload(toUpload);
-						// ServiceTags uploaded successfully
-						uploadWorkItem.uploadCompleted(uploaded);
+						if (uploaded == null) { // Treat this as if an Exception is thrown by doUpload
+							doRetry = true;
+							Thread.sleep(rangerAdminConnectionCheckInterval);
+						} else {
+							// ServiceTags uploaded successfully
+							uploadWorkItem.uploadCompleted(uploaded);
+						}
 					} catch (InterruptedException interrupted) {
 						LOG.error("Caught exception..: ", interrupted);
 						return;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d6912887/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasNotificationMapper.java
----------------------------------------------------------------------
diff --git a/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasNotificationMapper.java
b/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasNotificationMapper.java
index 793ac28..06e4d95 100644
--- a/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasNotificationMapper.java
+++ b/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasNotificationMapper.java
@@ -153,13 +153,17 @@ public class AtlasNotificationMapper {
 			ret.getServiceResources().add(serviceResource);
 		} else {
 			ret = buildServiceTags(entityWithTraits, null);
-			// tag-definitions should NOT be deleted as part of service-resource delete
-			ret.setTagDefinitions(MapUtils.EMPTY_MAP);
-			// Ranger deletes tags associated with deleted service-resource
-			ret.setTags(MapUtils.EMPTY_MAP);
+			if (ret != null) {
+				// tag-definitions should NOT be deleted as part of service-resource delete
+				ret.setTagDefinitions(MapUtils.EMPTY_MAP);
+				// Ranger deletes tags associated with deleted service-resource
+				ret.setTags(MapUtils.EMPTY_MAP);
+			}
 		}
 
-		ret.setOp(ServiceTags.OP_DELETE);
+		if (ret != null) {
+			ret.setOp(ServiceTags.OP_DELETE);
+		}
 
 		return ret;
 	}


Mime
View raw message