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;
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;
}
......
......@@ -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;
}
......
......@@ -805,6 +805,7 @@ public abstract class BaseHiveEvent {
case ALTERTABLE_RENAMECOL:
case ALTERVIEW_PROPERTIES:
case ALTERVIEW_RENAME:
case ALTERVIEW_AS:
return true;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
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