Commit ae23e783 by Madhan Neethiraj

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

parent 60c05eb7
...@@ -21,6 +21,8 @@ package org.apache.atlas.hive.hook.events; ...@@ -21,6 +21,8 @@ package org.apache.atlas.hive.hook.events;
import org.apache.atlas.hive.hook.AtlasHiveHookContext; import org.apache.atlas.hive.hook.AtlasHiveHookContext;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.notification.HookNotification; 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.Collections;
import java.util.List; import java.util.List;
...@@ -32,9 +34,12 @@ public class AlterDatabase extends CreateDatabase { ...@@ -32,9 +34,12 @@ public class AlterDatabase extends CreateDatabase {
@Override @Override
public List<HookNotification> getNotificationMessages() throws Exception { public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
AtlasEntitiesWithExtInfo entities = getEntities(); AtlasEntitiesWithExtInfo entities = getEntities();
HookNotification notification = new HookNotification.EntityUpdateRequestV2(getUserName(), entities);
List<HookNotification> ret = Collections.singletonList(notification); if (entities != null && CollectionUtils.isNotEmpty(entities.getEntities())) {
ret = Collections.singletonList(new EntityUpdateRequestV2(getUserName(), entities));
}
return ret; return ret;
} }
......
...@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext; ...@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.notification.HookNotification; import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2; import org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2;
import org.apache.commons.collections.CollectionUtils;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -33,9 +34,12 @@ public class AlterTable extends CreateTable { ...@@ -33,9 +34,12 @@ public class AlterTable extends CreateTable {
@Override @Override
public List<HookNotification> getNotificationMessages() throws Exception { public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
AtlasEntitiesWithExtInfo entities = getEntities(); AtlasEntitiesWithExtInfo entities = getEntities();
HookNotification notification = new EntityUpdateRequestV2(getUserName(), entities);
List<HookNotification> ret = Collections.singletonList(notification); if (entities != null && CollectionUtils.isNotEmpty(entities.getEntities())) {
ret = Collections.singletonList(new EntityUpdateRequestV2(getUserName(), entities));
}
return ret; return ret;
} }
......
...@@ -805,6 +805,7 @@ public abstract class BaseHiveEvent { ...@@ -805,6 +805,7 @@ public abstract class BaseHiveEvent {
case ALTERTABLE_RENAMECOL: case ALTERTABLE_RENAMECOL:
case ALTERVIEW_PROPERTIES: case ALTERVIEW_PROPERTIES:
case ALTERVIEW_RENAME: case ALTERVIEW_RENAME:
case ALTERVIEW_AS:
return true; return true;
} }
......
...@@ -23,6 +23,7 @@ import org.apache.atlas.model.instance.AtlasEntity; ...@@ -23,6 +23,7 @@ import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.notification.HookNotification; import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2; 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.metastore.api.Database;
import org.apache.hadoop.hive.ql.hooks.Entity; import org.apache.hadoop.hive.ql.hooks.Entity;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -40,9 +41,12 @@ public class CreateDatabase extends BaseHiveEvent { ...@@ -40,9 +41,12 @@ public class CreateDatabase extends BaseHiveEvent {
@Override @Override
public List<HookNotification> getNotificationMessages() throws Exception { public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
AtlasEntitiesWithExtInfo entities = getEntities(); AtlasEntitiesWithExtInfo entities = getEntities();
HookNotification notification = new EntityCreateRequestV2(getUserName(), entities);
List<HookNotification> ret = Collections.singletonList(notification); if (entities != null && CollectionUtils.isNotEmpty(entities.getEntities())) {
ret = Collections.singletonList(new EntityCreateRequestV2(getUserName(), entities));
}
return ret; return ret;
} }
......
...@@ -53,8 +53,12 @@ public class CreateHiveProcess extends BaseHiveEvent { ...@@ -53,8 +53,12 @@ public class CreateHiveProcess extends BaseHiveEvent {
@Override @Override
public List<HookNotification> getNotificationMessages() throws Exception { public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
AtlasEntitiesWithExtInfo entities = getEntities(); 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; return ret;
} }
......
...@@ -23,6 +23,7 @@ import org.apache.atlas.model.instance.AtlasEntity; ...@@ -23,6 +23,7 @@ import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.notification.HookNotification; import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2; 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.TableType;
import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.ql.hooks.Entity; import org.apache.hadoop.hive.ql.hooks.Entity;
...@@ -42,9 +43,12 @@ public class CreateTable extends BaseHiveEvent { ...@@ -42,9 +43,12 @@ public class CreateTable extends BaseHiveEvent {
@Override @Override
public List<HookNotification> getNotificationMessages() throws Exception { public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
AtlasEntitiesWithExtInfo entities = getEntities(); AtlasEntitiesWithExtInfo entities = getEntities();
HookNotification notification = new EntityCreateRequestV2(getUserName(), entities);
List<HookNotification> ret = Collections.singletonList(notification); if (entities != null && CollectionUtils.isNotEmpty(entities.getEntities())) {
ret = Collections.singletonList(new EntityCreateRequestV2(getUserName(), entities));
}
return ret; return ret;
} }
......
...@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext; ...@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.notification.HookNotification; import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2; import org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.hadoop.hive.ql.hooks.Entity; import org.apache.hadoop.hive.ql.hooks.Entity;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -35,9 +36,16 @@ public class DropDatabase extends BaseHiveEvent { ...@@ -35,9 +36,16 @@ public class DropDatabase extends BaseHiveEvent {
@Override @Override
public List<HookNotification> getNotificationMessages() throws Exception { public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
List<AtlasObjectId> entities = getEntities(); List<AtlasObjectId> entities = getEntities();
HookNotification notification = new EntityDeleteRequestV2(getUserName(), entities);
List<HookNotification> ret = Collections.singletonList(notification); if (CollectionUtils.isNotEmpty(entities)) {
ret = new ArrayList<>(entities.size());
for (AtlasObjectId entity : entities) {
ret.add(new EntityDeleteRequestV2(getUserName(), Collections.singletonList(entity)));
}
}
return ret; return ret;
} }
......
...@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext; ...@@ -22,6 +22,7 @@ import org.apache.atlas.hive.hook.AtlasHiveHookContext;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.notification.HookNotification; import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2; import org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.hadoop.hive.ql.hooks.Entity; import org.apache.hadoop.hive.ql.hooks.Entity;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -35,9 +36,16 @@ public class DropTable extends BaseHiveEvent { ...@@ -35,9 +36,16 @@ public class DropTable extends BaseHiveEvent {
@Override @Override
public List<HookNotification> getNotificationMessages() throws Exception { public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
List<AtlasObjectId> entities = getEntities(); List<AtlasObjectId> entities = getEntities();
HookNotification notification = new EntityDeleteRequestV2(getUserName(), entities);
List<HookNotification> ret = Collections.singletonList(notification); if (CollectionUtils.isNotEmpty(entities)) {
ret = new ArrayList<>(entities.size());
for (AtlasObjectId entity : entities) {
ret.add(new EntityDeleteRequestV2(getUserName(), Collections.singletonList(entity)));
}
}
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment