Repository: atlas
Updated Branches:
  refs/heads/master 60c05eb75 -> ae23e7836


ATLAS-2491: Hive hook using V2 notifications (#2)


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

Branch: refs/heads/master
Commit: ae23e78369ce765c5353923754374bbd74c1bd47
Parents: 60c05eb
Author: Madhan Neethiraj <[email protected]>
Authored: Thu Mar 22 22:47:54 2018 -0700
Committer: Madhan Neethiraj <[email protected]>
Committed: Fri Mar 23 08:33:52 2018 -0700

----------------------------------------------------------------------
 .../apache/atlas/hive/hook/events/AlterDatabase.java  | 11 ++++++++---
 .../org/apache/atlas/hive/hook/events/AlterTable.java | 10 +++++++---
 .../apache/atlas/hive/hook/events/BaseHiveEvent.java  |  1 +
 .../apache/atlas/hive/hook/events/CreateDatabase.java | 10 +++++++---
 .../atlas/hive/hook/events/CreateHiveProcess.java     |  6 +++++-
 .../apache/atlas/hive/hook/events/CreateTable.java    | 10 +++++++---
 .../apache/atlas/hive/hook/events/DropDatabase.java   | 14 +++++++++++---
 .../org/apache/atlas/hive/hook/events/DropTable.java  | 14 +++++++++++---
 8 files changed, 57 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterDatabase.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterDatabase.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterDatabase.java
index e6cd9d9..6808574 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterDatabase.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterDatabase.java
@@ -21,6 +21,8 @@ package org.apache.atlas.hive.hook.events;
 import org.apache.atlas.hive.hook.AtlasHiveHookContext;
 import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
 import org.apache.atlas.model.notification.HookNotification;
+import 
org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2;
+import org.apache.commons.collections.CollectionUtils;
 
 import java.util.Collections;
 import java.util.List;
@@ -32,9 +34,12 @@ public class AlterDatabase extends CreateDatabase {
 
     @Override
     public List<HookNotification> getNotificationMessages() throws Exception {
-        AtlasEntitiesWithExtInfo entities     = getEntities();
-        HookNotification         notification = new 
HookNotification.EntityUpdateRequestV2(getUserName(), entities);
-        List<HookNotification>   ret          = 
Collections.singletonList(notification);
+        List<HookNotification>   ret      = null;
+        AtlasEntitiesWithExtInfo entities = getEntities();
+
+        if (entities != null && 
CollectionUtils.isNotEmpty(entities.getEntities())) {
+            ret = Collections.singletonList(new 
EntityUpdateRequestV2(getUserName(), entities));
+        }
 
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTable.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTable.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTable.java
index d7d6de8..adad81a 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTable.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTable.java
@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext;
 import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
 import org.apache.atlas.model.notification.HookNotification;
 import 
org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2;
+import org.apache.commons.collections.CollectionUtils;
 
 import java.util.Collections;
 import java.util.List;
@@ -33,9 +34,12 @@ public class AlterTable extends CreateTable {
 
     @Override
     public List<HookNotification> getNotificationMessages() throws Exception {
-        AtlasEntitiesWithExtInfo entities     = getEntities();
-        HookNotification         notification = new 
EntityUpdateRequestV2(getUserName(), entities);
-        List<HookNotification>   ret          = 
Collections.singletonList(notification);
+        List<HookNotification>   ret      = null;
+        AtlasEntitiesWithExtInfo entities = getEntities();
+
+        if (entities != null && 
CollectionUtils.isNotEmpty(entities.getEntities())) {
+            ret = Collections.singletonList(new 
EntityUpdateRequestV2(getUserName(), entities));
+        }
 
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/BaseHiveEvent.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/BaseHiveEvent.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/BaseHiveEvent.java
index 2b0c5d9..0c38bb3 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/BaseHiveEvent.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/BaseHiveEvent.java
@@ -805,6 +805,7 @@ public abstract class BaseHiveEvent {
             case ALTERTABLE_RENAMECOL:
             case ALTERVIEW_PROPERTIES:
             case ALTERVIEW_RENAME:
+            case ALTERVIEW_AS:
                 return true;
         }
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateDatabase.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateDatabase.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateDatabase.java
index 2454fbb..d017dbe 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateDatabase.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateDatabase.java
@@ -23,6 +23,7 @@ import org.apache.atlas.model.instance.AtlasEntity;
 import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
 import org.apache.atlas.model.notification.HookNotification;
 import 
org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.hadoop.hive.metastore.api.Database;
 import org.apache.hadoop.hive.ql.hooks.Entity;
 import org.slf4j.Logger;
@@ -40,9 +41,12 @@ public class CreateDatabase extends BaseHiveEvent {
 
     @Override
     public List<HookNotification> getNotificationMessages() throws Exception {
-        AtlasEntitiesWithExtInfo entities     = getEntities();
-        HookNotification         notification = new 
EntityCreateRequestV2(getUserName(), entities);
-        List<HookNotification>   ret          = 
Collections.singletonList(notification);
+        List<HookNotification>   ret      = null;
+        AtlasEntitiesWithExtInfo entities = getEntities();
+
+        if (entities != null && 
CollectionUtils.isNotEmpty(entities.getEntities())) {
+            ret = Collections.singletonList(new 
EntityCreateRequestV2(getUserName(), entities));
+        }
 
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
index 1209852..86027f2 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
@@ -53,8 +53,12 @@ public class CreateHiveProcess extends BaseHiveEvent {
 
     @Override
     public List<HookNotification> getNotificationMessages() throws Exception {
+        List<HookNotification>   ret      = null;
         AtlasEntitiesWithExtInfo entities = getEntities();
-        List<HookNotification>   ret      = entities != null ? 
Collections.singletonList(new EntityCreateRequestV2(getUserName(), entities)) : 
null;
+
+        if (entities != null && 
CollectionUtils.isNotEmpty(entities.getEntities())) {
+            ret = Collections.singletonList(new 
EntityCreateRequestV2(getUserName(), entities));
+        }
 
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateTable.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateTable.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateTable.java
index 19fe8d3..1c072e9 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateTable.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateTable.java
@@ -23,6 +23,7 @@ import org.apache.atlas.model.instance.AtlasEntity;
 import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
 import org.apache.atlas.model.notification.HookNotification;
 import 
org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.hadoop.hive.metastore.TableType;
 import org.apache.hadoop.hive.metastore.api.Database;
 import org.apache.hadoop.hive.ql.hooks.Entity;
@@ -42,9 +43,12 @@ public class CreateTable extends BaseHiveEvent {
 
     @Override
     public List<HookNotification> getNotificationMessages() throws Exception {
-        AtlasEntitiesWithExtInfo entities     = getEntities();
-        HookNotification         notification = new 
EntityCreateRequestV2(getUserName(), entities);
-        List<HookNotification>   ret          = 
Collections.singletonList(notification);
+        List<HookNotification>   ret      = null;
+        AtlasEntitiesWithExtInfo entities = getEntities();
+
+        if (entities != null && 
CollectionUtils.isNotEmpty(entities.getEntities())) {
+            ret = Collections.singletonList(new 
EntityCreateRequestV2(getUserName(), entities));
+        }
 
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropDatabase.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropDatabase.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropDatabase.java
index fabb00c..1795bf2 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropDatabase.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropDatabase.java
@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext;
 import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.notification.HookNotification;
 import 
org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.hadoop.hive.ql.hooks.Entity;
 
 import java.util.ArrayList;
@@ -35,9 +36,16 @@ public class DropDatabase extends BaseHiveEvent {
 
     @Override
     public List<HookNotification> getNotificationMessages() throws Exception {
-        List<AtlasObjectId>    entities     = getEntities();
-        HookNotification       notification = new 
EntityDeleteRequestV2(getUserName(), entities);
-        List<HookNotification> ret          = 
Collections.singletonList(notification);
+        List<HookNotification> ret      = null;
+        List<AtlasObjectId>    entities = getEntities();
+
+        if (CollectionUtils.isNotEmpty(entities)) {
+            ret = new ArrayList<>(entities.size());
+
+            for (AtlasObjectId entity : entities) {
+                ret.add(new EntityDeleteRequestV2(getUserName(), 
Collections.singletonList(entity)));
+            }
+        }
 
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/ae23e783/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropTable.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropTable.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropTable.java
index 2099095..a0f7d8a 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropTable.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/DropTable.java
@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext;
 import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.notification.HookNotification;
 import 
org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.hadoop.hive.ql.hooks.Entity;
 
 import java.util.ArrayList;
@@ -35,9 +36,16 @@ public class DropTable extends BaseHiveEvent {
 
     @Override
     public List<HookNotification> getNotificationMessages() throws Exception {
-        List<AtlasObjectId>    entities     = getEntities();
-        HookNotification       notification = new 
EntityDeleteRequestV2(getUserName(), entities);
-        List<HookNotification> ret          = 
Collections.singletonList(notification);
+        List<HookNotification> ret      = null;
+        List<AtlasObjectId>    entities = getEntities();
+
+        if (CollectionUtils.isNotEmpty(entities)) {
+            ret = new ArrayList<>(entities.size());
+
+            for (AtlasObjectId entity : entities) {
+                ret.add(new EntityDeleteRequestV2(getUserName(), 
Collections.singletonList(entity)));
+            }
+        }
 
         return ret;
     }

Reply via email to