Search in sources :

Example 1 with EntityChangeListener

use of org.apache.atlas.listener.EntityChangeListener 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 EntityChangeListener

use of org.apache.atlas.listener.EntityChangeListener 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 EntityChangeListener

use of org.apache.atlas.listener.EntityChangeListener 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 EntityChangeListener

use of org.apache.atlas.listener.EntityChangeListener in project incubator-atlas by apache.

the class TestUtils method setupGraphProvider.

/**
 * Triggers the Atlas initialization process using the specified MetadataRepository.
 * This causes the built-in types and their indices to be created.
 */
public static void setupGraphProvider(MetadataRepository repo) throws AtlasException {
    TypeCache typeCache = null;
    try {
        typeCache = AtlasRepositoryConfiguration.getTypeCache().newInstance();
    } catch (Throwable t) {
        typeCache = new DefaultTypeCache();
    }
    final GraphBackedSearchIndexer indexer = new GraphBackedSearchIndexer(new AtlasTypeRegistry());
    Configuration config = ApplicationProperties.get();
    ITypeStore typeStore = new GraphBackedTypeStore(AtlasGraphProvider.getGraphInstance());
    DefaultMetadataService defaultMetadataService = new DefaultMetadataService(repo, typeStore, new HashSet<TypesChangeListener>() {

        {
            add(indexer);
        }
    }, new HashSet<EntityChangeListener>(), TypeSystem.getInstance(), config, typeCache, // Fixme: Can we work with Noop
    new InMemoryEntityAuditRepository());
    // commit the created types
    getGraph().commit();
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasRepositoryConfiguration(org.apache.atlas.util.AtlasRepositoryConfiguration) Configuration(org.apache.commons.configuration.Configuration) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) InMemoryEntityAuditRepository(org.apache.atlas.repository.audit.InMemoryEntityAuditRepository) ITypeStore(org.apache.atlas.repository.typestore.ITypeStore) GraphBackedSearchIndexer(org.apache.atlas.repository.graph.GraphBackedSearchIndexer) TypesChangeListener(org.apache.atlas.listener.TypesChangeListener) GraphBackedTypeStore(org.apache.atlas.repository.typestore.GraphBackedTypeStore) DefaultMetadataService(org.apache.atlas.services.DefaultMetadataService) TypeCache(org.apache.atlas.typesystem.types.cache.TypeCache) DefaultTypeCache(org.apache.atlas.typesystem.types.cache.DefaultTypeCache) DefaultTypeCache(org.apache.atlas.typesystem.types.cache.DefaultTypeCache)

Example 5 with EntityChangeListener

use of org.apache.atlas.listener.EntityChangeListener in project incubator-atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationAddedToEntity.

public void onClassificationAddedToEntity(String entityId, List<AtlasClassification> classifications) throws AtlasBaseException {
    // Only new classifications need to be used for a partial full text string which can be
    // appended to the existing fullText
    updateFullTextMapping(entityId, classifications);
    ITypedReferenceableInstance entity = toITypedReferenceable(entityId);
    List<ITypedStruct> traits = toITypedStructs(classifications);
    if (entity == null || CollectionUtils.isEmpty(traits)) {
        return;
    }
    for (EntityChangeListener listener : entityChangeListeners) {
        try {
            listener.onTraitsAdded(entity, 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) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) AtlasException(org.apache.atlas.AtlasException)

Aggregations

EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)7 AtlasException (org.apache.atlas.AtlasException)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 EntityChangeListenerV2 (org.apache.atlas.listener.EntityChangeListenerV2)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)3 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)2 Struct (org.apache.atlas.v1.model.instance.Struct)2 TypesChangeListener (org.apache.atlas.listener.TypesChangeListener)1 InMemoryEntityAuditRepository (org.apache.atlas.repository.audit.InMemoryEntityAuditRepository)1 GraphBackedSearchIndexer (org.apache.atlas.repository.graph.GraphBackedSearchIndexer)1 GraphBackedTypeStore (org.apache.atlas.repository.typestore.GraphBackedTypeStore)1 ITypeStore (org.apache.atlas.repository.typestore.ITypeStore)1 DefaultMetadataService (org.apache.atlas.services.DefaultMetadataService)1 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)1 DefaultTypeCache (org.apache.atlas.typesystem.types.cache.DefaultTypeCache)1 TypeCache (org.apache.atlas.typesystem.types.cache.TypeCache)1 AtlasRepositoryConfiguration (org.apache.atlas.util.AtlasRepositoryConfiguration)1 Configuration (org.apache.commons.configuration.Configuration)1