Search in sources :

Example 31 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EntityGraphRetriever method mapVertexToRelationshipAttribute.

private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException {
    Object ret = null;
    AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName());
    if (relationshipDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null");
    }
    AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
    AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType());
    AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType());
    AtlasRelationshipEndDef attributeEndDef = null;
    if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) {
        attributeEndDef = endDef1;
    } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) {
        attributeEndDef = endDef2;
    }
    if (attributeEndDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, relationshipDef.toString());
    }
    switch(attributeEndDef.getCardinality()) {
        case SINGLE:
            ret = mapRelatedVertexToObjectId(entityVertex, attribute);
            break;
        case LIST:
        case SET:
            ret = mapRelationshipArrayAttribute(entityVertex, attribute);
            break;
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 32 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException 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 33 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException 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 34 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasEntityChangeNotifier method doFullTextMapping.

private void doFullTextMapping(List<AtlasEntityHeader> entityHeaders) {
    if (CollectionUtils.isEmpty(entityHeaders)) {
        return;
    }
    try {
        if (!AtlasRepositoryConfiguration.isFullTextSearchEnabled()) {
            return;
        }
    } catch (AtlasException e) {
        LOG.warn("Unable to determine if FullText is disabled. Proceeding with FullText mapping");
    }
    for (AtlasEntityHeader entityHeader : entityHeaders) {
        if (GraphHelper.isInternalType(entityHeader.getTypeName())) {
            continue;
        }
        String guid = entityHeader.getGuid();
        AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (vertex == null) {
            continue;
        }
        try {
            String fullText = fullTextMapperV2.getIndexTextForEntity(guid);
            GraphHelper.setProperty(vertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText);
        } catch (AtlasBaseException e) {
            LOG.error("FullText mapping failed for Vertex[ guid = {} ]", guid, e);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasException(org.apache.atlas.AtlasException)

Example 35 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException 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)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 Test (org.testng.annotations.Test)60 ArrayList (java.util.ArrayList)59 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24