Search in sources :

Example 1 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationDeletedFromEntity.

public void onClassificationDeletedFromEntity(AtlasEntity entity, List<String> deletedClassificationNames) throws AtlasBaseException {
    if (isV2EntityNotificationEnabled()) {
        doFullTextMapping(entity.getGuid());
        for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
            listener.onClassificationsDeleted(entity, deletedClassificationNames);
        }
    } else {
        doFullTextMapping(entity.getGuid());
        Referenceable entityRef = toReferenceable(entity.getGuid());
        if (entityRef == null || CollectionUtils.isEmpty(deletedClassificationNames)) {
            return;
        }
        for (EntityChangeListener listener : entityChangeListeners) {
            try {
                listener.onTraitsDeleted(entityRef, deletedClassificationNames);
            } catch (AtlasException e) {
                throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitDelete");
            }
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityChangeListenerV2(org.apache.atlas.listener.EntityChangeListenerV2) AtlasException(org.apache.atlas.AtlasException)

Example 2 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationAddedToEntity.

public void onClassificationAddedToEntity(AtlasEntity entity, List<AtlasClassification> addedClassifications) throws AtlasBaseException {
    if (isV2EntityNotificationEnabled()) {
        doFullTextMapping(entity.getGuid());
        for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
            listener.onClassificationsAdded(entity, addedClassifications);
        }
    } else {
        updateFullTextMapping(entity.getGuid(), addedClassifications);
        Referenceable entityRef = toReferenceable(entity.getGuid());
        List<Struct> traits = toStruct(addedClassifications);
        if (entity == null || CollectionUtils.isEmpty(traits)) {
            return;
        }
        for (EntityChangeListener listener : entityChangeListeners) {
            try {
                listener.onTraitsAdded(entityRef, traits);
            } catch (AtlasException e) {
                throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitAdd");
            }
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityChangeListenerV2(org.apache.atlas.listener.EntityChangeListenerV2) AtlasException(org.apache.atlas.AtlasException) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 3 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationUpdatedToEntity.

public void onClassificationUpdatedToEntity(AtlasEntity entity, List<AtlasClassification> updatedClassifications) throws AtlasBaseException {
    if (isV2EntityNotificationEnabled()) {
        doFullTextMapping(entity.getGuid());
        for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
            listener.onClassificationsUpdated(entity, updatedClassifications);
        }
    } else {
        doFullTextMapping(entity.getGuid());
        Referenceable entityRef = toReferenceable(entity.getGuid());
        List<Struct> traits = toStruct(updatedClassifications);
        if (entityRef == null || CollectionUtils.isEmpty(traits)) {
            return;
        }
        for (EntityChangeListener listener : entityChangeListeners) {
            try {
                listener.onTraitsUpdated(entityRef, traits);
            } catch (AtlasException e) {
                throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitUpdate");
            }
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityChangeListenerV2(org.apache.atlas.listener.EntityChangeListenerV2) AtlasException(org.apache.atlas.AtlasException) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 4 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class AuditRepositoryTestBase method testAddEvents.

@Test
public void testAddEvents() throws Exception {
    EntityAuditEvent event = new EntityAuditEvent(rand(), System.currentTimeMillis(), "u1", EntityAuditEvent.EntityAuditAction.ENTITY_CREATE, "d1", new Referenceable(rand()));
    eventRepository.putEventsV1(event);
    List<EntityAuditEvent> events = eventRepository.listEventsV1(event.getEntityId(), null, (short) 10);
    assertEquals(events.size(), 1);
    assertEventEquals(events.get(0), event);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 5 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class AuditRepositoryTestBase method testListPagination.

@Test
public void testListPagination() throws Exception {
    String id1 = "id1" + rand();
    String id2 = "id2" + rand();
    String id3 = "id3" + rand();
    long ts = System.currentTimeMillis();
    Referenceable entity = new Referenceable(rand());
    List<EntityAuditEvent> expectedEvents = new ArrayList<>(3);
    for (int i = 0; i < 3; i++) {
        // Add events for both ids
        EntityAuditEvent event = new EntityAuditEvent(id2, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.ENTITY_UPDATE, "details" + i, entity);
        eventRepository.putEventsV1(event);
        expectedEvents.add(event);
        eventRepository.putEventsV1(new EntityAuditEvent(id1, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.TAG_DELETE, "details" + i, entity));
        eventRepository.putEventsV1(new EntityAuditEvent(id3, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.TAG_ADD, "details" + i, entity));
    }
    // Use ts for which there is no event - ts + 2
    List<EntityAuditEvent> events = eventRepository.listEventsV1(id2, null, (short) 3);
    assertEquals(events.size(), 3);
    assertEventEquals(events.get(0), expectedEvents.get(0));
    assertEventEquals(events.get(1), expectedEvents.get(1));
    assertEventEquals(events.get(2), expectedEvents.get(2));
    // Use last event's timestamp for next list(). Should give only 1 event and shouldn't include events from other id
    events = eventRepository.listEventsV1(id2, events.get(2).getEventKey(), (short) 3);
    assertEquals(events.size(), 1);
    assertEventEquals(events.get(0), expectedEvents.get(2));
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ArrayList(java.util.ArrayList) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)143 Test (org.testng.annotations.Test)64 Id (org.apache.atlas.v1.model.instance.Id)37 Struct (org.apache.atlas.v1.model.instance.Struct)23 ArrayList (java.util.ArrayList)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 HashMap (java.util.HashMap)12 List (java.util.List)10 AtlasException (org.apache.atlas.AtlasException)10 HookNotification (org.apache.atlas.model.notification.HookNotification)10 Map (java.util.Map)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 AtlasServiceException (org.apache.atlas.AtlasServiceException)8 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)8 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)7 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)5