You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ab...@apache.org on 2022/08/24 05:33:27 UTC

[ranger] branch master updated: RANGER-3864: Spurious creation of service-resource objects in Ranger

This is an automated email from the ASF dual-hosted git repository.

abhay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new dc609a2e2 RANGER-3864: Spurious creation of service-resource objects in Ranger
dc609a2e2 is described below

commit dc609a2e24fee741616e9d6fb7a77290e5b180b4
Author: Abhay Kulkarni <ab...@apache.org>
AuthorDate: Tue Aug 23 21:55:47 2022 -0700

    RANGER-3864: Spurious creation of service-resource objects in Ranger
---
 .../apache/ranger/rest/ServiceTagsProcessor.java   |  5 ++++
 .../source/atlas/AtlasNotificationMapper.java      |  4 ++--
 .../tagsync/source/atlas/AtlasTagSource.java       | 28 ++++++++++++++--------
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java b/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java
index b256e2838..1d6c48a4e 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java
@@ -396,6 +396,11 @@ public class ServiceTagsProcessor {
 					}
 					tagStore.refreshServiceResource(resourceInStore.getId());
 					RangerPerfTracer.logAlways(perf);
+				} else {
+					if (CollectionUtils.isEmpty(tagIds)) {
+						// No tags associated with the resource - delete the resource too
+						tagStore.deleteServiceResource(resourceInStore.getId());
+					}
 				}
 			}
 		}
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 1b81bafae..dadc76a54 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
@@ -44,7 +44,7 @@ public class AtlasNotificationMapper {
     private static final    Logger              LOG                 = LoggerFactory.getLogger(AtlasNotificationMapper.class);
     private static          Map<String, Long>   unhandledEventTypes = new HashMap<>();
 
-    private static void logUnhandledEntityNotification(EntityNotificationWrapper entityNotification) {
+    public static void logUnhandledEntityNotification(EntityNotificationWrapper entityNotification) {
 
         boolean skipLogging = entityNotification.getIsEntityCreateOp() && entityNotification.getIsEmptyClassifications();
 
@@ -110,7 +110,7 @@ public class AtlasNotificationMapper {
         return ret;
     }
 
-    static private boolean isNotificationHandled(EntityNotificationWrapper entityNotification) {
+    public static boolean isNotificationHandled(EntityNotificationWrapper entityNotification) {
         boolean ret = false;
 
         EntityNotificationWrapper.NotificationOpType opType = entityNotification.getOpType();
diff --git a/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasTagSource.java b/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasTagSource.java
index 2f93ebd31..1a3ddecb5 100644
--- a/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasTagSource.java
+++ b/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasTagSource.java
@@ -212,14 +212,20 @@ public class AtlasTagSource extends AbstractTagSource {
 										LOG.debug("Message-offset=" + message.getOffset() + ", Notification=" + getPrintableEntityNotification(notificationWrapper));
 									}
 
-									RangerAtlasEntityWithTags entityWithTags = new RangerAtlasEntityWithTags(notificationWrapper);
+									if (AtlasNotificationMapper.isNotificationHandled(notificationWrapper)) {
 
-									if ((notificationWrapper.getIsEntityDeleteOp() && !isHandlingDeleteOps) || (!notificationWrapper.getIsEntityDeleteOp() && isHandlingDeleteOps)) {
-										buildAndUploadServiceTags();
-										isHandlingDeleteOps = !isHandlingDeleteOps;
+										RangerAtlasEntityWithTags entityWithTags = new RangerAtlasEntityWithTags(notificationWrapper);
+
+										if ((notificationWrapper.getIsEntityDeleteOp() && !isHandlingDeleteOps) || (!notificationWrapper.getIsEntityDeleteOp() && isHandlingDeleteOps)) {
+											buildAndUploadServiceTags();
+											isHandlingDeleteOps = !isHandlingDeleteOps;
+										}
+
+										atlasEntitiesWithTags.add(entityWithTags);
+									} else {
+										AtlasNotificationMapper.logUnhandledEntityNotification(notificationWrapper);
 									}
 
-									atlasEntitiesWithTags.add(entityWithTags);
 									messages.add(message);
 								}
 							} else {
@@ -275,14 +281,16 @@ public class AtlasTagSource extends AbstractTagSource {
 					}
 					updateSink(entry.getValue());
 				}
-				offsetOfLastMessageDeliveredToRanger = messages.get(messages.size()-1).getOffset();
-				if (LOG.isDebugEnabled()) {
-					LOG.debug("Completed processing batch of messages of size:[" + messages.size() + "] received from NotificationConsumer");
-				}
+			}
 
-				commitToKafka();
+			offsetOfLastMessageDeliveredToRanger = messages.get(messages.size()-1).getOffset();
+
+			if (LOG.isDebugEnabled()) {
+				LOG.debug("Completed processing batch of messages of size:[" + messages.size() + "] received from NotificationConsumer");
 			}
 
+			commitToKafka();
+
 			atlasEntitiesWithTags.clear();
 			messages.clear();