Repository: incubator-atlas Updated Branches: refs/heads/master ef9ef3c10 -> 47619ee69
ATLAS-605 Hook Notifications for DELETE entity needs to be supported (sumasai) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/47619ee6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/47619ee6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/47619ee6 Branch: refs/heads/master Commit: 47619ee69422f13bdf73d1586bfa8d54dac61599 Parents: ef9ef3c Author: Suma Shivaprasad <[email protected]> Authored: Tue Apr 5 12:20:15 2016 -0700 Committer: Suma Shivaprasad <[email protected]> Committed: Tue Apr 5 12:20:15 2016 -0700 ---------------------------------------------------------------------- .../main/java/org/apache/atlas/AtlasClient.java | 2 +- .../notification/NotificationHookConsumer.java | 8 ++++ .../notification/hook/HookNotification.java | 42 +++++++++++++++++++- release-log.txt | 1 + .../notification/EntityNotificationIT.java | 19 +++++++++ .../NotificationHookConsumerIT.java | 22 ++++++++++ 6 files changed, 92 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/47619ee6/client/src/main/java/org/apache/atlas/AtlasClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/atlas/AtlasClient.java b/client/src/main/java/org/apache/atlas/AtlasClient.java index ccd6fbf..c3b4ba9 100755 --- a/client/src/main/java/org/apache/atlas/AtlasClient.java +++ b/client/src/main/java/org/apache/atlas/AtlasClient.java @@ -627,7 +627,7 @@ public class AtlasClient { JSONObject jsonResponse = callAPIWithResource(API.DELETE_ENTITIES, resource, null); return extractResults(jsonResponse, GUID); } - + /** * Get an entity given the entity id * @param guid entity id http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/47619ee6/notification/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java ---------------------------------------------------------------------- diff --git a/notification/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java b/notification/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java index ca53fd2..1f2df3e 100644 --- a/notification/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java +++ b/notification/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java @@ -202,6 +202,14 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl partialUpdateRequest.getAttributeValue(), partialUpdateRequest.getEntity()); break; + case ENTITY_DELETE: + HookNotification.EntityDeleteRequest deleteRequest = + (HookNotification.EntityDeleteRequest) message; + atlasClient.deleteEntity(deleteRequest.getTypeName(), + deleteRequest.getAttribute(), + deleteRequest.getAttributeValue()); + break; + case ENTITY_FULL_UPDATE: HookNotification.EntityUpdateRequest updateRequest = (HookNotification.EntityUpdateRequest) message; http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/47619ee6/notification/src/main/java/org/apache/atlas/notification/hook/HookNotification.java ---------------------------------------------------------------------- diff --git a/notification/src/main/java/org/apache/atlas/notification/hook/HookNotification.java b/notification/src/main/java/org/apache/atlas/notification/hook/HookNotification.java index 4c7f6de..80c96fa 100644 --- a/notification/src/main/java/org/apache/atlas/notification/hook/HookNotification.java +++ b/notification/src/main/java/org/apache/atlas/notification/hook/HookNotification.java @@ -54,6 +54,9 @@ public class HookNotification implements JsonDeserializer<HookNotification.HookN case ENTITY_PARTIAL_UPDATE: return context.deserialize(json, EntityPartialUpdateRequest.class); + case ENTITY_DELETE: + return context.deserialize(json, EntityDeleteRequest.class); + case TYPE_CREATE: case TYPE_UPDATE: return context.deserialize(json, TypeRequest.class); @@ -67,7 +70,7 @@ public class HookNotification implements JsonDeserializer<HookNotification.HookN * Type of the hook message. */ public enum HookNotificationType { - TYPE_CREATE, TYPE_UPDATE, ENTITY_CREATE, ENTITY_PARTIAL_UPDATE, ENTITY_FULL_UPDATE + TYPE_CREATE, TYPE_UPDATE, ENTITY_CREATE, ENTITY_PARTIAL_UPDATE, ENTITY_FULL_UPDATE, ENTITY_DELETE } /** @@ -208,4 +211,41 @@ public class HookNotification implements JsonDeserializer<HookNotification.HookN return attributeValue; } } + + /** + * Hook message for creating new entities. + */ + public static class EntityDeleteRequest extends HookNotificationMessage { + + private String typeName; + private String attribute; + private String attributeValue; + + private EntityDeleteRequest() { + } + + public EntityDeleteRequest(String user, String typeName, String attribute, String attributeValue) { + this(HookNotificationType.ENTITY_DELETE, user, typeName, attribute, attributeValue); + } + + protected EntityDeleteRequest(HookNotificationType type, + String user, String typeName, String attribute, String attributeValue) { + super(type, user); + this.typeName = typeName; + this.attribute = attribute; + this.attributeValue = attributeValue; + } + + public String getTypeName() { + return typeName; + } + + public String getAttribute() { + return attribute; + } + + public String getAttributeValue() { + return attributeValue; + } + } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/47619ee6/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 1ae8a72..2750de1 100644 --- a/release-log.txt +++ b/release-log.txt @@ -13,6 +13,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags) ALL CHANGES: +ATLAS-605 Hook Notifications for DELETE entity needs to be supported (sumasai) ATLAS-607 Add Support for delete entity through a qualifiedName (sumasai via yhemanth) ATLAS-571 Modify Atlas client for necessary changes in context of HA (yhemanth via sumasai) ATLAS-620 Disable hbase based entity audit (shwethags) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/47619ee6/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java b/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java index 7086c24..d6199ab 100644 --- a/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java +++ b/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java @@ -104,6 +104,25 @@ public class EntityNotificationIT extends BaseResourceIT { newNotificationPredicate(EntityNotification.OperationType.ENTITY_UPDATE, HIVE_TABLE_TYPE, guid)); } + @Test + public void testDeleteEntity() throws Exception { + final String tableName = "table-" + randomString(); + Referenceable tableInstance = createHiveTableInstance(DATABASE_NAME, tableName); + final Id tableId = createInstance(tableInstance); + final String guid = tableId._getId(); + + waitForNotification(notificationConsumer, MAX_WAIT_TIME, + newNotificationPredicate(EntityNotification.OperationType.ENTITY_CREATE, HIVE_TABLE_TYPE, guid)); + + final String property = "name"; + final String name = (String) tableInstance.get(property); + + serviceClient.deleteEntity(HIVE_TABLE_TYPE, property, name); + + waitForNotification(notificationConsumer, MAX_WAIT_TIME, + newNotificationPredicate(EntityNotification.OperationType.ENTITY_DELETE, HIVE_TABLE_TYPE, guid)); + } + @Test(dependsOnMethods = "testCreateEntity") public void testAddTrait() throws Exception { String superSuperTraitName = "SuperTrait" + randomString(); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/47619ee6/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java index f38cffe..b2e9f91 100644 --- a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java +++ b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java @@ -126,6 +126,26 @@ public class NotificationHookConsumerIT extends BaseResourceIT { } @Test + public void testDeleteByQualifiedName() throws Exception { + final Referenceable entity = new Referenceable(DATABASE_TYPE); + final String dbName = "db" + randomString(); + entity.set("name", dbName); + entity.set("description", randomString()); + serviceClient.createEntity(entity); + + sendHookMessage( + new HookNotification.EntityDeleteRequest(TEST_USER, DATABASE_TYPE, "name", dbName)); + waitFor(MAX_WAIT_TIME, new Predicate() { + @Override + public boolean evaluate() throws Exception { + JSONArray results = serviceClient.searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, + dbName)); + return results.length() == 0; + } + }); + } + + @Test public void testUpdateEntityFullUpdate() throws Exception { Referenceable entity = new Referenceable(DATABASE_TYPE); final String dbName = "db" + randomString(); @@ -153,4 +173,6 @@ public class NotificationHookConsumerIT extends BaseResourceIT { assertEquals(actualEntity.get("description"), newEntity.get("description")); assertEquals(actualEntity.get("owner"), newEntity.get("owner")); } + + }
