Search in sources :

Example 1 with EntityNotificationV1

use of org.apache.atlas.v1.model.notification.EntityNotificationV1 in project atlas by apache.

the class EntityNotificationIT method testDeleteTrait.

public void testDeleteTrait() throws Exception {
    final String guid = tableId._getId();
    atlasClientV1.deleteTrait(guid, traitName);
    EntityNotificationV1 entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(EntityNotificationV1.OperationType.TRAIT_DELETE, HIVE_TABLE_TYPE_BUILTIN, guid));
    assertFalse(entityNotification.getEntity().getTraitNames().contains(traitName));
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1)

Example 2 with EntityNotificationV1

use of org.apache.atlas.v1.model.notification.EntityNotificationV1 in project atlas by apache.

the class EntityNotificationIT method testAddTrait.

public void testAddTrait() throws Exception {
    String superSuperTraitName = "SuperTrait" + randomString();
    String superTraitName = "SuperTrait" + randomString();
    traitName = "Trait" + randomString();
    createTrait(superSuperTraitName);
    createTrait(superTraitName, superSuperTraitName);
    createTrait(traitName, superTraitName);
    Struct traitInstance = new Struct(traitName);
    String traitInstanceJSON = AtlasType.toV1Json(traitInstance);
    LOG.debug("Trait instance = {}", traitInstanceJSON);
    final String guid = tableId._getId();
    atlasClientV1.addTrait(guid, traitInstance);
    EntityNotificationV1 entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(OperationType.TRAIT_ADD, HIVE_TABLE_TYPE_BUILTIN, guid));
    Referenceable entity = entityNotification.getEntity();
    assertTrue(entity.getTraitNames().contains(traitName));
    List<Struct> allTraits = entityNotification.getAllTraits();
    List<String> allTraitNames = new LinkedList<>();
    for (Struct struct : allTraits) {
        allTraitNames.add(struct.getTypeName());
    }
    assertTrue(allTraitNames.contains(traitName));
    assertTrue(allTraitNames.contains(superTraitName));
    assertTrue(allTraitNames.contains(superSuperTraitName));
    String anotherTraitName = "Trait" + randomString();
    createTrait(anotherTraitName, superTraitName);
    traitInstance = new Struct(anotherTraitName);
    traitInstanceJSON = AtlasType.toV1Json(traitInstance);
    LOG.debug("Trait instance = {}", traitInstanceJSON);
    atlasClientV1.addTrait(guid, traitInstance);
    entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(OperationType.TRAIT_ADD, HIVE_TABLE_TYPE_BUILTIN, guid));
    allTraits = entityNotification.getAllTraits();
    allTraitNames = new LinkedList<>();
    for (Struct struct : allTraits) {
        allTraitNames.add(struct.getTypeName());
    }
    assertTrue(allTraitNames.contains(traitName));
    assertTrue(allTraitNames.contains(anotherTraitName));
    // verify that the super type shows up twice in all traits
    assertEquals(2, Collections.frequency(allTraitNames, superTraitName));
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 3 with EntityNotificationV1

use of org.apache.atlas.v1.model.notification.EntityNotificationV1 in project atlas by apache.

the class NotificationEntityChangeListener method notifyOfEntityEvent.

// send notification of entity change
private void notifyOfEntityEvent(Collection<Referenceable> entityDefinitions, OperationType operationType) throws AtlasException {
    List<EntityNotificationV1> messages = new ArrayList<>();
    for (Referenceable entityDefinition : entityDefinitions) {
        if (GraphHelper.isInternalType(entityDefinition.getTypeName())) {
            continue;
        }
        Referenceable entity = new Referenceable(entityDefinition);
        Map<String, Object> attributesMap = entity.getValuesMap();
        List<String> entityNotificationAttrs = getNotificationAttributes(entity.getTypeName());
        if (MapUtils.isNotEmpty(attributesMap) && CollectionUtils.isNotEmpty(entityNotificationAttrs)) {
            Collection<String> attributesToRemove = CollectionUtils.subtract(attributesMap.keySet(), entityNotificationAttrs);
            for (String attributeToRemove : attributesToRemove) {
                attributesMap.remove(attributeToRemove);
            }
        }
        EntityNotificationV1 notification = new EntityNotificationV1(entity, operationType, getAllTraits(entity, typeRegistry));
        messages.add(notification);
    }
    if (!messages.isEmpty()) {
        notificationInterface.send(NotificationType.ENTITIES, messages);
    }
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) Referenceable(org.apache.atlas.v1.model.instance.Referenceable)

Example 4 with EntityNotificationV1

use of org.apache.atlas.v1.model.notification.EntityNotificationV1 in project atlas by apache.

the class EntityNotificationDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    Referenceable entity = EntityNotificationTest.getEntity("id");
    String traitName = "MyTrait";
    List<Struct> traits = Collections.singletonList(new Struct(traitName, Collections.<String, Object>emptyMap()));
    EntityNotificationV1 notification = new EntityNotificationV1(entity, EntityNotificationV1.OperationType.TRAIT_ADD, traits);
    List<String> jsonMsgList = new ArrayList<>();
    AbstractNotification.createNotificationMessages(notification, jsonMsgList);
    EntityNotification deserializedNotification = null;
    for (String jsonMsg : jsonMsgList) {
        deserializedNotification = deserializer.deserialize(jsonMsg);
        if (deserializedNotification != null) {
            break;
        }
    }
    assertTrue(deserializedNotification instanceof EntityNotificationV1);
    EntityNotificationV1 entityNotificationV1 = (EntityNotificationV1) deserializedNotification;
    assertEquals(entityNotificationV1.getOperationType(), notification.getOperationType());
    assertEquals(entityNotificationV1.getEntity().getId(), notification.getEntity().getId());
    assertEquals(entityNotificationV1.getEntity().getTypeName(), notification.getEntity().getTypeName());
    assertEquals(entityNotificationV1.getEntity().getTraits(), notification.getEntity().getTraits());
    assertEquals(entityNotificationV1.getEntity().getTrait(traitName), notification.getEntity().getTrait(traitName));
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityNotification(org.apache.atlas.model.notification.EntityNotification) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 5 with EntityNotificationV1

use of org.apache.atlas.v1.model.notification.EntityNotificationV1 in project atlas by apache.

the class EntityNotificationTest method testGetEntity.

@Test
public void testGetEntity() throws Exception {
    Referenceable entity = getEntity("id");
    EntityNotificationV1 entityNotification = new EntityNotificationV1(entity, OperationType.ENTITY_CREATE, Collections.<Struct>emptyList());
    assertEquals(entity, entityNotification.getEntity());
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Test(org.testng.annotations.Test)

Aggregations

EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)9 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)8 Test (org.testng.annotations.Test)6 Struct (org.apache.atlas.v1.model.instance.Struct)4 ArrayList (java.util.ArrayList)1 EntityNotification (org.apache.atlas.model.notification.EntityNotification)1 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)1 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)1