Search in sources :

Example 6 with AtlasBaseException

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

the class AtlasEntityStoreV1 method updateEntity.

@Override
@GraphTransaction
public EntityMutationResponse updateEntity(AtlasObjectId objectId, AtlasEntityWithExtInfo updatedEntityInfo, boolean isPartialUpdate) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> updateEntity({}, {}, {})", objectId, updatedEntityInfo, isPartialUpdate);
    }
    if (objectId == null || updatedEntityInfo == null || updatedEntityInfo.getEntity() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "null entity-id/entity");
    }
    final String guid;
    if (AtlasTypeUtil.isAssignedGuid(objectId.getGuid())) {
        guid = objectId.getGuid();
    } else {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objectId.getTypeName());
        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, objectId.getTypeName());
        }
        guid = AtlasGraphUtilsV1.getGuidByUniqueAttributes(typeRegistry.getEntityTypeByName(objectId.getTypeName()), objectId.getUniqueAttributes());
    }
    AtlasEntity entity = updatedEntityInfo.getEntity();
    entity.setGuid(guid);
    return createOrUpdate(new AtlasEntityStream(updatedEntityInfo), isPartialUpdate, false);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 7 with AtlasBaseException

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

the class AtlasEntityStoreV1 method deleteById.

@Override
@GraphTransaction
public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
    AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
    if (vertex != null) {
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex);
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, entityHeader), "delete entity: guid=", guid);
        deletionCandidates.add(vertex);
    } else {
        if (LOG.isDebugEnabled()) {
            // Entity does not exist - treat as non-error, since the caller
            // wanted to delete the entity and it's already gone.
            LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
        }
    }
    EntityMutationResponse ret = deleteVertices(deletionCandidates);
    // Notify the change listeners
    entityChangeNotifier.onEntitiesMutated(ret, false);
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 8 with AtlasBaseException

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

the class AtlasRelationshipStoreV1 method validateRelationship.

private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, Map<String, Object> attributes) throws AtlasBaseException {
    String end1TypeName = AtlasGraphUtilsV1.getTypeName(end1Vertex);
    String end2TypeName = AtlasGraphUtilsV1.getTypeName(end2Vertex);
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);
    if (relationshipType == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
    }
    boolean validEndTypes = false;
    if (relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName)) {
        validEndTypes = relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName);
    } else if (relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {
        validEndTypes = relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName);
    }
    if (!validEndTypes) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName, relationshipType.getEnd2Type().getTypeName(), end1TypeName);
    }
    List<String> messages = new ArrayList<>();
    AtlasRelationship relationship = new AtlasRelationship(relationshipName, attributes);
    relationshipType.validateValue(relationship, relationshipName, messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages);
    }
    relationshipType.getNormalizedValue(relationship);
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship)

Example 9 with AtlasBaseException

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

the class EntityGraphMapper method mapCollectionElementsToVertex.

private Object mapCollectionElementsToVertex(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    switch(ctx.getAttrType().getTypeCategory()) {
        case PRIMITIVE:
        case ENUM:
        case MAP:
        case ARRAY:
            return ctx.getValue();
        case STRUCT:
            return mapStructValue(ctx, context);
        case OBJECT_ID_TYPE:
            AtlasEntityType instanceType = getInstanceType(ctx.getValue());
            ctx.setElementType(instanceType);
            return mapObjectIdValueUsingRelationship(ctx, context);
        default:
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, ctx.getAttrType().getTypeCategory().name());
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 10 with AtlasBaseException

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

the class EntityGraphMapper method deleteClassifications.

public void deleteClassifications(String entityGuid, List<String> classificationNames) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(classificationNames)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_CLASSIFICATION_PARAMS, "delete", entityGuid);
    }
    AtlasVertex entityVertex = AtlasGraphUtilsV1.findByGuid(entityGuid);
    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, entityGuid);
    }
    List<String> traitNames = getTraitNames(entityVertex);
    if (CollectionUtils.isEmpty(traitNames)) {
        throw new AtlasBaseException(AtlasErrorCode.NO_CLASSIFICATIONS_FOUND_FOR_ENTITY, entityGuid);
    }
    validateClassificationExists(traitNames, classificationNames);
    Map<AtlasVertex, List<String>> removedClassifications = new HashMap<>();
    for (String classificationName : classificationNames) {
        AtlasVertex classificationVertex = getClassificationVertex(entityVertex, classificationName);
        // remove classification from propagated entities if propagation is turned on
        if (isPropagationEnabled(classificationVertex)) {
            List<AtlasVertex> impactedVertices = removeTagPropagation(classificationVertex);
            if (CollectionUtils.isNotEmpty(impactedVertices)) {
                for (AtlasVertex impactedVertex : impactedVertices) {
                    List<String> classifications = removedClassifications.get(impactedVertex);
                    if (classifications == null) {
                        classifications = new ArrayList<>();
                        removedClassifications.put(impactedVertex, classifications);
                    }
                    classifications.add(classificationName);
                }
            }
        }
        // remove classifications from associated entity
        if (LOG.isDebugEnabled()) {
            LOG.debug("Removing classification: [{}] from: [{}][{}] with edge label: [{}]", classificationName, getTypeName(entityVertex), entityGuid, CLASSIFICATION_LABEL);
        }
        AtlasEdge edge = getClassificationEdge(entityVertex, classificationVertex);
        deleteHandler.deleteEdgeReference(edge, CLASSIFICATION, false, true, entityVertex);
        traitNames.remove(classificationName);
    }
    removedClassifications.put(entityVertex, classificationNames);
    updateTraitNamesProperty(entityVertex, traitNames);
    updateModificationMetadata(entityVertex);
    for (Map.Entry<AtlasVertex, List<String>> entry : removedClassifications.entrySet()) {
        String guid = GraphHelper.getGuid(entry.getKey());
        List<String> deletedClassificationNames = entry.getValue();
        AtlasEntityWithExtInfo entityWithExtInfo = instanceConverter.getAndCacheEntity(guid);
        AtlasEntity entity = (entityWithExtInfo != null) ? entityWithExtInfo.getEntity() : null;
        entityChangeNotifier.onClassificationDeletedFromEntity(entity, deletedClassificationNames);
    }
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

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