Commit 47619ee6 by Suma Shivaprasad

ATLAS-605 Hook Notifications for DELETE entity needs to be supported (sumasai)

parent ef9ef3c1
......@@ -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
......
......@@ -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;
......
......@@ -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;
}
}
}
......@@ -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)
......
......@@ -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();
......
......@@ -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"));
}
}
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